Undo framework

Stefan Majewsky majewsky at gmx.net
Sun Apr 26 21:41:27 BST 2009


Hi,

Qt provides a generic Undo/Redo framework, which allows to fill QUndoStacks 
with QUndoCommands and navigate in this stack with undo/redo actions or a 
QUndoView (which is seen in Step for example). On the other side, in Kolf 2, I 
have QObjects which expose all of their variables through QMetaProperties 
(with the Q_PROPERTY macro).

I'm about to combine both parts into a UndoStack implementation for Kolf. As 
this will be done in a very generic way, I would like to ask if anyone's 
interested to get this stuff into kdelibs. The nice thing about what I'm 
planning is that it allows easy persistency through writing the complete 
UndoStack into a KConfigBase instance.

Now let me sketch what I'm planning:
- A KObjectState class contains the values of all properties as well as the 
class name. The KObjectState can be applied to the same object later on to 
restore it to the state which it had at the time when the KObjectState was 
created. When given a factory method, it can use the saved class name to 
reincarnate the object even after it has been deleted, through the use of the 
class name. A similar class is already available at [1].
- A KStatefulObject is wrapped around a QObject and contains a stack of 
KObjectState instances in chronological order.
- The KStatefulObjectGroup contains several KStatefulObjects, and defines the 
chronological order between the KObjectState instances in the 
KStatefulObjects. This class would be a subclass of QUndoStack, and its public 
interface would be something along the lines of:
   void [add|remove]Object([Q|KStateful]Object* object);
   slots: void pushStateOf([Q|KStateful]Object* object);

Such an undo stack could be useful for every application that allows to 
manipulate an arbitrary bunch of objects. The only drawback I'm seeing is that 
reading QMetaProperties is not as fast as direct access to the objects, but 
the given approach could save much development time.

Greetings
Stefan

[1] http://lxr.kde.org/source/playground/games/kolf-ng/engine/objectstate.h
and http://lxr.kde.org/source/playground/games/kolf-ng/engine/objectstate.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20090426/d4c69449/attachment.sig>
-------------- next part --------------
 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<


More information about the kde-core-devel mailing list