qtvariantproperty.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. #ifndef QTVARIANTPROPERTY_H
  41. #define QTVARIANTPROPERTY_H
  42. #include "qtpropertybrowser.h"
  43. #include <QVariant>
  44. #include <QIcon>
  45. #if QT_VERSION >= 0x040400
  46. QT_BEGIN_NAMESPACE
  47. #endif
  48. typedef QMap<int, QIcon> QtIconMap;
  49. class QtVariantPropertyManager;
  50. class QtVariantPropertyPrivate;
  51. class QT_QTPROPERTYBROWSER_EXPORT QtVariantProperty : public QtProperty
  52. {
  53. public:
  54. ~QtVariantProperty();
  55. QVariant value() const;
  56. QVariant attributeValue(const QString &attribute) const;
  57. int valueType() const;
  58. int propertyType() const;
  59. void setValue(const QVariant &value);
  60. void setAttribute(const QString &attribute, const QVariant &value);
  61. protected:
  62. QtVariantProperty(QtVariantPropertyManager *manager);
  63. private:
  64. friend class QtVariantPropertyManager;
  65. QtVariantPropertyPrivate *d_ptr;
  66. };
  67. class QtVariantPropertyManagerPrivate;
  68. class QT_QTPROPERTYBROWSER_EXPORT QtVariantPropertyManager : public QtAbstractPropertyManager
  69. {
  70. Q_OBJECT
  71. public:
  72. QtVariantPropertyManager(QObject *parent = 0);
  73. ~QtVariantPropertyManager();
  74. virtual QtVariantProperty *addProperty(int propertyType, const QString &name = QString());
  75. int propertyType(const QtProperty *property) const;
  76. int valueType(const QtProperty *property) const;
  77. QtVariantProperty *variantProperty(const QtProperty *property) const;
  78. virtual bool isPropertyTypeSupported(int propertyType) const;
  79. virtual int valueType(int propertyType) const;
  80. virtual QStringList attributes(int propertyType) const;
  81. virtual int attributeType(int propertyType, const QString &attribute) const;
  82. virtual QVariant value(const QtProperty *property) const;
  83. virtual QVariant attributeValue(const QtProperty *property, const QString &attribute) const;
  84. static int enumTypeId();
  85. static int flagTypeId();
  86. static int groupTypeId();
  87. static int iconMapTypeId();
  88. public Q_SLOTS:
  89. virtual void setValue(QtProperty *property, const QVariant &val);
  90. virtual void setAttribute(QtProperty *property,
  91. const QString &attribute, const QVariant &value);
  92. Q_SIGNALS:
  93. void valueChanged(QtProperty *property, const QVariant &val);
  94. void attributeChanged(QtProperty *property,
  95. const QString &attribute, const QVariant &val);
  96. protected:
  97. virtual bool hasValue(const QtProperty *property) const;
  98. QString valueText(const QtProperty *property) const;
  99. QIcon valueIcon(const QtProperty *property) const;
  100. virtual void initializeProperty(QtProperty *property);
  101. virtual void uninitializeProperty(QtProperty *property);
  102. virtual QtProperty *createProperty();
  103. private:
  104. QtVariantPropertyManagerPrivate *d_ptr;
  105. Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, int))
  106. Q_PRIVATE_SLOT(d_func(), void slotRangeChanged(QtProperty *, int, int))
  107. Q_PRIVATE_SLOT(d_func(), void slotSingleStepChanged(QtProperty *, int))
  108. Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, double))
  109. Q_PRIVATE_SLOT(d_func(), void slotRangeChanged(QtProperty *, double, double))
  110. Q_PRIVATE_SLOT(d_func(), void slotSingleStepChanged(QtProperty *, double))
  111. Q_PRIVATE_SLOT(d_func(), void slotDecimalsChanged(QtProperty *, int))
  112. Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, bool))
  113. Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QString &))
  114. Q_PRIVATE_SLOT(d_func(), void slotRegExpChanged(QtProperty *, const QRegExp &))
  115. Q_PRIVATE_SLOT(d_func(), void slotEchoModeChanged(QtProperty *, int))
  116. Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QDate &))
  117. Q_PRIVATE_SLOT(d_func(), void slotRangeChanged(QtProperty *, const QDate &, const QDate &))
  118. Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QTime &))
  119. Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QDateTime &))
  120. Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QKeySequence &))
  121. Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QChar &))
  122. Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QLocale &))
  123. Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QPoint &))
  124. Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QPointF &))
  125. Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QSize &))
  126. Q_PRIVATE_SLOT(d_func(), void slotRangeChanged(QtProperty *, const QSize &, const QSize &))
  127. Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QSizeF &))
  128. Q_PRIVATE_SLOT(d_func(), void slotRangeChanged(QtProperty *, const QSizeF &, const QSizeF &))
  129. Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QRect &))
  130. Q_PRIVATE_SLOT(d_func(), void slotConstraintChanged(QtProperty *, const QRect &))
  131. Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QRectF &))
  132. Q_PRIVATE_SLOT(d_func(), void slotConstraintChanged(QtProperty *, const QRectF &))
  133. Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QColor &))
  134. Q_PRIVATE_SLOT(d_func(), void slotEnumNamesChanged(QtProperty *, const QStringList &))
  135. Q_PRIVATE_SLOT(d_func(), void slotEnumIconsChanged(QtProperty *, const QMap<int, QIcon> &))
  136. Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QSizePolicy &))
  137. Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QFont &))
  138. Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QCursor &))
  139. Q_PRIVATE_SLOT(d_func(), void slotFlagNamesChanged(QtProperty *, const QStringList &))
  140. Q_PRIVATE_SLOT(d_func(), void slotReadOnlyChanged(QtProperty *, bool))
  141. Q_PRIVATE_SLOT(d_func(), void slotTextVisibleChanged(QtProperty *, bool))
  142. Q_PRIVATE_SLOT(d_func(), void slotPropertyInserted(QtProperty *, QtProperty *, QtProperty *))
  143. Q_PRIVATE_SLOT(d_func(), void slotPropertyRemoved(QtProperty *, QtProperty *))
  144. Q_DECLARE_PRIVATE(QtVariantPropertyManager)
  145. Q_DISABLE_COPY(QtVariantPropertyManager)
  146. };
  147. class QtVariantEditorFactoryPrivate;
  148. class QT_QTPROPERTYBROWSER_EXPORT QtVariantEditorFactory : public QtAbstractEditorFactory<QtVariantPropertyManager>
  149. {
  150. Q_OBJECT
  151. public:
  152. QtVariantEditorFactory(QObject *parent = 0);
  153. ~QtVariantEditorFactory();
  154. protected:
  155. void connectPropertyManager(QtVariantPropertyManager *manager);
  156. QWidget *createEditor(QtVariantPropertyManager *manager, QtProperty *property,
  157. QWidget *parent);
  158. void disconnectPropertyManager(QtVariantPropertyManager *manager);
  159. private:
  160. QtVariantEditorFactoryPrivate *d_ptr;
  161. Q_DECLARE_PRIVATE(QtVariantEditorFactory)
  162. Q_DISABLE_COPY(QtVariantEditorFactory)
  163. };
  164. #if QT_VERSION >= 0x040400
  165. QT_END_NAMESPACE
  166. #endif
  167. Q_DECLARE_METATYPE(QIcon)
  168. Q_DECLARE_METATYPE(QtIconMap)
  169. #endif