[Qgis-developer] Undo/Redo when adding/changing features from Python

Marco Hugentobler marco.hugentobler at sourcepole.ch
Wed Mar 7 04:48:50 EST 2012


Hi Bernhard

Use QgsVectorLayer::beginEditCommand before adding the feature, then 
endEditCommand or destroyEditCommand after.

Regards,
Marco

On 07.03.2012 10:40, bernhard.stroebl at jena.de wrote:
> Dear list,
>
> I am currently doing a Python plugin that adds/changes features in an 
> editable QgsVectorLayer:
>
> <code>
> # case 1 change
> myLayer.changeGeometry(myFid, newGeometry)
> # case 2 add
> if self.iface.openFeatureForm(myLayer, newFeature):
>   myLayer.addFeature(newFeature)
> </code>
>
> The Undo/Redo Window does not list anything to undo in case 1 (change) 
> and only the attributes changed if I accept the featureForm in case 2.
> I would expect "Feature changed" in case 1 and "Feature added" in case 
> 2. If I digitize a feature the feature form pops up as soon I have 
> finished digitizing and accepting it gives me a "Feature added"-undo 
> option.
> I found the QgsUndoCommand class in the docs but get a
> NameError: name 'QgsUndoCommand' is not defined
>
> any help appreciated
>
> Bernhard
>
>
>
> ________ Information from NOD32 ________
> This message was checked by NOD32 Antivirus System for Linux Mail Server.
> http://www.nod32.com
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer


-- 
Dr. Marco Hugentobler
Sourcepole -  Linux&  Open Source Solutions
Churerstrasse 22, CH-8808 Pfäffikon SZ, Switzerland
marco.hugentobler at sourcepole.ch http://www.sourcepole.ch
Technical Advisor QGIS Project Steering Committee



More information about the Qgis-developer mailing list