Understanding Qt’s QUndoStack: clean and clear

“Clean” and “clear” are separate but related classes of states.

The clean state has getter isClean() and setter setClean().

The clear state has getter: count() <= 0, and setter clear().  (The getter method is not defined by Qt, but let’s name it “isClear”.)

“isClean” does not imply “isClear”.  A clean undo stack may still have commands that can be redone/undone.

“isClear” implies “isClean.”  A clear undo stack does not have any commands on it.

Typically, when you save a document (or open an existing one), you call clear().  At that point, your app behaves just as if the user newly opened the document: there is nothing to undo or redo.

Subsequently, if the user does something, but undoes it, the document is “clean”.  That is, in the same condition as is saved.  Typically, an app shows the unclean state in the title bar, for example by an asterisk in front of the document name.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s