ROOT logo
ROOT » CORE » BASE » TQUndoManager

class TQUndoManager: public TQCommand

The Command design pattern is based on the idea, that all editing
in an application is done by creating instances of command objects.
Command objects apply changes to the edited object and then are
stored  on a command stack. Furthermore, each command knows how to
undo its changes to bring the edited object back to its previous
state. As long as the application only uses command objects to
change the state of the edited object, it is possible to undo
a sequence of commands by traversing the command stack downwards and
calling the "undo" method of each command in turn. It is also
possible to redo a sequence of commands by traversing the command
stack upwards and calling the "redo" method of each command.


1. Create a new command

TQCommand *com = new TQCommand("TH1", hpx, "SetFillColor(Color_t)"

1st parameter - the name of class
2nd parameter - object
3rd parameter - the name of do/redo method
4th parameter - the name of undo method

Since redo,undo methods are the same, undo name can be omitted, e.g.

TQCommand *com = new TQCommand("TH1", hpx, "SetFillColor(Color_t)");

For objects derived from TObject class name can be omitted, e.g.

TQCommand *com = new TQCommand(hpx, "SetFillColor(Color_t)");

2. Setting undo, redo parameters.

Color_t old_color = hpx->GetFillColor();
Color_t new_color = 4;  // blue color

com->SetRedoArgs(1, new_color);
com->SetUndoArgs(1, old_color);

1st argument - the number of undo, redo parameters
the other arguments - undo, redo values

Since the number of undo,redo parameters is the same one can use

com->SetArgs(1, new_color, old_color);

3. Undo, redo method execution

com->Redo(); // execute redo method
com->Undo(); // execute undo method

4. Merged commands

It possible to group several commands together so an end user
can undo and redo them with one command.

TQCommand *update = new TQCommand(gPad, "Modified()");

5. Macro commands

"Merging" allows to create macro commands, e.g.

TQCommand *macro = new TQCommand("my macro");

During Redo operation commands composing macro command are executed
sequentially in direct  order (first in first out). During Undo,
they are executed in reverse order (last in first out).

6. Undo manager.

TQUndoManager is recorder of undo and redo operations. This is
command history list which can be traversed backwards and upwards
performing undo and redo operations.
To register command TQUndoManager::Add(TObject*) method is used.

TQUndoManager *history = new TQUndoManager();

TQUndoManager::Add automatically invokes execution of command's
Redo method.

Use TQUndoManager::Undo to undo commands in  history list.
 Redo is Undo for undo action. Use TQUndoManager::Redo method for that

Function Members (Methods)

voidTObject::AbstractMethod(const char* method) const
virtual voidAdd(TObject* obj)
virtual voidAdd(TObject* obj, Option_t* opt)
virtual voidTList::AddAfter(const TObject* after, TObject* obj)
virtual voidTList::AddAfter(TObjLink* after, TObject* obj)
virtual voidTCollection::AddAll(const TCollection* col)
virtual voidTList::AddAt(TObject* obj, Int_t idx)
virtual voidTList::AddBefore(const TObject* before, TObject* obj)
virtual voidTList::AddBefore(TObjLink* before, TObject* obj)
virtual voidTList::AddFirst(TObject* obj)
virtual voidTList::AddFirst(TObject* obj, Option_t* opt)
virtual voidTList::AddLast(TObject* obj)
virtual voidTList::AddLast(TObject* obj, Option_t* opt)
voidTCollection::AddVector(TObject* obj1)
virtual TObject*TList::After(const TObject* obj) const
virtual voidTObject::AppendPad(Option_t* option = "")
static Bool_tTQObject::AreAllSignalsBlocked()
Bool_tTQObject::AreSignalsBlocked() const
Bool_tTCollection::AssertClass(TClass* cl) const
virtual TObject*TList::At(Int_t idx) const
virtual TObject*TList::Before(const TObject* obj) const
static Bool_tTQObject::BlockAllSignals(Bool_t b)
Bool_tTQObject::BlockSignals(Bool_t b)
virtual voidTCollection::Browse(TBrowser* b)
virtual Bool_tTQCommand::CanCompress(TQCommand* c) const
virtual Bool_tTQCommand::CanMerge(TQCommand* c) const
virtual Bool_tCanRedo() const
virtual Bool_tCanUndo() const
Int_tTCollection::Capacity() const
virtual voidTQObject::ChangedBy(const char* method)SIGNAL
static TClass*Class()
virtual const char*TObject::ClassName() const
virtual voidTList::Clear(Option_t* option = "")
virtual TObject*TCollection::Clone(const char* newname = "") const
voidTQObject::CollectClassSignalLists(TList& list, TClass* cls)
virtual Int_tTCollection::Compare(const TObject* obj) const
virtual voidTQCommand::Compress(TQCommand* c)
Bool_tTQObject::Connect(const char* signal, const char* receiver_class, void* receiver, const char* slot)
static Bool_tTQObject::Connect(TQObject* sender, const char* signal, const char* receiver_class, void* receiver, const char* slot)
static Bool_tTQObject::Connect(const char* sender_class, const char* signal, const char* receiver_class, void* receiver, const char* slot)
virtual voidTQObject::Connected(const char*)
Bool_tTCollection::Contains(const char* name) const
Bool_tTCollection::Contains(const TObject* obj) const
virtual voidTObject::Copy(TObject& object) const
virtual voidCurrentChanged(TQCommand* c)SIGNAL
virtual voidTQCommand::Delete(Option_t* option = "")
virtual voidTQObject::Destroyed()SIGNAL
Bool_tTQObject::Disconnect(const char* signal = 0, void* receiver = 0, const char* slot = 0)
static Bool_tTQObject::Disconnect(TQObject* sender, const char* signal = 0, void* receiver = 0, const char* slot = 0)
static Bool_tTQObject::Disconnect(const char* class_name, const char* signal, void* receiver = 0, const char* slot = 0)
virtual voidTQObject::Disconnected(const char*)
virtual Int_tTObject::DistancetoPrimitive(Int_t px, Int_t py)
virtual voidTCollection::Draw(Option_t* option = "")
virtual voidTObject::DrawClass() constMENU
virtual TObject*TObject::DrawClone(Option_t* option = "") constMENU
virtual voidTCollection::Dump() const
voidTQObject::Emit(const char* signal)
voidTQObject::Emit(const char* signal, Long_t* paramArr)
voidTQObject::Emit(const char* signal, const char* params)
voidTQObject::Emit(const char* signal, Double_t param)
voidTQObject::Emit(const char* signal, Long_t param)
voidTQObject::Emit(const char* signal, Long64_t param)
voidTQObject::Emit(const char* signal, Bool_t param)
voidTQObject::Emit(const char* signal, Char_t param)
voidTQObject::Emit(const char* signal, UChar_t param)
voidTQObject::Emit(const char* signal, Short_t param)
voidTQObject::Emit(const char* signal, UShort_t param)
voidTQObject::Emit(const char* signal, Int_t param)
voidTQObject::Emit(const char* signal, UInt_t param)
voidTQObject::Emit(const char* signal, ULong_t param)
voidTQObject::Emit(const char* signal, ULong64_t param)
voidTQObject::Emit(const char* signal, Float_t param)
voidTQObject::EmitVA(const char* signal, Int_t nargs)
voidTQObject::EmitVA(const char* signal, Int_t nargs, va_list va)
static voidTCollection::EmptyGarbageCollection()
virtual voidTObject::Error(const char* method, const char* msgfmt) const
virtual voidTObject::Execute(const char* method, const char* params, Int_t* error = 0)
virtual voidTObject::Execute(TMethod* method, TObjArray* params, Int_t* error = 0)
virtual voidTObject::ExecuteEvent(Int_t event, Int_t px, Int_t py)
virtual voidTObject::Fatal(const char* method, const char* msgfmt) const
virtual TObject*TList::FindObject(const char* name) const
virtual TObject*TList::FindObject(const TObject* obj) const
virtual TObject*TList::First() const
virtual TObjLink*TList::FirstLink() const
static voidTCollection::GarbageCollect(TObject* obj)
static TQCommand*TQCommand::GetCommand()
TQCommand*GetCurrent() const
static TCollection*TCollection::GetCurrentCollection()
TQCommand*GetCursor() const
virtual Option_t*TObject::GetDrawOption() const
static Long_tTObject::GetDtorOnly()
virtual Int_tTCollection::GetEntries() const
virtual const char*TObject::GetIconName() const
virtual Int_tTSeqCollection::GetLast() const
UInt_tGetLimit() const
TList*TQObject::GetListOfClassSignals() const
TList*TQObject::GetListOfConnections() const
TList*TQObject::GetListOfSignals() const
virtual const char*TQCommand::GetName() const
Int_tTQCommand::GetNRargs() const
Int_tTQCommand::GetNUargs() const
void*TQCommand::GetObject() const
virtual char*TObject::GetObjectInfo(Int_t px, Int_t py) const
virtual TObject**TList::GetObjectRef(const TObject* obj) const
static Bool_tTObject::GetObjectStat()
virtual Option_t*TObject::GetOption() const
TQConnection*TQCommand::GetRedo() const
Long_t*TQCommand::GetRedoArgs() const
const char*TQCommand::GetRedoName() const
virtual Int_tTCollection::GetSize() const
Int_tTQCommand::GetStatus() const
virtual const char*TQCommand::GetTitle() const
TQConnection*TQCommand::GetUndo() const
Long_t*TQCommand::GetUndoArgs() const
const char*TQCommand::GetUndoName() const
virtual UInt_tTObject::GetUniqueID() const
virtual Int_tTCollection::GrowBy(Int_t delta) const
virtual Bool_tTObject::HandleTimer(TTimer* timer)
virtual Bool_tTQObject::HasConnection(const char* signal_name) const
virtual ULong_tTCollection::Hash() const
virtual voidTQObject::HighPriority(const char* signal_name, const char* slot_name = 0)
virtual Int_tTSeqCollection::IndexOf(const TObject* obj) const
virtual voidTObject::Info(const char* method, const char* msgfmt) const
virtual Bool_tTObject::InheritsFrom(const char* classname) const
virtual Bool_tTObject::InheritsFrom(const TClass* cl) const
virtual voidTObject::Inspect() constMENU
voidTObject::InvertBit(UInt_t f)
virtual TClass*IsA() const
Bool_tTCollection::IsArgNull(const char* where, const TObject* obj) const
virtual Bool_tTCollection::IsEmpty() const
virtual Bool_tTQCommand::IsEqual(const TObject* obj) const
Bool_tTQCommand::IsExecuting() const
virtual Bool_tTCollection::IsFolder() const
Bool_tIsLogging() const
Bool_tTQCommand::IsMacro() const
Bool_tTObject::IsOnHeap() const
Bool_tTCollection::IsOwner() const
Bool_tTQCommand::IsRedoing() const
virtual Bool_tTQCommand::IsSetter() const
virtual Bool_tTCollection::IsSortable() const
virtual Bool_tTSeqCollection::IsSorted() const
Bool_tTQCommand::IsUndoing() const
Bool_tTObject::IsZombie() const
virtual TObject*TList::Last() const
Int_tTSeqCollection::LastIndex() const
virtual TObjLink*TList::LastLink() const
static voidTQObject::LoadRQ_OBJECT()
virtual voidTQObject::LowPriority(const char* signal_name, const char* slot_name = 0)
virtual voidls(Option_t* option = "") const
virtual TIterator*TList::MakeIterator(Bool_t dir = kIterForward) const
virtual TIterator*TCollection::MakeReverseIterator() const
voidTObject::MayNotUse(const char* method) const
virtual voidTQCommand::Merge(TQCommand* c)
virtual Long64_tTQCommand::Merge(TCollection*, TFileMergeInfo*)
virtual voidTQObject::Message(const char* msg)SIGNAL
virtual Bool_tTObject::Notify()
virtual Int_tTQObject::NumberOfConnections() const
virtual Int_tTQObject::NumberOfSignals() const
static Int_tTSeqCollection::ObjCompare(TObject* a, TObject* b)
voidTObject::Obsolete(const char* method, const char* asOfVers, const char* removedFromVers) const
static voidTObject::operator delete(void* ptr)
static voidTObject::operator delete(void* ptr, void* vp)
static voidTObject::operator delete[](void* ptr)
static voidTObject::operator delete[](void* ptr, void* vp)
void*TObject::operator new(size_t sz)
void*TObject::operator new(size_t sz, void* vp)
void*TObject::operator new[](size_t sz)
void*TObject::operator new[](size_t sz, void* vp)
TObject*TCollection::operator()(const char* name) const
TObject&TObject::operator=(const TObject& rhs)
virtual voidTCollection::Paint(Option_t* option = "")
virtual voidTObject::Pop()
virtual voidTCollection::Print(Option_t* option = "") const
virtual voidTCollection::Print(Option_t* option, Int_t recurse) const
virtual voidTCollection::Print(Option_t* option, const char* wildcard, Int_t recurse = 1) const
virtual voidTCollection::Print(Option_t* option, TPRegexp& regexp, Int_t recurse = 1) const
static voidTSeqCollection::QSort(TObject** a, Int_t first, Int_t last)
static voidTSeqCollection::QSort(TObject** a, TObject** b, Int_t first, Int_t last)
static voidTSeqCollection::QSort(TObject** a, Int_t nBs, TObject*** b, Int_t first, Int_t last)
virtual Int_tTObject::Read(const char* name)
virtual voidTList::RecursiveRemove(TObject* obj)
virtual voidRedo(Option_t* option = "")
virtual TObject*TList::Remove(TObject* obj)
virtual TObject*TList::Remove(TObjLink* lnk)
virtual voidTSeqCollection::RemoveAfter(TObject* after)
virtual voidTCollection::RemoveAll(TCollection* col)
virtual TObject*TSeqCollection::RemoveAt(Int_t idx)
virtual voidTSeqCollection::RemoveBefore(TObject* before)
virtual voidTSeqCollection::RemoveFirst()
virtual voidTList::RemoveLast()
voidTObject::ResetBit(UInt_t f)
virtual voidTObject::SaveAs(const char* filename = "", Option_t* option = "") constMENU
virtual voidTObject::SavePrimitive(ostream& out, Option_t* option = "")
virtual voidTQCommand::SetArgs(Int_t nargs)
voidTObject::SetBit(UInt_t f)
voidTObject::SetBit(UInt_t f, Bool_t set)
virtual voidTObject::SetDrawOption(Option_t* option = "")MENU
static voidTObject::SetDtorOnly(void* obj)
virtual voidSetLimit(UInt_t limit)
virtual voidSetLogging(Bool_t on = kTRUE)
virtual voidTQCommand::SetName(const char* name)
static voidTObject::SetObjectStat(Bool_t stat)
virtual voidTCollection::SetOwner(Bool_t enable = kTRUE)
virtual voidTQCommand::SetRedoArgs(Int_t nargs)
virtual voidTQCommand::SetTitle(const char* title)
virtual voidTQCommand::SetUndoArgs(Int_t nargs)
virtual voidTObject::SetUniqueID(UInt_t uid)
virtual voidShowMembers(TMemberInspector& insp)
virtual voidTList::Sort(Bool_t order = kSortAscending)
static voidTCollection::StartGarbageCollection()
virtual voidStreamer(TBuffer& b)
voidStreamerNVirtual(TBuffer& b)
virtual voidTObject::SysError(const char* method, const char* msgfmt) const
Bool_tTObject::TestBit(UInt_t f) const
Int_tTObject::TestBits(UInt_t f) const
virtual voidUndo(Option_t* option = "")
virtual voidTObject::UseCurrentStyle()
virtual voidTObject::Warning(const char* method, const char* msgfmt) const
virtual Int_tTCollection::Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0)
virtual Int_tTCollection::Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0) const
virtual voidTSeqCollection::Changed()
static Int_tTQObject::CheckConnectArgs(TQObject* sender, TClass* sender_class, const char* signal, TClass* receiver_class, const char* slot)
static Bool_tTQObject::ConnectToClass(TQObject* sender, const char* signal, TClass* receiver_class, void* receiver, const char* slot)
static Bool_tTQObject::ConnectToClass(const char* sender_class, const char* signal, TClass* receiver_class, void* receiver, const char* slot)
virtual voidTList::DeleteLink(TObjLink* lnk)
virtual voidTObject::DoError(int level, const char* location, const char* fmt, va_list va) const
TObjLink**TList::DoSort(TObjLink** head, Int_t n)
TObjLink*TList::FindLink(const TObject* obj, Int_t& idx) const
virtual const char*TCollection::GetCollectionEntryName(TObject* entry) const
virtual void*TQObject::GetSender()
virtual const char*TQObject::GetSenderClassName() const
virtual voidTQCommand::Init(const char* cl, void* object, const char* redo, const char* undo)
TObjLink*TList::LinkAt(Int_t idx) const
Bool_tTList::LnkCompare(TObjLink* l1, TObjLink* l2)
virtual TObjLink*TList::NewLink(TObject* obj, TObjLink* prev = NULL)
virtual TObjLink*TList::NewOptLink(TObject* obj, Option_t* opt, TObjLink* prev = NULL)
virtual voidPrintCollectionEntry(TObject* entry, Option_t* option, Int_t recurse) const
virtual voidTQCommand::PrintCollectionHeader(Option_t* option) const

