Unable to understand Undo Redo Framework in Qt

I am learning how to use Qt to develop my application, and I am developing my application very successfully. Now I want to implement the Undo Redo functionality for my application. doc for this topic a little information. I even tried to understand from two examples in the SDK. But it's hard for me to understand how this works. Can someone please feel free to explain to me how to implement it? There are different states in my application for which I want to provide this functionality. So can there be an explanation from a general point of view? If there are already articles on the Internet explaining the same thing, please let me know. That would be very helpful. Thank.

+5
source share
1 answer

There are 2 main classes: QUndoCommand and QUndoStack ;

  • QUndoCommand is the base class of your command class. You must implement undo () and redo () yourself.
  • QUndoStack is basically a container of QUndoCommand objects, with additional methods such as creating a QAction, requesting undo / redo the text of the current QUndoCommand (simple functions that you can easily implement)

What you need to do:

  • Implement your teams. You need to decide how to implement redo / undo yourself according to your needs. the AppendText class is a good example: http://qt-project.org/doc/qt-5.0/qtwidgets/qundocommand.html
  • Store a QUndoStack instance for each document (or one instance if there is only one document in the application).
  • , "AppendText" "" . "", AppendText QUndoStack:: push (appendCmd). QUndoStack:: push() AppendText:: redo(), .

.

+8

All Articles