aboutsummaryrefslogtreecommitdiffstats
path: root/3rdparty/QtPropertyBrowser/examples/object_controller
diff options
context:
space:
mode:
authorMiodrag Milanovic <mmicko@gmail.com>2018-06-11 18:22:20 +0200
committerMiodrag Milanovic <mmicko@gmail.com>2018-06-11 21:30:22 +0200
commiteb392f649ea544742849e50d920be677d09aa344 (patch)
treed3032358009998a515874bcc368c7cef5f5882ae /3rdparty/QtPropertyBrowser/examples/object_controller
parentbe73894bea1c5719eccfad6b8c7e7ae44798a68a (diff)
downloadnextpnr-eb392f649ea544742849e50d920be677d09aa344.tar.gz
nextpnr-eb392f649ea544742849e50d920be677d09aa344.tar.bz2
nextpnr-eb392f649ea544742849e50d920be677d09aa344.zip
Added QtPropertyBrowser source
Diffstat (limited to '3rdparty/QtPropertyBrowser/examples/object_controller')
-rw-r--r--3rdparty/QtPropertyBrowser/examples/object_controller/CMakeLists.txt16
-rw-r--r--3rdparty/QtPropertyBrowser/examples/object_controller/main.cpp167
-rw-r--r--3rdparty/QtPropertyBrowser/examples/object_controller/object_controller.qdoc54
-rw-r--r--3rdparty/QtPropertyBrowser/examples/object_controller/objectcontroller.cpp391
-rw-r--r--3rdparty/QtPropertyBrowser/examples/object_controller/objectcontroller.h64
5 files changed, 692 insertions, 0 deletions
diff --git a/3rdparty/QtPropertyBrowser/examples/object_controller/CMakeLists.txt b/3rdparty/QtPropertyBrowser/examples/object_controller/CMakeLists.txt
new file mode 100644
index 00000000..390d0173
--- /dev/null
+++ b/3rdparty/QtPropertyBrowser/examples/object_controller/CMakeLists.txt
@@ -0,0 +1,16 @@
+# Tell CMake to run moc when necessary:
+set(CMAKE_AUTOMOC ON)
+
+# As moc files are generated in the binary dir, tell CMake
+# to always look for includes there:
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+SET(example_name object_controller)
+
+SET(KIT_SRCS
+ main.cpp
+ objectcontroller.cpp
+ )
+
+ADD_EXECUTABLE(${example_name} ${KIT_SRCS})
+TARGET_LINK_LIBRARIES(${example_name} ${PROJECT_NAME}) \ No newline at end of file
diff --git a/3rdparty/QtPropertyBrowser/examples/object_controller/main.cpp b/3rdparty/QtPropertyBrowser/examples/object_controller/main.cpp
new file mode 100644
index 00000000..96d64398
--- /dev/null
+++ b/3rdparty/QtPropertyBrowser/examples/object_controller/main.cpp
@@ -0,0 +1,167 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of a Qt Solutions component.
+**
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <QSpinBox>
+#include <QDialogButtonBox>
+#include <QLineEdit>
+#include <QDialog>
+#include <QComboBox>
+#include <QToolButton>
+#include <QPushButton>
+#include <QBoxLayout>
+#include <QTreeWidget>
+#include <QAction>
+#include <QDesktopWidget>
+#include <QTextDocument>
+#include <QCalendarWidget>
+#include <QTimeLine>
+#include "objectcontroller.h"
+
+class MyController : public QDialog
+{
+ Q_OBJECT
+public:
+ MyController(QWidget *parent = 0);
+ ~MyController();
+private slots:
+ void createAndControl();
+private:
+ QComboBox *theClassCombo;
+ ObjectController *theController;
+ QStringList theClassNames;
+ QObject *theControlledObject;
+};
+
+MyController::MyController(QWidget *parent)
+ : QDialog(parent), theControlledObject(0)
+{
+ theClassCombo = new QComboBox(this);
+ QToolButton *button = new QToolButton(this);
+ theController = new ObjectController(this);
+ QDialogButtonBox *buttonBox = new QDialogButtonBox(this);
+
+ connect(button, SIGNAL(clicked()), this, SLOT(createAndControl()));
+ connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
+
+ button->setText(tr("Create And Control"));
+ buttonBox->setStandardButtons(QDialogButtonBox::Close);
+
+ QVBoxLayout *layout = new QVBoxLayout(this);
+ QHBoxLayout *internalLayout = new QHBoxLayout();
+ internalLayout->addWidget(theClassCombo);
+ internalLayout->addWidget(button);
+ layout->addLayout(internalLayout);
+ layout->addWidget(theController);
+ layout->addWidget(buttonBox);
+
+ theClassNames.append(QLatin1String("QWidget"));
+ theClassNames.append(QLatin1String("QPushButton"));
+ theClassNames.append(QLatin1String("QDialogButtonBox"));
+ theClassNames.append(QLatin1String("QTreeWidget"));
+ theClassNames.append(QLatin1String("QCalendarWidget"));
+ theClassNames.append(QLatin1String("QAction"));
+ theClassNames.append(QLatin1String("QTimeLine"));
+ theClassNames.append(QLatin1String("QTextDocument"));
+
+ theClassCombo->addItems(theClassNames);
+}
+
+MyController::~MyController()
+{
+ if (theControlledObject)
+ delete theControlledObject;
+}
+
+void MyController::createAndControl()
+{
+ QObject *newObject = 0;
+ QString className = theClassNames.at(theClassCombo->currentIndex());
+ if (className == QLatin1String("QWidget"))
+ newObject = new QWidget();
+ else if (className == QLatin1String("QPushButton"))
+ newObject = new QPushButton();
+ else if (className == QLatin1String("QDialogButtonBox"))
+ newObject = new QDialogButtonBox();
+ else if (className == QLatin1String("QTreeWidget"))
+ newObject = new QTreeWidget();
+ else if (className == QLatin1String("QCalendarWidget"))
+ newObject = new QCalendarWidget();
+ else if (className == QLatin1String("QAction"))
+ newObject = new QAction(0);
+ else if (className == QLatin1String("QTimeLine"))
+ newObject = new QTimeLine();
+ else if (className == QLatin1String("QTextDocument"))
+ newObject = new QTextDocument();
+
+ if (!newObject)
+ return;
+
+ QWidget *newWidget = qobject_cast<QWidget *>(newObject);
+ if (newWidget) {
+ QRect r = newWidget->geometry();
+ r.setSize(newWidget->sizeHint());
+ r.setWidth(qMax(r.width(), 150));
+ r.setHeight(qMax(r.height(), 50));
+ r.moveCenter(QApplication::desktop()->geometry().center());
+ newWidget->setGeometry(r);
+ newWidget->setWindowTitle(tr("Controlled Object: %1").arg(className));
+ newWidget->show();
+ }
+
+ if (theControlledObject)
+ delete theControlledObject;
+
+ theControlledObject = newObject;
+ theController->setObject(theControlledObject);
+}
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+
+ MyController *controller = new MyController();
+ controller->show();
+
+ int ret = app.exec();
+
+ return ret;
+}
+
+#include "main.moc"
diff --git a/3rdparty/QtPropertyBrowser/examples/object_controller/object_controller.qdoc b/3rdparty/QtPropertyBrowser/examples/object_controller/object_controller.qdoc
new file mode 100644
index 00000000..116a4d3b
--- /dev/null
+++ b/3rdparty/QtPropertyBrowser/examples/object_controller/object_controller.qdoc
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of a Qt Solutions component.
+**
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+****************************************************************************/
+
+/*!
+ \page qtpropertybrowser-example-object_controller.html
+ \title The Object Controller Example.
+
+ \image object_controller.png
+
+ This example implements a simple widget component which shows
+ QObject's and its subclasses' properties. The user can modify these properies interacively
+ and the object controller applies the changes to the controlled object.
+ The object controller is similar to the property editor used in QDesigner application.
+ To control the object just instantiate ObjectController, set controlled object (any QObject subclass) by
+ calling ObjectController::setObject() and show the controller.
+
+ The source files can be found in examples/object_controller directory of the package.
+*/
diff --git a/3rdparty/QtPropertyBrowser/examples/object_controller/objectcontroller.cpp b/3rdparty/QtPropertyBrowser/examples/object_controller/objectcontroller.cpp
new file mode 100644
index 00000000..1c09b0a1
--- /dev/null
+++ b/3rdparty/QtPropertyBrowser/examples/object_controller/objectcontroller.cpp
@@ -0,0 +1,391 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of a Qt Solutions component.
+**
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+****************************************************************************/
+
+#include <QMetaObject>
+#include <QMetaProperty>
+#include <QVBoxLayout>
+#include <QScrollArea>
+#include "objectcontroller.h"
+#include "qtvariantproperty.h"
+#include "qtgroupboxpropertybrowser.h"
+#include "qttreepropertybrowser.h"
+#include "qtpropertybrowser.h"
+
+class ObjectControllerPrivate
+{
+ ObjectController *q_ptr;
+ Q_DECLARE_PUBLIC(ObjectController)
+public:
+
+ void addClassProperties(const QMetaObject *metaObject);
+ void updateClassProperties(const QMetaObject *metaObject, bool recursive);
+ void saveExpandedState();
+ void restoreExpandedState();
+ void slotValueChanged(QtProperty *property, const QVariant &value);
+ int enumToInt(const QMetaEnum &metaEnum, int enumValue) const;
+ int intToEnum(const QMetaEnum &metaEnum, int intValue) const;
+ int flagToInt(const QMetaEnum &metaEnum, int flagValue) const;
+ int intToFlag(const QMetaEnum &metaEnum, int intValue) const;
+ bool isSubValue(int value, int subValue) const;
+ bool isPowerOf2(int value) const;
+
+ QObject *m_object;
+
+ QMap<const QMetaObject *, QtProperty *> m_classToProperty;
+ QMap<QtProperty *, const QMetaObject *> m_propertyToClass;
+ QMap<QtProperty *, int> m_propertyToIndex;
+ QMap<const QMetaObject *, QMap<int, QtVariantProperty *> > m_classToIndexToProperty;
+
+ QMap<QtProperty *, bool> m_propertyToExpanded;
+
+ QList<QtProperty *> m_topLevelProperties;
+
+ QtAbstractPropertyBrowser *m_browser;
+ QtVariantPropertyManager *m_manager;
+ QtVariantPropertyManager *m_readOnlyManager;
+};
+
+int ObjectControllerPrivate::enumToInt(const QMetaEnum &metaEnum, int enumValue) const
+{
+ QMap<int, int> valueMap; // dont show multiple enum values which have the same values
+ int pos = 0;
+ for (int i = 0; i < metaEnum.keyCount(); i++) {
+ int value = metaEnum.value(i);
+ if (!valueMap.contains(value)) {
+ if (value == enumValue)
+ return pos;
+ valueMap[value] = pos++;
+ }
+ }
+ return -1;
+}
+
+int ObjectControllerPrivate::intToEnum(const QMetaEnum &metaEnum, int intValue) const
+{
+ QMap<int, bool> valueMap; // dont show multiple enum values which have the same values
+ QList<int> values;
+ for (int i = 0; i < metaEnum.keyCount(); i++) {
+ int value = metaEnum.value(i);
+ if (!valueMap.contains(value)) {
+ valueMap[value] = true;
+ values.append(value);
+ }
+ }
+ if (intValue >= values.count())
+ return -1;
+ return values.at(intValue);
+}
+
+bool ObjectControllerPrivate::isSubValue(int value, int subValue) const
+{
+ if (value == subValue)
+ return true;
+ int i = 0;
+ while (subValue) {
+ if (!(value & (1 << i))) {
+ if (subValue & 1)
+ return false;
+ }
+ i++;
+ subValue = subValue >> 1;
+ }
+ return true;
+}
+
+bool ObjectControllerPrivate::isPowerOf2(int value) const
+{
+ while (value) {
+ if (value & 1) {
+ return value == 1;
+ }
+ value = value >> 1;
+ }
+ return false;
+}
+
+int ObjectControllerPrivate::flagToInt(const QMetaEnum &metaEnum, int flagValue) const
+{
+ if (!flagValue)
+ return 0;
+ int intValue = 0;
+ QMap<int, int> valueMap; // dont show multiple enum values which have the same values
+ int pos = 0;
+ for (int i = 0; i < metaEnum.keyCount(); i++) {
+ int value = metaEnum.value(i);
+ if (!valueMap.contains(value) && isPowerOf2(value)) {
+ if (isSubValue(flagValue, value))
+ intValue |= (1 << pos);
+ valueMap[value] = pos++;
+ }
+ }
+ return intValue;
+}
+
+int ObjectControllerPrivate::intToFlag(const QMetaEnum &metaEnum, int intValue) const
+{
+ QMap<int, bool> valueMap; // dont show multiple enum values which have the same values
+ QList<int> values;
+ for (int i = 0; i < metaEnum.keyCount(); i++) {
+ int value = metaEnum.value(i);
+ if (!valueMap.contains(value) && isPowerOf2(value)) {
+ valueMap[value] = true;
+ values.append(value);
+ }
+ }
+ int flagValue = 0;
+ int temp = intValue;
+ int i = 0;
+ while (temp) {
+ if (i >= values.count())
+ return -1;
+ if (temp & 1)
+ flagValue |= values.at(i);
+ i++;
+ temp = temp >> 1;
+ }
+ return flagValue;
+}
+
+void ObjectControllerPrivate::updateClassProperties(const QMetaObject *metaObject, bool recursive)
+{
+ if (!metaObject)
+ return;
+
+ if (recursive)
+ updateClassProperties(metaObject->superClass(), recursive);
+
+ QtProperty *classProperty = m_classToProperty.value(metaObject);
+ if (!classProperty)
+ return;
+
+ for (int idx = metaObject->propertyOffset(); idx < metaObject->propertyCount(); idx++) {
+ QMetaProperty metaProperty = metaObject->property(idx);
+ if (metaProperty.isReadable()) {
+ if (m_classToIndexToProperty.contains(metaObject) && m_classToIndexToProperty[metaObject].contains(idx)) {
+ QtVariantProperty *subProperty = m_classToIndexToProperty[metaObject][idx];
+ if (metaProperty.isEnumType()) {
+ if (metaProperty.isFlagType())
+ subProperty->setValue(flagToInt(metaProperty.enumerator(), metaProperty.read(m_object).toInt()));
+ else
+ subProperty->setValue(enumToInt(metaProperty.enumerator(), metaProperty.read(m_object).toInt()));
+ } else {
+ subProperty->setValue(metaProperty.read(m_object));
+ }
+ }
+ }
+ }
+}
+
+void ObjectControllerPrivate::addClassProperties(const QMetaObject *metaObject)
+{
+ if (!metaObject)
+ return;
+
+ addClassProperties(metaObject->superClass());
+
+ QtProperty *classProperty = m_classToProperty.value(metaObject);
+ if (!classProperty) {
+ QString className = QLatin1String(metaObject->className());
+ classProperty = m_manager->addProperty(QtVariantPropertyManager::groupTypeId(), className);
+ m_classToProperty[metaObject] = classProperty;
+ m_propertyToClass[classProperty] = metaObject;
+
+ for (int idx = metaObject->propertyOffset(); idx < metaObject->propertyCount(); idx++) {
+ QMetaProperty metaProperty = metaObject->property(idx);
+ int type = metaProperty.userType();
+ QtVariantProperty *subProperty = 0;
+ if (!metaProperty.isReadable()) {
+ subProperty = m_readOnlyManager->addProperty(QVariant::String, QLatin1String(metaProperty.name()));
+ subProperty->setValue(QLatin1String("< Non Readable >"));
+ } else if (metaProperty.isEnumType()) {
+ if (metaProperty.isFlagType()) {
+ subProperty = m_manager->addProperty(QtVariantPropertyManager::flagTypeId(), QLatin1String(metaProperty.name()));
+ QMetaEnum metaEnum = metaProperty.enumerator();
+ QMap<int, bool> valueMap;
+ QStringList flagNames;
+ for (int i = 0; i < metaEnum.keyCount(); i++) {
+ int value = metaEnum.value(i);
+ if (!valueMap.contains(value) && isPowerOf2(value)) {
+ valueMap[value] = true;
+ flagNames.append(QLatin1String(metaEnum.key(i)));
+ }
+ subProperty->setAttribute(QLatin1String("flagNames"), flagNames);
+ subProperty->setValue(flagToInt(metaEnum, metaProperty.read(m_object).toInt()));
+ }
+ } else {
+ subProperty = m_manager->addProperty(QtVariantPropertyManager::enumTypeId(), QLatin1String(metaProperty.name()));
+ QMetaEnum metaEnum = metaProperty.enumerator();
+ QMap<int, bool> valueMap; // dont show multiple enum values which have the same values
+ QStringList enumNames;
+ for (int i = 0; i < metaEnum.keyCount(); i++) {
+ int value = metaEnum.value(i);
+ if (!valueMap.contains(value)) {
+ valueMap[value] = true;
+ enumNames.append(QLatin1String(metaEnum.key(i)));
+ }
+ }
+ subProperty->setAttribute(QLatin1String("enumNames"), enumNames);
+ subProperty->setValue(enumToInt(metaEnum, metaProperty.read(m_object).toInt()));
+ }
+ } else if (m_manager->isPropertyTypeSupported(type)) {
+ if (!metaProperty.isWritable())
+ subProperty = m_readOnlyManager->addProperty(type, QLatin1String(metaProperty.name()) + QLatin1String(" (Non Writable)"));
+ if (!metaProperty.isDesignable())
+ subProperty = m_readOnlyManager->addProperty(type, QLatin1String(metaProperty.name()) + QLatin1String(" (Non Designable)"));
+ else
+ subProperty = m_manager->addProperty(type, QLatin1String(metaProperty.name()));
+ subProperty->setValue(metaProperty.read(m_object));
+ } else {
+ subProperty = m_readOnlyManager->addProperty(QVariant::String, QLatin1String(metaProperty.name()));
+ subProperty->setValue(QLatin1String("< Unknown Type >"));
+ subProperty->setEnabled(false);
+ }
+ classProperty->addSubProperty(subProperty);
+ m_propertyToIndex[subProperty] = idx;
+ m_classToIndexToProperty[metaObject][idx] = subProperty;
+ }
+ } else {
+ updateClassProperties(metaObject, false);
+ }
+
+ m_topLevelProperties.append(classProperty);
+ m_browser->addProperty(classProperty);
+}
+
+void ObjectControllerPrivate::saveExpandedState()
+{
+
+}
+
+void ObjectControllerPrivate::restoreExpandedState()
+{
+
+}
+
+void ObjectControllerPrivate::slotValueChanged(QtProperty *property, const QVariant &value)
+{
+ if (!m_propertyToIndex.contains(property))
+ return;
+
+ int idx = m_propertyToIndex.value(property);
+
+ const QMetaObject *metaObject = m_object->metaObject();
+ QMetaProperty metaProperty = metaObject->property(idx);
+ if (metaProperty.isEnumType()) {
+ if (metaProperty.isFlagType())
+ metaProperty.write(m_object, intToFlag(metaProperty.enumerator(), value.toInt()));
+ else
+ metaProperty.write(m_object, intToEnum(metaProperty.enumerator(), value.toInt()));
+ } else {
+ metaProperty.write(m_object, value);
+ }
+
+ updateClassProperties(metaObject, true);
+}
+
+///////////////////
+
+ObjectController::ObjectController(QWidget *parent)
+ : QWidget(parent)
+{
+ d_ptr = new ObjectControllerPrivate;
+ d_ptr->q_ptr = this;
+
+ d_ptr->m_object = 0;
+/*
+ QScrollArea *scroll = new QScrollArea(this);
+ scroll->setWidgetResizable(true);
+
+ d_ptr->m_browser = new QtGroupBoxPropertyBrowser(this);
+ QVBoxLayout *layout = new QVBoxLayout(this);
+ layout->setMargin(0);
+ layout->addWidget(scroll);
+ scroll->setWidget(d_ptr->m_browser);
+*/
+ QtTreePropertyBrowser *browser = new QtTreePropertyBrowser(this);
+ browser->setRootIsDecorated(false);
+ d_ptr->m_browser = browser;
+ QVBoxLayout *layout = new QVBoxLayout(this);
+ layout->setMargin(0);
+ layout->addWidget(d_ptr->m_browser);
+
+ d_ptr->m_readOnlyManager = new QtVariantPropertyManager(this);
+ d_ptr->m_manager = new QtVariantPropertyManager(this);
+ QtVariantEditorFactory *factory = new QtVariantEditorFactory(this);
+ d_ptr->m_browser->setFactoryForManager(d_ptr->m_manager, factory);
+
+ connect(d_ptr->m_manager, SIGNAL(valueChanged(QtProperty *, const QVariant &)),
+ this, SLOT(slotValueChanged(QtProperty *, const QVariant &)));
+}
+
+ObjectController::~ObjectController()
+{
+ delete d_ptr;
+}
+
+void ObjectController::setObject(QObject *object)
+{
+ if (d_ptr->m_object == object)
+ return;
+
+ if (d_ptr->m_object) {
+ d_ptr->saveExpandedState();
+ QListIterator<QtProperty *> it(d_ptr->m_topLevelProperties);
+ while (it.hasNext()) {
+ d_ptr->m_browser->removeProperty(it.next());
+ }
+ d_ptr->m_topLevelProperties.clear();
+ }
+
+ d_ptr->m_object = object;
+
+ if (!d_ptr->m_object)
+ return;
+
+ d_ptr->addClassProperties(d_ptr->m_object->metaObject());
+
+ d_ptr->restoreExpandedState();
+}
+
+QObject *ObjectController::object() const
+{
+ return d_ptr->m_object;
+}
+
+#include "moc_objectcontroller.cpp"
diff --git a/3rdparty/QtPropertyBrowser/examples/object_controller/objectcontroller.h b/3rdparty/QtPropertyBrowser/examples/object_controller/objectcontroller.h
new file mode 100644
index 00000000..f470b636
--- /dev/null
+++ b/3rdparty/QtPropertyBrowser/examples/object_controller/objectcontroller.h
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of a Qt Solutions component.
+**
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+****************************************************************************/
+
+#ifndef OBJECTCONTROLLER_H
+#define OBJECTCONTROLLER_H
+
+#include <QWidget>
+
+class ObjectControllerPrivate;
+
+class ObjectController : public QWidget
+{
+ Q_OBJECT
+public:
+ ObjectController(QWidget *parent = 0);
+ ~ObjectController();
+
+ void setObject(QObject *object);
+ QObject *object() const;
+
+private:
+ ObjectControllerPrivate *d_ptr;
+ Q_DECLARE_PRIVATE(ObjectController)
+ Q_DISABLE_COPY(ObjectController)
+ Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QVariant &))
+};
+
+#endif