Data Members

Bool_tTList::fAscending! sorting order (when calling Sort() or for TSortedList)
TObjLink*TList::fCache! cache to speedup sequential calling of Before() and After() functions
TQCommand*fCurrentthe latest executed command
TObjLink*fCursorcurrent position in history stack
TObjLink*TList::fFirst! pointer to first entry in linked list
TObjLink*TList::fLast! pointer to last entry in linked list
UInt_tfLimitmaximum number of commands can be located in stack
TList*TQObject::fListOfConnections! list of connections to this object
TList*TQObject::fListOfSignals! list of signals from this object
TList*fLogBooklisting of all actions during execution
Bool_tfLoggingkTRUE if logging is ON
Int_tTQCommand::fNRargsnumber of redo arguments
Int_tTQCommand::fNUargsnumber of undo arguments
TStringTQCommand::fNamecommand name. Default is "ClassName::RedoName(args)"
TStringTCollection::fNamename of the collection
Bool_tTQCommand::fNewDeletekTRUE if Redo/Undo methods are new/delete
void*TQCommand::fObjectobject to which undo/redo actions applied
TQConnection*TQCommand::fRedodo/redo action
Long_t*TQCommand::fRedoArgsredo values
Bool_tTQObject::fSignalsBlocked! flag used for suppression of signals
Int_tTCollection::fSizenumber of elements in collection
Bool_tTSeqCollection::fSortedtrue if collection has been sorted
Int_tTQCommand::fState-1 undoing on, 1 redoing on, 0 nothing in progress
Int_tTQCommand::fStatusfStatus++ after Redo(), fStatus-- after Undo()
TStringTQCommand::fTitlecommand description
TQConnection*TQCommand::fUndoundo action
Long_t*TQCommand::fUndoArgsundo values
static Bool_tTQObject::fgAllSignalsBlockedflag used for suppression of all signals

