[Qgis-developer] How to stopediting/rollback in a plugin before changing the project-file

Martin Dobias wonder.sk at gmail.com
Fri Dec 5 07:17:45 EST 2008


On Fri, Dec 5, 2008 at 7:49 AM, bjsvwpfe <Michael.Pfeiffer at bd.so.ch> wrote:
>
> Hi everybody,
>
> I'm working on a plugin in which the user is editing a database-layer.
> So I'm loading automatically a project with all the necessary layers.
> The layer to be edited is already switched editable.
> When the user closes the plugin the changes in the edited layer are saved
> automatically.
> You see we are doing everything for our users :-)
> But now my problem. If the user clicks by mistake the "load new Project"
> button and then doesn't save the project (I know this is not very supposable
> :thinking:) I want to rollback the edited layer or save the changes.
> But how to do this? The only possibility I found is to listen on the
> triggered() SIGNAL of the actionNewProject().
>
> QObject.connect(self.iface.actionNewProject(),SIGNAL("triggered(bool)"),self.deleteRubberBand)
>
> # Entfernt das RubberBand
>  def deleteRubberBand(self,rubberLayer="default"):
>    if (rubberLayer == False): # The triggered Signal sents False
>      self.layer.rollBack() #This is the layer I want to save/rollback
>    for value in self.mRubberBand:
>      value.reset()
>
> But when the signal was sent, it is to late, my QgsVectorLayer doesn't exist
> anymore.
> So how can I save/rollback the edited layer before everything is deleted?
> Maybe there is sth like a closeProject Signal respectively what happens when
> the user clicks the discard button in the "save the current project" dialog?

What about using layerWillBeRemoved signal from QgsMapLayerRegistry?

Martin


More information about the Qgis-developer mailing list