Logo ROOT   6.12/07
Reference Guide
TQCommand.h
Go to the documentation of this file.
1 // @(#)root/base:$Id$
2 // Author: Valeriy Onuchin 04/27/2004
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TQCommand
13 #define ROOT_TQCommand
14 
15 //////////////////////////////////////////////////////////////////////////
16 // //
17 // TQCommand, TQUndoManager - support for multiple Undo/Redo operations //
18 // //
19 //////////////////////////////////////////////////////////////////////////
20 
21 #include "TList.h"
22 
23 #include "TQObject.h"
24 
25 class TQConnection;
26 
27 class TQCommand : public TList, public TQObject {
28 
29 friend class TQUndoManager;
30 
31 protected:
32  TQConnection *fRedo; // do/redo action
33  TQConnection *fUndo; // undo action
34  Long_t *fRedoArgs; // redo values
35  Long_t *fUndoArgs; // undo values
36  Int_t fNRargs; // number of redo arguments
37  Int_t fNUargs; // number of undo arguments
38  Int_t fState; // -1 undoing on, 1 redoing on, 0 nothing in progress
39  Int_t fStatus; // fStatus++ after Redo(), fStatus-- after Undo()
40  Bool_t fNewDelete; // kTRUE if Redo/Undo methods are new/delete
41  TString fName; // command name. Default is "ClassName::RedoName(args)"
42  TString fTitle; // command description
43  void *fObject; // object to which undo/redo actions applied
44 
45  virtual void Init(const char *cl, void *object,
46  const char *redo, const char *undo);
47  virtual void PrintCollectionHeader(Option_t* option) const;
48 
49 private:
50  TQCommand &operator=(const TQCommand &); // Not yet implemented.
51 
52 public:
53  TQCommand(const char *cl = 0, void *object = 0,
54  const char *redo = 0, const char *undo = 0);
55  TQCommand(TObject *obj, const char *redo = 0, const char *undo = 0);
56  TQCommand(const TQCommand &com);
57  virtual ~TQCommand();
58 
59  virtual void Redo(Option_t *option=""); //*SIGNAL*
60  virtual void Undo(Option_t *option=""); //*SIGNAL*
61  virtual void SetArgs(Int_t nargs, ...);
62  virtual void SetUndoArgs(Int_t nargs, ...);
63  virtual void SetRedoArgs(Int_t nargs, ...);
64  virtual Bool_t CanMerge(TQCommand *c) const;
65  virtual void Merge(TQCommand *c);
67  virtual Bool_t CanCompress(TQCommand *c) const;
68  virtual void Compress(TQCommand *c);
69  virtual Bool_t IsEqual(const TObject* obj) const;
70  virtual Bool_t IsSetter() const;
71  virtual Bool_t CanRedo() const;
72  virtual Bool_t CanUndo() const;
73  const char *GetRedoName() const;
74  const char *GetUndoName() const;
75  TQConnection *GetRedo() const { return fRedo; }
76  TQConnection *GetUndo() const { return fUndo; }
77  Long_t *GetRedoArgs() const;
78  Long_t *GetUndoArgs() const;
79  Int_t GetNRargs() const;
80  Int_t GetNUargs() const;
81  void *GetObject() const;
82  Int_t GetStatus() const;
83  Bool_t IsMacro() const;
84  Bool_t IsUndoing() const;
85  Bool_t IsRedoing() const;
86  Bool_t IsExecuting() const;
87  virtual void SetName(const char *name);
88  virtual void SetTitle(const char *title);
89  virtual void ls(Option_t *option="") const;
90  virtual void Add(TObject *obj, Option_t *opt);
91  virtual void Add(TObject *obj) { Add(obj, 0); }
92  virtual void Delete(Option_t *option="");
93  virtual const char *GetName() const;
94  virtual const char *GetTitle() const;
95 
96  static TQCommand *GetCommand();
97 
98  ClassDef(TQCommand,0) // encapsulates the information for undo/redo a single action.
99 };
100 
101 
102 //////////////////////////////////////////////////////////////////////////
103 class TQUndoManager : public TQCommand {
104 
105 protected:
106  TObjLink *fCursor; // current position in history stack
107  TQCommand *fCurrent; // the latest executed command
108  UInt_t fLimit; // maximum number of commands can be located in stack
109  TList *fLogBook; // listing of all actions during execution
110  Bool_t fLogging; // kTRUE if logging is ON
111 
112  virtual void PrintCollectionEntry(TObject* entry, Option_t* option, Int_t recurse) const;
113 
114 public:
115  TQUndoManager();
116  virtual ~TQUndoManager();
117 
118  virtual void Add(TObject *obj, Option_t *opt);
119  virtual void Add(TObject *obj) { Add(obj, 0); }
120  virtual void Redo(Option_t *option="");
121  virtual void Undo(Option_t *option="");
122  virtual Bool_t CanRedo() const;
123  virtual Bool_t CanUndo() const;
124  virtual void SetLogging(Bool_t on = kTRUE);
125  Bool_t IsLogging() const;
126  TQCommand *GetCurrent() const;
127  TQCommand *GetCursor() const;
128  UInt_t GetLimit() const;
129  virtual void SetLimit(UInt_t limit);
130  virtual void CurrentChanged(TQCommand *c); //*SIGNAL*
131  virtual void ls(Option_t *option="") const;
132 
133  ClassDef(TQUndoManager,0) // recorder of operations for undo and redo
134 };
135 
136 #endif
virtual void Add(TObject *obj)
Definition: TQCommand.h:119
virtual void Add(TObject *obj)
Definition: TQCommand.h:91
virtual void SetUndoArgs(Int_t nargs,...)
Set undo parameters.
Definition: TQCommand.cxx:543
virtual void Merge(TQCommand *c)
Add command to the list of merged commands.
Definition: TQCommand.cxx:330
TString fName
Definition: TQCommand.h:41
Int_t fNRargs
Definition: TQCommand.h:36
long long Long64_t
Definition: RtypesCore.h:69
Int_t fNUargs
Definition: TQCommand.h:37
Int_t fState
Definition: TQCommand.h:38
Long_t * GetUndoArgs() const
Returns a pointer to array of undo arguments.
Definition: TQCommand.cxx:761
Bool_t IsUndoing() const
Undo action is in progress.
Definition: TQCommand.cxx:809
TQConnection * fUndo
Definition: TQCommand.h:33
const char Option_t
Definition: RtypesCore.h:62
TQCommand * fCurrent
Definition: TQCommand.h:107
Bool_t IsRedoing() const
Redo action is in progress.
Definition: TQCommand.cxx:817
const char * GetUndoName() const
Returns the name of undo command.
Definition: TQCommand.cxx:745
Long_t * fUndoArgs
Definition: TQCommand.h:35
virtual void Compress(TQCommand *c)
Compress command.
Definition: TQCommand.cxx:403
TList * fLogBook
Definition: TQCommand.h:109
This is the ROOT implementation of the Qt object communication mechanism (see also http://www...
Definition: TQObject.h:49
Long_t * GetRedoArgs() const
Returns a pointer to array of redo arguments.
Definition: TQCommand.cxx:753
virtual Bool_t CanMerge(TQCommand *c) const
Two commands can be merged if they can be composed into a single command (Macro command).
Definition: TQCommand.cxx:315
virtual void Init(const char *cl, void *object, const char *redo, const char *undo)
Common protected method used in several constructors.
Definition: TQCommand.cxx:121
Long_t * fRedoArgs
Definition: TQCommand.h:34
TQConnection * GetRedo() const
Definition: TQCommand.h:75
Basic string class.
Definition: TString.h:125
virtual Bool_t IsEqual(const TObject *obj) const
Equal comparison.
Definition: TQCommand.cxx:419
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual Bool_t IsSetter() const
Returns kTRUE is command if Redo is the same as Undo function and is the setter action.
Definition: TQCommand.cxx:441
virtual Bool_t CanRedo() const
Returns kTRUE if Redo action is possible, kFALSE if it's not.
Definition: TQCommand.cxx:572
virtual ~TQCommand()
dtor.
Definition: TQCommand.cxx:250
virtual void Redo(Option_t *option="")
Execute command and then merge commands.
Definition: TQCommand.cxx:589
TQConnection * GetUndo() const
Definition: TQCommand.h:76
Int_t GetNRargs() const
Returns a number of redo arguments.
Definition: TQCommand.cxx:769
Int_t GetNUargs() const
Returns a number of undo arguments.
Definition: TQCommand.cxx:777
virtual void SetArgs(Int_t nargs,...)
Set do/redo and undo parameters.
Definition: TQCommand.cxx:466
#define ClassDef(name, id)
Definition: Rtypes.h:320
TString fTitle
Definition: TQCommand.h:42
virtual void PrintCollectionEntry(TObject *entry, Option_t *option, Int_t recurse) const
Print the collection entry.
Bool_t fNewDelete
Definition: TQCommand.h:40
TQCommand(const char *cl=0, void *object=0, const char *redo=0, const char *undo=0)
Constructor.
Definition: TQCommand.cxx:169
TQConnection * fRedo
Definition: TQCommand.h:32
Bool_t IsExecuting() const
Returns kTRUE if command execution is in progress.
Definition: TQCommand.cxx:825
UInt_t fLimit
Definition: TQCommand.h:108
A doubly linked list.
Definition: TList.h:44
void * GetObject() const
Returns an object for which undo redo actions are applied.
Definition: TQCommand.cxx:785
TQConnection class is an internal class, used in the object communication mechanism.
Definition: TQConnection.h:37
Collection abstract base class.
Definition: TCollection.h:63
TQCommand & operator=(const TQCommand &)
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual Bool_t CanCompress(TQCommand *c) const
By default, commands can be compressed if they are:
Definition: TQCommand.cxx:388
virtual void Delete(Option_t *option="")
If "opt" is not zero delete every merged command which option string is equal to "opt".
Definition: TQCommand.cxx:286
Int_t GetStatus() const
Returns a number of sequential undo or redo operations.
Definition: TQCommand.cxx:793
virtual Bool_t CanUndo() const
Returns kTRUE if Undo action is possible, kFALSE if it's not.
Definition: TQCommand.cxx:581
Bool_t fLogging
Definition: TQCommand.h:110
friend class TQUndoManager
Definition: TQCommand.h:29
virtual void SetTitle(const char *title)
Sets description of the command.
Definition: TQCommand.cxx:841
virtual void ls(Option_t *option="") const
ls this command and merged commands
Definition: TQCommand.cxx:849
long Long_t
Definition: RtypesCore.h:50
Bool_t IsMacro() const
Returns kTRUE if neither redo nor undo action specified.
Definition: TQCommand.cxx:801
virtual void SetName(const char *name)
Sets name of the command.
Definition: TQCommand.cxx:833
virtual void Add(TObject *obj, Option_t *opt)
Add command to the list of merged commands.
Definition: TQCommand.cxx:361
virtual const char * GetTitle() const
Returns command description.
Definition: TQCommand.cxx:714
virtual void SetRedoArgs(Int_t nargs,...)
Set redo parameters.
Definition: TQCommand.cxx:509
virtual void Undo(Option_t *option="")
Un-execute all merged commands and the command.
Definition: TQCommand.cxx:627
Mother of all ROOT objects.
Definition: TObject.h:37
Recorder of operations for undo and redo.
Definition: TQCommand.h:103
static TQCommand * GetCommand()
Return a command which is doing redo/undo action.
Definition: TQCommand.cxx:277
void * fObject
Definition: TQCommand.h:43
virtual const char * GetName() const
Returns the command name.
Definition: TQCommand.cxx:671
The Command design pattern is based on the idea, that all editing in an application is done by creati...
Definition: TQCommand.h:27
const char * GetRedoName() const
Returns the name of redo command.
Definition: TQCommand.cxx:737
TObjLink * fCursor
Definition: TQCommand.h:106
const Bool_t kTRUE
Definition: RtypesCore.h:87
virtual void PrintCollectionHeader(Option_t *option) const
Print collection header.
Definition: TQCommand.cxx:865
Int_t fStatus
Definition: TQCommand.h:39
char name[80]
Definition: TGX11.cxx:109