summaryrefslogtreecommitdiffstats
path: root/kpovmodeler/pmcommand.h
blob: 9bdca16fa50d14373c8cfaffb6876513fe70b8e2 (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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//-*-C++-*-
/*
**************************************************************************
                                 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 PMCOMMAND_H
#define PMCOMMAND_H

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

#include <qstring.h>
#include <qptrlist.h>

#include "pmmessage.h"
#include "pmerrorflags.h"

class PMCommandManager;
class PMObject;
class PMPart;

/**
 * Constants for object changes
 *
 * PMCAdd: An object was added
 *
 * PMCRemove: An object was removed. A signal with this constant has
 * to be emitted _before_ the object is removed.
 *
 * PMCChildren: Some children are added or removed. Do not use. Use PMCAdd and
 * PMCRemove for all childrens.
 *
 * PMCData: Data (for dialog views) is changed
 *
 * PMCDescription: The name or pixmap of the object has changed. Always
 * together with PMCData.
 *
 * PMCViewStructure: The rendering has changed
 *
 * PMCNewSelection: The object was selected and all other deleselected.
 * If the changed object is 0, all objects are deselected!
 *
 * PMCSelected: The object was selected.
 *
 * PMCDeselected: The object was deselected.
 *
 * PMCNewControlPoints: The list of control points has changed.
 *
 * PMCControlPointSelection: The control point selection has changed.
 *
 * PMCInsertError: The added object couldn't be inserted and was appended
 * to the insert errors. Always together with PMCAdd.
 *
 * PMCNothing: Nothing was changed
 */
enum PMChange
{
   PMCNothing = 0, PMCAdd = 1, PMCRemove = 2, PMCChildren = 4,
   PMCData = 8, PMCDescription = 16, PMCViewStructure = 32,
   PMCGraphicalChange = 64,
   PMCNewSelection = 128, PMCSelected = 256,
   PMCDeselected = 512,
   PMCNewControlPoints = 1024, PMCControlPointSelection = 2048,
   PMCInsertError = 4096
};

/**
 * Base class for all commands, that support undo/redo.
 */
class PMCommand
{
   friend class PMCommandManager; // only PMCommandManager can execute commands
public:
   /**
    * Creates an empty command object.
    */
   PMCommand( ) { }
   /**
    * Creates a command with command text text
    */
   PMCommand( const QString &text )
   { m_text = text; }
   /**
    * Deletes the command.
    */
   virtual ~PMCommand( ) { }

   /**
    * Command text shown in the undo/redo menues
    */
   QString text( ) const { return m_text; }
   /**
    * Sets the command text
    */
   void setText( const QString& s ) { m_text = s; }

   /**
    * Checks if the command is valid and sets the error message
    *
    * Returns a bitwise combination of @ref PMErrorFlags flags
    */
   virtual int errorFlags( PMPart* ) { return PMENone; }
   /**
    * Returns the error message
    */
   PMMessageList messages( ) { return m_errors; }

protected:
   /**
    * Executes the command and stores undo information.
    */
   virtual void execute( PMCommandManager* theManager ) = 0;
   /**
    * Undoes the command
    */
   virtual void undo( PMCommandManager* theManager ) = 0;
   /**
    * The error messages
    */
   PMMessageList m_errors;

private:
   /**
    * The command text.
    */
   QString m_text;
};

typedef QPtrList<PMCommand> PMCommandList;

#endif