summaryrefslogtreecommitdiffstats
path: root/kpovmodeler/pmdeletecommand.h
blob: d11cf3484f3ad9af15bcdfb58f40358c772da79a (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
//-*-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 PMDELETECOMMAND_H
#define PMDELETECOMMAND_H

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

#include "pmcommand.h"
#include <tqstring.h>

#include "pmobject.h"

class PMMemento;

/**
 * Class that stores undo information for the @ref PMDeleteCommand
 */
class PMDeleteInfo
{
public:
   /**
    * Creates undo information for the object deletedObject.
    * The object has to have a parent!
    */
   PMDeleteInfo( PMObject* deletedObject )
   {
      m_pDeletedObject = deletedObject;
      m_pParent = deletedObject->parent( );
      m_pPrevSibling = deletedObject->prevSibling( );
      m_insertError = false;
   }
   /**
    * Deletes the object. The object deletedObject will not be deleted!
    */
   ~PMDeleteInfo( ) { };
   /**
    * Returns a pointer to the deleted object
    */
   PMObject* deletedObject( ) const { return m_pDeletedObject; }
   /**
    * Returns a pointer to the parent of the deleted object
    */
   PMObject* parent( ) const { return m_pParent; }
   /**
    * Returns the previous sibling of the deleted object
    */
   PMObject* prevSibling( ) const { return m_pPrevSibling; }
   /**
    * Returns true if this object could not be inserted in a move command
    */
   bool insertError( ) const { return m_insertError; }
   /**
    * Sets the insert error flag
    */
   void setInsertError( ) { m_insertError = true; }
private:
   PMObject* m_pDeletedObject;
   PMObject* m_pParent;
   PMObject* m_pPrevSibling;
   bool m_insertError;
};

typedef TQPtrList<PMDeleteInfo> PMDeleteInfoList;
typedef TQPtrListIterator<PMDeleteInfo> PMDeleteInfoListIterator;

/**
 * Command class for removing PMObjects
 */
class PMDeleteCommand : public PMCommand
{
public:
   /**
    * Delete Command that removes the object obj.
    */
   PMDeleteCommand( PMObject* obj );
   /**
    * Command that deletes a list of PMObjects. The list has to be sorted!
    */
   PMDeleteCommand( const PMObjectList& list );
   /**
    * Deletes the command. The deleted object will be deleted, if removed
    */
   virtual ~PMDeleteCommand( );

   /** */
   virtual int errorFlags( PMPart* );

protected:
   /**
    * Executes the command and stores undo information
    */
   virtual void execute( PMCommandManager* theManager );
   /**
    * Undo the command
    */
   virtual void undo( PMCommandManager* theManager );

private:
   PMDeleteInfoList m_infoList;
   bool m_executed, m_firstExecution;
   PMObjectList m_links;
   PMObjectList m_linkedDeclares;
   bool m_linksCreated;
   TQPtrList<PMMemento> m_dataChanges;
};

#endif