summaryrefslogtreecommitdiffstats
path: root/kpovmodeler/pmobject.cpp
blob: d6bb94b36336c3813e02a2ca9267116a3d43aa2f (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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/*
**************************************************************************
                                 description
                             --------------------
    copyright            : (C) 2000-2003 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.                                   *
*                                                                        *
**************************************************************************/


#include "pmobject.h"
#include "pmcontrolpoint.h"
#include "pmdialogeditbase.h"
#include "pmmemento.h"
#include "pmprototypemanager.h"
#include "pminsertrulesystem.h"
#include "pmpart.h"

PMDefinePropertyClass( PMObject, PMObjectProperty );

PMMetaObject* PMObject::s_pMetaObject = 0;

PMObject::PMObject( PMPart* part )
{
   m_pParent = 0;
   m_selected = false;
   m_pPrevSibling = 0;
   m_pNextSibling = 0;
   m_pMemento = 0;
   m_readOnly = false;
   m_pPart = part;

   if( !m_pPart )
      kdError( PMArea ) << "PMObject::PMObject: The part may not be null" << endl;
}

PMObject::PMObject( const PMObject& o )
{
   m_pParent = 0;
   m_selected = false;
   m_pPrevSibling = 0;
   m_pNextSibling = 0;
   m_pMemento = 0;
   m_readOnly = false;
   m_pPart = o.m_pPart;
}

PMObject::~PMObject( )
{
}

PMMetaObject* PMObject::metaObject( ) const
{
   if( !s_pMetaObject )
   {
      s_pMetaObject = new PMMetaObject( "Object", 0 );
      s_pMetaObject->addProperty(
         new PMObjectProperty( "readOnly", &PMObject::setReadOnly, &PMObject::isReadOnly ) );
      s_pMetaObject->addProperty(
         new PMObjectProperty( "numberOfChildren", 0, &PMObject::countChildren ) );
   }
   return s_pMetaObject;
}

PMObject* PMObject::newObject( ) const
{
   return metaObject( )->newObject( m_pPart );
}

bool PMObject::insertChildAfter( PMObject*, PMObject* )
{
   kdError( PMArea ) << "Tried to insert object into a non composite object" << "\n";
   return false;
}

bool PMObject::insertChildBefore( PMObject*, PMObject* )
{
   kdError( PMArea ) << "Tried to insert object into a non composite object" << "\n";
   return false;
}

void PMObject::setSelected( bool s )
{
   if( m_selected != s )
   {
      if( s )
      {
         if( isSelectable( ) )
         {
            m_selected = true;
            if( m_pParent )
               m_pParent->adjustSelectedChildren( 1 );
         }
      }
      else
      {
         m_selected = false;
         if( m_pParent )
            m_pParent->adjustSelectedChildren( -1 );
      }
   }
}

bool PMObject::isSelectable( )
{
   bool is = true;
   PMObject* o;

   for( o = m_pParent; o && is; o = o->m_pParent )
      if( o->isSelected( ) )
         is = false;

   return is;
}

bool PMObject::isReadOnly( ) const
{
   if( m_readOnly )
      return true;
   if( m_pParent )
      return m_pParent->isReadOnly( );
   return false;
}

bool PMObject::takeChild( PMObject* )
{
   kdError( PMArea ) << "Tried to remove object out of a non composite object" << "\n";
   return false;
}

bool PMObject::takeChild( uint )
{
   kdError( PMArea ) << "Tried to remove object out of a non composite object" << "\n";
   return false;
}

PMDialogEditBase* PMObject::editWidget( QWidget* parent ) const
{
   return new PMDialogEditBase( parent );
//   return 0;
}

void PMObject::createMemento( )
{
   if( m_pMemento )
      delete m_pMemento;
   m_pMemento = new PMMemento( this );
}

PMMemento* PMObject::takeMemento( )
{
   PMMemento* tmp = m_pMemento;
   m_pMemento = 0;
   return tmp;
}

void PMObject::restoreMemento( PMMemento* /* s */ )
{
   // nothing to be done at the moment
}

PMMatrix PMObject::transformedWith( ) const
{
   PMMatrix result = PMMatrix::identity( );
   const PMObject* o = this;

   if( o->firstChild( ) )
      o = o->firstChild( );
   else if( o->nextSibling( ) )
      o = o->nextSibling( );
   else
      o = o->parent( );

   while( o )
   {
      if( o->hasTransformationMatrix( ) )
         result = o->transformationMatrix( ) * result;

      if( o->nextSibling( ) )
         o = o->nextSibling( );
      else
         o = o->parent( );
   }

   return result;
}

QDomElement PMObject::serialize( QDomDocument& doc ) const
{
   QDomElement e = doc.createElement( className( ).lower( ) );
   serialize( e, doc );
   return e;
}

void PMObject::readAttributes( const PMXMLHelper& )
{
}

void PMObject::cleanUp( ) const
{
   if( s_pMetaObject )
   {
      delete s_pMetaObject;
      s_pMetaObject = 0;
   }
}

bool PMObject::setProperty( const QString& name, const PMVariant& v )
{
   PMPropertyBase* p = metaObject( )->property( name );
   if( !p )
      return false;
   return p->setProperty( this, v );
}

QStringList PMObject::properties( ) const
{
   QStringList lst;
   PMPropertyIterator it = metaObject( )->properties( );
   
   for( ; it.current( ); ++it )
      lst.append( it.current( )->name( ) );

   return lst;
}

PMVariant PMObject::property( const QString& name ) const
{
   PMPropertyBase* p = metaObject( )->property( name );
   if( !p )
      return PMVariant( );
   return p->getProperty( this );
}

bool PMObject::isA( const QString& className ) const
{
   if( !m_pPart )
      return false;
   return m_pPart->prototypeManager( )->isA( metaObject( ), className );
}

QString PMObject::type( ) const
{
   return metaObject( )->className( );
}

bool PMObject::canInsert( const QString& className, const PMObject* after,
                          const PMObjectList* objectsBetween ) const
{
   if( !m_pPart )
      return false;
   return m_pPart->insertRuleSystem( )->canInsert( this, className, after, objectsBetween );
}

bool PMObject::canInsert( const PMObject* o, const PMObject* after,
                          const PMObjectList* objectsBetween ) const
{
   if( !m_pPart )
      return false;
   return m_pPart->insertRuleSystem( )->canInsert( this, o, after, objectsBetween );
}

int PMObject::canInsert( const PMObjectList& list, const PMObject* after ) const
{
   if( !m_pPart )
      return false;
   return m_pPart->insertRuleSystem( )->canInsert( this, list, after );
}

int PMObject::canInsert( const QStringList& classes, const PMObject* after ) const
{
   if( !m_pPart )
      return false;
   return m_pPart->insertRuleSystem( )->canInsert( this, classes, after );
}