KProperty

KPropertyFactory.h
1 /* This file is part of the KDE project
2  Copyright (C) 2008-2015 Jarosław Staniek <[email protected]>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18 */
19 
20 #ifndef KPROPERTY_FACTORY_H
21 #define KPROPERTY_FACTORY_H
22 
23 #include "KProperty.h"
24 
26 
32 class KPROPERTYCORE_EXPORT KComposedPropertyInterface
33 {
34 public:
35  explicit KComposedPropertyInterface(KProperty *parent);
36  virtual ~KComposedPropertyInterface();
37 
47  virtual void setValue(KProperty *property, const QVariant &value, KProperty::ValueOptions valueOptions) = 0;
48 
49  void childValueChangedInternal(KProperty *child, const QVariant &value, KProperty::ValueOptions valueOptions);
50 
51  bool childValueChangedEnabled() const;
52 
53  void setChildValueChangedEnabled(bool set);
54 
58  inline virtual bool valuesEqual(const QVariant &first, const QVariant &second) { return first == second; }
59 
60 protected:
61  virtual void childValueChanged(KProperty *child, const QVariant &value, KProperty::ValueOptions valueOptions) = 0;
62 
65  void emitPropertyChanged();
66 
67 private:
68  Q_DISABLE_COPY(KComposedPropertyInterface)
69  class Private;
70  Private * const d;
71 };
72 
73 class KPROPERTYCORE_EXPORT KComposedPropertyCreatorInterface
74 {
75 public:
76  KComposedPropertyCreatorInterface();
77 
78  virtual ~KComposedPropertyCreatorInterface();
79 
80  virtual KComposedPropertyInterface* createComposedProperty(KProperty *parent) const = 0;
81 
82 private:
83  Q_DISABLE_COPY(KComposedPropertyCreatorInterface)
84  class Private;
85  Private * const d;
86 };
87 
89 template<class ComposedProperty>
90 class KComposedPropertyCreator : public KComposedPropertyCreatorInterface
91 {
92 public:
93  KComposedPropertyCreator() : KComposedPropertyCreatorInterface() {}
94 
95  ~KComposedPropertyCreator() override {}
96 
97  ComposedProperty* createComposedProperty(KProperty *parent) const override {
98  return new ComposedProperty(parent);
99  }
100 
101  Q_DISABLE_COPY(KComposedPropertyCreator)
102 };
103 
105 class KPROPERTYCORE_EXPORT KPropertyValueDisplayInterface
106 {
107 public:
109 
111 
112  virtual QString propertyValueToString(const KProperty* property, const QLocale &locale) const
113  { return valueToString(property->value(), locale); }
114 
115  virtual QString valueToString(const QVariant& value, const QLocale &locale) const = 0;
116 
121  static int maxStringValueLength();
122 
125  static QString valueToLocalizedString(const QVariant& value);
126 
127 private:
128  Q_DISABLE_COPY(KPropertyValueDisplayInterface)
129  class Private;
130  Private * const d;
131 };
132 
133 class KPROPERTYCORE_EXPORT KPropertyFactory
134 {
135 public:
136  KPropertyFactory();
137 
138  virtual ~KPropertyFactory();
139 
140  QHash<int, KComposedPropertyCreatorInterface*> composedPropertyCreators() const;
141  QHash<int, KPropertyValueDisplayInterface*> valueDisplays() const;
142 
143  void addComposedPropertyCreator(int type, KComposedPropertyCreatorInterface* creator);
144 
145  void addDisplay(int type, KPropertyValueDisplayInterface *display);
146 
147 protected:
148  void addComposedPropertyCreatorInternal(int type,
149  KComposedPropertyCreatorInterface* creator, bool own = true);
150 
153  void addDisplayInternal(int type, KPropertyValueDisplayInterface *display, bool own = true);
154 
155  Q_DISABLE_COPY(KPropertyFactory)
156  class Private;
157  Private * const d;
158 };
159 
160 class KPROPERTYCORE_EXPORT KPropertyFactoryManager : public QObject
161 {
162  Q_OBJECT
163 public:
164  KComposedPropertyInterface* createComposedProperty(KProperty *parent);
165 
167  void registerFactory(KPropertyFactory *factory);
168 
170  static KPropertyFactoryManager* self();
171 
172  bool canConvertValueToText(int type) const;
173 
174  bool canConvertValueToText(const KProperty* property) const;
175 
176  QString propertyValueToString(const KProperty* property) const;
177 
178  QString valueToString(int type, const QVariant &value) const;
179 
180  QString propertyValueToLocalizedString(const KProperty* property) const;
181 
182  QString valueToLocalizedString(int type, const QVariant &value) const;
183 
184  KPropertyFactoryManager();
185  ~KPropertyFactoryManager() override;
186 
189  static void addInitFunction(void (*initFunction)());
190 
191 private:
192  Q_DISABLE_COPY(KPropertyFactoryManager)
193  class Private;
194  Private * const d;
195 };
196 
197 #endif
virtual bool valuesEqual(const QVariant &first, const QVariant &second)
An interface for for composed property handlers.
The base class representing a single property.
Definition: KProperty.h:95
QVariant value() const
Definition: KProperty.cpp:394
Creator returning composed property object.
Provides a specialized conversion of value to string depending on type.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Nov 26 2020 23:01:37 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.