KProperty

KPropertySet.h
1 /* This file is part of the KDE project
2  Copyright (C) 2004 Cedric Pasteur <[email protected]>
3  Copyright (C) 2004 Alexander Dymo <[email protected]>
4  Copyright (C) 2004-2017 Jarosław Staniek <[email protected]>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20 */
21 
22 #ifndef KPROPERTY_SET_H
23 #define KPROPERTY_SET_H
24 
25 #include <QObject>
26 #include <QHash>
27 #include <QDebug>
28 
29 #include "KProperty.h"
30 
31 class KPropertySetPrivate;
32 
34 
35 class KPROPERTYCORE_EXPORT KPropertySelector
36 {
37 public:
39  virtual ~KPropertySelector();
40 
42  virtual bool operator()(const KProperty& prop) const = 0;
43 
46  virtual KPropertySelector* clone() const = 0;
47 };
48 
50 
57 class KPROPERTYCORE_EXPORT KPropertySetIterator
58 {
59 public:
61 
63  explicit KPropertySetIterator(const KPropertySet &set);
64 
66 
70  KPropertySetIterator(const KPropertySet &set, const KPropertySelector& selector);
71 
75 
77 
80  KPropertySetIterator& operator=(const KPropertySetIterator &other);
81 
84  bool operator==(const KPropertySetIterator &other) const;
85 
88  inline bool operator!=(const KPropertySetIterator &other) const { return !operator==(other); }
89 
91 
92  enum class Order {
93  Insertion,
94  Alphabetical,
95  AlphabeticalByName
96  };
97 
99  void setOrder(Order order);
100 
102  Order order() const;
103 
104  void operator++();
105 
106  inline KProperty* operator*() const { return current(); }
107 
108  KProperty* current() const;
109 
110  friend class KPropertySet;
111 
112 private:
113  class Private;
114  Private * const d;
115 };
116 
119 class KPROPERTYCORE_EXPORT KPropertySet : public QObject
120 {
121  Q_OBJECT
122 public:
124  explicit KPropertySet(QObject *parent = nullptr);
125 
128  explicit KPropertySet(const KPropertySet& set);
129 
130  ~KPropertySet() override;
131 
133  int count() const;
134 
137  int count(const KPropertySelector& selector) const;
138 
140  bool isEmpty() const;
141 
143  bool hasVisibleProperties() const;
144 
147  bool hasProperties(const KPropertySelector& selector) const;
148 
157  bool isReadOnly() const;
158 
160  bool contains(const QByteArray &name) const;
161 
164  KProperty& property(const QByteArray &name) const;
165 
183  KProperty& operator[](const QByteArray &name) const;
184 
187  QVariant propertyValue(const QByteArray &name, const QVariant& defaultValue = QVariant()) const;
188 
190  KPropertySet& operator= (const KPropertySet &set);
191 
195  QString groupCaption(const QByteArray &group) const;
196 
198  QString groupIconName(const QByteArray &group) const;
199 
205  QByteArray groupNameForProperty(const QByteArray &propertyName) const;
206 
211  QByteArray groupNameForProperty(const KProperty &property) const;
212 
214  QList<QByteArray> groupNames() const;
215 
218  QList<QByteArray> propertyNamesForGroup(const QByteArray &group) const;
219 
222  QByteArray previousSelection() const;
223 
225  void debug() const;
226 
228  QMap<QByteArray, QVariant> propertyValues() const;
229 
235  void clearModifiedFlags();
236 
242  bool isModified() const;
243 
244 public Q_SLOTS:
248  void addProperty(KProperty *property, const QByteArray &group = "common");
249 
252  void removeProperty(KProperty *property);
253 
256  void removeProperty(const QByteArray &name);
257 
259  void clear();
260 
263  void changeProperty(const QByteArray &property, const QVariant &value);
264 
268  void changePropertyIfExists(const QByteArray &property, const QVariant &value);
269 
272  void setGroupCaption(const QByteArray &group, const QString &caption);
273 
275  void setGroupIconName(const QByteArray &group, const QString& iconName);
276 
279  void setPreviousSelection(const QByteArray &prevSelection);
280 
283  void setReadOnly(bool readOnly);
284 
285 Q_SIGNALS:
287  void propertyChanged(KPropertySet& set, KProperty& property);
288 
291  void propertyChangedInternal(KPropertySet& set, KProperty& property);
292 
294  void propertyReset(KPropertySet& set, KProperty& property);
295 
297  void aboutToDeleteProperty(KPropertySet& set, KProperty& property);
298 
301  void aboutToBeCleared();
302 
304  void aboutToBeDeleted();
305 
307  void readOnlyFlagChanged();
308 
309 protected:
311  explicit KPropertySet(bool propertyOwner);
312 
313 private:
314  KPropertySetPrivate * const d;
315  friend class KPropertySetPrivate;
316 };
317 
319 KPROPERTYCORE_EXPORT QDebug operator<<(QDebug dbg, const KPropertySet &set);
320 
321 #endif
A class to iterate over a KPropertySet.
Definition: KPropertySet.h:57
Order
Ordering options for properties.
Definition: KPropertySet.h:92
bool operator!=(const KPropertySetIterator &other) const
Definition: KPropertySet.h:88
An interface for functor selecting properties.
Definition: KPropertySet.h:35
Set of properties.
Definition: KPropertySet.h:119
The base class representing a single property.
Definition: KProperty.h:95
QDataStream & operator<<(QDataStream &out, const KDateTime::Spec &spec)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Wed Jul 8 2020 23:01:42 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.