From e1244a0dff7815ad325ae433bc890275916b4fe8 Mon Sep 17 00:00:00 2001 From: Dominik Riebeling Date: Sat, 5 Mar 2011 21:12:31 +0000 Subject: Remove outdated and unmaintained wpseditor. The wpseditor is superseded by the Theme Editor these days. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29528 a1c6a512-1295-4272-9138-f99709370657 --- .../gui/src/QPropertyEditor/ColorCombo.cpp | 73 ------- .../wpseditor/gui/src/QPropertyEditor/ColorCombo.h | 49 ----- .../wpseditor/gui/src/QPropertyEditor/Property.cpp | 136 ------------ utils/wpseditor/gui/src/QPropertyEditor/Property.h | 157 -------------- .../gui/src/QPropertyEditor/QPropertyEditor.pro | 26 --- .../src/QPropertyEditor/QPropertyEditorWidget.cpp | 56 ----- .../src/QPropertyEditor/QPropertyEditorWidget.h | 113 ---------- .../gui/src/QPropertyEditor/QPropertyModel.cpp | 236 --------------------- .../gui/src/QPropertyEditor/QPropertyModel.h | 105 --------- .../gui/src/QPropertyEditor/QVariantDelegate.cpp | 105 --------- .../gui/src/QPropertyEditor/QVariantDelegate.h | 78 ------- 11 files changed, 1134 deletions(-) delete mode 100644 utils/wpseditor/gui/src/QPropertyEditor/ColorCombo.cpp delete mode 100644 utils/wpseditor/gui/src/QPropertyEditor/ColorCombo.h delete mode 100644 utils/wpseditor/gui/src/QPropertyEditor/Property.cpp delete mode 100644 utils/wpseditor/gui/src/QPropertyEditor/Property.h delete mode 100644 utils/wpseditor/gui/src/QPropertyEditor/QPropertyEditor.pro delete mode 100644 utils/wpseditor/gui/src/QPropertyEditor/QPropertyEditorWidget.cpp delete mode 100644 utils/wpseditor/gui/src/QPropertyEditor/QPropertyEditorWidget.h delete mode 100644 utils/wpseditor/gui/src/QPropertyEditor/QPropertyModel.cpp delete mode 100644 utils/wpseditor/gui/src/QPropertyEditor/QPropertyModel.h delete mode 100644 utils/wpseditor/gui/src/QPropertyEditor/QVariantDelegate.cpp delete mode 100644 utils/wpseditor/gui/src/QPropertyEditor/QVariantDelegate.h (limited to 'utils/wpseditor/gui/src/QPropertyEditor') diff --git a/utils/wpseditor/gui/src/QPropertyEditor/ColorCombo.cpp b/utils/wpseditor/gui/src/QPropertyEditor/ColorCombo.cpp deleted file mode 100644 index f5eeb030dc..0000000000 --- a/utils/wpseditor/gui/src/QPropertyEditor/ColorCombo.cpp +++ /dev/null @@ -1,73 +0,0 @@ -// ************************************************************************************************* -// -// QPropertyEditor v 0.1 -// -// -------------------------------------- -// Copyright (C) 2007 Volker Wiendl -// -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -// -// -// This class is based on the Color Editor Factory Example by Trolltech -// -// ************************************************************************************************* - -#include "ColorCombo.h" - -#include - -ColorCombo::ColorCombo(QWidget* parent /*= 0*/) : QComboBox(parent) { - QStringList colorNames = QColor::colorNames(); - for (int i = 0; i < colorNames.size(); ++i) { - QColor color(colorNames[i]); - insertItem(i, colorNames[i]); - setItemData(i, color, Qt::DecorationRole); - } - addItem(tr("Custom"), QVariant((int)QVariant::UserType)); - connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(currentChanged(int))); -} - - -ColorCombo::~ColorCombo() {} - - -QColor ColorCombo::color() const { - return qVariantValue(itemData(currentIndex(), Qt::DecorationRole)); -} - -void ColorCombo::setColor(QColor color) { - m_init = color; - setCurrentIndex(findData(color, int(Qt::DecorationRole))); - if (currentIndex() == -1) { - addItem(color.name()); - setItemData(count()-1, color, Qt::DecorationRole); - setCurrentIndex(count()-1); - } -} - -void ColorCombo::currentChanged(int index) { - if (itemData(index).isValid() && itemData(index) == QVariant((int)QVariant::UserType)) { - QColor color = QColorDialog::getColor(m_init, this); - if (color.isValid()) { - if (findData(color, int(Qt::DecorationRole)) == -1) { - addItem(color.name()); - setItemData(count()-1, color, Qt::DecorationRole); - } - setCurrentIndex(findData(color, int(Qt::DecorationRole))); - } else - setCurrentIndex(findData(m_init)); - } -} diff --git a/utils/wpseditor/gui/src/QPropertyEditor/ColorCombo.h b/utils/wpseditor/gui/src/QPropertyEditor/ColorCombo.h deleted file mode 100644 index 530b05bbc5..0000000000 --- a/utils/wpseditor/gui/src/QPropertyEditor/ColorCombo.h +++ /dev/null @@ -1,49 +0,0 @@ -// ************************************************************************************************* -// -// QPropertyEditor v 0.1 -// -// -------------------------------------- -// Copyright (C) 2007 Volker Wiendl -// -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -// -// -// This class is based on the Color Editor Factory Example by Trolltech -// -// ************************************************************************************************* - -#ifndef COLORCOMBO_H_ -#define COLORCOMBO_H_ - -#include - -class ColorCombo : public QComboBox { - Q_OBJECT -public: - ColorCombo(QWidget* parent = 0); - virtual ~ColorCombo(); - - QColor color() const; - void setColor(QColor c); - -private slots: - void currentChanged(int index); - -private: - QColor m_init; - -}; -#endif diff --git a/utils/wpseditor/gui/src/QPropertyEditor/Property.cpp b/utils/wpseditor/gui/src/QPropertyEditor/Property.cpp deleted file mode 100644 index 0746d15140..0000000000 --- a/utils/wpseditor/gui/src/QPropertyEditor/Property.cpp +++ /dev/null @@ -1,136 +0,0 @@ -// **************************************************************************************** -// -// QPropertyEditor Library -// -------------------------------------- -// Copyright (C) 2007 Volker Wiendl -// -// This file is part of the Horde3D Scene Editor. -// -// The QPropertyEditor Library is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation version 3 of the License -// -// The Horde3D Scene Editor is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// -// **************************************************************************************** - -#include "Property.h" -#include "ColorCombo.h" - -#include -#include - -#include - -Property::Property(const QString& name /*= QString()*/, QObject* propertyObject /*= 0*/, QObject* parent /*= 0*/) : QObject(parent), - m_propertyObject(propertyObject) { - setObjectName(name); -} - -QVariant Property::value(int /*role = Qt::UserRole*/) const { - if (m_propertyObject) - return m_propertyObject->property(qPrintable(objectName())); - else - return QVariant(); -} - -void Property::setValue(const QVariant &value) { - if (m_propertyObject) - m_propertyObject->setProperty(qPrintable(objectName()), value); -} - -bool Property::isReadOnly() { - if (m_propertyObject && m_propertyObject->metaObject()->property(m_propertyObject->metaObject()->indexOfProperty(qPrintable(objectName()))).isWritable()) - return false; - else - return true; -} - -QWidget* Property::createEditor(QWidget *parent, const QStyleOptionViewItem &option) { - (void)option; - QWidget* editor = 0; - switch (value().type()) { - case QVariant::Color: - editor = new ColorCombo(parent); - break; - case QVariant::Int: - editor = new QSpinBox(parent); - editor->setProperty("minimum", -INT_MAX); - editor->setProperty("maximum", INT_MAX); - connect(editor, SIGNAL(valueChanged(int)), this, SLOT(setValue(int))); - break; - case QMetaType::Float: - case QVariant::Double: - editor = new QDoubleSpinBox(parent); - editor->setProperty("minimum", -INT_MAX); - editor->setProperty("maximum", INT_MAX); - connect(editor, SIGNAL(valueChanged(double)), this, SLOT(setValue(double))); - break; - default: - return editor; - } - return editor; -} - -bool Property::setEditorData(QWidget *editor, const QVariant &data) { - switch (value().type()) { - case QVariant::Color: - static_cast(editor)->setColor(data.value()); - return true; - ; - case QVariant::Int: - editor->blockSignals(true); - static_cast(editor)->setValue(data.toInt()); - editor->blockSignals(false); - return true; - case QMetaType::Float: - case QVariant::Double: - editor->blockSignals(true); - static_cast(editor)->setValue(data.toDouble()); - editor->blockSignals(false); - return true; - default: - return false; - } - return false; -} - -QVariant Property::editorData(QWidget *editor) { - switch (value().type()) { - case QVariant::Color: - return QVariant::fromValue(static_cast(editor)->color()); - case QVariant::Int: - return QVariant(static_cast(editor)->value()); - case QMetaType::Float: - case QVariant::Double: - return QVariant(static_cast(editor)->value()); - break; - default: - return QVariant(); - } -} - -Property* Property::findPropertyObject(QObject* propertyObject) { - if (m_propertyObject == propertyObject) - return this; - for (int i=0; i(children()[i])->findPropertyObject(propertyObject); - if (child) - return child; - } - return 0; -} - -void Property::setValue(double value) { - setValue(QVariant(value)); -} - -void Property::setValue(int value) { - setValue(QVariant(value)); -} diff --git a/utils/wpseditor/gui/src/QPropertyEditor/Property.h b/utils/wpseditor/gui/src/QPropertyEditor/Property.h deleted file mode 100644 index 52d6842987..0000000000 --- a/utils/wpseditor/gui/src/QPropertyEditor/Property.h +++ /dev/null @@ -1,157 +0,0 @@ -// ************************************************************************************************* -// -// QPropertyEditor v 0.1 -// -// -------------------------------------- -// Copyright (C) 2007 Volker Wiendl -// -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -// -// ************************************************************************************************* - -#ifndef PROPERTY_H_ -#define PROPERTY_H_ - -#include -#include -#include - -/** - * The Property class is the base class for all properties in the QPropertyEditor - * You can implement custom properties inherited from this class to further enhence the - * functionality of the QPropertyEditor - */ -class Property : public QObject { - Q_OBJECT - -public: - - /** - * Constructor - * - * @param name the name of the property within the propertyObject (will be used in the QPropertyEditorWidget view too) - * @param propertyObject the object that contains the property - * @param parent optional parent object - */ - Property(const QString& name = QString(), QObject* propertyObject = 0, QObject* parent = 0); - - /** - * The value stored by this property - * @return QVariant the data converted to a QVariant - */ - virtual QVariant value(int role = Qt::UserRole) const; - /** - * Sets the value stored by this property - * @param value the data converted to a QVariant - */ - virtual void setValue(const QVariant& value); - - /** - * Returns the QObject which contains the property managed by this instance - * @return QObject* pointer to the QObject that contains user defined properties - */ - QObject* propertyObject() { - return m_propertyObject; - } - - /** - * Flag if property is used for indicating a group or really manages a property - * @return bool true if this property is only used to display a category in the QPropertyEditorWidget - */ - bool isRoot() { - return m_propertyObject == 0; - } - - /** - * Flag if the property can be set - * @return bool true if this property has no set method - */ - bool isReadOnly(); - - /** - * Returns the row of this instance within the QPropertyModel - * @return int row within the QPropertyModel - */ - int row() { - return parent()->children().indexOf(this); - } - - /** - * returns optional settings for the editor widget that is used to manipulate the properties value - * @return QString a string that contains property settings for the editor widget (e.g. "minimum=1.0;maximum=10.0;") - */ - QString editorHints() { - return m_hints; - } - - /** - * Sets properties for the editor widget that is used to manipulate the data value managed by this instance - * @param hints a string containing property settings for the editor widget that manipulates this property - */ - virtual void setEditorHints(const QString& hints) { - m_hints = hints; - } - - /** - * Creates an editor for the data managed by this instance - * @param parent widget the newly created editor widget will be child of - * @param option currently not used - * @return QWidget* pointer to the editor widget - */ - virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option); - - /** - * Returns the data of the editor widget used to manipulate this instance - * @return QVariant the data converted to a QVariant - */ - virtual QVariant editorData(QWidget *editor); - - /** - * Changes the editor widget's data to a specific value - * @param editor the editor widget - * @param data the data to set in the editor widget - * @return bool true if editor widget was set to the given data successfully, false if the data can not be set in the editor (e.g. wrong datatype) - */ - virtual bool setEditorData(QWidget *editor, const QVariant& data); - - /** - * Tries to find the first property that manages the given propertyObject - * @param propertyObject - * @return Property - */ - Property* findPropertyObject(QObject* propertyObject); - -private slots: - /** - * This slot is used to immediately set the properties when the editor widget's value of a double or float - * property has changed - * @param value the new value - */ - void setValue(double value); - /** - * This slot is used to immediately set the properties when the editor widget's value of an integer - * property has changed - * @param value the new value - */ - void setValue(int value); - -private: - QObject* m_propertyObject; - QString m_hints; - -}; - -#endif diff --git a/utils/wpseditor/gui/src/QPropertyEditor/QPropertyEditor.pro b/utils/wpseditor/gui/src/QPropertyEditor/QPropertyEditor.pro deleted file mode 100644 index ad1e31ce9a..0000000000 --- a/utils/wpseditor/gui/src/QPropertyEditor/QPropertyEditor.pro +++ /dev/null @@ -1,26 +0,0 @@ -TEMPLATE = lib -CONFIG += staticlib debug -SOURCES = ColorCombo.cpp \ - Property.cpp \ - QPropertyEditorWidget.cpp \ - QPropertyModel.cpp \ - QVariantDelegate.cpp -HEADERS = ColorCombo.h \ - Property.h \ - QPropertyEditorWidget.h \ - QPropertyModel.h \ - QVariantDelegate.h -INCLUDEPATH += . -DESTDIR = ../../lib -UI_DIR = . -CONFIG(debug, debug|release) { - TARGET = QPropertyEditord - OBJECTS_DIR = ../../build/QPropertyEditor/debug - MOC_DIR = ../../build/QPropertyEditor/debug -} -CONFIG(release, debug|release) { - TARGET = QPropertyEditor - OBJECTS_DIR = ../../build/QPropertyEditor/release - MOC_DIR = ../../build/QPropertyEditor/release - DEFINES += QT_NO_DEBUG -} diff --git a/utils/wpseditor/gui/src/QPropertyEditor/QPropertyEditorWidget.cpp b/utils/wpseditor/gui/src/QPropertyEditor/QPropertyEditorWidget.cpp deleted file mode 100644 index fc4b90c227..0000000000 --- a/utils/wpseditor/gui/src/QPropertyEditor/QPropertyEditorWidget.cpp +++ /dev/null @@ -1,56 +0,0 @@ -// ************************************************************************************************* -// -// QPropertyEditor v 0.1 -// -// -------------------------------------- -// Copyright (C) 2007 Volker Wiendl -// -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -// -// ************************************************************************************************* - -#include "QPropertyEditorWidget.h" -#include "QPropertyModel.h" -#include "QVariantDelegate.h" -#include "Property.h" - -QPropertyEditorWidget::QPropertyEditorWidget(QWidget* parent /*= 0*/) : QTreeView(parent) { - m_model = new QPropertyModel(this); - setModel(m_model); - setItemDelegate(new QVariantDelegate(this)); -} - - -QPropertyEditorWidget::~QPropertyEditorWidget() {} - -void QPropertyEditorWidget::addObject(QObject* propertyObject) { - m_model->addItem(propertyObject); - expandToDepth(0); -} - -void QPropertyEditorWidget::setObject(QObject* propertyObject) { - m_model->clear(); - if (propertyObject) - addObject(propertyObject); -} - -void QPropertyEditorWidget::updateObject(QObject* propertyObject) { - m_model->updateItem(propertyObject); -} - -void QPropertyEditorWidget::setCustomPropertyCB(UserTypeCB callback) { - m_model->setCustomPropertyCB(callback); -} diff --git a/utils/wpseditor/gui/src/QPropertyEditor/QPropertyEditorWidget.h b/utils/wpseditor/gui/src/QPropertyEditor/QPropertyEditorWidget.h deleted file mode 100644 index 2dab87722a..0000000000 --- a/utils/wpseditor/gui/src/QPropertyEditor/QPropertyEditorWidget.h +++ /dev/null @@ -1,113 +0,0 @@ -// ************************************************************************************************* -// -// QPropertyEditor v 0.1 -// -// -------------------------------------- -// Copyright (C) 2007 Volker Wiendl -// -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -// -// ************************************************************************************************* - -#ifndef QPROPERTYEDITORWIDGET_H_ -#define QPROPERTYEDITORWIDGET_H_ - -#include - -class QPropertyModel; -class Property; - -/** - * \mainpage QPropertyEditor - * - * \section intro_sec Introduction - * - * The main purpose for the QPropertyEditor is the visualization and manipulation of properties defined via the Q_PROPERTY macro in - * QObject based classes. - */ - -/** - * \brief The QPropertyEditorWidget offers an easy to use mechanism to visualize properties of a class inherited from QObject. - * - * Qt provides a nice way to define class properties by using the Q_PROPERTY macro. The purpose of the QPropertyEditor - * is to visualize these properties in an easy way. - * - * To use the property editor, all you have to do is to create a class that defines it's properties by using Q_PROPERTY - * and to add this class by using the addObject() method of this QPropertyEditorWidget class. - * The QPropertyEditorWidget is inherited from QTreeView and will display the properties in a tree with two columns: Name and Value - * - * For basic data types the build in editor widgets of Qt will be used. The QPropertyEditor itself only defines an additional - * editor for QColor (based on the Color Editor Factory Example from Trolltech). But it can easily be extended by yourself - * either within the library or for special datatypes also outside of the library in your application. - */ -class QPropertyEditorWidget : public QTreeView { - Q_OBJECT -public: - - /** - * A typedef for a callback used to create user defined properties for custom datatypes - */ - typedef Property* (*UserTypeCB)(const QString& name, QObject* propertyObject, Property* parent); - - /** - * \brief Constructor - * - * Creates a new editor widget based on QTreeView - * @param parent optional parent widget - */ - QPropertyEditorWidget(QWidget* parent = 0); - - /// Destructor - virtual ~QPropertyEditorWidget(); - - /** - * Adds the user properties of the given class to the QPropertyModel associated with this view - * - * @param propertyObject the class inherited from QObject that contains user properties that should be - * managed by the QPropertyModel associated with this view - */ - void addObject(QObject* propertyObject); - - /** - * Similar to the addObject() method this method adds the properties of the given class to the QPropertyModel - * associated with this view. But in contrast to addObject() it will clear the model before, removing all - * previously added objects. - * - * @param propertyObject the class inherited from QObject that contains user properties that should be - * managed by the QPropertyModel associated with this view - */ - void setObject(QObject* propertyObject); - - /** - * Updates the view for the given object. This can be usefull if a property was changed programmatically instead - * of using the view. In this case the view normally will display the new property values only after the user clicked - * on it. To overcome this problem you can call updateObject with the object whose property was changed. - */ - void updateObject(QObject* propertyObject); - - /** - * If you define custom datatypes outside of this library the QPropertyModel will check if you - * also defined a callback that is responsible to create custom property classes inherited from Property to handle - * these datatypes. With this method you can set such a callback that will create custom properties for custom datatypes. - */ - void setCustomPropertyCB(UserTypeCB callback); - -private: - /// The Model for this view - QPropertyModel* m_model; - -}; -#endif diff --git a/utils/wpseditor/gui/src/QPropertyEditor/QPropertyModel.cpp b/utils/wpseditor/gui/src/QPropertyEditor/QPropertyModel.cpp deleted file mode 100644 index b147cd089d..0000000000 --- a/utils/wpseditor/gui/src/QPropertyEditor/QPropertyModel.cpp +++ /dev/null @@ -1,236 +0,0 @@ -// ************************************************************************************************* -// -// QPropertyEditor v 0.1 -// -// -------------------------------------- -// Copyright (C) 2007 Volker Wiendl -// -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -// -// ************************************************************************************************* - -#include "QPropertyModel.h" - -#include "Property.h" - -#include -#include -#include - -struct PropertyPair { - PropertyPair(const QMetaObject* obj, QMetaProperty property) : Property(property), Object(obj) {} - - QMetaProperty Property; - const QMetaObject* Object; - - bool operator==(const PropertyPair& other) const { - return QString(other.Property.name()) == QString(Property.name()); - } -}; - - -QPropertyModel::QPropertyModel(QObject* parent /*= 0*/) : QAbstractItemModel(parent), m_userCallback(0) { - m_rootItem = new Property("Root",0, this); -} - - -QPropertyModel::~QPropertyModel() {} - -QModelIndex QPropertyModel::index ( int row, int column, const QModelIndex & parent /*= QModelIndex()*/ ) const { - Property *parentItem = m_rootItem; - if (parent.isValid()) - parentItem = static_cast(parent.internalPointer()); - if (row >= parentItem->children().size()) - return QModelIndex(); - return createIndex(row, column, parentItem->children().at(row)); - -} - -QModelIndex QPropertyModel::parent ( const QModelIndex & index ) const { - if (!index.isValid()) - return QModelIndex(); - - Property *childItem = static_cast(index.internalPointer()); - Property *parentItem = qobject_cast(childItem->parent()); - - if (!parentItem || parentItem == m_rootItem) - return QModelIndex(); - - return createIndex(parentItem->row(), 0, parentItem); -} - -int QPropertyModel::rowCount ( const QModelIndex & parent /*= QModelIndex()*/ ) const { - Property *parentItem = m_rootItem; - if (parent.isValid()) - parentItem = static_cast(parent.internalPointer()); - return parentItem->children().size(); -} - -int QPropertyModel::columnCount ( const QModelIndex & parent /*= QModelIndex()*/ ) const { - (void)parent; - return 2; -} - -QVariant QPropertyModel::data ( const QModelIndex & index, int role /*= Qt::DisplayRole*/ ) const { - if (!index.isValid()) - return QVariant(); - - Property *item = static_cast(index.internalPointer()); - switch (role) { - case Qt::ToolTipRole: - case Qt::DecorationRole: - case Qt::DisplayRole: - case Qt::EditRole: - if (index.column() == 0) - return item->objectName(); - if (index.column() == 1) - return item->value(role); - case Qt::BackgroundRole: - if (item->isRoot()) return QApplication::palette("QTreeView").brush(QPalette::Normal, QPalette::Button).color(); - break; - }; - return QVariant(); -} - -// edit methods -bool QPropertyModel::setData ( const QModelIndex & index, const QVariant & value, int role /*= Qt::EditRole*/ ) { - if (index.isValid() && role == Qt::EditRole) { - Property *item = static_cast(index.internalPointer()); - item->setValue(value); - emit dataChanged(index, index); - return true; - } - return false; -} - -Qt::ItemFlags QPropertyModel::flags ( const QModelIndex & index ) const { - if (!index.isValid()) - return Qt::ItemIsEnabled; - Property *item = static_cast(index.internalPointer()); - // only allow change of value attribute - if (item->isRoot()) - return Qt::ItemIsEnabled; - else if (item->isReadOnly()) - return Qt::ItemIsDragEnabled | Qt::ItemIsSelectable; - else - return Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable; -} - - -QVariant QPropertyModel::headerData ( int section, Qt::Orientation orientation, int role /*= Qt::DisplayRole*/ ) const { - if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { - switch (section) { - case 0: - return tr("Name"); - case 1: - return tr("Value"); - } - } - return QVariant(); -} - -QModelIndex QPropertyModel::buddy ( const QModelIndex & index ) const { - if (index.isValid() && index.column() == 0) - return createIndex(index.row(), 1, index.internalPointer()); - return index; -} - -void QPropertyModel::addItem(QObject *propertyObject) { - // first create property <-> class hierarchy - QList propertyMap; - QList classList; - const QMetaObject* metaObject = propertyObject->metaObject(); - do { - int count = metaObject->propertyCount(); - for (int i=0; iproperty(i); - if (property.isUser()) // Hide Qt specific properties - { - PropertyPair pair(metaObject, property); - int index = propertyMap.indexOf(pair); - if (index != -1) - propertyMap[index] = pair; - else - propertyMap.push_back(pair); - } - } - classList.push_front(metaObject); - } while ((metaObject = metaObject->superClass())!=0); - - QList finalClassList; - // remove empty classes from hierarchy list - foreach(const QMetaObject* obj, classList) { - bool keep = false; - foreach(PropertyPair pair, propertyMap) { - if (pair.Object == obj) { - keep = true; - break; - } - } - if (keep) - finalClassList.push_back(obj); - } - - // finally insert properties for classes containing them - int i=rowCount(); - beginInsertRows(QModelIndex(), i, i + finalClassList.count()); - foreach(const QMetaObject* metaObject, finalClassList) { - // Set default name of the hierarchy property to the class name - QString name = metaObject->className(); - // Check if there is a special name for the class - int index = metaObject->indexOfClassInfo(qPrintable(name)); - if (index != -1) - name = metaObject->classInfo(index).value(); - // Create Property Item for class node - Property* propertyItem = new Property(name, 0, m_rootItem); - foreach(PropertyPair pair, propertyMap) { - // Check if the property is associated with the current class from the finalClassList - if (pair.Object == metaObject) { - QMetaProperty property(pair.Property); - Property* p = 0; - if (property.type() == QVariant::UserType && m_userCallback) - p = m_userCallback(property.name(), propertyObject, propertyItem); - else - p = new Property(property.name(), propertyObject, propertyItem); - int index = metaObject->indexOfClassInfo(property.name()); - if (index != -1) - p->setEditorHints(metaObject->classInfo(index).value()); - } - } - } - endInsertRows(); -} - -void QPropertyModel::updateItem ( QObject* propertyObject, const QModelIndex& parent /*= QModelIndex() */ ) { - Property *parentItem = m_rootItem; - if (parent.isValid()) - parentItem = static_cast(parent.internalPointer()); - if (parentItem->propertyObject() != propertyObject) - parentItem = parentItem->findPropertyObject(propertyObject); - if (parentItem) // Indicate view that the data for the indices have changed - dataChanged(createIndex(parentItem->row(), 0, static_cast(parentItem)), createIndex(parentItem->row(), 1, static_cast(parentItem))); -} - -void QPropertyModel::clear() { - beginRemoveRows(QModelIndex(), 0, rowCount()); - delete m_rootItem; - m_rootItem = new Property("Root",0, this); - endRemoveRows(); -} - -void QPropertyModel::setCustomPropertyCB(QPropertyEditorWidget::UserTypeCB callback) { - m_userCallback = callback; -} diff --git a/utils/wpseditor/gui/src/QPropertyEditor/QPropertyModel.h b/utils/wpseditor/gui/src/QPropertyEditor/QPropertyModel.h deleted file mode 100644 index 8a52bbe87c..0000000000 --- a/utils/wpseditor/gui/src/QPropertyEditor/QPropertyModel.h +++ /dev/null @@ -1,105 +0,0 @@ -// ************************************************************************************************* -// -// QPropertyEditor v 0.1 -// -// -------------------------------------- -// Copyright (C) 2007 Volker Wiendl -// -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -// -// ************************************************************************************************* -#ifndef QPROPERTYMODEL_H_ -#define QPROPERTYMODEL_H_ - -#include -#include - -#include "QPropertyEditorWidget.h" - -class Property; - -/** - * The QPropertyModel handles the user defined properties of QObjects - */ -class QPropertyModel : public QAbstractItemModel { - Q_OBJECT -public: - /** - * Constructor - * @param parent optional parent object - */ - QPropertyModel(QObject* parent = 0); - /// Destructor - virtual ~QPropertyModel(); - - /// QAbstractItemModel implementation - QModelIndex index ( int row, int column, const QModelIndex & parent = QModelIndex() ) const; - - /// QAbstractItemModel implementation - QModelIndex parent ( const QModelIndex & index ) const; - /// QAbstractItemModel implementation - int rowCount ( const QModelIndex & parent = QModelIndex() ) const; - /// QAbstractItemModel implementation - int columnCount ( const QModelIndex & parent = QModelIndex() ) const; - /// QAbstractItemModel implementation - QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const; - - /// QAbstractItemModel implementation - bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole ); - /// QAbstractItemModel implementation - Qt::ItemFlags flags ( const QModelIndex & index ) const; - - /// QAbstractItemModel implementation - QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const; - - /// QAbstractItemModel implementation - QModelIndex buddy ( const QModelIndex & index ) const; - - /** - * Adds the user properties of the given class to the QPropertyModel instance - * - * @param propertyObject the class inherited from QObject that contains user properties that should be - * managed by this instance - */ - void addItem(QObject* propertyObject); - - /** - * Creates a dataChanged signal for the given object - * @param propertyObject the instance of a QObject based class that should be updated - * @param parent optional model index the propertyObject is child of - */ - void updateItem ( QObject* propertyObject, const QModelIndex& parent = QModelIndex() ) ; - - /** - * Removes all objects from the model - */ - void clear(); - - /** - * Sets custom callback that will be used to create Property instances for custom datatypes - */ - void setCustomPropertyCB(QPropertyEditorWidget::UserTypeCB callback); - -private: - - /// The Root Property for all objects - Property* m_rootItem; - - /// Custom callback - QPropertyEditorWidget::UserTypeCB m_userCallback; - -}; -#endif diff --git a/utils/wpseditor/gui/src/QPropertyEditor/QVariantDelegate.cpp b/utils/wpseditor/gui/src/QPropertyEditor/QVariantDelegate.cpp deleted file mode 100644 index ebda9b2c31..0000000000 --- a/utils/wpseditor/gui/src/QPropertyEditor/QVariantDelegate.cpp +++ /dev/null @@ -1,105 +0,0 @@ -// ************************************************************************************************* -// -// QPropertyEditor v 0.1 -// -// -------------------------------------- -// Copyright (C) 2007 Volker Wiendl -// -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -// -// ************************************************************************************************* - -#include "QVariantDelegate.h" - -#include "Property.h" - -#include - - -QVariantDelegate::QVariantDelegate(QObject* parent) : QItemDelegate(parent) {} - - -QVariantDelegate::~QVariantDelegate() {} - -QWidget *QVariantDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem& option , const QModelIndex & index ) const { - QWidget* editor = 0; - Property* p = static_cast(index.internalPointer()); - switch (p->value().type()) { - case QVariant::Color: - case QVariant::Int: - case QMetaType::Float: - case QVariant::Double: - case QVariant::UserType: - editor = p->createEditor(parent, option); - if (editor) break; // if no editor could be created take default case - default: - editor = QItemDelegate::createEditor(parent, option, index); - } - parseEditorHints(editor, p->editorHints()); - return editor; -} - -void QVariantDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { - QVariant data = index.model()->data(index, Qt::EditRole); - switch (data.type()) { - case QVariant::Color: - case QMetaType::Double: - case QMetaType::Float: - case QVariant::UserType: - if (static_cast(index.internalPointer())->setEditorData(editor, data)) // if editor couldn't be recognized use default - break; - default: - QItemDelegate::setEditorData(editor, index); - break; - } -} - -void QVariantDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { - QVariant data = index.model()->data(index, Qt::EditRole); - switch (data.type()) { - case QVariant::Color: - case QMetaType::Double: - case QMetaType::Float: - case QVariant::UserType: { - QVariant data = static_cast(index.internalPointer())->editorData(editor); - if (data.isValid()) { - model->setData(index, data , Qt::EditRole); - break; - } - } - default: - QItemDelegate::setModelData(editor, model, index); - break; - } -} - -void QVariantDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex& index ) const { - return QItemDelegate::updateEditorGeometry(editor, option, index); -} - -void QVariantDelegate::parseEditorHints(QWidget* editor, const QString& editorHints) const { - if (editor && !editorHints.isEmpty()) { - // Parse for property values - QRegExp rx("(.*)(=\\s*)(.*)(;{1})"); - rx.setMinimal(true); - int pos = 0; - while ((pos = rx.indexIn(editorHints, pos)) != -1) { - qDebug("Setting %s to %s", qPrintable(rx.cap(1)), qPrintable(rx.cap(3))); - editor->setProperty(qPrintable(rx.cap(1).trimmed()), rx.cap(3).trimmed()); - pos += rx.matchedLength(); - } - } -} diff --git a/utils/wpseditor/gui/src/QPropertyEditor/QVariantDelegate.h b/utils/wpseditor/gui/src/QPropertyEditor/QVariantDelegate.h deleted file mode 100644 index e06265af82..0000000000 --- a/utils/wpseditor/gui/src/QPropertyEditor/QVariantDelegate.h +++ /dev/null @@ -1,78 +0,0 @@ -// ************************************************************************************************* -// -// QPropertyEditor v 0.1 -// -// -------------------------------------- -// Copyright (C) 2007 Volker Wiendl -// -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -// -// ************************************************************************************************* - -#ifndef COLORSELECTIONBUTTON_H_ -#define COLORSELECTIONBUTTON_H_ - -#include - - -/** - * This class is used to create the editor widgets for datatypes encapsulated in QVariant variables - */ -class QVariantDelegate : public QItemDelegate { - Q_OBJECT - -public: - /** - * Constructor - * @param parent optional parent object - */ - QVariantDelegate(QObject* parent = 0); - /// Destructor - virtual ~QVariantDelegate(); - - /** - * Creates an editor widget as child of a given widget for a specific QModelIndex - * - * @param parent the parent widget for the editor - * @param option some style options that the editor should use - * @param index the index of the item the editor will be created for - * @return QWidget the editor widget - */ - QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const; - - /** - * Tries to set the editor data based on the value stored at a specific QModelIndex - * @param editor the editor widget - * @param index the model index of the value that should be used in the editor - */ - virtual void setEditorData(QWidget *editor, const QModelIndex &index) const; - - /** - * Sets the data of a specific QModelIndex to tha value of the editor widget - * @param editor the editor widget that contains the new value - * @param model the model that contains the index - * @param index the index within the model whose data value should be set to the data value of the editor - */ - virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const; - - /// QItemDelegate implementation - virtual void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const; - -protected: - void parseEditorHints(QWidget* editor, const QString& editorHints) const; - -}; -#endif -- cgit v1.2.3