File indexing completed on 2024-05-12 04:35:10
0001 /**************************************************************************** 0002 ** 0003 ** Copyright (C) 2016 The Qt Company Ltd. 0004 ** Contact: https://www.qt.io/licensing/ 0005 ** 0006 ** This file is part of the tools applications of the Qt Toolkit. 0007 ** 0008 ** $QT_BEGIN_LICENSE:LGPL$ 0009 ** Commercial License Usage 0010 ** Licensees holding valid commercial Qt licenses may use this file in 0011 ** accordance with the commercial license agreement provided with the 0012 ** Software or, alternatively, in accordance with the terms contained in 0013 ** a written agreement between you and The Qt Company. For licensing terms 0014 ** and conditions see https://www.qt.io/terms-conditions. For further 0015 ** information use the contact form at https://www.qt.io/contact-us. 0016 ** 0017 ** GNU Lesser General Public License Usage 0018 ** Alternatively, this file may be used under the terms of the GNU Lesser 0019 ** General Public License version 3 as published by the Free Software 0020 ** Foundation and appearing in the file LICENSE.LGPL3 included in the 0021 ** packaging of this file. Please review the following information to 0022 ** ensure the GNU Lesser General Public License version 3 requirements 0023 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. 0024 ** 0025 ** GNU General Public License Usage 0026 ** Alternatively, this file may be used under the terms of the GNU 0027 ** General Public License version 2.0 or (at your option) the GNU General 0028 ** Public license version 3 or any later version approved by the KDE Free 0029 ** Qt Foundation. The licenses are as published by the Free Software 0030 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 0031 ** included in the packaging of this file. Please review the following 0032 ** information to ensure the GNU General Public License requirements will 0033 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and 0034 ** https://www.gnu.org/licenses/gpl-3.0.html. 0035 ** 0036 ** $QT_END_LICENSE$ 0037 ** 0038 ****************************************************************************/ 0039 0040 #ifndef QTPROPERTYBROWSER_H 0041 #define QTPROPERTYBROWSER_H 0042 0043 #include <QtWidgets/QWidget> 0044 #include <QtCore/QSet> 0045 0046 QT_BEGIN_NAMESPACE 0047 0048 #if defined(Q_OS_WIN) 0049 # if !defined(QT_QTPROPERTYBROWSER_EXPORT) && !defined(QT_QTPROPERTYBROWSER_IMPORT) 0050 # define QT_QTPROPERTYBROWSER_EXPORT 0051 # elif defined(QT_QTPROPERTYBROWSER_IMPORT) 0052 # if defined(QT_QTPROPERTYBROWSER_EXPORT) 0053 # undef QT_QTPROPERTYBROWSER_EXPORT 0054 # endif 0055 # define QT_QTPROPERTYBROWSER_EXPORT __declspec(dllimport) 0056 # elif defined(QT_QTPROPERTYBROWSER_EXPORT) 0057 # undef QT_QTPROPERTYBROWSER_EXPORT 0058 # define QT_QTPROPERTYBROWSER_EXPORT __declspec(dllexport) 0059 # endif 0060 #else 0061 # define QT_QTPROPERTYBROWSER_EXPORT 0062 #endif 0063 0064 0065 class QtAbstractPropertyManager; 0066 class QtPropertyPrivate; 0067 0068 class QT_QTPROPERTYBROWSER_EXPORT QtProperty 0069 { 0070 public: 0071 virtual ~QtProperty(); 0072 0073 QList<QtProperty *> subProperties() const; 0074 0075 QtAbstractPropertyManager *propertyManager() const; 0076 0077 QString toolTip() const { return valueToolTip(); } // Compatibility 0078 QString valueToolTip() const; 0079 QString descriptionToolTip() const; 0080 QString statusTip() const; 0081 QString whatsThis() const; 0082 QString propertyName() const; 0083 bool isEnabled() const; 0084 bool isModified() const; 0085 0086 bool hasValue() const; 0087 QIcon valueIcon() const; 0088 QString valueText() const; 0089 0090 void setToolTip(const QString &text) { setValueToolTip(text); } // Compatibility 0091 void setValueToolTip(const QString &text); 0092 void setDescriptionToolTip(const QString &text); 0093 void setStatusTip(const QString &text); 0094 void setWhatsThis(const QString &text); 0095 void setPropertyName(const QString &text); 0096 void setEnabled(bool enable); 0097 void setModified(bool modified); 0098 0099 void addSubProperty(QtProperty *property); 0100 void insertSubProperty(QtProperty *property, QtProperty *afterProperty); 0101 void removeSubProperty(QtProperty *property); 0102 protected: 0103 explicit QtProperty(QtAbstractPropertyManager *manager); 0104 void propertyChanged(); 0105 private: 0106 friend class QtAbstractPropertyManager; 0107 QScopedPointer<QtPropertyPrivate> d_ptr; 0108 }; 0109 0110 class QtAbstractPropertyManagerPrivate; 0111 0112 class QtAbstractPropertyManager : public QObject 0113 { 0114 Q_OBJECT 0115 public: 0116 0117 explicit QtAbstractPropertyManager(QObject *parent = 0); 0118 ~QtAbstractPropertyManager(); 0119 0120 QSet<QtProperty *> properties() const; 0121 void clear() const; 0122 0123 QtProperty *addProperty(const QString &name = QString()); 0124 Q_SIGNALS: 0125 0126 void propertyInserted(QtProperty *property, 0127 QtProperty *parent, QtProperty *after); 0128 void propertyChanged(QtProperty *property); 0129 void propertyRemoved(QtProperty *property, QtProperty *parent); 0130 void propertyDestroyed(QtProperty *property); 0131 protected: 0132 virtual bool hasValue(const QtProperty *property) const; 0133 virtual QIcon valueIcon(const QtProperty *property) const; 0134 virtual QString valueText(const QtProperty *property) const; 0135 virtual void initializeProperty(QtProperty *property) = 0; 0136 virtual void uninitializeProperty(QtProperty *property); 0137 virtual QtProperty *createProperty(); 0138 private: 0139 friend class QtProperty; 0140 QScopedPointer<QtAbstractPropertyManagerPrivate> d_ptr; 0141 Q_DECLARE_PRIVATE(QtAbstractPropertyManager) 0142 Q_DISABLE_COPY(QtAbstractPropertyManager) 0143 }; 0144 0145 class QtAbstractEditorFactoryBase : public QObject 0146 { 0147 Q_OBJECT 0148 public: 0149 virtual QWidget *createEditor(QtProperty *property, QWidget *parent) = 0; 0150 protected: 0151 explicit QtAbstractEditorFactoryBase(QObject *parent = 0) 0152 : QObject(parent) {} 0153 0154 virtual void breakConnection(QtAbstractPropertyManager *manager) = 0; 0155 protected Q_SLOTS: 0156 virtual void managerDestroyed(QObject *manager) = 0; 0157 0158 friend class QtAbstractPropertyBrowser; 0159 }; 0160 0161 template <class PropertyManager> 0162 class QtAbstractEditorFactory : public QtAbstractEditorFactoryBase 0163 { 0164 public: 0165 explicit QtAbstractEditorFactory(QObject *parent) : QtAbstractEditorFactoryBase(parent) {} 0166 QWidget *createEditor(QtProperty *property, QWidget *parent) 0167 { 0168 for (PropertyManager *manager : qAsConst(m_managers)) { 0169 if (manager == property->propertyManager()) { 0170 return createEditor(manager, property, parent); 0171 } 0172 } 0173 return 0; 0174 } 0175 void addPropertyManager(PropertyManager *manager) 0176 { 0177 if (m_managers.contains(manager)) 0178 return; 0179 m_managers.insert(manager); 0180 connectPropertyManager(manager); 0181 connect(manager, SIGNAL(destroyed(QObject *)), 0182 this, SLOT(managerDestroyed(QObject *))); 0183 } 0184 void removePropertyManager(PropertyManager *manager) 0185 { 0186 if (!m_managers.contains(manager)) 0187 return; 0188 disconnect(manager, SIGNAL(destroyed(QObject *)), 0189 this, SLOT(managerDestroyed(QObject *))); 0190 disconnectPropertyManager(manager); 0191 m_managers.remove(manager); 0192 } 0193 QSet<PropertyManager *> propertyManagers() const 0194 { 0195 return m_managers; 0196 } 0197 PropertyManager *propertyManager(QtProperty *property) const 0198 { 0199 QtAbstractPropertyManager *manager = property->propertyManager(); 0200 for (PropertyManager *m : qAsConst(m_managers)) { 0201 if (m == manager) { 0202 return m; 0203 } 0204 } 0205 return 0; 0206 } 0207 protected: 0208 virtual void connectPropertyManager(PropertyManager *manager) = 0; 0209 virtual QWidget *createEditor(PropertyManager *manager, QtProperty *property, 0210 QWidget *parent) = 0; 0211 virtual void disconnectPropertyManager(PropertyManager *manager) = 0; 0212 void managerDestroyed(QObject *manager) 0213 { 0214 for (PropertyManager *m : qAsConst(m_managers)) { 0215 if (m == manager) { 0216 m_managers.remove(m); 0217 return; 0218 } 0219 } 0220 } 0221 private: 0222 void breakConnection(QtAbstractPropertyManager *manager) 0223 { 0224 for (PropertyManager *m : qAsConst(m_managers)) { 0225 if (m == manager) { 0226 removePropertyManager(m); 0227 return; 0228 } 0229 } 0230 } 0231 private: 0232 QSet<PropertyManager *> m_managers; 0233 friend class QtAbstractPropertyEditor; 0234 }; 0235 0236 class QtAbstractPropertyBrowser; 0237 class QtBrowserItemPrivate; 0238 0239 class QtBrowserItem 0240 { 0241 public: 0242 QtProperty *property() const; 0243 QtBrowserItem *parent() const; 0244 QList<QtBrowserItem *> children() const; 0245 QtAbstractPropertyBrowser *browser() const; 0246 private: 0247 explicit QtBrowserItem(QtAbstractPropertyBrowser *browser, QtProperty *property, QtBrowserItem *parent); 0248 ~QtBrowserItem(); 0249 QScopedPointer<QtBrowserItemPrivate> d_ptr; 0250 friend class QtAbstractPropertyBrowserPrivate; 0251 }; 0252 0253 class QtAbstractPropertyBrowserPrivate; 0254 0255 class QtAbstractPropertyBrowser : public QWidget 0256 { 0257 Q_OBJECT 0258 public: 0259 0260 explicit QtAbstractPropertyBrowser(QWidget *parent = 0); 0261 ~QtAbstractPropertyBrowser(); 0262 0263 QList<QtProperty *> properties() const; 0264 QList<QtBrowserItem *> items(QtProperty *property) const; 0265 QtBrowserItem *topLevelItem(QtProperty *property) const; 0266 QList<QtBrowserItem *> topLevelItems() const; 0267 void clear(); 0268 0269 template <class PropertyManager> 0270 void setFactoryForManager(PropertyManager *manager, 0271 QtAbstractEditorFactory<PropertyManager> *factory) { 0272 QtAbstractPropertyManager *abstractManager = manager; 0273 QtAbstractEditorFactoryBase *abstractFactory = factory; 0274 0275 if (addFactory(abstractManager, abstractFactory)) 0276 factory->addPropertyManager(manager); 0277 } 0278 0279 void unsetFactoryForManager(QtAbstractPropertyManager *manager); 0280 0281 QtBrowserItem *currentItem() const; 0282 void setCurrentItem(QtBrowserItem *); 0283 0284 Q_SIGNALS: 0285 void currentItemChanged(QtBrowserItem *); 0286 0287 public Q_SLOTS: 0288 0289 QtBrowserItem *addProperty(QtProperty *property); 0290 QtBrowserItem *insertProperty(QtProperty *property, QtProperty *afterProperty); 0291 void removeProperty(QtProperty *property); 0292 0293 protected: 0294 0295 virtual void itemInserted(QtBrowserItem *item, QtBrowserItem *afterItem) = 0; 0296 virtual void itemRemoved(QtBrowserItem *item) = 0; 0297 // can be tooltip, statustip, whatsthis, name, icon, text. 0298 virtual void itemChanged(QtBrowserItem *item) = 0; 0299 0300 virtual QWidget *createEditor(QtProperty *property, QWidget *parent); 0301 private: 0302 0303 bool addFactory(QtAbstractPropertyManager *abstractManager, 0304 QtAbstractEditorFactoryBase *abstractFactory); 0305 0306 QScopedPointer<QtAbstractPropertyBrowserPrivate> d_ptr; 0307 Q_DECLARE_PRIVATE(QtAbstractPropertyBrowser) 0308 Q_DISABLE_COPY(QtAbstractPropertyBrowser) 0309 Q_PRIVATE_SLOT(d_func(), void slotPropertyInserted(QtProperty *, 0310 QtProperty *, QtProperty *)) 0311 Q_PRIVATE_SLOT(d_func(), void slotPropertyRemoved(QtProperty *, 0312 QtProperty *)) 0313 Q_PRIVATE_SLOT(d_func(), void slotPropertyDestroyed(QtProperty *)) 0314 Q_PRIVATE_SLOT(d_func(), void slotPropertyDataChanged(QtProperty *)) 0315 0316 }; 0317 0318 QT_END_NAMESPACE 0319 0320 #endif // QTPROPERTYBROWSER_H