Changeset View
Changeset View
Standalone View
Standalone View
src/KPropertyFactory.h
Show All 19 Lines | |||||
20 | #ifndef KPROPERTY_FACTORY_H | 20 | #ifndef KPROPERTY_FACTORY_H | ||
21 | #define KPROPERTY_FACTORY_H | 21 | #define KPROPERTY_FACTORY_H | ||
22 | 22 | | |||
23 | #include "KProperty.h" | 23 | #include "KProperty.h" | ||
24 | 24 | | |||
25 | #include <QObject> | 25 | #include <QObject> | ||
26 | #include <QVariant> | 26 | #include <QVariant> | ||
27 | #include <QHash> | 27 | #include <QHash> | ||
28 | | ||||
29 | #ifdef KPROPERTY_WIDGET | ||||
28 | #include <QLabel> | 30 | #include <QLabel> | ||
29 | #include <QPainter> | 31 | #include <QPainter> | ||
30 | #include <QStyleOptionViewItem> | 32 | #include <QStyleOptionViewItem> | ||
33 | #endif | ||||
31 | 34 | | |||
32 | //! An interface for for composed property handlers | 35 | //! An interface for for composed property handlers | ||
33 | /*! You have to subclass KComposedPropertyInterface to override the behaviour of a property type.\n | 36 | /*! You have to subclass KComposedPropertyInterface to override the behaviour of a property type.\n | ||
34 | In the constructor, you should create the child properties (if needed). | 37 | In the constructor, you should create the child properties (if needed). | ||
35 | Then, you need to implement the functions concerning values.\n | 38 | Then, you need to implement the functions concerning values.\n | ||
36 | 39 | | |||
37 | Example implementation of composed properties can be found in editors/ directory. | 40 | Example implementation of composed properties can be found in editors/ directory. | ||
38 | */ | 41 | */ | ||
Show All 32 Lines | |||||
71 | public: | 74 | public: | ||
72 | KComposedPropertyCreatorInterface(); | 75 | KComposedPropertyCreatorInterface(); | ||
73 | 76 | | |||
74 | virtual ~KComposedPropertyCreatorInterface(); | 77 | virtual ~KComposedPropertyCreatorInterface(); | ||
75 | 78 | | |||
76 | virtual KComposedPropertyInterface* createComposedProperty(KProperty *parent) const = 0; | 79 | virtual KComposedPropertyInterface* createComposedProperty(KProperty *parent) const = 0; | ||
77 | }; | 80 | }; | ||
78 | 81 | | |||
82 | #ifdef KPROPERTY_WIDGET | ||||
79 | //! An interface for editor widget creators. | 83 | //! An interface for editor widget creators. | ||
80 | /*! Options can be set in the options attribute in order to customize | 84 | /*! Options can be set in the options attribute in order to customize | ||
81 | widget creation process. Do this in the EditorCreatorInterface constructor. | 85 | widget creation process. Do this in the EditorCreatorInterface constructor. | ||
82 | */ | 86 | */ | ||
83 | class KPROPERTY_EXPORT KPropertyEditorCreatorInterface | 87 | class KPROPERTY_EXPORT KPropertyEditorCreatorInterface | ||
84 | { | 88 | { | ||
85 | public: | 89 | public: | ||
86 | KPropertyEditorCreatorInterface(); | 90 | KPropertyEditorCreatorInterface(); | ||
Show All 33 Lines | 123 | public: | |||
120 | KPropertyValueDisplayInterface(); | 124 | KPropertyValueDisplayInterface(); | ||
121 | virtual ~KPropertyValueDisplayInterface(); | 125 | virtual ~KPropertyValueDisplayInterface(); | ||
122 | virtual QString displayTextForProperty( const KProperty* property ) const | 126 | virtual QString displayTextForProperty( const KProperty* property ) const | ||
123 | { return displayText(property->value()); } | 127 | { return displayText(property->value()); } | ||
124 | virtual QString displayText( const QVariant& value ) const | 128 | virtual QString displayText( const QVariant& value ) const | ||
125 | { return value.toString(); } | 129 | { return value.toString(); } | ||
126 | }; | 130 | }; | ||
127 | 131 | | |||
132 | | ||||
128 | //! Label widget that can be used for displaying text-based read-only items | 133 | //! Label widget that can be used for displaying text-based read-only items | ||
129 | //! Used in LabelCreator. | 134 | //! Used in LabelCreator. | ||
130 | class KPROPERTY_EXPORT KPropertyLabel : public QLabel | 135 | class KPROPERTY_EXPORT KPropertyLabel : public QLabel | ||
131 | { | 136 | { | ||
132 | Q_OBJECT | 137 | Q_OBJECT | ||
133 | Q_PROPERTY(QVariant value READ value WRITE setValue USER true) | 138 | Q_PROPERTY(QVariant value READ value WRITE setValue USER true) | ||
134 | public: | 139 | public: | ||
135 | KPropertyLabel(QWidget *parent, const KPropertyValueDisplayInterface *iface); | 140 | KPropertyLabel(QWidget *parent, const KPropertyValueDisplayInterface *iface); | ||
Show All 39 Lines | 177 | { | |||
175 | r.setLeft(r.left()+1); | 180 | r.setLeft(r.left()+1); | ||
176 | painter->drawText( r, Qt::AlignLeft | Qt::AlignVCenter, | 181 | painter->drawText( r, Qt::AlignLeft | Qt::AlignVCenter, | ||
177 | displayText( index.data(Qt::EditRole) ) ); | 182 | displayText( index.data(Qt::EditRole) ) ); | ||
178 | painter->restore(); | 183 | painter->restore(); | ||
179 | } | 184 | } | ||
180 | }; | 185 | }; | ||
181 | 186 | | |||
182 | typedef KPropertyEditorCreator<KPropertyLabel> KPropertyLabelCreator; | 187 | typedef KPropertyEditorCreator<KPropertyLabel> KPropertyLabelCreator; | ||
188 | #endif | ||||
183 | 189 | | |||
184 | //! Creator returning composed property object | 190 | //! Creator returning composed property object | ||
185 | template<class ComposedProperty> | 191 | template<class ComposedProperty> | ||
186 | class KPROPERTY_EXPORT KComposedPropertyCreator : public KComposedPropertyCreatorInterface | 192 | class KPROPERTY_EXPORT KComposedPropertyCreator : public KComposedPropertyCreatorInterface | ||
187 | { | 193 | { | ||
188 | public: | 194 | public: | ||
189 | KComposedPropertyCreator() : KComposedPropertyCreatorInterface() {} | 195 | KComposedPropertyCreator() : KComposedPropertyCreatorInterface() {} | ||
190 | 196 | | |||
191 | virtual ~KComposedPropertyCreator() {} | 197 | virtual ~KComposedPropertyCreator() {} | ||
192 | 198 | | |||
193 | virtual ComposedProperty* createComposedProperty(KProperty *parent) const { | 199 | virtual ComposedProperty* createComposedProperty(KProperty *parent) const { | ||
194 | return new ComposedProperty(parent); | 200 | return new ComposedProperty(parent); | ||
195 | } | 201 | } | ||
196 | }; | 202 | }; | ||
197 | 203 | | |||
198 | class KPROPERTY_EXPORT KPropertyFactory | 204 | class KPROPERTY_EXPORT KPropertyFactory | ||
199 | { | 205 | { | ||
200 | public: | 206 | public: | ||
201 | KPropertyFactory(); | 207 | KPropertyFactory(); | ||
202 | virtual ~KPropertyFactory(); | 208 | virtual ~KPropertyFactory(); | ||
203 | QHash<int, KComposedPropertyCreatorInterface*> composedPropertyCreators() const; | 209 | QHash<int, KComposedPropertyCreatorInterface*> composedPropertyCreators() const; | ||
210 | void addComposedPropertyCreator( int type, KComposedPropertyCreatorInterface* creator ); | ||||
211 | | ||||
212 | #ifdef KPROPERTY_WIDGET | ||||
204 | QHash<int, KPropertyEditorCreatorInterface*> editorCreators() const; | 213 | QHash<int, KPropertyEditorCreatorInterface*> editorCreators() const; | ||
205 | QHash<int, KPropertyValuePainterInterface*> valuePainters() const; | 214 | QHash<int, KPropertyValuePainterInterface*> valuePainters() const; | ||
206 | QHash<int, KPropertyValueDisplayInterface*> valueDisplays() const; | 215 | QHash<int, KPropertyValueDisplayInterface*> valueDisplays() const; | ||
207 | 216 | | |||
208 | //! Adds editor creator @a creator for type @a type. | 217 | //! Adds editor creator @a creator for type @a type. | ||
209 | //! The creator becomes owned by the factory. | 218 | //! The creator becomes owned by the factory. | ||
210 | void addEditor(int type, KPropertyEditorCreatorInterface *creator); | 219 | void addEditor(int type, KPropertyEditorCreatorInterface *creator); | ||
211 | 220 | | |||
212 | void addComposedPropertyCreator( int type, KComposedPropertyCreatorInterface* creator ); | | |||
213 | | ||||
214 | void addPainter(int type, KPropertyValuePainterInterface *painter); | 221 | void addPainter(int type, KPropertyValuePainterInterface *painter); | ||
215 | 222 | | |||
216 | void addDisplay(int type, KPropertyValueDisplayInterface *display); | 223 | void addDisplay(int type, KPropertyValueDisplayInterface *display); | ||
217 | 224 | | |||
218 | static void paintTopGridLine(QWidget *widget); | 225 | static void paintTopGridLine(QWidget *widget); | ||
219 | static void setTopAndBottomBordersUsingStyleSheet(QWidget *widget, QWidget* parent, | 226 | static void setTopAndBottomBordersUsingStyleSheet(QWidget *widget, QWidget* parent, | ||
220 | const QString& extraStyleSheet = QString()); | 227 | const QString& extraStyleSheet = QString()); | ||
221 | 228 | #endif | |||
222 | protected: | 229 | protected: | ||
223 | void addEditorInternal(int type, KPropertyEditorCreatorInterface *editor, bool own = true); | | |||
224 | | ||||
225 | void addComposedPropertyCreatorInternal(int type, | 230 | void addComposedPropertyCreatorInternal(int type, | ||
226 | KComposedPropertyCreatorInterface* creator, bool own = true); | 231 | KComposedPropertyCreatorInterface* creator, bool own = true); | ||
232 | #ifdef KPROPERTY_WIDGET | ||||
233 | void addEditorInternal(int type, KPropertyEditorCreatorInterface *editor, bool own = true); | ||||
227 | 234 | | |||
228 | //! Adds value painter @a painter for type @a type. | 235 | //! Adds value painter @a painter for type @a type. | ||
229 | //! The painter becomes owned by the factory. | 236 | //! The painter becomes owned by the factory. | ||
230 | void addPainterInternal(int type, KPropertyValuePainterInterface *painter, bool own = true); | 237 | void addPainterInternal(int type, KPropertyValuePainterInterface *painter, bool own = true); | ||
231 | 238 | | |||
232 | //! Adds value-to-text converted @a painter for type @a type. | 239 | //! Adds value-to-text converted @a painter for type @a type. | ||
233 | //! The converter becomes owned by the factory. | 240 | //! The converter becomes owned by the factory. | ||
234 | void addDisplayInternal(int type, KPropertyValueDisplayInterface *display, bool own = true); | 241 | void addDisplayInternal(int type, KPropertyValueDisplayInterface *display, bool own = true); | ||
242 | #endif | ||||
235 | 243 | | |||
236 | class Private; | 244 | class Private; | ||
237 | Private * const d; | 245 | Private * const d; | ||
238 | }; | 246 | }; | ||
239 | 247 | | |||
240 | class KProperty; | 248 | class KProperty; | ||
241 | class KCustomProperty; | 249 | class KCustomProperty; | ||
242 | 250 | | |||
243 | class KPROPERTY_EXPORT KPropertyFactoryManager : public QObject | 251 | class KPROPERTY_EXPORT KPropertyFactoryManager : public QObject | ||
244 | { | 252 | { | ||
245 | Q_OBJECT | 253 | Q_OBJECT | ||
246 | public: | 254 | public: | ||
247 | bool isEditorForTypeAvailable( int type ) const; | 255 | bool isEditorForTypeAvailable( int type ) const; | ||
248 | 256 | | |||
257 | #ifdef KPROPERTY_WIDGET | ||||
249 | QWidget * createEditor( | 258 | QWidget * createEditor( | ||
250 | int type, | 259 | int type, | ||
251 | QWidget *parent, | 260 | QWidget *parent, | ||
252 | const QStyleOptionViewItem & option, | 261 | const QStyleOptionViewItem & option, | ||
253 | const QModelIndex & index ) const; | 262 | const QModelIndex & index ) const; | ||
254 | 263 | | |||
255 | bool paint( int type, | 264 | bool paint( int type, | ||
256 | QPainter * painter, | 265 | QPainter * painter, | ||
257 | const QStyleOptionViewItem & option, | 266 | const QStyleOptionViewItem & option, | ||
258 | const QModelIndex & index ) const; | 267 | const QModelIndex & index ) const; | ||
268 | #endif | ||||
259 | 269 | | |||
260 | KComposedPropertyInterface* createComposedProperty(KProperty *parent); | 270 | KComposedPropertyInterface* createComposedProperty(KProperty *parent); | ||
261 | 271 | | |||
262 | bool canConvertValueToText( int type ) const; | 272 | bool canConvertValueToText( int type ) const; | ||
263 | 273 | | |||
264 | bool canConvertValueToText( const KProperty* property ) const; | 274 | bool canConvertValueToText( const KProperty* property ) const; | ||
265 | 275 | | |||
266 | QString convertValueToText( const KProperty* property ) const; | 276 | QString convertValueToText( const KProperty* property ) const; | ||
Show All 18 Lines |