1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2015 The Qt Company Ltd. 4 ** Contact: http://www.qt.io/licensing/ 5 ** 6 ** This file is part of the tools applications of the Qt Toolkit. 7 ** 8 ** $QT_BEGIN_LICENSE:LGPL21$ 9 ** Commercial License Usage 10 ** Licensees holding valid commercial Qt licenses may use this file in 11 ** accordance with the commercial license agreement provided with the 12 ** Software or, alternatively, in accordance with the terms contained in 13 ** a written agreement between you and The Qt Company. For licensing terms 14 ** and conditions see http://www.qt.io/terms-conditions. For further 15 ** information use the contact form at http://www.qt.io/contact-us. 16 ** 17 ** GNU Lesser General Public License Usage 18 ** Alternatively, this file may be used under the terms of the GNU Lesser 19 ** General Public License version 2.1 or version 3 as published by the Free 20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and 21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the 22 ** following information to ensure the GNU Lesser General Public License 23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and 24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 25 ** 26 ** As a special exception, The Qt Company gives you certain additional 27 ** rights. These rights are described in The Qt Company LGPL Exception 28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 29 ** 30 ** $QT_END_LICENSE$ 31 ** 32 ****************************************************************************/ 33 34 35 #ifndef QTVARIANTPROPERTY_H 36 #define QTVARIANTPROPERTY_H 37 38 #include "qtpropertybrowser.h" 39 #include <QtCore/QVariant> 40 #include <QtGui/QIcon> 41 42 QT_BEGIN_NAMESPACE 43 44 typedef QMap<int, QIcon> QtIconMap; 45 46 class QtVariantPropertyManager; 47 class QtVariantPropertyPrivate; 48 49 class QtVariantProperty : public QtProperty 50 { 51 public: 52 ~QtVariantProperty(); 53 QVariant value() const; 54 QVariant attributeValue(const QString &attribute) const; 55 int valueType() const; 56 int propertyType() const; 57 58 void setValue(const QVariant &value); 59 void setAttribute(const QString &attribute, const QVariant &value); 60 protected: 61 QtVariantProperty(QtVariantPropertyManager *manager); 62 private: 63 friend class QtVariantPropertyManager; 64 QtVariantPropertyPrivate *d_ptr; 65 }; 66 67 class QtVariantPropertyManagerPrivate; 68 69 class QtVariantPropertyManager : public QtAbstractPropertyManager 70 { 71 Q_OBJECT 72 public: 73 QtVariantPropertyManager(QObject *parent = 0); 74 ~QtVariantPropertyManager(); 75 76 virtual QtVariantProperty *addProperty(int propertyType, const QString &name = QString()); 77 78 int propertyType(const QtProperty *property) const; 79 int valueType(const QtProperty *property) const; 80 QtVariantProperty *variantProperty(const QtProperty *property) const; 81 82 virtual bool isPropertyTypeSupported(int propertyType) const; 83 virtual int valueType(int propertyType) const; 84 virtual QStringList attributes(int propertyType) const; 85 virtual int attributeType(int propertyType, const QString &attribute) const; 86 87 virtual QVariant value(const QtProperty *property) const; 88 virtual QVariant attributeValue(const QtProperty *property, const QString &attribute) const; 89 90 static int enumTypeId(); 91 static int flagTypeId(); 92 static int groupTypeId(); 93 static int iconMapTypeId(); 94 public Q_SLOTS: 95 virtual void setValue(QtProperty *property, const QVariant &val); 96 virtual void setAttribute(QtProperty *property, 97 const QString &attribute, const QVariant &value); 98 Q_SIGNALS: 99 void valueChanged(QtProperty *property, const QVariant &val); 100 void attributeChanged(QtProperty *property, 101 const QString &attribute, const QVariant &val); 102 protected: 103 virtual bool hasValue(const QtProperty *property) const; 104 QString valueText(const QtProperty *property) const; 105 QIcon valueIcon(const QtProperty *property) const; 106 virtual void initializeProperty(QtProperty *property); 107 virtual void uninitializeProperty(QtProperty *property); 108 virtual QtProperty *createProperty(); 109 private: 110 QtVariantPropertyManagerPrivate *d_ptr; 111 Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, int)) 112 Q_PRIVATE_SLOT(d_func(), void slotRangeChanged(QtProperty *, int, int)) 113 Q_PRIVATE_SLOT(d_func(), void slotSingleStepChanged(QtProperty *, int)) 114 Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, double)) 115 Q_PRIVATE_SLOT(d_func(), void slotRangeChanged(QtProperty *, double, double)) 116 Q_PRIVATE_SLOT(d_func(), void slotSingleStepChanged(QtProperty *, double)) 117 Q_PRIVATE_SLOT(d_func(), void slotDecimalsChanged(QtProperty *, int)) 118 Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, bool)) 119 Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QString &)) 120 Q_PRIVATE_SLOT(d_func(), void slotRegExpChanged(QtProperty *, const QRegExp &)) 121 Q_PRIVATE_SLOT(d_func(), void slotEchoModeChanged(QtProperty *, int)) 122 Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QDate &)) 123 Q_PRIVATE_SLOT(d_func(), void slotRangeChanged(QtProperty *, const QDate &, const QDate &)) 124 Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QTime &)) 125 Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QDateTime &)) 126 Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QKeySequence &)) 127 Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QChar &)) 128 Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QLocale &)) 129 Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QPoint &)) 130 Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QPointF &)) 131 Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QSize &)) 132 Q_PRIVATE_SLOT(d_func(), void slotRangeChanged(QtProperty *, const QSize &, const QSize &)) 133 Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QSizeF &)) 134 Q_PRIVATE_SLOT(d_func(), void slotRangeChanged(QtProperty *, const QSizeF &, const QSizeF &)) 135 Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QRect &)) 136 Q_PRIVATE_SLOT(d_func(), void slotConstraintChanged(QtProperty *, const QRect &)) 137 Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QRectF &)) 138 Q_PRIVATE_SLOT(d_func(), void slotConstraintChanged(QtProperty *, const QRectF &)) 139 Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QColor &)) 140 Q_PRIVATE_SLOT(d_func(), void slotEnumNamesChanged(QtProperty *, const QStringList &)) 141 Q_PRIVATE_SLOT(d_func(), void slotEnumIconsChanged(QtProperty *, const QMap<int, QIcon> &)) 142 Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QSizePolicy &)) 143 Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QFont &)) 144 Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QCursor &)) 145 Q_PRIVATE_SLOT(d_func(), void slotFlagNamesChanged(QtProperty *, const QStringList &)) 146 Q_PRIVATE_SLOT(d_func(), void slotReadOnlyChanged(QtProperty *, bool)) 147 Q_PRIVATE_SLOT(d_func(), void slotTextVisibleChanged(QtProperty *, bool)) 148 Q_PRIVATE_SLOT(d_func(), void slotPropertyInserted(QtProperty *, QtProperty *, QtProperty *)) 149 Q_PRIVATE_SLOT(d_func(), void slotPropertyRemoved(QtProperty *, QtProperty *)) 150 Q_DECLARE_PRIVATE(QtVariantPropertyManager) 151 Q_DISABLE_COPY(QtVariantPropertyManager) 152 }; 153 154 class QtVariantEditorFactoryPrivate; 155 156 class QtVariantEditorFactory : public QtAbstractEditorFactory<QtVariantPropertyManager> 157 { 158 Q_OBJECT 159 public: 160 QtVariantEditorFactory(QObject *parent = 0); 161 ~QtVariantEditorFactory(); 162 protected: 163 void connectPropertyManager(QtVariantPropertyManager *manager); 164 QWidget *createEditor(QtVariantPropertyManager *manager, QtProperty *property, 165 QWidget *parent); 166 void disconnectPropertyManager(QtVariantPropertyManager *manager); 167 private: 168 QtVariantEditorFactoryPrivate *d_ptr; 169 Q_DECLARE_PRIVATE(QtVariantEditorFactory) 170 Q_DISABLE_COPY(QtVariantEditorFactory) 171 }; 172 173 QT_END_NAMESPACE 174 175 Q_DECLARE_METATYPE(QIcon) 176 Q_DECLARE_METATYPE(QtIconMap) 177 #endif 178