summaryrefslogtreecommitdiffstats
path: root/kpovmodeler/pmcommandmanager.h
blob: 7f2cbdf22a259df28378e30b0b1aaf180ee1aaec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
**************************************************************************
                                 description
                             --------------------
    copyright            : (C) 2000-2001 by Andreas Zehender
    email                : zehender@kde.org
**************************************************************************

**************************************************************************
*                                                                        *
*  This program is free software; you can redistribute it and/or modify  *
*  it under the terms of the GNU General Public License as published by  *
*  the Free Software Foundation; either version 2 of the License, or     *
*  (at your option) any later version.                                   *
*                                                                        *
**************************************************************************/


#ifndef PMCOMMANDMANAGER_H
#define PMCOMMANDMANAGER_H

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "pmcommand.h"
#include <tqptrstack.h>
#include <tqobject.h>

class PMPart;

/**
 * Manager for PMCommand objects.
 *
 * The class PMCommandManager stores stacks of commands for undo/redo
 * operations.
 */
class PMCommandManager : public TQObject
{
   TQ_OBJECT
  
public:
   /**
    * Creates a new PMCommandManager
    */
   PMCommandManager( PMPart* thepart );
   /**
    * Deletes the command manager. All commands are deleted as well.
    */
   ~PMCommandManager( );
   /**
    * Adds the @ref PMCommand to the command stack.
    * All commands in the m_redoCommands stack are deleted.
    */
   void execute( PMCommand* cmd );
   /**
    * Moves the last command to the m_redoCommands stack.
    */
   void undo( );
   /**
    * Moves the last redo command to the command stack.
    */
   void redo( );
   /**
    * Deletes the commands
    */
   void clear( );
   /**
    * Returns the maximal number of items that can be undone/redone.
    */
   unsigned int maxUndoRedo( ) const { return m_maxUndoRedo; }
   /**
    * Sets the maximal number of items that can be undone/redone.
    */
   void setMaxUndoRedo( unsigned int n ) { m_maxUndoRedo = n; }
   /**
    * Called by an executed command. Will emit objectChanged( )
    */
   void cmdObjectChanged( PMObject* obj, const int mode );
   /**
    * Called by an executed command. Will emit idChanged( )
    */
   void cmdIDChanged( PMObject* obj, const TQString& oldID );
   /**
    * Returns a pointer to the part. For commands that need to access the
    * part directly.
    */
   PMPart* part( ) const { return m_pPart; }
signals:
   /**
    * emmited, when the undo and redo command texts change
    */
   void updateUndoRedo( const TQString& undo, const TQString& redo );
   /**
    * Signal that is emitted when an object is changed.
    * Mode is a bit combination of @ref PMChange constants.
    */
   void objectChanged( PMObject* obj, const int mode, TQObject* sender );
   /**
    * Signal that is emitted when the id of the object is changed
    */
   void idChanged( PMObject* obj, const TQString& oldID );
private:
   /**
    * The executed commands.
    */
   PMCommandList m_commands;
   /**
    * The undone commands.
    */
   PMCommandList m_redoCommands;
   // the maximal number of items that can be undone/redone.
   unsigned int m_maxUndoRedo;
   PMObject* m_pLastChangedObject;
   PMPart* m_pPart;
};

#endif