qtvariantproperty.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2016 The Qt Company Ltd.
  4. ** Contact: https://www.qt.io/licensing/
  5. **
  6. ** This file is part of the tools applications of the Qt Toolkit.
  7. **
  8. ** $QT_BEGIN_LICENSE:LGPL$
  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 https://www.qt.io/terms-conditions. For further
  15. ** information use the contact form at https://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 3 as published by the Free Software
  20. ** Foundation and appearing in the file LICENSE.LGPL3 included in the
  21. ** packaging of this file. Please review the following information to
  22. ** ensure the GNU Lesser General Public License version 3 requirements
  23. ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
  24. **
  25. ** GNU General Public License Usage
  26. ** Alternatively, this file may be used under the terms of the GNU
  27. ** General Public License version 2.0 or (at your option) the GNU General
  28. ** Public license version 3 or any later version approved by the KDE Free
  29. ** Qt Foundation. The licenses are as published by the Free Software
  30. ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
  31. ** included in the packaging of this file. Please review the following
  32. ** information to ensure the GNU General Public License requirements will
  33. ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
  34. ** https://www.gnu.org/licenses/gpl-3.0.html.
  35. **
  36. ** $QT_END_LICENSE$
  37. **
  38. ****************************************************************************/
  39. #ifndef QTVARIANTPROPERTY_H
  40. #define QTVARIANTPROPERTY_H
  41. #include "qtpropertybrowser.h"
  42. #include <QtCore/QVariant>
  43. #include <QtGui/QIcon>
  44. QT_BEGIN_NAMESPACE
  45. typedef QMap<int, QIcon> QtIconMap;
  46. class QtVariantPropertyManager;
  47. class QtVariantProperty : public QtProperty
  48. {
  49. public:
  50. ~QtVariantProperty();
  51. QVariant value() const;
  52. QVariant attributeValue(const QString &attribute) const;
  53. int valueType() const;
  54. int propertyType() const;
  55. void setValue(const QVariant &value);
  56. void setAttribute(const QString &attribute, const QVariant &value);
  57. protected:
  58. QtVariantProperty(QtVariantPropertyManager *manager);
  59. private:
  60. friend class QtVariantPropertyManager;
  61. QScopedPointer<class QtVariantPropertyPrivate> d_ptr;
  62. };
  63. class QtVariantPropertyManager : public QtAbstractPropertyManager
  64. {
  65. Q_OBJECT
  66. public:
  67. QtVariantPropertyManager(QObject *parent = 0);
  68. ~QtVariantPropertyManager();
  69. virtual QtVariantProperty *addProperty(int propertyType, const QString &name = QString());
  70. int propertyType(const QtProperty *property) const;
  71. int valueType(const QtProperty *property) const;
  72. QtVariantProperty *variantProperty(const QtProperty *property) const;
  73. virtual bool isPropertyTypeSupported(int propertyType) const;
  74. virtual int valueType(int propertyType) const;
  75. virtual QStringList attributes(int propertyType) const;
  76. virtual int attributeType(int propertyType, const QString &attribute) const;
  77. virtual QVariant value(const QtProperty *property) const;
  78. virtual QVariant attributeValue(const QtProperty *property, const QString &attribute) const;
  79. static int enumTypeId();
  80. static int flagTypeId();
  81. static int groupTypeId();
  82. static int iconMapTypeId();
  83. public Q_SLOTS:
  84. virtual void setValue(QtProperty *property, const QVariant &val);
  85. virtual void setAttribute(QtProperty *property,
  86. const QString &attribute, const QVariant &value);
  87. Q_SIGNALS:
  88. void valueChanged(QtProperty *property, const QVariant &val);
  89. void attributeChanged(QtProperty *property,
  90. const QString &attribute, const QVariant &val);
  91. protected:
  92. virtual bool hasValue(const QtProperty *property) const;
  93. QString valueText(const QtProperty *property) const;
  94. QIcon valueIcon(const QtProperty *property) const;
  95. virtual void initializeProperty(QtProperty *property);
  96. virtual void uninitializeProperty(QtProperty *property);
  97. virtual QtProperty *createProperty();
  98. private:
  99. QScopedPointer<class QtVariantPropertyManagerPrivate> d_ptr;
  100. Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, int))
  101. Q_PRIVATE_SLOT(d_func(), void slotRangeChanged(QtProperty *, int, int))
  102. Q_PRIVATE_SLOT(d_func(), void slotSingleStepChanged(QtProperty *, int))
  103. Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, double))
  104. Q_PRIVATE_SLOT(d_func(), void slotRangeChanged(QtProperty *, double, double))
  105. Q_PRIVATE_SLOT(d_func(), void slotSingleStepChanged(QtProperty *, double))
  106. Q_PRIVATE_SLOT(d_func(), void slotDecimalsChanged(QtProperty *, int))
  107. Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, bool))
  108. Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QString &))
  109. Q_PRIVATE_SLOT(d_func(), void slotRegExpChanged(QtProperty *, const QRegExp &))
  110. Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QDate &))
  111. Q_PRIVATE_SLOT(d_func(), void slotRangeChanged(QtProperty *, const QDate &, const QDate &))
  112. Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QTime &))
  113. Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QDateTime &))
  114. Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QKeySequence &))
  115. Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QChar &))
  116. Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QLocale &))
  117. Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QPoint &))
  118. Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QPointF &))
  119. Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QSize &))
  120. Q_PRIVATE_SLOT(d_func(), void slotRangeChanged(QtProperty *, const QSize &, const QSize &))
  121. Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QSizeF &))
  122. Q_PRIVATE_SLOT(d_func(), void slotRangeChanged(QtProperty *, const QSizeF &, const QSizeF &))
  123. Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QRect &))
  124. Q_PRIVATE_SLOT(d_func(), void slotConstraintChanged(QtProperty *, const QRect &))
  125. Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QRectF &))
  126. Q_PRIVATE_SLOT(d_func(), void slotConstraintChanged(QtProperty *, const QRectF &))
  127. Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QColor &))
  128. Q_PRIVATE_SLOT(d_func(), void slotEnumNamesChanged(QtProperty *, const QStringList &))
  129. Q_PRIVATE_SLOT(d_func(), void slotEnumIconsChanged(QtProperty *, const QMap<int, QIcon> &))
  130. Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QSizePolicy &))
  131. Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QFont &))
  132. Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QCursor &))
  133. Q_PRIVATE_SLOT(d_func(), void slotFlagNamesChanged(QtProperty *, const QStringList &))
  134. Q_PRIVATE_SLOT(d_func(), void slotPropertyInserted(QtProperty *, QtProperty *, QtProperty *))
  135. Q_PRIVATE_SLOT(d_func(), void slotPropertyRemoved(QtProperty *, QtProperty *))
  136. Q_DECLARE_PRIVATE(QtVariantPropertyManager)
  137. Q_DISABLE_COPY_MOVE(QtVariantPropertyManager)
  138. };
  139. class QtVariantEditorFactory : public QtAbstractEditorFactory<QtVariantPropertyManager>
  140. {
  141. Q_OBJECT
  142. public:
  143. QtVariantEditorFactory(QObject *parent = 0);
  144. ~QtVariantEditorFactory();
  145. protected:
  146. void connectPropertyManager(QtVariantPropertyManager *manager);
  147. QWidget *createEditor(QtVariantPropertyManager *manager, QtProperty *property,
  148. QWidget *parent);
  149. void disconnectPropertyManager(QtVariantPropertyManager *manager);
  150. private:
  151. QScopedPointer<class QtVariantEditorFactoryPrivate> d_ptr;
  152. Q_DECLARE_PRIVATE(QtVariantEditorFactory)
  153. Q_DISABLE_COPY_MOVE(QtVariantEditorFactory)
  154. };
  155. QT_END_NAMESPACE
  156. Q_DECLARE_METATYPE(QIcon)
  157. Q_DECLARE_METATYPE(QtIconMap)
  158. #endif