[Interest] QTextDocument and Undo

Igor Mironchik igor.mironchik at gmail.com
Fri Jul 1 09:01:14 CEST 2016


Let's say I'm doing vector graphics editor with QGraphicsScene.

I'm adding undo/redo commands to the editor. Everything is done, but...

I have Text item derived from QGraphicsTextItem. QGraphicsTextItem 
implemented with QTextDocument and QTextDocument has its own undo stack. 
Fine! But...

What if I create Text, then change text in it, then make two undo 
commands?! It undo changing text and creation of Text item. Ok. But...

Then I want to redo this two commands. I redo "create", so Text item now 
is created again, then I redo "text change" that implemented with 
QGraphicsTextItem::document()->redo(). But...

But Text item with its QTextDocument was created again so 
QTextDocument's undo stack is empty. I.e. redo() does nothing.

This is my problem.

And I want to ask you guys what would you do in such situation?

Implement your own undo commands for text interactions in Text item? 
It's so much work.

Keep as is, so when Text item was deleted redo will not be able to 
restore state of the item? It's ugly.

Thank you.

More information about the Interest mailing list