QUndoStack Usage.
-
Hi,
I have a gridLayout with widgets like QCombox and QLineEdit in the cells of the grid.
I need to do undo redo feature on it. I came to know we to use QUndoStack for that.
May i know how to use it. Can any one please help.Thanks
Deepak -
you will need to subclass "QUndoRedoCommand":http://qt-project.org/doc/qt-5.0/qtwidgets/qundocommand.html and implement it's undo() and redo() methods. You must save all values you need to perform undo/redo accordingly to your command.
This means initialize your instance of your undoredocommand object and set the old and new text of an line edit? Then push the instance on the QUndoRedoStack (note redo() will get called automatically on push to the undoredo-stack).
-
Hi,
May i know how to get the old value of QLineEdit. I am using the signal textChanged() whenever there is a textchange. I can get new text but how to get the old text?
Deepak
-
since you create a undo command for every text change you know the text from the last time you saved it for that widget. Best would be to subclass QLineEdit widget, listen to it's own textChanged signal and emit an "custom-signal" with the new and old text from the last emission of the custom-signal.
-
Hi,
May i know is it possible to delete a particular row from a QUndoStack?
Deepak
-
i don't think so... but i also can't think of a use case where you would need to?
-
Hi,
I have a row with 2 combobox and a linedit and a minus Button.The minus button click is supposed to delete that row ( deletes the comboBoxes and the lineEdit ).
1)Suppose i change the value in lineEdit, during this time the UndoStack gets populated. In my undo Command i am passing the pointer of lineEdit for undo , redo operations
2) Suppose i delete the row , and press undo. It will result in segmentation fault because the lineEdit pointer has been deleted. So before deletion of row if i could delete the entry from UndoStack that contains the QUndoCommand for change in lineEdit it could save me.Deepak
-
you should add an undo/redo command also for the deletion.
And don't delete the widgets but just remove them from the layout. -
Hi,
So is it sure that there is no way by which i can delete an entry from the QUndoStack if the index is specified?
-
i don't see a method to do so on QUndoRedoStack class...