In Qt's undo framework, you can have a stack of QUndoCommand
instances. Each of these describes an action in the user interface. In our application, we have a set of views working on a set of models, some in combination, and we often have more than one view working on the same set of models. I'm now looking at the ability to undo actions based on this framework.
Now, I am familiar with the general pattern of having command classes to describe UI actions, but are these supposed to represent a state change in UI elements, or a data change in the underlying model(s)? How much data and state is a command class supposed to contain?
An example to illustrate my point: suppose you have a QStandardItemModel
as base model, and a number of proxy models sitting on top of this. Each proxy model will do a transformation of sorts, such as filtering by occurrence of a certain value. Then if I create a command class to specifically alter one value in one of these proxy models, and the filter conditions change, the state of that command class becomes invalid. So I have to include the state of the filter as well, or a mapping to the ultimate, underlying model. Another option is to add commands for all of the state changes in the UI (the ones causing the filter condition to change, for example) as well, but the downside of this appears to be that the list of commands to undo becomes rather large.
What are the best practices here?