Changeset View
Changeset View
Standalone View
Standalone View
src/KPropertySet.h
Show First 20 Lines • Show All 107 Lines • ▼ Show 20 Line(s) | 107 | /*! \brief Set of properties | |||
---|---|---|---|---|---|
108 | 108 | | |||
109 | \author Cedric Pasteur <cedric.pasteur@free.fr> | 109 | \author Cedric Pasteur <cedric.pasteur@free.fr> | ||
110 | \author Alexander Dymo <cloudtemple@mskat.net> | 110 | \author Alexander Dymo <cloudtemple@mskat.net> | ||
111 | \author Jarosław Staniek <staniek@kde.org> | 111 | \author Jarosław Staniek <staniek@kde.org> | ||
112 | */ | 112 | */ | ||
113 | class KPROPERTYCORE_EXPORT KPropertySet : public QObject | 113 | class KPROPERTYCORE_EXPORT KPropertySet : public QObject | ||
114 | { | 114 | { | ||
115 | Q_OBJECT | 115 | Q_OBJECT | ||
116 | | ||||
117 | public: | 116 | public: | ||
118 | //! Constructs a new property set object. | 117 | //! Constructs a new property set object. | ||
119 | explicit KPropertySet(QObject *parent = 0); | 118 | explicit KPropertySet(QObject *parent = 0); | ||
120 | 119 | | |||
121 | /*! Constructs a deep copy of \a set. | 120 | /*! Constructs a deep copy of \a set. | ||
122 | The new object will not have a QObject parent even if \a set has such parent. */ | 121 | The new object will not have a QObject parent even if \a set has such parent. */ | ||
123 | explicit KPropertySet(const KPropertySet& set); | 122 | explicit KPropertySet(const KPropertySet& set); | ||
124 | 123 | | |||
125 | virtual ~KPropertySet(); | 124 | virtual ~KPropertySet(); | ||
126 | 125 | | |||
127 | /*! Adds the property to the set, in the group. | | |||
128 | The property becomes owned by the set. | | |||
129 | Any name can be used for the @a group. "common" is the default for a basic top-level group. */ | | |||
130 | void addProperty(KProperty *property, const QByteArray &group = "common"); | | |||
131 | | ||||
132 | /*! Removes property from the set and deletes the object. | | |||
133 | Emits aboutToDeleteProperty before removing. */ | | |||
134 | void removeProperty(KProperty *property); | | |||
135 | | ||||
136 | /*! Removes property with the given name from the set and deletes the object. | | |||
137 | Emits aboutToDeleteProperty() before removing.*/ | | |||
138 | void removeProperty(const QByteArray &name); | | |||
139 | | ||||
140 | /*! Removes all property objects from the property set and deletes them. */ | | |||
141 | void clear(); | | |||
142 | | ||||
143 | /*! @return the number of top-level properties in the set. */ | 126 | /*! @return the number of top-level properties in the set. */ | ||
144 | uint count() const; | 127 | uint count() const; | ||
145 | 128 | | |||
146 | /*! @return the number of top-level properties in the set | 129 | /*! @return the number of top-level properties in the set | ||
147 | matching criteria defined by @a selector. */ | 130 | matching criteria defined by @a selector. */ | ||
148 | uint count(const KPropertySelector& selector) const; | 131 | uint count(const KPropertySelector& selector) const; | ||
149 | 132 | | |||
150 | /*! @return true if the set is empty, i.e. count() is 0; otherwise returns false. */ | 133 | /*! @return true if the set is empty, i.e. count() is 0; otherwise returns false. */ | ||
Show All 11 Lines | |||||
162 | In a read-only property set no property can be modified by the user regardless of read-only flag | 145 | In a read-only property set no property can be modified by the user regardless of read-only flag | ||
163 | of any property (KProperty::isReadOnly()). On the other hand if KProperty::isReadOnly() is @c true | 146 | of any property (KProperty::isReadOnly()). On the other hand if KProperty::isReadOnly() is @c true | ||
164 | and KPropertySet::isReadOnly() is @c false, the property is still read-only. | 147 | and KPropertySet::isReadOnly() is @c false, the property is still read-only. | ||
165 | Read-only property set prevents editing in the property editor but it is still possible to change | 148 | Read-only property set prevents editing in the property editor but it is still possible to change | ||
166 | value or other parameters of property programatically using KProperty::setValue(), | 149 | value or other parameters of property programatically using KProperty::setValue(), | ||
167 | KProperty::resetValue(), etc. */ | 150 | KProperty::resetValue(), etc. */ | ||
168 | bool isReadOnly() const; | 151 | bool isReadOnly() const; | ||
169 | 152 | | |||
170 | /*! Sets this set to be read-only. | | |||
171 | @see isReadOnly */ | | |||
172 | void setReadOnly(bool readOnly); | | |||
173 | | ||||
174 | /*! \return true if the set contains property names \a name. */ | 153 | /*! \return true if the set contains property names \a name. */ | ||
175 | bool contains(const QByteArray &name) const; | 154 | bool contains(const QByteArray &name) const; | ||
176 | 155 | | |||
177 | /*! \return property named with \a name. If no such property is found, | 156 | /*! \return property named with \a name. If no such property is found, | ||
178 | null property (KProperty()) is returned. */ | 157 | null property (KProperty()) is returned. */ | ||
179 | KProperty& property(const QByteArray &name) const; | 158 | KProperty& property(const QByteArray &name) const; | ||
180 | 159 | | |||
181 | /*! Accesses a property by name. | 160 | /*! Accesses a property by name. | ||
Show All 17 Lines | |||||
199 | 178 | | |||
200 | /*! @return value for property named with @a name. | 179 | /*! @return value for property named with @a name. | ||
201 | If no such property is found, default value @a defaultValue is returned. */ | 180 | If no such property is found, default value @a defaultValue is returned. */ | ||
202 | QVariant propertyValue(const QByteArray &name, const QVariant& defaultValue = QVariant()) const; | 181 | QVariant propertyValue(const QByteArray &name, const QVariant& defaultValue = QVariant()) const; | ||
203 | 182 | | |||
204 | /*! Creates a deep copy of \a set and assigns it to this property set. */ | 183 | /*! Creates a deep copy of \a set and assigns it to this property set. */ | ||
205 | KPropertySet& operator= (const KPropertySet &set); | 184 | KPropertySet& operator= (const KPropertySet &set); | ||
206 | 185 | | |||
207 | /*! Change the value of property whose key is \a property to \a value. | | |||
208 | @see void changePropertyIfExists(const QByteArray &, const QVariant &) */ | | |||
209 | void changeProperty(const QByteArray &property, const QVariant &value); | | |||
210 | | ||||
211 | /*! Change the value of property whose key is \a property to \a value | | |||
212 | only if it exists in the set. | | |||
213 | @see void changeProperty(const QByteArray &, const QVariant &) */ | | |||
214 | void changePropertyIfExists(const QByteArray &property, const QVariant &value) { | | |||
215 | if (contains(property)) | | |||
216 | changeProperty(property, value); | | |||
217 | } | | |||
218 | | ||||
219 | /*! Sets @a caption as a user-visible translated string that will be shown in editor to represent | | |||
220 | \a group. */ | | |||
221 | void setGroupCaption(const QByteArray &group, const QString &caption); | | |||
222 | | ||||
223 | /*! \return the user-visible translated caption string for \a group that will | 186 | /*! \return the user-visible translated caption string for \a group that will | ||
224 | be shown in property editor to represent \a group. If there is no special | 187 | be shown in property editor to represent \a group. If there is no special | ||
225 | caption set for the group, \a group is just returned. */ | 188 | caption set for the group, \a group is just returned. */ | ||
226 | QString groupCaption(const QByteArray &group) const; | 189 | QString groupCaption(const QByteArray &group) const; | ||
227 | 190 | | |||
228 | /*! Sets the icon name \a icon to be displayed for \a group. */ | | |||
229 | void setGroupIconName(const QByteArray &group, const QString& iconName); | | |||
230 | | ||||
231 | /*! \return the icons name for \a group. */ | 191 | /*! \return the icons name for \a group. */ | ||
232 | QString groupIconName(const QByteArray &group) const; | 192 | QString groupIconName(const QByteArray &group) const; | ||
233 | 193 | | |||
234 | /*! \return a list of all group names. The order of items is undefined. */ | 194 | /*! \return a list of all group names. The order of items is undefined. */ | ||
235 | QList<QByteArray> groupNames() const; | 195 | QList<QByteArray> groupNames() const; | ||
236 | 196 | | |||
237 | /*! \return a list of all property names for group @ group. | 197 | /*! \return a list of all property names for group @a group. | ||
238 | The order of items is undefined. */ | 198 | The order of items is undefined. */ | ||
239 | QList<QByteArray> propertyNamesForGroup(const QByteArray &group) const; | 199 | QList<QByteArray> propertyNamesForGroup(const QByteArray &group) const; | ||
240 | 200 | | |||
241 | /*! Used by property editor to preserve previous selection when this set | 201 | /*! Used by property editor to preserve previous selection when this set | ||
242 | is assigned again. */ | 202 | is assigned again. */ | ||
243 | QByteArray previousSelection() const; | 203 | QByteArray previousSelection() const; | ||
244 | 204 | | |||
245 | void setPreviousSelection(const QByteArray& prevSelection); | | |||
246 | | ||||
247 | /*! Prints debug output for this set. */ | 205 | /*! Prints debug output for this set. */ | ||
248 | void debug() const; | 206 | void debug() const; | ||
249 | 207 | | |||
250 | //! @return property values for this set | 208 | //! @return property values for this set | ||
251 | QMap<QByteArray, QVariant> propertyValues() const; | 209 | QMap<QByteArray, QVariant> propertyValues() const; | ||
252 | 210 | | |||
253 | protected: | 211 | public Q_SLOTS: | ||
254 | /*! Constructs a set which owns or does not own it's properties.*/ | 212 | /*! Adds the property to the set, in the group. | ||
255 | explicit KPropertySet(bool propertyOwner); | 213 | The property becomes owned by the set. | ||
214 | Any name can be used for the @a group. "common" is the default for a basic top-level group. */ | ||||
215 | void addProperty(KProperty *property, const QByteArray &group = "common"); | ||||
216 | | ||||
217 | /*! Removes property from the set and deletes the object. | ||||
218 | Emits aboutToDeleteProperty before removing. */ | ||||
219 | void removeProperty(KProperty *property); | ||||
220 | | ||||
221 | /*! Removes property with the given name from the set and deletes the object. | ||||
222 | Emits aboutToDeleteProperty() before removing.*/ | ||||
223 | void removeProperty(const QByteArray &name); | ||||
224 | | ||||
225 | /*! Removes all property objects from the property set and deletes them. */ | ||||
226 | void clear(); | ||||
227 | | ||||
228 | /*! Change the value of property whose key is \a property to \a value. | ||||
229 | @see void changePropertyIfExists(const QByteArray &, const QVariant &) */ | ||||
230 | void changeProperty(const QByteArray &property, const QVariant &value); | ||||
231 | | ||||
232 | /*! Change the value of property whose key is \a property to \a value | ||||
233 | only if it exists in the set. | ||||
234 | @see void changeProperty(const QByteArray &, const QVariant &) */ | ||||
235 | void changePropertyIfExists(const QByteArray &property, const QVariant &value); | ||||
piggz: Add inline? | |||||
staniek: Changed to non-inline | |||||
236 | | ||||
237 | /*! Sets @a caption as a user-visible translated string that will be shown in editor to represent | ||||
238 | \a group. */ | ||||
239 | void setGroupCaption(const QByteArray &group, const QString &caption); | ||||
240 | | ||||
241 | /*! Sets the icon name \a icon to be displayed for \a group. */ | ||||
242 | void setGroupIconName(const QByteArray &group, const QString& iconName); | ||||
243 | | ||||
244 | //! Sets previous section. | ||||
245 | //! @see previousSelection() | ||||
246 | void setPreviousSelection(const QByteArray &prevSelection); | ||||
247 | | ||||
248 | /*! Sets this set to be read-only. | ||||
249 | @see isReadOnly */ | ||||
250 | void setReadOnly(bool readOnly); | ||||
256 | 251 | | |||
257 | Q_SIGNALS: | 252 | Q_SIGNALS: | ||
258 | /*! Emitted when the value of the property is changed.*/ | 253 | /*! Emitted when the value of the property is changed.*/ | ||
259 | void propertyChanged(KPropertySet& set, KProperty& property); | 254 | void propertyChanged(KPropertySet& set, KProperty& property); | ||
260 | 255 | | |||
261 | /*! @internal Exists to be sure that we emitted it before propertyChanged(), | 256 | /*! @internal Exists to be sure that we emitted it before propertyChanged(), | ||
262 | so editor object can handle this. */ | 257 | so editor object can handle this. */ | ||
263 | void propertyChangedInternal(KPropertySet& set, KProperty& property); | 258 | void propertyChangedInternal(KPropertySet& set, KProperty& property); | ||
Show All 9 Lines | |||||
273 | void aboutToBeCleared(); | 268 | void aboutToBeCleared(); | ||
274 | 269 | | |||
275 | /*! Emitted when property set object is about to be deleted.*/ | 270 | /*! Emitted when property set object is about to be deleted.*/ | ||
276 | void aboutToBeDeleted(); | 271 | void aboutToBeDeleted(); | ||
277 | 272 | | |||
278 | /*! Emitted when property set object's read-only flag has changed.*/ | 273 | /*! Emitted when property set object's read-only flag has changed.*/ | ||
279 | void readOnlyFlagChanged(); | 274 | void readOnlyFlagChanged(); | ||
280 | 275 | | |||
276 | protected: | ||||
277 | /*! Constructs a set which owns or does not own it's properties.*/ | ||||
278 | explicit KPropertySet(bool propertyOwner); | ||||
279 | | ||||
281 | private: | 280 | private: | ||
282 | KPropertySetPrivate * const d; | 281 | KPropertySetPrivate * const d; | ||
283 | friend class KPropertySetPrivate; | 282 | friend class KPropertySetPrivate; | ||
284 | }; | 283 | }; | ||
285 | 284 | | |||
286 | //! qDebug() stream operator. Writes this set to the debug output in a nicely formatted way. | 285 | //! qDebug() stream operator. Writes this set to the debug output in a nicely formatted way. | ||
287 | KPROPERTYCORE_EXPORT QDebug operator<<(QDebug dbg, const KPropertySet &set); | 286 | KPROPERTYCORE_EXPORT QDebug operator<<(QDebug dbg, const KPropertySet &set); | ||
288 | 287 | | |||
Show All 27 Lines |
Add inline?