summaryrefslogtreecommitdiffstats
path: root/kpovmodeler/pmcompositeobject.h
blob: c2e2da58bb37bddeeea655d3f43f47d7054c0a9a (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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
//-*-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 PMCOMPOBJECT_H
#define PMCOMPOBJECT_H

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

#include "pmobject.h"

/**
 * Base class for all povray objects that can have child objects.
 *
 * Used pattern: Composite
 */
class PMCompositeObject : public PMObject
{
   typedef PMObject Base;
public:
   /**
    * Creates an empty PMCompositeObject
    */
   PMCompositeObject( PMPart* part );
   /**
    * Copy constructor
    */
   PMCompositeObject( const PMCompositeObject& o );
   /**
    * Deletes the object and all children.
    */
   virtual ~PMCompositeObject( );

   /** */
   virtual PMMetaObject* metaObject( ) const;
   /** */
   virtual void cleanUp( ) const;

   /**
    * Returns a pointer to the first child.
    */
   virtual PMObject* firstChild( ) const { return m_pFirstChild; }
   /**
    * Returns a pointer to the last child.
    */
   virtual PMObject* lastChild( ) const { return m_pLastChild; }
   /**
    * Returns a pointer to the child object at position index,
    * or null if the index is out of range.
    */
   virtual PMObject* childAt( uint index ) const;

   /**
    * Returns true if the object contains the child object o
    */
   virtual bool containsChild( PMObject* o ) const
   { return ( ( PMObject* )this == o->parent( ) ); }
   /**
    * Returns the index of the object or -1 if not found
    */
   virtual int findChild( PMObject* o );

   /**
    * Inserts the object as child at index i.
    * If i is -1, the object is appended.
    * Returns true if successful.
    */
   virtual bool insertChild( PMObject* o, int i );
   /**
    * Inserts the object as child after the child object after
    */
   virtual bool insertChildAfter( PMObject* object, PMObject* after );
   /**
    * Inserts the object as child before the child object before
    */
   virtual bool insertChildBefore( PMObject* object, PMObject* before );
   /**
    * Appends the object as child. Returns true if successful.
    */
   virtual bool appendChild( PMObject* );
   /**
    * Returns the number of children.
    */
   virtual int countChildren( ) const;
   /**
    * Removes a child object. Does not delete it!
    * Returns true if successful.*/
   virtual bool takeChild( PMObject* o );
   /**
    * Removes a child object at index i. Does not delete it!
    */
   virtual bool takeChild( uint i );

   /** */
   virtual void serialize( QDomElement& e, QDomDocument& doc ) const;

   /**
    * Returns the number of selected child items. All selected items in
    * any depth are counted
    */
   virtual int selectedChildren( ) const { return m_selectedChildren; }
   /**
    * Deselects recursively all child objects
    */
   virtual void deselectChildren( );

   /**
    * Returns the view structure of the object.
    *
    * If the view structure has changed since the last call, the
    * structure is created or updated, or the default view structure
    * is used.
    *
    * If the default view structure can't be used, this function calls
    * createViewStructure, which has to create a non default view structure.
    */
   virtual PMViewStructure* viewStructure( );
protected:
   /**
    * Adds num to the number of selected objects in this object and all
    * parent objects. num can be negative.
    */
   virtual void adjustSelectedChildren( int num );

   /**
    * Returns the default view structure for the object. This view
    * structure can be shared between all objects of this type.
    *
    * Only the data can be shared, NOT the pointer!!!
    *
    * The default view structure has to be created when this function
    * is called first.
    */
   virtual PMViewStructure* defaultViewStructure( ) const { return 0; }
   /**
    * Returns a key that represents the view structure parameter.
    *
    * Each time a view structure parameter is changed (=detail level),
    * this key has to be incremented.
    */
   virtual int viewStructureParameterKey( ) const { return 0; }

   /**
    * Returns true if the objects attributes are default and the default
    * view structure can be used
    */
   virtual bool isDefault( ) { return false; }
   /**
    * The object has to create or update a non default view structure
    */
   virtual void createViewStructure( ) { };
   /**
    * Calls setViewStructureChanged( ) for the memento (if one has been created)
    * and marks the current view structure as outdated.
    */
   void setViewStructureChanged( );
   /**
    * The view structure.
    */
   PMViewStructure* m_pViewStructure;
private:
   /**
    * Pointer to the first child
    */
   PMObject* m_pFirstChild;
   /**
    * Pointer to the last child
    */
   PMObject* m_pLastChild;
   /**
    * number of selected child items.
    */
   int m_selectedChildren;
   /**
    * The modify flag for the view structure
    */
   bool m_bViewStructureChanged;
   static PMMetaObject* s_pMetaObject;
};

#endif