[Qgis-developer] Ending edit shapefile in Python plugin

Benoit de Cabissole benoit at exigesa.com
Tue Aug 24 13:24:03 EDT 2010


To whom may be interested,

A workaround to the problem described below is to call:
   self.theLayer.setSelectedFeatures([])
after
   self.iface.mapCanvas().refresh()

This will reset the edit toolbar to the correct state (no edit).

I do not think it is the correct way of doing things but it works!

Cheers,
Benoit

> Sent: Monday, 23 August 2010 22:52
> To: qgis-developer at lists.osgeo.org
> Subject: [Qgis-developer] Ending edit shapefile in Python plugin
>
>
> Hi Developers,
>
> I'm playing with a plugin that allows editing of a shapefile.
> When editing is finished, I want to save (commit) the changes to
> disk, so I
> use:
>
>   if self.theLayer.startEditing():
>
>      #do edits here
>
>      if self.theLayer.commitChanges():
>          #all ok
>          showOKMessage()
>      else:
>          #error
>          showErrorMessage()
>      self.iface.mapCanvas().refresh()
>
> Now, the OK message is displayed and the icon of the vector, in
> the legend,
> is changed from "in edit mode" (little black pen)  to "normal
> mode" (points
> icon in my case). So far so good. BUT, the edit toolbar stays in
> "edit mode"
> and I have to press twice the "toggle edit" button to sync the toolbar and
> the legend.
>
> Question is: is there a way to sync the edit toolbar on successful
> commitChanges()?
>
> I've also tried not to use commitChanges() but instead use
> beginEditCommand/endEditCommand/mapCanvas().refresh() but those leave the
> legend and edit toolbar in "edit mode" and I have to commit the changes
> manually by clicking on the "toggle edit" button.
>
>
> Any hints?
>
> Chers,
> Benoit
>
>
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer



More information about the Qgis-developer mailing list