<div>Hi Martin,<br>i try to implement a solution without QTimer patch.<br>Can you tell me if it could be work properly:<br><br>1- layer.undoStack().indexChanged.connect(self.undoStackChanged) -- get the signal from undo stack <br>2-  layer.featureAdded.connect(self.setFeatureId) --get signal of feature added<br>3- def setFeatureId(self,feat_id):<br>       ##get the feature id added<br>        self.feat_id = feat_id<br></div><span> 4-  def undoStackChanged(self,id): ### check the command from undo stack (if it is a add feature command) . If it is a dd feature command run my </span><span><span>added_Feature function (that i bound in my previous code </span>with featureAdded signal) passing the feature id already added<br>        command = self.activeLayer.undoStack().command(id-1)<br>        if command and command.actionText() == 'add feature':<br><br>            self.handlelayerobject.added_Feature(self.feat_id)<br></span><span></span><br>
I checked that feature added event is trigger before addind new command to undo stack. Is it true?<br>Do you think that is is a solution?<br><br><br>Thanks<br><br><br>Francesco<br><br>
<blockquote>
----Messaggio originale----<br>
Da: wonder.sk@gmail.com<br>
Data: 16/03/2015 5.19<br>
A: "francescoboccacci@libero.it"<francescoboccacci@libero.it><br>
Cc: "qgis-dev"<qgis-developer@lists.osgeo.org><br>
Ogg: Re: [Qgis-developer] wrapping changeAttributeValue between begin and end EditCommand<br>
<br>
<div dir="ltr">Hi Francesco<div><br></div><div>Currently it is not safe to do calls that modify vector layer data in slots connected to signals notifying about data change (such as featureAdded). The issue is that at the point when those signals are emitted, their underlying undo commands were not yet pushed onto the stack, so doing further editing calls causes corruption of undo stack (undo command for follow up operation is placed before the first operation).</div><div><br></div><div>As a workaround you could defer the change attribute operations - e.g. with a QTimer. Not an elegant solution though...</div><div><br></div><div>Regards</div><div>Martin</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Mar 15, 2015 at 9:04 PM, <a href="mailto:francescoboccacci@libero.it">francescoboccacci@libero.it</a> <span dir="ltr"><<a href="mailto:francescoboccacci@libero.it" target="_blank">francescoboccacci@libero.it</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div></div><br>
Hi all,<br>i have a problem with beginEditCommand and endEditCommand wrapping.<br>In my plugin i capture the layer.featureAdded signal :<br>self.layer.featureAdded.connect(self.myfunction)<br> The scope of my function is to change attribute of the feature added according with some rules.<br>I wrap self.layer.changeAttributevalue between self.layer.beginEditCommand('My custom value') and self.layer.endEditCommand() but when i added a feature i can't see in Undo/redo window the label My custom value but my value is changed.<br>This cause a Qgis 2.8.2 crash when i try to rollback my changes.<br><br>P.S If i comment my change values function and i write the code in a python console i can see  my beginEditCommand label and no crash happend.<br><br>Anyone can help me?<br><br>Thanks<br><br>Francesco<br>
<br>_______________________________________________<br>
Qgis-developer mailing list<br>
<a href="mailto:Qgis-developer@lists.osgeo.org">Qgis-developer@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/qgis-developer" target="_blank">http://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br></blockquote></div><br></div>
<br>
</blockquote><br>