qtvariantproperty.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the Qt Solutions component.
7 **
8 ** $QT_BEGIN_LICENSE:BSD$
9 ** You may use this file under the terms of the BSD license as follows:
10 **
11 ** "Redistribution and use in source and binary forms, with or without
12 ** modification, are permitted provided that the following conditions are
13 ** met:
14 ** * Redistributions of source code must retain the above copyright
15 ** notice, this list of conditions and the following disclaimer.
16 ** * Redistributions in binary form must reproduce the above copyright
17 ** notice, this list of conditions and the following disclaimer in
18 ** the documentation and/or other materials provided with the
19 ** distribution.
20 ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
21 ** of its contributors may be used to endorse or promote products derived
22 ** from this software without specific prior written permission.
23 **
24 **
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36 **
37 ** $QT_END_LICENSE$
38 **
39 ****************************************************************************/
40 
41 
42 #pragma once
43 
44 #include "qtpropertybrowser.h"
45 #include <QVariant>
46 #include <QIcon>
47 
48 QT_BEGIN_NAMESPACE
49 
50 using QtIconMap = QMap<int, QIcon>;
51 
54 
56 {
57 public:
58  ~QtVariantProperty() override;
59  QVariant value() const;
60  QVariant attributeValue(const QString& attribute) const;
61  int valueType() const;
62  int propertyType() const;
63 
64  void setValue(const QVariant& value);
65  void setAttribute(const QString& attribute, const QVariant& value);
66 protected:
68 private:
71 };
72 
74 
76 {
77  Q_OBJECT
78 public:
79  QtVariantPropertyManager(QObject* parent = 0);
80  ~QtVariantPropertyManager() override;
81 
82  virtual QtVariantProperty* addProperty(int propertyType, const QString& name = QString());
83 
84  int propertyType(const QtProperty* property) const;
85  int valueType(const QtProperty* property) const;
86  QtVariantProperty* variantProperty(const QtProperty* property) const;
87 
88  virtual bool isPropertyTypeSupported(int propertyType) const;
89  virtual int valueType(int propertyType) const;
90  virtual QStringList attributes(int propertyType) const;
91  virtual int attributeType(int propertyType, const QString& attribute) const;
92 
93  virtual QVariant value(const QtProperty* property) const;
94  virtual QVariant attributeValue(const QtProperty* property, const QString& attribute) const;
95 
96  static int enumTypeId();
97  static int flagTypeId();
98  static int groupTypeId();
99  static int iconMapTypeId();
100 public Q_SLOTS:
101  virtual void setValue(QtProperty* property, const QVariant& val);
102  virtual void setAttribute(QtProperty* property,
103  const QString& attribute, const QVariant& value);
104 Q_SIGNALS:
105  void valueChanged(QtProperty* property, const QVariant& val);
106  void attributeChanged(QtProperty* property,
107  const QString& attribute, const QVariant& val);
108 protected:
109  bool hasValue(const QtProperty* property) const override;
110  QString valueText(const QtProperty* property) const override;
111  QIcon valueIcon(const QtProperty* property) const override;
112  void initializeProperty(QtProperty* property) override;
113  void uninitializeProperty(QtProperty* property) override;
114  QtProperty* createProperty() override;
115 private:
117  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty*, int))
118  Q_PRIVATE_SLOT(d_func(), void slotRangeChanged(QtProperty*, int, int))
119  Q_PRIVATE_SLOT(d_func(), void slotSingleStepChanged(QtProperty*, int))
120  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty*, double))
121  Q_PRIVATE_SLOT(d_func(), void slotRangeChanged(QtProperty*, double, double))
122  Q_PRIVATE_SLOT(d_func(), void slotSingleStepChanged(QtProperty*, double))
123  Q_PRIVATE_SLOT(d_func(), void slotDecimalsChanged(QtProperty*, int))
124  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty*, bool))
125  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty*, const QString&))
126  Q_PRIVATE_SLOT(d_func(), void slotRegExpChanged(QtProperty*, const QRegExp&))
127  Q_PRIVATE_SLOT(d_func(), void slotEchoModeChanged(QtProperty*, int))
128  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty*, const QDate&))
129  Q_PRIVATE_SLOT(d_func(), void slotRangeChanged(QtProperty*, const QDate&, const QDate&))
130  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty*, const QTime&))
131  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty*, const QDateTime&))
132  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty*, const QKeySequence&))
133  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty*, const QChar&))
134  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty*, const QLocale&))
135  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty*, const QPoint&))
136  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty*, const QPointF&))
137  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty*, const QSize&))
138  Q_PRIVATE_SLOT(d_func(), void slotRangeChanged(QtProperty*, const QSize&, const QSize&))
139  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty*, const QSizeF&))
140  Q_PRIVATE_SLOT(d_func(), void slotRangeChanged(QtProperty*, const QSizeF&, const QSizeF&))
141  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty*, const QRect&))
142  Q_PRIVATE_SLOT(d_func(), void slotConstraintChanged(QtProperty*, const QRect&))
143  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty*, const QRectF&))
144  Q_PRIVATE_SLOT(d_func(), void slotConstraintChanged(QtProperty*, const QRectF&))
145  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty*, const QColor&))
146  Q_PRIVATE_SLOT(d_func(), void slotEnumNamesChanged(QtProperty*, const QStringList&))
147  Q_PRIVATE_SLOT(d_func(), void slotEnumIconsChanged(QtProperty*, const QMap<int, QIcon>&))
148  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty*, const QSizePolicy&))
149  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty*, const QFont&))
150  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty*, const QCursor&))
151  Q_PRIVATE_SLOT(d_func(), void slotFlagNamesChanged(QtProperty*, const QStringList&))
152  Q_PRIVATE_SLOT(d_func(), void slotReadOnlyChanged(QtProperty*, bool))
153  Q_PRIVATE_SLOT(d_func(), void slotTextVisibleChanged(QtProperty*, bool))
154  Q_PRIVATE_SLOT(d_func(), void slotPropertyInserted(QtProperty*, QtProperty*, QtProperty*))
155  Q_PRIVATE_SLOT(d_func(), void slotPropertyRemoved(QtProperty*, QtProperty*))
156  Q_DECLARE_PRIVATE(QtVariantPropertyManager)
157  Q_DISABLE_COPY(QtVariantPropertyManager)
158 };
159 
161 
163 {
164  Q_OBJECT
165 public:
166  QtVariantEditorFactory(QObject* parent = 0);
167  ~QtVariantEditorFactory() override;
168 protected:
169  void connectPropertyManager(QtVariantPropertyManager* manager) override;
170  QWidget* createEditor(QtVariantPropertyManager* manager, QtProperty* property,
171  QWidget* parent) override;
172  void disconnectPropertyManager(QtVariantPropertyManager* manager) override;
173 private:
175  Q_DECLARE_PRIVATE(QtVariantEditorFactory)
176  Q_DISABLE_COPY(QtVariantEditorFactory)
177 };
178 
179 QT_END_NAMESPACE
180 
181 Q_DECLARE_METATYPE(QIcon)
182 Q_DECLARE_METATYPE(QtIconMap)
QtAbstractEditorFactory::disconnectPropertyManager
virtual void disconnectPropertyManager(PropertyManager *manager)=0
QtAbstractPropertyManager::createProperty
virtual QtProperty * createProperty()
Definition: qtpropertybrowser.cpp:849
QtAbstractPropertyManager::addProperty
QtProperty * addProperty(const QString &name=QString())
Definition: qtpropertybrowser.cpp:826
QtAbstractEditorFactory::createEditor
QWidget * createEditor(QtProperty *property, QWidget *parent) override
Definition: qtpropertybrowser.h:168
QT_QTPROPERTYBROWSER_EXPORT
#define QT_QTPROPERTYBROWSER_EXPORT
Definition: qtpropertybrowser.h:63
QtAbstractPropertyManager::hasValue
virtual bool hasValue(const QtProperty *property) const
Definition: qtpropertybrowser.cpp:753
QtVariantPropertyManager
The QtVariantPropertyManager class provides and manages QVariant based properties.
Definition: qtvariantproperty.h:75
QtVariantPropertyPrivate
Definition: qtvariantproperty.cpp:141
QtProperty
The QtProperty class encapsulates an instance of a property.
Definition: qtpropertybrowser.h:71
qtpropertybrowser.h
QtVariantEditorFactoryPrivate
Definition: qtvariantproperty.cpp:2368
QtVariantProperty
The QtVariantProperty class is a convenience class handling QVariant based properties.
Definition: qtvariantproperty.h:55
QtAbstractEditorFactory::connectPropertyManager
virtual void connectPropertyManager(PropertyManager *manager)=0
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
QtAbstractEditorFactory
The QtAbstractEditorFactory is the base template class for editor factories.
Definition: qtpropertybrowser.h:164
QtVariantPropertyManagerPrivate
Definition: qtvariantproperty.cpp:291
QtVariantEditorFactory
The QtVariantEditorFactory class provides widgets for properties created by QtVariantPropertyManager ...
Definition: qtvariantproperty.h:162
QtAbstractPropertyManager
The QtAbstractPropertyManager provides an interface for property managers.
Definition: qtpropertybrowser.h:112
QtAbstractPropertyManager::valueText
virtual QString valueText(const QtProperty *property) const
Definition: qtpropertybrowser.cpp:783
QtIconMap
QMap< int, QIcon > QtIconMap
Definition: qtvariantproperty.h:50
QtAbstractPropertyManager::initializeProperty
virtual void initializeProperty(QtProperty *property)=0
QtAbstractPropertyManager::uninitializeProperty
virtual void uninitializeProperty(QtProperty *property)
Definition: qtpropertybrowser.cpp:882
QtAbstractPropertyManager::valueIcon
virtual QIcon valueIcon(const QtProperty *property) const
Definition: qtpropertybrowser.cpp:768