Replacement for Qt's Undo Framework
aspotashev at gmail.com
Mon Apr 25 19:12:55 BST 2011
The Qt's Undo Framework (QUndoCommand, QUndoStack, QUndoGroup,
QUndoView) has a few oddities:
1. The names of undo actions can only have a predefined prefix
2. You can't use different strings for the name of undo action (Edit
-> Undo/Redo [some action]) and for the items in the undo history
(there is such panel, for example, in Step and Krita). The reason for
having different strings is to make grammatical cases of the names of
actions consistent with the context (in Russian and a few other
languages you should put %1 in accusative case in "Undo %1").
If I'm not mistaken, those problems can't be solved by just deriving
your own classes from QUndo*, because you need to override methods
like createUndoAction which are not "virtual" (sure, you can name
those methods differently, but then other problems may arise).
The solution is to fork QUndo* classes and fix the problems in the new
classes, so did I:
(the code looks like garbage, I only made it working, but didn't try
to clean it up)
At the first glance, the only way to use two strings for every
UndoCommand is to add yet another argument to the constructor of
UndoCommand. But then a huge amount of code would need changes, that's
not very good. Also, most languages don't really need different names
for undo actions and items in undo history.
I kept the arguments of UndoCommand() the same, but now if you put
something like "Create a document|-|creation of a document" as the
"text" into the constructor (or translate it with a similar string
with "|-|"), you'll get "Create a document" as the name of an item in
Undo History panel, and the "Undo ..." menu item will be called "Undo
creation of a document".
http://ompldr.org/vOGYxaQ -- translation in Lokalize (into Russian)
http://ompldr.org/vOGYxag -- Step using different translations for
"Undo ..." command and undo history.
The patch I used for Step is attached.
What do you think about inclusion of KUndo*2 into kdelibs?
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 6910 bytes
Desc: not available
More information about the kde-core-devel