class TQCommand: public TList, public TQObject

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)

TQCommand(const TQCommand& com)
TQCommand(TObject* obj, const char* redo = 0, const char* undo = 0)
TQCommand(const char* cl = 0, void* object = 0, const char* redo = 0, const char* undo = 0)
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_tCanCompress(TQCommand* c) const
virtual Bool_tCanMerge(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*TObject::Clone(const char* newname = "") const
voidTQObject::CollectClassSignalLists(TList& list, TClass* cls)
virtual Int_tTCollection::Compare(const TObject* obj) const
virtual voidCompress(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 voidDelete(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*GetCommand()
static TCollection*TCollection::GetCurrentCollection()
virtual Option_t*TObject::GetDrawOption() const
static Long_tTObject::GetDtorOnly()
virtual Int_tTCollection::GetEntries() const
virtual const char*TObject::GetIconName() const
TList*TQObject::GetListOfClassSignals() const
TList*TQObject::GetListOfConnections() const
TList*TQObject::GetListOfSignals() const
virtual const char*GetName() const
Int_tGetNRargs() const
Int_tGetNUargs() const
void*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*GetRedo() const
Long_t*GetRedoArgs() const
const char*GetRedoName() const
virtual Int_tTCollection::GetSize() const
Int_tGetStatus() const
virtual const char*GetTitle() const
TQConnection*GetUndo() const
Long_t*GetUndoArgs() const
const char*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_tIsEqual(const TObject* obj) const
Bool_tIsExecuting() const
virtual Bool_tTCollection::IsFolder() const
Bool_tIsMacro() const
Bool_tTObject::IsOnHeap() const
Bool_tTCollection::IsOwner() const
Bool_tIsRedoing() const
virtual Bool_tIsSetter() const
virtual Bool_tTCollection::IsSortable() const
virtual Bool_tTSeqCollection::IsSorted() const
Bool_tIsUndoing() 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 voidMerge(TQCommand* c)
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)
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)
virtual Int_tTObject::Read(const char* name)
virtual voidTList::RecursiveRemove(TObject* obj)
virtual voidRedo(Option_t* option = "")SIGNAL
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 voidTSeqCollection::RemoveLast()
voidTObject::ResetBit(UInt_t f)
virtual voidTObject::SaveAs(const char* filename = "", Option_t* option = "") constMENU
virtual voidTObject::SavePrimitive(basic_ostream<char,char_traits<char> >& out, Option_t* option = "")
virtual voidSetArgs(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 voidSetName(const char* name)
static voidTObject::SetObjectStat(Bool_t stat)
virtual voidTCollection::SetOwner(Bool_t enable = kTRUE)
virtual voidSetRedoArgs(Int_t nargs)
virtual voidSetTitle(const char* title)
virtual voidSetUndoArgs(Int_t nargs)
virtual voidTObject::SetUniqueID(UInt_t uid)
virtual voidShowMembers(TMemberInspector& insp, char* parent)
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 = "")SIGNAL
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 voidInit(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 voidTCollection::PrintCollectionEntry(TObject* entry, Option_t* option, Int_t recurse) const
virtual voidPrintCollectionHeader(Option_t* option) const

Data Members

enum TCollection::[unnamed] { kIsOwner
enum TObject::EStatusBits { kCanDelete
enum TObject::[unnamed] { kIsOnHeap
Bool_tTList::fAscending! sorting order (when calling Sort() or for TSortedList)
TObjLink*TList::fCache! cache to speedup sequential calling of Before() and After() functions
TObjLink*TList::fFirst! pointer to first entry in linked list
TObjLink*TList::fLast! pointer to last entry in linked list
TList*TQObject::fListOfConnections! list of connections to this object
TList*TQObject::fListOfSignals! list of signals from this object
Int_tfNRargsnumber of redo arguments
Int_tfNUargsnumber of undo arguments
TStringfNamecommand name. Default is "ClassName::RedoName(args)"
TStringTCollection::fNamename of the collection
Bool_tfNewDeletekTRUE if Redo/Undo methods are new/delete
void*fObjectobject to which undo/redo actions applied
TQConnection*fRedodo/redo action
Long_t*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_tfState-1 undoing on, 1 redoing on, 0 nothing in progress
Int_tfStatusfStatus++ after Redo(), fStatus-- after Undo()
TStringfTitlecommand description
TQConnection*fUndoundo action
Long_t*fUndoArgsundo values
static Bool_tTQObject::fgAllSignalsBlockedflag used for suppression of all signals

Class Charts

Inheritance Inherited Members Includes Libraries
Class Charts

Function documentation

void Init(const char* cl, void* object, const char* redo, const char* undo)
 common protected method used in several constructors
TQCommand(const char* cl = 0, void* object = 0, const char* redo = 0, const char* undo = 0)

   Input parameters:
     1. clname - class name.
     2. obj - an object
     3. redo - method or function to do/redo operation
     4. undo - method or function to undo operation

    - if either clname or obj is NULL that means that redo/undo is function
    - to specify default arguments for redo/undo method/function
       '=' must precede to argument value.

    TQCommand("TPad", gPad, "SetEditable(=kTRUE)", "SetEditable(=kFALSE)");

    - undo method can be same as redo one. In that case undo parameter
       can be omitted.

    TQCommand("TPad", gPad, "SetFillStyle(Style_t)");
TQCommand(TObject* obj, const char* redo = 0, const char* undo = 0)

   Input parameters:
     1. obj - an object
     2. redo - method or function to do/redo operation
     3. undo - method or function to undo operation

    - to specify default arguments for redo/undo method/function
       '=' must precede to argument value.

    TQCommand(gPad, "SetEditable(=kTRUE)", "SetEditable(=kFALSE)");

    - undo method can be same as redo one. In that case "undo"
       can parameter be omitted.

    TQCommand(gPad, "SetFillStyle(Style_t)");
TQCommand(const TQCommand& com)
 Copy constructor.
TQCommand * GetCommand()
 Return a command which is doing redo/undo action.

 This static method allows to set undo parameters dynamically, i.e.
 during execution of Redo function.

    For redo actions like TGTextEdit::DelChar() it is not possible to
    know ahead what character will be deleted.
    To set arguments for undo action ( e.g. TGTextEdit::InsChar(char)),
    one needs to call TQCommand::SetUndoArgs(1, character) from
    inside of TGTextEdit::DelChar() method, i.e.

    TQCommand::GetCommand()->SetUndoArgs(1, somechar);
void Delete(Option_t* option = "")
 If "opt" is not zero delete every merged command which option string is
 equal to "opt". If "opt" is zero - delete all merged commands.
Bool_t CanMerge(TQCommand* c) const
 Two commands can be merged if they can be composed into
 a single command (Macro command).

 To allow merging commands user might override this function.
void Merge(TQCommand* c)
 Add command to the list of merged commands.
 This make it possible to group complex actions together so an end user
 can undo and redo them with one command. Execution of TQUndoManager::Undo(),
 TQUndoManager::Redo() methods only invokes the top level command as a whole.

 Merge method is analogous to logical join operation.

 Note:  Merge method invokes redo action.
void Add(TObject* obj, Option_t* opt)
 Add command to the list of merged commands.

 Option string can contain substrings:
  "compress" - try to compress input command
  "radd" - execute redo action of input command
  "uadd" - execute undo action of input command
Bool_t CanCompress(TQCommand* c) const
 By default, commands can be compressed if they are:

  - equal
  - setter commands

 More complicated commands might want to override this function.
void Compress(TQCommand* c)
 Compress command. Compression is analogous to arithmetic "addition operation".

    - The compressed command will be deleted.
    - Execution Compress method invokes Redo action with new redo arguments
      inheritied from compressed command.

 More complicated commands might want to override this function.
Bool_t IsEqual(const TObject* obj) const
 Equal comparison. The commands are equal if they are
 applied to the same object and have the same Redo/Undo actions

 More complicated commands might want to override this function.
Bool_t IsSetter()
 Returns kTRUE is command if Redo is the same as Undo function
 and is the setter action.

 By default, all functions with names like "SetXXX" or "setXXX"
 considered as setters. Another type of setters are Move, Resize operations

 More complicated commands might want to override this function.
void SetArgs(Int_t narg, ...)
 Set do/redo and undo parameters. The format is
    SetArgs(number_of_params, redo_params, undo_params)

     move_command->SetArgs(2, 100, 100, 200, 200);
      2 params, (100,100) - do/redo position, (200,200) - undo position
void SetRedoArgs(Int_t narg, ...)
 Set redo parameters. The format is
    SetRedoArgs(number_of_params, params)

     move_command->SetRedoArgs(2, 100, 100);
void SetUndoArgs(Int_t narg, ...)
 Set undo parameters. The format is
    SetUndoArgs(number_of_params, params)

     move_command->SetUndoArgs(2, 200, 200);
Bool_t CanRedo()
 Returns kTRUE if Redo action is possible, kFALSE if it's not.
 By default, only single sequential redo action is possible.
Bool_t CanUndo()
 Returns kTRUE if Undo action is possible, kFALSE if it's not.
 By default, only single tial undo action is possible.
void Redo(Option_t* option = "")
 Execute command and then smerged commands
void Undo(Option_t* option = "")
 Unexecute all merged commands and the command.
 Merged commands are executed in reverse order.
const char * GetName()
 Returns the command name. Default name is "ClassName::RedoName(args)"
 If list of merged commands is not empty the name is
 "ClassName::RedoName(args):cname1:cname2 ..."
const char * GetTitle()
 Returns command description.
 By default, "ClassName::RedoName(args)_ClassName::UndoName(args)"
const char * GetRedoName()
 Returns the name of redo command
const char * GetUndoName()
 Returns the name of undo command
Long_t * GetRedoArgs()
 Returns a pointer to array of redo arguments
Long_t * GetUndoArgs()
 Returns a pointer to array of undo arguments
Int_t GetNRargs()
 Returns a number of redo arguments
Int_t GetNUargs()
 Returns a number of undo arguments
void * GetObject()
 Returns an object for which undo redo acions are applied
Int_t GetStatus()
 Returns a number of sequential undo or redo operations
Bool_t IsMacro()
 Returns kTRUE if neither redo nor undo action specified
Bool_t IsUndoing()
 Undo action is in progress
Bool_t IsRedoing()
 Redo action is in progress
Bool_t IsExecuting()
 Returns kTRUE if command execution is in progress
void SetName(const char* name)
 Sets name of the command
void SetTitle(const char* title)
 Sets description of the command
void ls(Option_t* option = "") const
 ls this command and merged commands
void PrintCollectionHeader(Option_t* option) const
 Print collection header.
TQConnection * GetRedo()
{ return fRedo; }
TQConnection * GetUndo()
{ return fUndo; }
void Add(TObject* obj, Option_t* opt)

Author: Valeriy Onuchin 04/27/2004
Last change: root/base:$Id: TQCommand.h 25128 2008-08-12 17:59:19Z pcanal $
Last generated: 2008-08-13 08:19
Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *

This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.