propertylist.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "propertylist.h"
00021
00022 #include "property.h"
00023 #include "multiproperty.h"
00024
00025 namespace PropertyLib{
00026
00027 PropertyList::PropertyList()
00028 :QObject(0, 0), m_propertyOwner(true)
00029 {
00030 }
00031
00032 PropertyList::PropertyList(bool propertyOwner)
00033 :QObject(0, 0), m_propertyOwner(propertyOwner)
00034 {
00035 }
00036
00037 PropertyList::~PropertyList()
00038 {
00039 clear();
00040 }
00041
00042 MultiProperty *PropertyList::operator[](const QString &name)
00043 {
00044 if (m_list.contains(name))
00045 return m_list[name];
00046 else
00047 return new MultiProperty(this);
00048 }
00049
00050 void PropertyList::addProperty(Property *property)
00051 {
00052 if (property == 0)
00053 return;
00054 MultiProperty *mp = 0;
00055 if ( m_list.contains(property->name()) )
00056 {
00057 mp = m_list[property->name()];
00058 mp->addProperty(property);
00059 }
00060 else
00061 {
00062 mp = new MultiProperty(this, property);
00063 m_list[property->name()] = mp;
00064 addToGroup("", mp);
00065 }
00066 }
00067
00068 void PropertyList::addProperty(const QString &group, Property *property)
00069 {
00070 if (property == 0)
00071 return;
00072
00073 MultiProperty *mp = 0;
00074 if (m_list.contains(property->name()))
00075 {
00076 mp = m_list[property->name()];
00077 mp->addProperty(property);
00078 }
00079 else
00080 {
00081 mp = new MultiProperty(this, property);
00082 m_list[property->name()] = mp;
00083 addToGroup(group, mp);
00084 }
00085 }
00086
00087 void PropertyList::removeProperty(Property *property)
00088 {
00089 if (property == 0)
00090 return;
00091
00092 if (m_propertyOwner)
00093 emit aboutToDeleteProperty(property);
00094
00095 MultiProperty *mp = m_list[property->name()];
00096 QString group = m_groupOfProperty[mp];
00097 removeFromGroup(mp);
00098 QString pname = property->name();
00099 mp->removeProperty(property);
00100 if (m_propertyOwner)
00101 delete property;
00102 if (mp->list.count() == 0)
00103 {
00104
00105 m_list.remove(pname);
00106 delete mp;
00107 }
00108 else
00109 addToGroup(group, mp);
00110 }
00111
00112 void PropertyList::removeProperty(const QString &name)
00113 {
00114 if (m_list.contains(name))
00115 {
00116 QString group = m_groupOfProperty[m_list[name]];
00117 removeFromGroup(m_list[name]);
00118 Property *property;
00119 for (property = m_list[name]->list.first(); property; property = m_list[name]->list.next())
00120 {
00121 if (m_propertyOwner)
00122 emit aboutToDeleteProperty(property);
00123
00124 m_list[property->name()]->removeProperty(property);
00125 if (m_propertyOwner)
00126 delete property;
00127 }
00128 if (m_list[name]->list.count() == 0)
00129 {
00130
00131 delete m_list[name];
00132 m_list.remove(name);
00133 }
00134 else
00135 {
00136 addToGroup(group, m_list[name]);
00137 }
00138 }
00139 }
00140
00141 const QValueList<QPair<QString, QValueList<QString> > >& PropertyList::propertiesOfGroup() const
00142 {
00143 return m_propertiesOfGroup;
00144 }
00145
00146 const QMap<MultiProperty*, QString>& PropertyList::groupOfProperty() const
00147 {
00148 return m_groupOfProperty;
00149 }
00150
00151 void PropertyList::addToGroup(const QString &group, MultiProperty *property)
00152 {
00153 if (!property)
00154 return;
00155
00156
00157 if (m_groupOfProperty.contains(property) && (m_groupOfProperty[property] == group))
00158 return;
00159
00160 QPair<QString, QValueList<QString> > *groupPair = 0;
00161 for(QValueList<QPair<QString, QValueList<QString> > >::iterator it = m_propertiesOfGroup.begin();
00162 it != m_propertiesOfGroup.end(); ++it)
00163 {
00164 if ((*it).first == group)
00165 {
00166 groupPair = &(*it);
00167 break;
00168 }
00169 }
00170 if (groupPair == 0)
00171 {
00172 groupPair = new QPair<QString, QValueList<QString> >();
00173 groupPair->first = group;
00174 groupPair->second.append(property->name());
00175 m_propertiesOfGroup.append(*groupPair);
00176 m_groupOfProperty[property] = group;
00177 return;
00178 }
00179
00180 if (!groupPair->second.contains(property->name()))
00181 groupPair->second.append(property->name());
00182
00183 m_groupOfProperty[property] = group;
00184 }
00185
00186 void PropertyList::removeFromGroup(MultiProperty *property)
00187 {
00188 QString group = m_groupOfProperty[property];
00189
00190
00191 for(QValueList<QPair<QString, QValueList<QString> > >::iterator it = m_propertiesOfGroup.begin();
00192 it != m_propertiesOfGroup.end(); ++it)
00193 {
00194
00195 if ((*it).first == group)
00196 {
00197
00198 (*it).second.remove(property->name());
00199 break;
00200 }
00201 }
00202
00203 m_groupOfProperty.remove(property);
00204 }
00205
00206 PropertyBuffer::PropertyBuffer( )
00207 :PropertyList(false)
00208 {
00209 }
00210
00211 void PropertyBuffer::intersect(const PropertyList *list)
00212 {
00213 for (QMap<QString, MultiProperty*>::iterator it = m_list.begin(); it != m_list.end(); ++it)
00214 {
00215
00216 if (list->m_list.contains(it.key()))
00217 {
00218
00219
00220
00221
00222
00223 if ( ((*it.data()) == *(list->m_list[it.key()]))
00224 && (list->m_groupOfProperty[list->m_list[it.key()]] == m_groupOfProperty[it.data()]) )
00225 {
00226
00227 it.data()->addProperty(list->m_list[it.key()]);
00228 continue;
00229 }
00230 }
00231
00232 removeProperty(it.key());
00233 }
00234 }
00235
00236 PropertyBuffer::PropertyBuffer(PropertyList *list)
00237 :PropertyList(false)
00238 {
00239
00240 for (QMap<QString, MultiProperty*>::const_iterator it = list->m_list.begin();
00241 it != list->m_list.end(); ++it)
00242 {
00243 MultiProperty *mp = new MultiProperty(*it.data());
00244 mp->m_propertyList = this;
00245 addToGroup(list->m_groupOfProperty[it.data()], mp);
00246 m_list[it.key()] = mp;
00247 }
00248 }
00249
00250 void PropertyList::clear( )
00251 {
00252 for (QMap<QString, MultiProperty*>::iterator it = m_list.begin(); it != m_list.end(); ++it)
00253 removeProperty(it.key());
00254 }
00255
00256 bool PropertyList::contains( const QString & name )
00257 {
00258 if (m_list.contains(name))
00259 return true;
00260 return false;
00261 }
00262
00263 QPtrList<Property> PropertyList::properties(const QString &name)
00264 {
00265 if (m_list.contains(name))
00266 return m_list[name]->list;
00267 return QPtrList<Property>();
00268 }
00269
00270 }
00271
00272 #ifndef PURE_QT
00273 #include "propertylist.moc"
00274 #endif
This file is part of the documentation for KDevelop Version 3.1.2.