library: libCore
#include "TQCommand.h"

TQUndoManager


class description - source file - inheritance tree (.pdf)

class TQUndoManager : public TQCommand

Inheritance Chart:
TObject
<-
TCollection
<-
TSeqCollection
<-
TList
TQObject
<-
TQCommand
<-
TQUndoManager

    public:
TQUndoManager() virtual ~TQUndoManager() virtual void Add(TObject* obj, Option_t* opt) virtual void Add(TObject* obj) virtual Bool_t CanRedo() const virtual Bool_t CanUndo() const static TClass* Class() virtual void CurrentChanged(TQCommand* c) TQCommand* GetCurrent() const TQCommand* GetCursor() const UInt_t GetLimit() const virtual TClass* IsA() const Bool_t IsLogging() const virtual void ls(Option_t* option = "") const virtual void Print(Option_t* option = "") const virtual void Print(Option_t*, Option_t* option) const virtual void Redo(Option_t* option = "") virtual void SetLimit(UInt_t limit) virtual void SetLogging(Bool_t on = kTRUE) virtual void ShowMembers(TMemberInspector& insp, char* parent) virtual void Streamer(TBuffer& b) void StreamerNVirtual(TBuffer& b) virtual void Undo(Option_t* option = "")

Data Members


    protected:
TObjLink* fCursor current position in history stack TQCommand* fCurrent the latest executed command UInt_t fLimit maximum number of commands can be located in stack TList* fLogBook listing of all actions during execution Bool_t fLogging kTRUE if logging is ON

Class Description

                                                                      
 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.         
                                                                      
                                                                      
 Examples:                                                            
                                                                      
 1. Create a new command                                              
                                                                      
 TQCommand *com = new TQCommand("TH1", hpx, "SetFillColor(Color_t)"   
                                "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()");            
    com->Add(update);                                                 
                                                                      
 5. Macro commands                                                    
                                                                      
 "Merging" allows to create macro commands, e.g.                      
                                                                      
    TQCommand *macro = new TQCommand("my macro");                     
    macro->Add(com1);                                                 
    macro->Add(com2);                                                 
    ...                                                               
                                                                      
 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();                     
    history->Add(com);                                                
                                                                      
 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
                                                                      


TQUndoManager() : TQCommand(0, 0, 0, 0)
 Constructor

~TQUndoManager()
 Destructor

void ls(Option_t *option) const
 Lists all commands in stack

void Print(Option_t *option) const
 Prints all commands in history stack

void SetLogging(Bool_t on)
 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



Inline Functions


               void Add(TObject* obj)
               void Print(Option_t*, Option_t* option) const
            TClass* Class()
            TClass* IsA() const
               void ShowMembers(TMemberInspector& insp, char* parent)
               void Streamer(TBuffer& b)
               void StreamerNVirtual(TBuffer& b)


Author: Valeriy Onuchin 04/27/2004
Last update: root/base:$Name: $:$Id: TQCommand.cxx,v 1.4 2005/02/11 18:40:08 rdm Exp $
Copyright (C) 1995-2001, Rene Brun and Fons Rademakers. *


ROOT page - Class index - Class Hierarchy - Top of the page

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.