• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • KDevelop Property Editing Library
 

KDevelop Property Editing Library

  • lib
  • widgets
  • propeditor
propertylist.cpp
1 /***************************************************************************
2  * Copyright (C) 2004 by Alexander Dymo *
3  * cloudtemple@mskat.net *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU Library General Public License as *
7  * published by the Free Software Foundation; either version 2 of the *
8  * License, or (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU Library General Public *
16  * License along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19  ***************************************************************************/
20 #include "propertylist.h"
21 
22 #include "property.h"
23 #include "multiproperty.h"
24 
25 namespace PropertyLib{
26 
27 PropertyList::PropertyList()
28  :TQObject(0, 0), m_propertyOwner(true)
29 {
30 }
31 
32 PropertyList::PropertyList(bool propertyOwner)
33  :TQObject(0, 0), m_propertyOwner(propertyOwner)
34 {
35 }
36 
37 PropertyList::~PropertyList()
38 {
39  clear();
40 }
41 
42 MultiProperty *PropertyList::operator[](const TQString &name)
43 {
44  if (m_list.contains(name))
45  return m_list[name];
46  else
47  return new MultiProperty(this);
48 }
49 
50 MultiProperty *PropertyList::property( const TQString &name )
51 {
52  if (m_list.contains(name))
53  return m_list[name];
54  else
55  return new MultiProperty(this);
56 }
57 
58 void PropertyList::addProperty(Property *property)
59 {
60  if (property == 0)
61  return;
62  MultiProperty *mp = 0;
63  if ( m_list.contains(property->name()) )
64  {
65  mp = m_list[property->name()];
66  mp->addProperty(property);
67  }
68  else
69  {
70  mp = new MultiProperty(this, property);
71  m_list[property->name()] = mp;
72  addToGroup("", mp);
73  }
74 }
75 
76 void PropertyList::addProperty(const TQString &group, Property *property)
77 {
78  if (property == 0)
79  return;
80 
81  MultiProperty *mp = 0;
82  if (m_list.contains(property->name()))
83  {
84  mp = m_list[property->name()];
85  mp->addProperty(property);
86  }
87  else
88  {
89  mp = new MultiProperty(this, property);
90  m_list[property->name()] = mp;
91  addToGroup(group, mp);
92  }
93 }
94 
95 void PropertyList::removeProperty(Property *property)
96 {
97  if (property == 0)
98  return;
99 
100  if (m_propertyOwner)
101  emit aboutToDeleteProperty(property);
102 
103  MultiProperty *mp = m_list[property->name()];
104  TQString group = m_groupOfProperty[mp];
105  removeFromGroup(mp);
106  TQString pname = property->name();
107  mp->removeProperty(property);
108  if (m_propertyOwner)
109  delete property;
110  if (mp->list.count() == 0)
111  {
112 // tqWarning("rp: removing mp for %s itself", pname.ascii());
113  m_list.remove(pname);
114  delete mp;
115  }
116  else
117  addToGroup(group, mp);
118 }
119 
120 void PropertyList::removeProperty(const TQString &name)
121 {
122  if (m_list.contains(name))
123  {
124  TQString group = m_groupOfProperty[m_list[name]];
125  removeFromGroup(m_list[name]);
126  Property *property;
127  for (property = m_list[name]->list.first(); property; property = m_list[name]->list.next())
128  {
129  if (m_propertyOwner)
130  emit aboutToDeleteProperty(property);
131 
132  m_list[property->name()]->removeProperty(property);
133  if (m_propertyOwner)
134  delete property;
135  }
136  if (m_list[name]->list.count() == 0)
137  {
138 // tqWarning("rp2: removing mp for %s itself", name.ascii());
139  delete m_list[name];
140  m_list.remove(name);
141  }
142  else
143  {
144  addToGroup(group, m_list[name]);
145  }
146  }
147 }
148 
149 const TQValueList<TQPair<TQString, TQValueList<TQString> > >& PropertyList::propertiesOfGroup() const
150 {
151  return m_propertiesOfGroup;
152 }
153 
154 const TQMap<MultiProperty*, TQString>& PropertyList::groupOfProperty() const
155 {
156  return m_groupOfProperty;
157 }
158 
159 void PropertyList::addToGroup(const TQString &group, MultiProperty *property)
160 {
161  if (!property)
162  return;
163 
164  //do not add same property to the group twice
165  if (m_groupOfProperty.contains(property) && (m_groupOfProperty[property] == group))
166  return;
167 
168  TQPair<TQString, TQValueList<TQString> > *groupPair = 0;
169  for(TQValueList<TQPair<TQString, TQValueList<TQString> > >::iterator it = m_propertiesOfGroup.begin();
170  it != m_propertiesOfGroup.end(); ++it)
171  {
172  if ((*it).first == group)
173  {
174  groupPair = &(*it);
175  break;
176  }
177  }
178  if (groupPair == 0)
179  {
180  groupPair = new TQPair<TQString, TQValueList<TQString> >();
181  groupPair->first = group;
182  groupPair->second.append(property->name());
183  m_propertiesOfGroup.append(*groupPair);
184  m_groupOfProperty[property] = group;
185  return;
186  }
187  //check if group already contains property with the same name
188  if (!groupPair->second.contains(property->name()))
189  groupPair->second.append(property->name());
190 
191  m_groupOfProperty[property] = group;
192 }
193 
194 void PropertyList::removeFromGroup(MultiProperty *property)
195 {
196  TQString group = m_groupOfProperty[property];
197 // tqWarning("removeFromGroup group=%s", group.ascii());
198 
199  for(TQValueList<TQPair<TQString, TQValueList<TQString> > >::iterator it = m_propertiesOfGroup.begin();
200  it != m_propertiesOfGroup.end(); ++it)
201  {
202 // tqWarning("removeFromGroup checking %s", (*it).first.ascii());
203  if ((*it).first == group)
204  {
205 // tqWarning("removeFromGroup removing %s", property->name().ascii());
206  (*it).second.remove(property->name());
207  break;
208  }
209  }
210 
211  m_groupOfProperty.remove(property);
212 }
213 
214 void PropertyList::clear( )
215 {
216  for (TQMap<TQString, MultiProperty*>::iterator it = m_list.begin(); it != m_list.end(); ++it)
217  removeProperty(it.key());
218 }
219 
220 bool PropertyList::contains( const TQString & name )
221 {
222  if (m_list.contains(name))
223  return true;
224  return false;
225 }
226 
227 TQPtrList<Property> PropertyList::properties(const TQString &name)
228 {
229  if (m_list.contains(name))
230  return m_list[name]->list;
231  return TQPtrList<Property>();
232 }
233 
234 PropertyList::Iterator PropertyList::begin()
235 {
236  return Iterator(this);
237 }
238 
239 PropertyList::Iterator PropertyList::end()
240 {
241  return Iterator(this, true);
242 }
243 
244 //PropertyList::Iterator class
245 
246 PropertyList::Iterator::Iterator(PropertyList *list)
247  :m_list(list)
248 {
249  current = m_list->m_list.begin();
250 }
251 
252 PropertyList::Iterator::Iterator(PropertyList *list, bool // end
253  )
254  :m_list(list)
255 {
256  current = m_list->m_list.end();
257 }
258 
259 void PropertyList::Iterator::operator ++()
260 {
261  next();
262 }
263 
264 void PropertyList::Iterator::operator ++(int)
265 {
266  next();
267 }
268 
269 void PropertyList::Iterator::next()
270 {
271  ++current;
272 }
273 
274 MultiProperty *PropertyList::Iterator::operator *()
275 {
276  return data();
277 }
278 
279 TQString PropertyList::Iterator::key()
280 {
281  return current.key();
282 }
283 
284 MultiProperty *PropertyList::Iterator::data()
285 {
286  return current.data();
287 }
288 
289 bool PropertyList::Iterator::operator !=(Iterator it)
290 {
291  return current != it.current;
292 }
293 
294 
295 // PropertyBuffer class
296 
297 
298 
299 
300 
301 PropertyBuffer::PropertyBuffer( )
302  :PropertyList(false)
303 {
304 }
305 
306 void PropertyBuffer::intersect(const PropertyList *list)
307 {
308  tqWarning("PropertyBuffer::intersect");
309  for (TQMap<TQString, MultiProperty*>::iterator it = m_list.begin(); it != m_list.end(); ++it)
310  {
311 // tqWarning("intersect:: for mp = %s", it.data()->name().ascii());
312  if (list->m_list.contains(it.key()))
313  {
314 /* tqWarning("intersect:: list contains %s", it.key().ascii());
315  if ( (*(it.data()) == *(list->m_list[it.key()])))
316  tqWarning("intersect:: equal properties");
317  else
318  tqWarning("intersect:: not equal properties");*/
319  if ( ((*it.data()) == *(list->m_list[it.key()]))
320  && (list->m_groupOfProperty[list->m_list[it.key()]] == m_groupOfProperty[it.data()]) )
321  {
322 // tqWarning("intersect:: equal properties, adding");
323  it.data()->addProperty(list->m_list[it.key()]);
324  continue;
325  }
326  }
327 // tqWarning("intersect:: removing %s from intersection", it.key().ascii());
328  removeProperty(it.key());
329  }
330  connect(list, TQT_SIGNAL(propertyValueChanged(Property*)), this, TQT_SLOT(intersectedValueChanged(Property*)));
331 }
332 
333 void PropertyBuffer::intersectedValueChanged(Property *property)
334 {
335 // tqWarning("PropertyBuffer::intersectedValueChanged");
336  TQString propertyName = property->name();
337  if (!contains(propertyName))
338  return;
339 
340  MultiProperty mp(property);
341  if (mp == *m_list[propertyName])
342  {
343  Property *prop;
344  TQPtrList<Property> props = properties(propertyName);
345  for (prop = props.first(); prop; prop = props.next())
346  emit propertyValueChanged(prop);
347  }
348 }
349 
350 PropertyBuffer::PropertyBuffer(PropertyList *list)
351  :PropertyList(false)
352 {
353  //deep copy of m_list
354  for (TQMap<TQString, MultiProperty*>::const_iterator it = list->m_list.begin();
355  it != list->m_list.end(); ++it)
356  {
357  MultiProperty *mp = new MultiProperty(*it.data());
358  mp->m_propertyList = this;
359  addToGroup(list->m_groupOfProperty[it.data()], mp);
360  m_list[it.key()] = mp;
361  }
362  connect(list, TQT_SIGNAL(propertyValueChanged(Property*)), this, TQT_SLOT(intersectedValueChanged(Property*)));
363 }
364 
365 }
366 
367 #ifndef PURE_QT
368 #include "propertylist.moc"
369 #endif
PropertyLib::PropertyList::addProperty
virtual void addProperty(Property *property)
Adds the property to the list to the "common" group.
Definition: propertylist.cpp:58
PropertyLib::PropertyList::propertiesOfGroup
virtual const TQValueList< TQPair< TQString, TQValueList< TQString > > > & propertiesOfGroup() const
Definition: propertylist.cpp:149
PropertyLib
Namespace which contain property editing classes.
Definition: childproperty.cpp:29
PropertyLib::PropertyList::removeProperty
virtual void removeProperty(Property *property)
Removes property from the list.
Definition: propertylist.cpp:95
PropertyLib::PropertyList::groupOfProperty
virtual const TQMap< MultiProperty *, TQString > & groupOfProperty() const
Definition: propertylist.cpp:154
multiproperty.h
Contains PropertyLib::MultiProperty class.
property.h
Contains PropertyLib::Property class and PropertyLib::Property::PropertyType enum.
propertylist.h
Contains PropertyLib::PropertyList class.
PropertyLib::MultiProperty::name
TQString name() const
Returns the name of a property.
Definition: multiproperty.cpp:46
PropertyLib::PropertyList::properties
TQPtrList< Property > properties(const TQString &name)
The list of properties with given name.
Definition: propertylist.cpp:227
PropertyLib::MultiProperty::removeProperty
void removeProperty(Property *prop)
Removes property from the list.
Definition: multiproperty.cpp:191
PropertyLib::PropertyList::contains
virtual bool contains(const TQString &name)
Returns true if the list of properties contains property with given name.
Definition: propertylist.cpp:220
PropertyLib::PropertyList::propertyValueChanged
void propertyValueChanged(Property *property)
Emitted when the value of the property is changed.
PropertyLib::PropertyBuffer::PropertyBuffer
PropertyBuffer()
Constructs an empty property buffer.
Definition: propertylist.cpp:301
PropertyLib::PropertyList
The list of properties.
Definition: propertylist.h:55
PropertyLib::PropertyBuffer::intersect
virtual void intersect(const PropertyList *list)
Intersects with other PropertyLib::PropertyList.
Definition: propertylist.cpp:306
PropertyLib::PropertyList::property
MultiProperty * property(const TQString &name)
Accesses a property by it&#39;s name.
Definition: propertylist.cpp:50
PropertyLib::PropertyList::removeFromGroup
void removeFromGroup(MultiProperty *property)
Removes property from a group.
Definition: propertylist.cpp:194
PropertyLib::PropertyList::addToGroup
void addToGroup(const TQString &group, MultiProperty *property)
Adds property to a group.
Definition: propertylist.cpp:159
PropertyLib::Property::name
virtual TQString name() const
Definition: property.cpp:57
PropertyLib::PropertyList::operator[]
virtual MultiProperty * operator[](const TQString &name)
Accesses a property by it&#39;s name.
Definition: propertylist.cpp:42
PropertyLib::PropertyList::clear
virtual void clear()
Clears the list of properties.
Definition: propertylist.cpp:214
PropertyLib::MultiProperty::addProperty
void addProperty(Property *prop)
Adds property to the list.
Definition: multiproperty.cpp:186
PropertyLib::Property
Property.
Definition: property.h:62
PropertyLib::MultiProperty
Holds a list of properties with the same name and type.
Definition: multiproperty.h:49
PropertyLib::PropertyList::aboutToDeleteProperty
void aboutToDeleteProperty(Property *property)
Emitted when property is about to be deleted.

KDevelop Property Editing Library

Skip menu "KDevelop Property Editing Library"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

KDevelop Property Editing Library

Skip menu "KDevelop Property Editing Library"
  • buildtools
  •   lib
  •     base
  •     parsers
  •       autotools
  •       qmake
  •     widgets
  •   api
  • languages
  •   lib
  •     debugger
  •     designer_integration
  •     interfaces
  • lib
  •   catalog
  •   interfaces
  •     extensions
  •     external
  •     extras
  •   util
  •   widgets
  •     propeditor
  • parts
  •   documentation
  •     interfaces
  • src
  •   profileengine
  •     lib
Generated for KDevelop Property Editing Library by doxygen 1.8.13
This website is maintained by Timothy Pearson.