diff options
author | Miodrag Milanovic <mmicko@gmail.com> | 2018-06-11 18:22:20 +0200 |
---|---|---|
committer | Miodrag Milanovic <mmicko@gmail.com> | 2018-06-11 21:30:22 +0200 |
commit | eb392f649ea544742849e50d920be677d09aa344 (patch) | |
tree | d3032358009998a515874bcc368c7cef5f5882ae /3rdparty/QtPropertyBrowser/examples/extension | |
parent | be73894bea1c5719eccfad6b8c7e7ae44798a68a (diff) | |
download | nextpnr-eb392f649ea544742849e50d920be677d09aa344.tar.gz nextpnr-eb392f649ea544742849e50d920be677d09aa344.tar.bz2 nextpnr-eb392f649ea544742849e50d920be677d09aa344.zip |
Added QtPropertyBrowser source
Diffstat (limited to '3rdparty/QtPropertyBrowser/examples/extension')
4 files changed, 314 insertions, 0 deletions
diff --git a/3rdparty/QtPropertyBrowser/examples/extension/CMakeLists.txt b/3rdparty/QtPropertyBrowser/examples/extension/CMakeLists.txt new file mode 100644 index 00000000..25d6b9cf --- /dev/null +++ b/3rdparty/QtPropertyBrowser/examples/extension/CMakeLists.txt @@ -0,0 +1,15 @@ +# 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 extension) + +SET(KIT_SRCS + main.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/extension/extension.pro b/3rdparty/QtPropertyBrowser/examples/extension/extension.pro new file mode 100644 index 00000000..7a13249d --- /dev/null +++ b/3rdparty/QtPropertyBrowser/examples/extension/extension.pro @@ -0,0 +1,8 @@ +TEMPLATE = app +DEPENDPATH += . +INCLUDEPATH += . + +include(../../src/qtpropertybrowser.pri) +# Input +SOURCES += main.cpp + diff --git a/3rdparty/QtPropertyBrowser/examples/extension/extension.qdoc b/3rdparty/QtPropertyBrowser/examples/extension/extension.qdoc new file mode 100644 index 00000000..81b94748 --- /dev/null +++ b/3rdparty/QtPropertyBrowser/examples/extension/extension.qdoc @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** 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-extension.html + \title Extension Example + + This example demonstrates how to extend the + QtVariantPropertyManager class to handle additional property + types. + + \image extension.png + + The variant manager is extended to handle the QPointF type. + + The source files can be found in examples/extension directory of the package. +*/ diff --git a/3rdparty/QtPropertyBrowser/examples/extension/main.cpp b/3rdparty/QtPropertyBrowser/examples/extension/main.cpp new file mode 100644 index 00000000..2a4fd61e --- /dev/null +++ b/3rdparty/QtPropertyBrowser/examples/extension/main.cpp @@ -0,0 +1,238 @@ +/**************************************************************************** +** +** 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 "qtvariantproperty.h" +#include "qteditorfactory.h" +#include "qttreepropertybrowser.h" + +class VariantManager : public QtVariantPropertyManager +{ + Q_OBJECT +public: + VariantManager(QObject *parent = 0); + ~VariantManager(); + + virtual QVariant value(const QtProperty *property) const; + virtual int valueType(int propertyType) const; + virtual bool isPropertyTypeSupported(int propertyType) const; + + QString valueText(const QtProperty *property) const; + +public slots: + virtual void setValue(QtProperty *property, const QVariant &val); +protected: + virtual void initializeProperty(QtProperty *property); + virtual void uninitializeProperty(QtProperty *property); +private slots: + void slotValueChanged(QtProperty *property, const QVariant &value); + void slotPropertyDestroyed(QtProperty *property); +private: + struct Data { + QVariant value; + QtVariantProperty *x; + QtVariantProperty *y; + }; + QMap<const QtProperty *, Data> propertyToData; + QMap<const QtProperty *, QtProperty *> xToProperty; + QMap<const QtProperty *, QtProperty *> yToProperty; +}; + +VariantManager::VariantManager(QObject *parent) + : QtVariantPropertyManager(parent) +{ + connect(this, SIGNAL(valueChanged(QtProperty *, const QVariant &)), + this, SLOT(slotValueChanged(QtProperty *, const QVariant &))); + connect(this, SIGNAL(propertyDestroyed(QtProperty *)), + this, SLOT(slotPropertyDestroyed(QtProperty *))); +} + +VariantManager::~VariantManager() +{ + +} + +void VariantManager::slotValueChanged(QtProperty *property, const QVariant &value) +{ + if (xToProperty.contains(property)) { + QtProperty *pointProperty = xToProperty[property]; + QVariant v = this->value(pointProperty); + QPointF p = v.value<QPointF>(); + p.setX(value.value<double>()); + setValue(pointProperty, p); + } else if (yToProperty.contains(property)) { + QtProperty *pointProperty = yToProperty[property]; + QVariant v = this->value(pointProperty); + QPointF p = v.value<QPointF>(); + p.setY(value.value<double>()); + setValue(pointProperty, p); + } +} + +void VariantManager::slotPropertyDestroyed(QtProperty *property) +{ + if (xToProperty.contains(property)) { + QtProperty *pointProperty = xToProperty[property]; + propertyToData[pointProperty].x = 0; + xToProperty.remove(property); + } else if (yToProperty.contains(property)) { + QtProperty *pointProperty = yToProperty[property]; + propertyToData[pointProperty].y = 0; + yToProperty.remove(property); + } +} + +bool VariantManager::isPropertyTypeSupported(int propertyType) const +{ + if (propertyType == QVariant::PointF) + return true; + return QtVariantPropertyManager::isPropertyTypeSupported(propertyType); +} + +int VariantManager::valueType(int propertyType) const +{ + if (propertyType == QVariant::PointF) + return QVariant::PointF; + return QtVariantPropertyManager::valueType(propertyType); +} + +QVariant VariantManager::value(const QtProperty *property) const +{ + if (propertyToData.contains(property)) + return propertyToData[property].value; + return QtVariantPropertyManager::value(property); +} + +QString VariantManager::valueText(const QtProperty *property) const +{ + if (propertyToData.contains(property)) { + QVariant v = propertyToData[property].value; + QPointF p = v.value<QPointF>(); + return QString(tr("(%1, %2)").arg(QString::number(p.x())) + .arg(QString::number(p.y()))); + } + return QtVariantPropertyManager::valueText(property); +} + +void VariantManager::setValue(QtProperty *property, const QVariant &val) +{ + if (propertyToData.contains(property)) { + if (val.type() != QVariant::PointF && !val.canConvert(QVariant::PointF)) + return; + QPointF p = val.value<QPointF>(); + Data d = propertyToData[property]; + d.value = p; + if (d.x) + d.x->setValue(p.x()); + if (d.y) + d.y->setValue(p.y()); + propertyToData[property] = d; + emit propertyChanged(property); + emit valueChanged(property, p); + return; + } + QtVariantPropertyManager::setValue(property, val); +} + +void VariantManager::initializeProperty(QtProperty *property) +{ + if (propertyType(property) == QVariant::PointF) { + Data d; + + d.value = QPointF(0, 0); + + VariantManager *that = (VariantManager *)this; + + d.x = that->addProperty(QVariant::Double); + d.x->setPropertyName(tr("Position X")); + property->addSubProperty(d.x); + xToProperty[d.x] = property; + + d.y = that->addProperty(QVariant::Double); + d.y->setPropertyName(tr("Position Y")); + property->addSubProperty(d.y); + yToProperty[d.y] = property; + + propertyToData[property] = d; + } + QtVariantPropertyManager::initializeProperty(property); +} + +void VariantManager::uninitializeProperty(QtProperty *property) +{ + if (propertyToData.contains(property)) { + Data d = propertyToData[property]; + if (d.x) + xToProperty.remove(d.x); + if (d.y) + yToProperty.remove(d.y); + propertyToData.remove(property); + } + QtVariantPropertyManager::uninitializeProperty(property); +} + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + VariantManager *variantManager = new VariantManager(); + + QtVariantProperty *item = variantManager->addProperty(QVariant::PointF, + "PointF Property"); + item->setValue(QPointF(2.5, 13.13)); + + QtVariantEditorFactory *variantFactory = new QtVariantEditorFactory(); + + QtTreePropertyBrowser ed1; + QtVariantPropertyManager *varMan = variantManager; + ed1.setFactoryForManager(varMan, variantFactory); + ed1.addProperty(item); + + + ed1.show(); + + int ret = app.exec(); + + delete variantFactory; + delete variantManager; + + return ret; +} + +#include "main.moc" |