ROOT  6.06/09
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 #ifndef ROOT_TList
22 #include "TList.h"
23 #endif
24 
25 #ifndef ROOT_TQObject
26 #include "TQObject.h"
27 #endif
28 
29 class TQCommand : public TList, public TQObject {
30 
31 friend class TQUndoManager;
32 
33 protected:
34  TQConnection *fRedo; // do/redo action
35  TQConnection *fUndo; // undo action
36  Long_t *fRedoArgs; // redo values
37  Long_t *fUndoArgs; // undo values
38  Int_t fNRargs; // number of redo arguments
39  Int_t fNUargs; // number of undo arguments
40  Int_t fState; // -1 undoing on, 1 redoing on, 0 nothing in progress
41  Int_t fStatus; // fStatus++ after Redo(), fStatus-- after Undo()
42  Bool_t fNewDelete; // kTRUE if Redo/Undo methods are new/delete
43  TString fName; // command name. Default is "ClassName::RedoName(args)"
44  TString fTitle; // command description
45  void *fObject; // object to which undo/redo actions applied
46 
47  virtual void Init(const char *cl, void *object,
48  const char *redo, const char *undo);
49  virtual void PrintCollectionHeader(Option_t* option) const;
50 
51 private:
52  TQCommand &operator=(const TQCommand &); // Not yet implemented.
53 
54 public:
55  TQCommand(const char *cl = 0, void *object = 0,
56  const char *redo = 0, const char *undo = 0);
57  TQCommand(TObject *obj, const char *redo = 0, const char *undo = 0);
58  TQCommand(const TQCommand &com);
59  virtual ~TQCommand();
60 
61  virtual void Redo(Option_t *option=""); //*SIGNAL*
62  virtual void Undo(Option_t *option=""); //*SIGNAL*
63  virtual void SetArgs(Int_t nargs, ...);
64  virtual void SetUndoArgs(Int_t nargs, ...);
65  virtual void SetRedoArgs(Int_t nargs, ...);
66  virtual Bool_t CanMerge(TQCommand *c) const;
67  virtual void Merge(TQCommand *c);
69  virtual Bool_t CanCompress(TQCommand *c) const;
70  virtual void Compress(TQCommand *c);
71  virtual Bool_t IsEqual(const TObject* obj) const;
72  virtual Bool_t IsSetter() const;
73  virtual Bool_t CanRedo() const;
74  virtual Bool_t CanUndo() const;
75  const char *GetRedoName() const;
76  const char *GetUndoName() const;
77  TQConnection *GetRedo() const { return fRedo; }
78  TQConnection *GetUndo() const { return fUndo; }
79  Long_t *GetRedoArgs() const;
80  Long_t *GetUndoArgs() const;
81  Int_t GetNRargs() const;
82  Int_t GetNUargs() const;
83  void *GetObject() const;
84  Int_t GetStatus() const;
85  Bool_t IsMacro() const;
86  Bool_t IsUndoing() const;
87  Bool_t IsRedoing() const;
88  Bool_t IsExecuting() const;
89  virtual void SetName(const char *name);
90  virtual void SetTitle(const char *title);
91  virtual void ls(Option_t *option="") const;
92  virtual void Add(TObject *obj, Option_t *opt);
93  virtual void Add(TObject *obj) { Add(obj, 0); }
94  virtual void Delete(Option_t *option="");
95  virtual const char *GetName() const;
96  virtual const char *GetTitle() const;
97 
98  static TQCommand *GetCommand();
99 
100  ClassDef(TQCommand,0) // encapsulates the information for undo/redo a single action.
101 };
102 
103 
104 //////////////////////////////////////////////////////////////////////////
105 class TQUndoManager : public TQCommand {
106 
107 protected:
108  TObjLink *fCursor; // current position in history stack
109  TQCommand *fCurrent; // the latest executed command
110  UInt_t fLimit; // maximum number of commands can be located in stack
111  TList *fLogBook; // listing of all actions during execution
112  Bool_t fLogging; // kTRUE if logging is ON
113 
114  virtual void PrintCollectionEntry(TObject* entry, Option_t* option, Int_t recurse) const;
115 
116 public:
117  TQUndoManager();
118  virtual ~TQUndoManager();
119 
120  virtual void Add(TObject *obj, Option_t *opt);
121  virtual void Add(TObject *obj) { Add(obj, 0); }
122  virtual void Redo(Option_t *option="");
123  virtual void Undo(Option_t *option="");
124  virtual Bool_t CanRedo() const;
125  virtual Bool_t CanUndo() const;
126  virtual void SetLogging(Bool_t on = kTRUE);
127  Bool_t IsLogging() const;
128  TQCommand *GetCurrent() const;
129  TQCommand *GetCursor() const;
130  UInt_t GetLimit() const;
131  virtual void SetLimit(UInt_t limit);
132  virtual void CurrentChanged(TQCommand *c); //*SIGNAL*
133  virtual void ls(Option_t *option="") const;
134 
135  ClassDef(TQUndoManager,0) // recorder of operations for undo and redo
136 };
137 
138 #endif
virtual const char * GetTitle() const
Returns command description.
Definition: TQCommand.cxx:701
virtual void Add(TObject *obj)
Definition: TQCommand.h:121
virtual Bool_t CanRedo() const
Returns kTRUE if redo action is possible.
Definition: TQCommand.cxx:1068
virtual void ls(Option_t *option="") const
Lists all commands in stack.
Definition: TQCommand.cxx:884
virtual void Add(TObject *obj)
Definition: TQCommand.h:93
virtual void SetUndoArgs(Int_t nargs,...)
Set undo parameters.
Definition: TQCommand.cxx:537
virtual void Merge(TQCommand *c)
Add command to the list of merged commands.
Definition: TQCommand.cxx:324
TString fName
Definition: TQCommand.h:43
virtual Bool_t CanUndo() const
Returns kTRUE if Undo action is possible, kFALSE if it's not.
Definition: TQCommand.cxx:575
const char * GetRedoName() const
Returns the name of redo command.
Definition: TQCommand.cxx:719
Int_t fNRargs
Definition: TQCommand.h:38
long long Long64_t
Definition: RtypesCore.h:69
Int_t fNUargs
Definition: TQCommand.h:39
Int_t GetStatus() const
Returns a number of sequential undo or redo operations.
Definition: TQCommand.cxx:775
virtual void SetLogging(Bool_t on=kTRUE)
Start logging.
Definition: TQCommand.cxx:921
virtual void PrintCollectionEntry(TObject *entry, Option_t *option, Int_t recurse) const
Print collection entry.
Definition: TQCommand.cxx:904
Int_t fState
Definition: TQCommand.h:40
virtual Bool_t CanUndo() const
Returns kTRUE if undo action is possible.
Definition: TQCommand.cxx:1082
TQConnection * fUndo
Definition: TQCommand.h:35
const char Option_t
Definition: RtypesCore.h:62
virtual void Add(TObject *obj, Option_t *opt)
Add command to the stack of commands.
Definition: TQCommand.cxx:942
TQCommand * fCurrent
Definition: TQCommand.h:109
Long_t * fUndoArgs
Definition: TQCommand.h:37
const char * GetUndoName() const
Returns the name of undo command.
Definition: TQCommand.cxx:727
virtual void Compress(TQCommand *c)
Compress command.
Definition: TQCommand.cxx:397
virtual void PrintCollectionHeader(Option_t *option) const
Print collection header.
Definition: TQCommand.cxx:847
Bool_t IsMacro() const
Returns kTRUE if neither redo nor undo action specified.
Definition: TQCommand.cxx:783
TList * fLogBook
Definition: TQCommand.h:111
TQUndoManager()
Constructor.
Definition: TQCommand.cxx:860
This is the ROOT implementation of the Qt object communication mechanism (see also http://www...
Definition: TQObject.h:53
virtual void Init(const char *cl, void *object, const char *redo, const char *undo)
Common protected method used in several constructors.
Definition: TQCommand.cxx:117
Long_t * fRedoArgs
Definition: TQCommand.h:36
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual void Undo(Option_t *option="")
Performs undo action. Move cursor position backward in history stack.
Definition: TQCommand.cxx:1004
Long_t * GetRedoArgs() const
Returns a pointer to array of redo arguments.
Definition: TQCommand.cxx:735
Bool_t IsRedoing() const
Redo action is in progress.
Definition: TQCommand.cxx:799
virtual ~TQCommand()
dtor.
Definition: TQCommand.cxx:246
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:435
virtual void Redo(Option_t *option="")
Execute command and then merge commands.
Definition: TQCommand.cxx:583
virtual ~TQUndoManager()
Destructor.
Definition: TQCommand.cxx:872
virtual void Redo(Option_t *option="")
Performs redo action. Move cursor position forward in history stack.
Definition: TQCommand.cxx:1036
virtual void SetArgs(Int_t nargs,...)
Set do/redo and undo parameters.
Definition: TQCommand.cxx:460
#define ClassDef(name, id)
Definition: Rtypes.h:254
void * GetObject() const
Returns an object for which undo redo actions are applied.
Definition: TQCommand.cxx:767
TString fTitle
Definition: TQCommand.h:44
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:309
Bool_t fNewDelete
Definition: TQCommand.h:42
TQCommand(const char *cl=0, void *object=0, const char *redo=0, const char *undo=0)
Constructor.
Definition: TQCommand.cxx:165
TQConnection * fRedo
Definition: TQCommand.h:34
UInt_t fLimit
Definition: TQCommand.h:110
A doubly linked list.
Definition: TList.h:47
virtual Bool_t IsEqual(const TObject *obj) const
Equal comparison.
Definition: TQCommand.cxx:413
UInt_t GetLimit() const
Returns a maximum number of commands which could be located in stack.
Definition: TQCommand.cxx:1128
Long_t * GetUndoArgs() const
Returns a pointer to array of undo arguments.
Definition: TQCommand.cxx:743
TQCommand * GetCursor() const
Returns a command correspondent to the current cursor position in stack.
Definition: TQCommand.cxx:1112
TQConnection class is an internal class, used in the object communication mechanism.
Definition: TQConnection.h:46
Bool_t IsExecuting() const
Returns kTRUE if command execution is in progress.
Definition: TQCommand.cxx:807
virtual void CurrentChanged(TQCommand *c)
emit signal
Definition: TQCommand.cxx:996
Collection abstract base class.
Definition: TCollection.h:48
TQCommand & operator=(const TQCommand &)
unsigned int UInt_t
Definition: RtypesCore.h:42
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:282
Bool_t fLogging
Definition: TQCommand.h:112
TQConnection * GetUndo() const
Definition: TQCommand.h:78
Long64_t entry
virtual void SetTitle(const char *title)
Sets description of the command.
Definition: TQCommand.cxx:823
TQCommand * GetCurrent() const
Returns the last executed command.
Definition: TQCommand.cxx:1104
long Long_t
Definition: RtypesCore.h:50
Int_t GetNUargs() const
Returns a number of undo arguments.
Definition: TQCommand.cxx:759
virtual void SetName(const char *name)
Sets name of the command.
Definition: TQCommand.cxx:815
virtual void Add(TObject *obj, Option_t *opt)
Add command to the list of merged commands.
Definition: TQCommand.cxx:355
#define name(a, b)
Definition: linkTestLib0.cpp:5
virtual void SetRedoArgs(Int_t nargs,...)
Set redo parameters.
Definition: TQCommand.cxx:503
virtual void Undo(Option_t *option="")
Un-execute all merged commands and the command.
Definition: TQCommand.cxx:621
Mother of all ROOT objects.
Definition: TObject.h:58
virtual Bool_t CanRedo() const
Returns kTRUE if Redo action is possible, kFALSE if it's not.
Definition: TQCommand.cxx:566
Recorder of operations for undo and redo.
Definition: TQCommand.h:105
virtual const char * GetName() const
Returns the command name.
Definition: TQCommand.cxx:665
static TQCommand * GetCommand()
Return a command which is doing redo/undo action.
Definition: TQCommand.cxx:273
void * fObject
Definition: TQCommand.h:45
TQConnection * GetRedo() const
Definition: TQCommand.h:77
The Command design pattern is based on the idea, that all editing in an application is done by creati...
Definition: TQCommand.h:29
Bool_t IsUndoing() const
Undo action is in progress.
Definition: TQCommand.cxx:791
Bool_t IsLogging() const
Returns kTRUE if logging is ON.
Definition: TQCommand.cxx:1096
virtual Bool_t CanCompress(TQCommand *c) const
By default, commands can be compressed if they are:
Definition: TQCommand.cxx:382
Int_t GetNRargs() const
Returns a number of redo arguments.
Definition: TQCommand.cxx:751
const Bool_t kTRUE
Definition: Rtypes.h:91
TObject * obj
TObjLink * fCursor
Definition: TQCommand.h:108
virtual void ls(Option_t *option="") const
ls this command and merged commands
Definition: TQCommand.cxx:831
Int_t fStatus
Definition: TQCommand.h:41
virtual void SetLimit(UInt_t limit)
Returns a maximum number of commands which could be located in stack.
Definition: TQCommand.cxx:1120