00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088 #ifndef QTPROPERTYBROWSER_H
00089 #define QTPROPERTYBROWSER_H
00090
00091 #include <QtGui/QWidget>
00092 #include <QtCore/QSet>
00093
00094 #if QT_VERSION >= 0x040400
00095 QT_BEGIN_NAMESPACE
00096 #endif
00097
00098 #if defined(Q_WS_WIN)
00099 # if !defined(QT_QTPROPERTYBROWSER_EXPORT) && !defined(QT_QTPROPERTYBROWSER_IMPORT)
00100 # define QT_QTPROPERTYBROWSER_EXPORT
00101 # elif defined(QT_QTPROPERTYBROWSER_IMPORT)
00102 # if defined(QT_QTPROPERTYBROWSER_EXPORT)
00103 # undef QT_QTPROPERTYBROWSER_EXPORT
00104 # endif
00105 # define QT_QTPROPERTYBROWSER_EXPORT __declspec(dllimport)
00106 # elif defined(QT_QTPROPERTYBROWSER_EXPORT)
00107 # undef QT_QTPROPERTYBROWSER_EXPORT
00108 # define QT_QTPROPERTYBROWSER_EXPORT __declspec(dllexport)
00109 # endif
00110 #else
00111 # define QT_QTPROPERTYBROWSER_EXPORT
00112 #endif
00113
00114
00115 class QtAbstractPropertyManager;
00116 class QtPropertyPrivate;
00117
00118 class QT_QTPROPERTYBROWSER_EXPORT QtProperty
00119 {
00120 public:
00121 virtual ~QtProperty();
00122
00123 QList<QtProperty *> subProperties() const;
00124
00125 QtAbstractPropertyManager *propertyManager() const;
00126
00127 QString toolTip() const;
00128 QString statusTip() const;
00129 QString whatsThis() const;
00130 QString propertyName() const;
00131 bool isEnabled() const;
00132 bool isModified() const;
00133
00134 bool hasValue() const;
00135 QIcon valueIcon() const;
00136 QString valueText() const;
00137
00138 void setToolTip(const QString &text);
00139 void setStatusTip(const QString &text);
00140 void setWhatsThis(const QString &text);
00141 void setPropertyName(const QString &text);
00142 void setEnabled(bool enable);
00143 void setModified(bool modified);
00144
00145 void addSubProperty(QtProperty *property);
00146 void insertSubProperty(QtProperty *property, QtProperty *afterProperty);
00147 void removeSubProperty(QtProperty *property);
00148 protected:
00149 explicit QtProperty(QtAbstractPropertyManager *manager);
00150 void propertyChanged();
00151 private:
00152 friend class QtAbstractPropertyManager;
00153 QtPropertyPrivate *d_ptr;
00154 };
00155
00156 class QtAbstractPropertyManagerPrivate;
00157
00158 class QT_QTPROPERTYBROWSER_EXPORT QtAbstractPropertyManager : public QObject
00159 {
00160 Q_OBJECT
00161 public:
00162
00163 explicit QtAbstractPropertyManager(QObject *parent = 0);
00164 ~QtAbstractPropertyManager();
00165
00166 QSet<QtProperty *> properties() const;
00167 void clear() const;
00168
00169 QtProperty *addProperty(const QString &name = QString());
00170 Q_SIGNALS:
00171
00172 void propertyInserted(QtProperty *property,
00173 QtProperty *parent, QtProperty *after);
00174 void propertyChanged(QtProperty *property);
00175 void propertyRemoved(QtProperty *property, QtProperty *parent);
00176 void propertyDestroyed(QtProperty *property);
00177 protected:
00178 virtual bool hasValue(const QtProperty *property) const;
00179 virtual QIcon valueIcon(const QtProperty *property) const;
00180 virtual QString valueText(const QtProperty *property) const;
00181 virtual void initializeProperty(QtProperty *property) = 0;
00182 virtual void uninitializeProperty(QtProperty *property);
00183 virtual QtProperty *createProperty();
00184 private:
00185 friend class QtProperty;
00186 QtAbstractPropertyManagerPrivate *d_ptr;
00187 Q_DECLARE_PRIVATE(QtAbstractPropertyManager)
00188 Q_DISABLE_COPY(QtAbstractPropertyManager)
00189 };
00190
00191 class QT_QTPROPERTYBROWSER_EXPORT QtAbstractEditorFactoryBase : public QObject
00192 {
00193 Q_OBJECT
00194 public:
00195 virtual QWidget *createEditor(QtProperty *property, QWidget *parent) = 0;
00196 protected:
00197 explicit QtAbstractEditorFactoryBase(QObject *parent = 0)
00198 : QObject(parent) {}
00199
00200 virtual void breakConnection(QtAbstractPropertyManager *manager) = 0;
00201 protected Q_SLOTS:
00202 virtual void managerDestroyed(QObject *manager) = 0;
00203
00204 friend class QtAbstractPropertyBrowser;
00205 };
00206
00207 template <class PropertyManager>
00208 class QtAbstractEditorFactory : public QtAbstractEditorFactoryBase
00209 {
00210 public:
00211 explicit QtAbstractEditorFactory(QObject *parent) : QtAbstractEditorFactoryBase(parent) {}
00212 QWidget *createEditor(QtProperty *property, QWidget *parent)
00213 {
00214 QSetIterator<PropertyManager *> it(m_managers);
00215 while (it.hasNext()) {
00216 PropertyManager *manager = it.next();
00217 if (manager == property->propertyManager()) {
00218 return createEditor(manager, property, parent);
00219 }
00220 }
00221 return 0;
00222 }
00223 void addPropertyManager(PropertyManager *manager)
00224 {
00225 if (m_managers.contains(manager))
00226 return;
00227 m_managers.insert(manager);
00228 connectPropertyManager(manager);
00229 connect(manager, SIGNAL(destroyed(QObject *)),
00230 this, SLOT(managerDestroyed(QObject *)));
00231 }
00232 void removePropertyManager(PropertyManager *manager)
00233 {
00234 if (!m_managers.contains(manager))
00235 return;
00236 disconnect(manager, SIGNAL(destroyed(QObject *)),
00237 this, SLOT(managerDestroyed(QObject *)));
00238 disconnectPropertyManager(manager);
00239 m_managers.remove(manager);
00240 }
00241 QSet<PropertyManager *> propertyManagers() const
00242 {
00243 return m_managers;
00244 }
00245 PropertyManager *propertyManager(QtProperty *property) const
00246 {
00247 QtAbstractPropertyManager *manager = property->propertyManager();
00248 QSetIterator<PropertyManager *> itManager(m_managers);
00249 while (itManager.hasNext()) {
00250 PropertyManager *m = itManager.next();
00251 if (m == manager) {
00252 return m;
00253 }
00254 }
00255 return 0;
00256 }
00257 protected:
00258 virtual void connectPropertyManager(PropertyManager *manager) = 0;
00259 virtual QWidget *createEditor(PropertyManager *manager, QtProperty *property,
00260 QWidget *parent) = 0;
00261 virtual void disconnectPropertyManager(PropertyManager *manager) = 0;
00262 void managerDestroyed(QObject *manager)
00263 {
00264 QSetIterator<PropertyManager *> it(m_managers);
00265 while (it.hasNext()) {
00266 PropertyManager *m = it.next();
00267 if (m == manager) {
00268 m_managers.remove(m);
00269 return;
00270 }
00271 }
00272 }
00273 private:
00274 void breakConnection(QtAbstractPropertyManager *manager)
00275 {
00276 QSetIterator<PropertyManager *> it(m_managers);
00277 while (it.hasNext()) {
00278 PropertyManager *m = it.next();
00279 if (m == manager) {
00280 removePropertyManager(m);
00281 return;
00282 }
00283 }
00284 }
00285 private:
00286 QSet<PropertyManager *> m_managers;
00287 friend class QtAbstractPropertyEditor;
00288 };
00289
00290 class QtAbstractPropertyBrowser;
00291 class QtBrowserItemPrivate;
00292
00293 class QT_QTPROPERTYBROWSER_EXPORT QtBrowserItem
00294 {
00295 public:
00296 QtProperty *property() const;
00297 QtBrowserItem *parent() const;
00298 QList<QtBrowserItem *> children() const;
00299 QtAbstractPropertyBrowser *browser() const;
00300 private:
00301 explicit QtBrowserItem(QtAbstractPropertyBrowser *browser, QtProperty *property, QtBrowserItem *parent);
00302 ~QtBrowserItem();
00303 QtBrowserItemPrivate *d_ptr;
00304 friend class QtAbstractPropertyBrowserPrivate;
00305 };
00306
00307 class QtAbstractPropertyBrowserPrivate;
00308
00309 class QT_QTPROPERTYBROWSER_EXPORT QtAbstractPropertyBrowser : public QWidget
00310 {
00311 Q_OBJECT
00312 public:
00313
00314 explicit QtAbstractPropertyBrowser(QWidget *parent = 0);
00315 ~QtAbstractPropertyBrowser();
00316
00317 QList<QtProperty *> properties() const;
00318 QList<QtBrowserItem *> items(QtProperty *property) const;
00319 QtBrowserItem *topLevelItem(QtProperty *property) const;
00320 QList<QtBrowserItem *> topLevelItems() const;
00321 void clear();
00322
00323 template <class PropertyManager>
00324 void setFactoryForManager(PropertyManager *manager,
00325 QtAbstractEditorFactory<PropertyManager> *factory) {
00326 QtAbstractPropertyManager *abstractManager = manager;
00327 QtAbstractEditorFactoryBase *abstractFactory = factory;
00328
00329 if (addFactory(abstractManager, abstractFactory))
00330 factory->addPropertyManager(manager);
00331 }
00332
00333 void unsetFactoryForManager(QtAbstractPropertyManager *manager);
00334
00335 QtBrowserItem *currentItem() const;
00336 void setCurrentItem(QtBrowserItem *);
00337
00338 Q_SIGNALS:
00339 void currentItemChanged(QtBrowserItem *);
00340
00341 public Q_SLOTS:
00342
00343 QtBrowserItem *addProperty(QtProperty *property);
00344 QtBrowserItem *insertProperty(QtProperty *property, QtProperty *afterProperty);
00345 void removeProperty(QtProperty *property);
00346
00347 protected:
00348
00349 virtual void itemInserted(QtBrowserItem *item, QtBrowserItem *afterItem) = 0;
00350 virtual void itemRemoved(QtBrowserItem *item) = 0;
00351
00352 virtual void itemChanged(QtBrowserItem *item) = 0;
00353
00354 virtual QWidget *createEditor(QtProperty *property, QWidget *parent);
00355 private:
00356
00357 bool addFactory(QtAbstractPropertyManager *abstractManager,
00358 QtAbstractEditorFactoryBase *abstractFactory);
00359
00360 QtAbstractPropertyBrowserPrivate *d_ptr;
00361 Q_DECLARE_PRIVATE(QtAbstractPropertyBrowser)
00362 Q_DISABLE_COPY(QtAbstractPropertyBrowser)
00363 Q_PRIVATE_SLOT(d_func(), void slotPropertyInserted(QtProperty *,
00364 QtProperty *, QtProperty *))
00365 Q_PRIVATE_SLOT(d_func(), void slotPropertyRemoved(QtProperty *,
00366 QtProperty *))
00367 Q_PRIVATE_SLOT(d_func(), void slotPropertyDestroyed(QtProperty *))
00368 Q_PRIVATE_SLOT(d_func(), void slotPropertyDataChanged(QtProperty *))
00369
00370 };
00371
00372 #if QT_VERSION >= 0x040400
00373 QT_END_NAMESPACE
00374 #endif
00375
00376 #endif // QTPROPERTYBROWSER_H