[scribus-dev] UndoState::transactionCode ?!

JLuc jluc at no-log.org
Thu Oct 22 09:25:36 UTC 2015


Le 22/10/2015 08:25, Miss AL-Bahanta a écrit :
> Hi,
> I'm trying to solve an issue that is related to undo/redo in Scribus, So I read through undostate.cpp and stopped at
> these methods TransactionState::undo() and TransactionState::redo(). I did not understand the usage of transactionCode
> which is an integer that is assigned either 0,1,2 or 3.What is the point of this integer and what is meant by assigning
> the above values before calling UndoState::undo() and UndoState::redo() ?!
> Asma

Interesting question.
Regarding transactionCode, here is what i found out.

undstate.h is pretty well documented.
UndoState is the main class and defines TrasactionCode as allways 0.
TransactionState is a subclass that provides a container where multiple UndoStates can be stored.

The states are stored chronologicaly when the action is created : order is meaningfull.

TransactionState::undo() and redo() defines the values for the stored UndoStates
so as to manage selection and display refresh.

For redo, order is the same as action creation order (see undostate.cpp 310)
0 in case there is only one element (AMOF, in sucha a case class could be plain UndoState)
1 when dealing with the first chronologicaly stored UndoState
2 when dealing with the last chronologicaly stored UndoState
3 when dealing with other stored UndoStates

For undo scribus begins with the last chronologicaly created state,
hence, the undoCode values are opposite regarding 1 and 2 (see undostate.cpp 290)
(but the same regarding "only one state" or "intermediate state" actions.

That's because there are special consequences when undoing or redoing the last undostate.

No screen refresh is required for most of the intermediate states,
refresh is only required for the last step, that's when Code == 2
and of course also when there is only one state (Code == 0)
(see pageitem.cpp 5496, 7023, 7059)

A special case is for creating elements :
the last existing object part has to be unselected before its creation is undone
that is before it is deleted. (scpage.cpp 337)


This explanation comes from looking at the source (I'm no core dev).
Hope it helps.

Undo and redo scribus management still features quite a lot of bugs
so its great if you can understand how it works and fix some of them.

JL




More information about the scribus-dev mailing list