QSapecNG
 All Classes Functions Enumerations Properties
qtpropertybrowser.h
00001 /****************************************************************************
00002 **
00003 ** This file is part of a Qt Solutions component.
00004 ** 
00005 ** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
00006 ** 
00007 ** Contact:  Qt Software Information (qt-info@nokia.com)
00008 ** 
00009 ** Commercial Usage  
00010 ** Licensees holding valid Qt Commercial licenses may use this file in
00011 ** accordance with the Qt Solutions Commercial License Agreement provided
00012 ** with the Software or, alternatively, in accordance with the terms
00013 ** contained in a written agreement between you and Nokia.
00014 ** 
00015 ** GNU Lesser General Public License Usage
00016 ** Alternatively, this file may be used under the terms of the GNU Lesser
00017 ** General Public License version 2.1 as published by the Free Software
00018 ** Foundation and appearing in the file LICENSE.LGPL included in the
00019 ** packaging of this file.  Please review the following information to
00020 ** ensure the GNU Lesser General Public License version 2.1 requirements
00021 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
00022 ** 
00023 ** In addition, as a special exception, Nokia gives you certain
00024 ** additional rights. These rights are described in the Nokia Qt LGPL
00025 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
00026 ** package.
00027 ** 
00028 ** GNU General Public License Usage 
00029 ** Alternatively, this file may be used under the terms of the GNU
00030 ** General Public License version 3.0 as published by the Free Software
00031 ** Foundation and appearing in the file LICENSE.GPL included in the
00032 ** packaging of this file.  Please review the following information to
00033 ** ensure the GNU General Public License version 3.0 requirements will be
00034 ** met: http://www.gnu.org/copyleft/gpl.html.
00035 ** 
00036 ** Please note Third Party Software included with Qt Solutions may impose
00037 ** additional restrictions and it is the user's responsibility to ensure
00038 ** that they have met the licensing requirements of the GPL, LGPL, or Qt
00039 ** Solutions Commercial license and the relevant license of the Third
00040 ** Party Software they are using.
00041 ** 
00042 ** If you are unsure which license is appropriate for your use, please
00043 ** contact the sales department at qt-sales@nokia.com.
00044 ** 
00045 ****************************************************************************/
00046 
00047 /****************************************************************************
00048 **
00049 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
00050 ** Contact: Qt Software Information (qt-info@nokia.com)
00051 **
00052 ** This file is part of the tools applications of the Qt Toolkit.
00053 **
00054 ** $QT_BEGIN_LICENSE:LGPL$
00055 ** No Commercial Usage
00056 ** This file contains pre-release code and may not be distributed.
00057 ** You may use this file in accordance with the terms and conditions
00058 ** contained in the either Technology Preview License Agreement or the
00059 ** Beta Release License Agreement.
00060 **
00061 ** GNU Lesser General Public License Usage
00062 ** Alternatively, this file may be used under the terms of the GNU Lesser
00063 ** General Public License version 2.1 as published by the Free Software
00064 ** Foundation and appearing in the file LICENSE.LGPL included in the
00065 ** packaging of this file.  Please review the following information to
00066 ** ensure the GNU Lesser General Public License version 2.1 requirements
00067 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
00068 **
00069 ** In addition, as a special exception, Nokia gives you certain
00070 ** additional rights. These rights are described in the Nokia Qt LGPL
00071 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
00072 ** package.
00073 **
00074 ** GNU General Public License Usage
00075 ** Alternatively, this file may be used under the terms of the GNU
00076 ** General Public License version 3.0 as published by the Free Software
00077 ** Foundation and appearing in the file LICENSE.GPL included in the
00078 ** packaging of this file.  Please review the following information to
00079 ** ensure the GNU General Public License version 3.0 requirements will be
00080 ** met: http://www.gnu.org/copyleft/gpl.html.
00081 **
00082 ** If you are unsure which license is appropriate for your use, please
00083 ** contact the sales department at qt-sales@nokia.com.
00084 ** $QT_END_LICENSE$
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     // can be tooltip, statustip, whatsthis, name, icon, text.
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
 All Classes Functions Enumerations Properties