multiproperty.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 #include "multiproperty.h"
00020
00021 #include "propertylist.h"
00022
00023 namespace PropertyLib{
00024
00025 MultiProperty::MultiProperty(Property *prop)
00026 :m_propertyList(0)
00027 {
00028 list.append(prop);
00029 }
00030
00031 MultiProperty::MultiProperty(PropertyList *propertyList)
00032 :m_propertyList(propertyList)
00033 {
00034 }
00035
00036 MultiProperty::MultiProperty(PropertyList *propertyList, Property *prop)
00037 :m_propertyList(propertyList)
00038 {
00039 list.append(prop);
00040 }
00041
00042 MultiProperty::~MultiProperty()
00043 {
00044 }
00045
00046 QString MultiProperty::name() const
00047 {
00048 if (list.count() >= 1)
00049 return list.getFirst()->name();
00050 return QString::null;
00051 }
00052
00053 int MultiProperty::type() const
00054 {
00055 if (list.count() >= 1)
00056 return list.getFirst()->type();
00057 return QVariant::Invalid;
00058 }
00059
00060 QVariant MultiProperty::value() const
00061 {
00062 QVariant value;
00063 if (list.count() >= 1)
00064 value = list.getFirst()->value();
00065
00066 QPtrListIterator<Property> it(list);
00067 Property *property;
00068 while ((property = it.current()) != 0)
00069 {
00070 if (property->value() != value)
00071 return QVariant::Invalid;
00072 ++it;
00073 }
00074
00075 return value;
00076 }
00077
00078 QString MultiProperty::description() const
00079 {
00080 QString description;
00081 if (list.count() >= 1)
00082 description = list.getFirst()->description();
00083
00084 QPtrListIterator<Property> it(list);
00085 Property *property;
00086 while ((property = it.current()) != 0)
00087 {
00088 if (property->description() != description)
00089 return QString::null;
00090 ++it;
00091 }
00092
00093 return description;
00094 }
00095
00096 bool MultiProperty::readOnly() const
00097 {
00098 bool v = true;
00099 if (list.count() >= 1)
00100 v = list.getFirst()->readOnly();
00101
00102 QPtrListIterator<Property> it(list);
00103 Property *property;
00104 while ((property = it.current()) != 0)
00105 {
00106 if (property->readOnly() != v)
00107 return false;
00108 ++it;
00109 }
00110
00111 return v;
00112 }
00113
00114 bool MultiProperty::visible() const
00115 {
00116 bool v = true;
00117 if (list.count() >= 1)
00118 v = list.getFirst()->readOnly();
00119
00120 QPtrListIterator<Property> it(list);
00121 Property *property;
00122 while ((property = it.current()) != 0)
00123 {
00124 if (property->visible() != v)
00125 return false;
00126 ++it;
00127 }
00128
00129 return v;
00130 }
00131
00132 QMap<QString, QVariant> MultiProperty::valueList() const
00133 {
00134 if (list.count() >= 1)
00135 return list.getFirst()->valueList;
00136 return QMap<QString, QVariant>();
00137 }
00138
00139 void MultiProperty::setDescription(const QString &description)
00140 {
00141 Property *property;
00142 for (property = list.first(); property; property = list.next())
00143 property->setDescription(description);
00144 }
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154 void MultiProperty::setValue(const QVariant &value)
00155 {
00156 Property *property;
00157 for (property = list.first(); property; property = list.next())
00158 {
00159 property->setValue(value);
00160 if (m_propertyList)
00161 emit m_propertyList->propertyValueChanged(property);
00162 }
00163 }
00164
00165 void MultiProperty::setValue(const QVariant &value, bool emitChange)
00166 {
00167 Property *property;
00168 for (property = list.first(); property; property = list.next())
00169 {
00170 property->setValue(value);
00171 if (emitChange && m_propertyList)
00172 emit m_propertyList->propertyValueChanged(property);
00173 }
00174 }
00175
00176 void MultiProperty::setValueList(const QMap<QString, QVariant> &valueList)
00177 {
00178 Property *property;
00179 for (property = list.first(); property; property = list.next())
00180 property->setValueList(valueList);
00181 }
00182
00183 void MultiProperty::addProperty(Property *prop)
00184 {
00185 list.append(prop);
00186 }
00187
00188 void MultiProperty::removeProperty(Property *prop)
00189 {
00190
00191
00192 list.remove(prop);
00193
00194
00195 }
00196
00197 bool MultiProperty::operator ==(const MultiProperty &prop) const
00198 {
00199 if ( (type() == prop.type()) && (name() == prop.name()) )
00200 return true;
00201 return false;
00202 }
00203
00204 bool MultiProperty::operator ==(const Property &prop) const
00205 {
00206
00207
00208 if ( (type() == prop.type()) && (name() == prop.name()) )
00209 return true;
00210 return false;
00211 }
00212
00213 void MultiProperty::addProperty( MultiProperty *prop)
00214 {
00215 Property *property;
00216 for (property = prop->list.first(); property; property = prop->list.next())
00217 addProperty(property);
00218 }
00219
00220 void MultiProperty::removeProperty( MultiProperty *prop)
00221 {
00222 Property *property;
00223 for (property = prop->list.first(); property; property = prop->list.next())
00224 removeProperty(property);
00225 }
00226
00227 QVariant MultiProperty::findValueDescription() const
00228 {
00229 QVariant val = value();
00230 if (type() != Property::ValueFromList)
00231 return val;
00232 QMap<QString, QVariant> vl = valueList();
00233 for (QMap<QString, QVariant>::const_iterator it = vl.begin(); it != vl.end(); ++ it)
00234 {
00235 if (it.data() == val)
00236 return it.key();
00237 }
00238 return "";
00239 }
00240
00241 QVariant MultiProperty::findValueDescription(QVariant val) const
00242 {
00243 if (type() != Property::ValueFromList)
00244 return val;
00245 QMap<QString, QVariant> vl = valueList();
00246 for (QMap<QString, QVariant>::const_iterator it = vl.begin(); it != vl.end(); ++ it)
00247 {
00248 if (it.data() == val)
00249 return it.key();
00250 }
00251 return "";
00252 }
00253
00254 bool MultiProperty::valid() const
00255 {
00256 return list.count() != 0;
00257 }
00258
00259 void MultiProperty::undo()
00260 {
00261 Property *property;
00262 for (property = list.first(); property; property = list.next())
00263 {
00264 property->setValue(property->oldValue(), false);
00265 if (m_propertyList)
00266 emit m_propertyList->propertyValueChanged(property);
00267 }
00268 }
00269
00270 }
This file is part of the documentation for KDevelop Version 3.1.2.