Class Charts

Inheritance Inherited Members Includes Libraries
Class Charts

Function documentation

void ls(Option_t* option = "") const
 Lists all commands in stack
void PrintCollectionEntry(TObject* entry, Option_t* option, Int_t recurse) const
 Print collection entry.
void SetLogging(Bool_t on = kTRUE)
 Start logging. Delete all previous log records
 Note: logging is not implemented yet
void Add(TObject* obj, Option_t* opt)
 Add command to the stack of commands.
 Command's redo action will be executed.

 option string can contain the following substrings:
    "merge" - input command will be merged
    "compress" - input command will be compressed
void CurrentChanged(TQCommand* c)
 emit signal
void Undo(Option_t* option = "")
 Performs undo action. Move cursor position backward in history stack
void Redo(Option_t* option = "")
 Performs redo action. Move cursor position forward in history stack
Bool_t CanRedo() const
 Returns kTRUE if redo action is possible
Bool_t CanUndo() const
 Returns kTRUE if undo action is possible
Bool_t IsLogging() const
 Returns kTRUE if logging is ON
TQCommand * GetCurrent() const
 Returns the last executed command
TQCommand * GetCursor() const
 Returns a command correspondent to the current cursor position in stack
void SetLimit(UInt_t limit)
 Returns a maximum number of commands which could be located in stack
UInt_t GetLimit() const
 Returns a maximum number of commands which  could be located in stack
void Add(TObject* obj, Option_t* opt)