From c48c6276823f603e1857fae4cbb63ab78ebf2aa8 Mon Sep 17 00:00:00 2001 From: dismine Date: Wed, 27 Aug 2014 15:39:54 +0300 Subject: [PATCH] New property for point type. --HG-- branch : feature --- .../widgets/vtooloptionspropertybrowser.cpp | 45 +++--- .../plugins/Vector3d/vvector3dproperty.h | 3 +- .../plugins/vpointfproperty.cpp | 129 ++++++++++++++++++ .../plugins/vpointfproperty.h | 71 ++++++++++ .../plugins/vstringproperty.cpp | 17 +-- .../plugins/vstringproperty.h | 17 +-- .../vpropertyexplorer/vpropertyexplorer.pro | 6 +- .../vpropertyexplorer/vpropertyformview.cpp | 2 +- 8 files changed, 240 insertions(+), 50 deletions(-) create mode 100644 src/libs/vpropertyexplorer/plugins/vpointfproperty.cpp create mode 100644 src/libs/vpropertyexplorer/plugins/vpointfproperty.h diff --git a/src/app/widgets/vtooloptionspropertybrowser.cpp b/src/app/widgets/vtooloptionspropertybrowser.cpp index a2f2fa7ed..9ed2b58dd 100644 --- a/src/app/widgets/vtooloptionspropertybrowser.cpp +++ b/src/app/widgets/vtooloptionspropertybrowser.cpp @@ -34,6 +34,7 @@ #include "visualization/vcontrolpointspline.h" #include "../libs/vpropertyexplorer/plugins/vnumberproperty.h" #include "../libs/vpropertyexplorer/plugins/vstringproperty.h" +#include "../libs/vpropertyexplorer/plugins/vpointfproperty.h" #include #include @@ -88,9 +89,17 @@ void VToolOptionsPropertyBrowser::itemClicked(QGraphicsItem *item) //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) { - if (!propertyToId.contains(property)) + VProperty *prop = property; + if (!propertyToId.contains(prop)) { - return; + if (!propertyToId.contains(prop->getParent()))// Maybe we know parent + { + return; + } + else + { + prop = prop->getParent(); + } } if (!currentItem) @@ -98,9 +107,9 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) return; } - QVariant variant = property->data(VProperty::DPC_Data); + QVariant variant = prop->data(VProperty::DPC_Data); - QString id = propertyToId[property]; + QString id = propertyToId[prop]; switch (currentItem->type()) { case VToolSinglePoint::Type: @@ -125,13 +134,9 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) } } } - else if (id == QLatin1String("posX")) + else if (id == QLatin1String("position")) { - currentItem->setX(variant.toDouble()); - } - else if (id == QLatin1String("posY")) - { - currentItem->setY(variant.toDouble()); + currentItem->setPos(variant.toPointF()); } break; } @@ -161,8 +166,7 @@ void VToolOptionsPropertyBrowser::UpdateOptions() { VToolSinglePoint *i = qgraphicsitem_cast(currentItem); idToProperty[QLatin1String("name")]->setValue(i->name()); - idToProperty[QLatin1String("posX")]->setValue(i->x()); - idToProperty[QLatin1String("posY")]->setValue(i->y()); + idToProperty[QLatin1String("position")]->setValue(i->pos()); break; } case VGraphicsSimpleTextItem::Type: @@ -181,7 +185,7 @@ void VToolOptionsPropertyBrowser::AddProperty(VProperty *property, const QString { propertyToId[property] = id; idToProperty[id] = property; - PropertyModel->addProperty(property, QLatin1String("name")); + PropertyModel->addProperty(property, id); } //--------------------------------------------------------------------------------------------------------------------- @@ -199,18 +203,9 @@ void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) itemName->setValue(i->name()); AddProperty(itemName, QLatin1String("name")); - VDoubleProperty* positionX = new VDoubleProperty(tr("Position X")); - positionX->setValue(i->x()); - AddProperty(positionX, QLatin1String("posX")); - - VDoubleProperty* positionY = new VDoubleProperty(tr("Position Y")); - positionY->setValue(i->y()); - AddProperty(positionY, QLatin1String("posY")); - -// QtVariantProperty *position = variantManager->addProperty(QVariant::PointF, tr("Position")); -// position->setValue(i->pos()); -// AddProperty(position, QLatin1String("position")); -// mainGroup->addSubProperty(position); + VPointFProperty* itemPosition = new VPointFProperty(tr("Position")); + itemPosition->setValue(i->pos()); + AddProperty(itemPosition, QLatin1String("position")); break; } case VGraphicsSimpleTextItem::Type: diff --git a/src/libs/vpropertyexplorer/plugins/Vector3d/vvector3dproperty.h b/src/libs/vpropertyexplorer/plugins/Vector3d/vvector3dproperty.h index 12eb17aeb..56f343639 100644 --- a/src/libs/vpropertyexplorer/plugins/Vector3d/vvector3dproperty.h +++ b/src/libs/vpropertyexplorer/plugins/Vector3d/vvector3dproperty.h @@ -31,8 +31,7 @@ public: Q_DECLARE_METATYPE(QPE::Vector3D) // todo - -namespace QPE{*/ +*/ class VPROPERTYEXPLORERSHARED_EXPORT QVector3DProperty : public VProperty { diff --git a/src/libs/vpropertyexplorer/plugins/vpointfproperty.cpp b/src/libs/vpropertyexplorer/plugins/vpointfproperty.cpp new file mode 100644 index 000000000..8d923502d --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vpointfproperty.cpp @@ -0,0 +1,129 @@ +/************************************************************************ + ** + ** @file vpointfproperty.cpp + ** @author Roman Telezhynskyi + ** @date 27 8, 2014 + ** + ** @brief + ** @copyright + ** All rights reserved. This program and the accompanying materials + ** are made available under the terms of the GNU Lesser General Public License + ** (LGPL) version 2.1 which accompanies this distribution, and is available at + ** http://www.gnu.org/licenses/lgpl-2.1.html + ** + ** 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. + ** + *************************************************************************/ + +#include "vpointfproperty.h" + +using namespace VPE; + +#include "vproperty_p.h" +#include "vnumberproperty.h" +#include + +VPE::VPointFProperty::VPointFProperty(const QString &name) + : VProperty(name, QVariant::PointF) +{ + d_ptr->VariantValue.setValue(0); + d_ptr->VariantValue.convert(QVariant::PointF); + + VDoubleProperty* tmpX = new VDoubleProperty("X"); + addChild(tmpX); + tmpX->setUpdateBehaviour(true, false); + + VDoubleProperty* tmpY = new VDoubleProperty("Y"); + addChild(tmpY); + tmpY->setUpdateBehaviour(true, false); + + setValue(QPointF()); +} + +QVariant VPointFProperty::data(int column, int role) const +{ + if(column == DPC_Data && Qt::DisplayRole == role) + { + return getPointF(); + } + else + return VProperty::data(column, role); +} + +Qt::ItemFlags VPointFProperty::flags(int column) const +{ + if(column == DPC_Name || column == DPC_Data) + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; + else + return Qt::NoItemFlags; +} + +QPointF VPointFProperty::getPointF() const +{ + QPointF tmpValue; + + if(d_ptr->Children.count() < 2) + return tmpValue; + + tmpValue.setX(d_ptr->Children.at(0)->getValue().toDouble()); + tmpValue.setY(d_ptr->Children.at(1)->getValue().toDouble()); + + return tmpValue; +} + +void VPointFProperty::setPointF(const QPointF &point) +{ + setPointF(point.x(), point.y()); +} + +void VPointFProperty::setPointF(qreal x, qreal y) +{ + if(d_ptr->Children.count() < 2) + return; + + QVariant tmpX(x); + tmpX.convert(QVariant::Double); + + QVariant tmpY(y); + tmpY.convert(QVariant::Double); + + d_ptr->Children.at(0)->setValue(tmpX); + d_ptr->Children.at(1)->setValue(tmpY); +} + +QString VPointFProperty::type() const +{ + return "pointF"; +} + +VProperty *VPointFProperty::clone(bool include_children, VProperty *container) const +{ + if(!container) { + container = new VPointFProperty(getName()); + + if(!include_children) { + QList tmpChildren = container->getChildren(); + foreach(VProperty* tmpChild, tmpChildren) { + container->removeChild(tmpChild); + delete tmpChild; + } + } + } + + return VProperty::clone(false, container); // Child +} + +void VPointFProperty::setValue(const QVariant &value) +{ + QPointF tmpPoint = value.toPointF(); + setPointF(tmpPoint); +} + +QVariant VPointFProperty::getValue() const +{ + QPointF tmpValue = getPointF(); + return QString("%1,%2").arg(QString::number(tmpValue.x()), QString::number(tmpValue.y())); +} diff --git a/src/libs/vpropertyexplorer/plugins/vpointfproperty.h b/src/libs/vpropertyexplorer/plugins/vpointfproperty.h new file mode 100644 index 000000000..2029dd304 --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vpointfproperty.h @@ -0,0 +1,71 @@ +/************************************************************************ + ** + ** @file vpointfproperty.h + ** @author Roman Telezhynskyi + ** @date 27 8, 2014 + ** + ** @brief + ** @copyright + ** All rights reserved. This program and the accompanying materials + ** are made available under the terms of the GNU Lesser General Public License + ** (LGPL) version 2.1 which accompanies this distribution, and is available at + ** http://www.gnu.org/licenses/lgpl-2.1.html + ** + ** 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. + ** + *************************************************************************/ + +#ifndef VPOINTFPROPERTY_H +#define VPOINTFPROPERTY_H + +#include "vpropertyexplorer_global.h" + +#include "vproperty.h" + +namespace VPE{ + +class VPROPERTYEXPLORERSHARED_EXPORT VPointFProperty : public VProperty +{ +public: + VPointFProperty(const QString& name); + + virtual ~VPointFProperty() {} + + //! Get the data how it should be displayed + virtual QVariant data (int column = DPC_Name, int role = Qt::DisplayRole) const; + + //! Returns item flags + Qt::ItemFlags flags(int column = DPC_Name) const; + + //! Returns the QPointF + virtual QPointF getPointF() const; + + //! Sets the QPointF + virtual void setPointF(const QPointF& point); + + //! Sets the QPointF + virtual void setPointF(qreal x, qreal y); + + //! Returns a string containing the type of the property + virtual QString type() const; + + //! Clones this property + //! \param include_children Indicates whether to also clone the children + //! \param container If a property is being passed here, no new VProperty is being created but instead it is tried to fill all the data into container. This can also be used when subclassing this function. + //! \return Returns the newly created property (or container, if it was not NULL) + virtual VProperty* clone(bool include_children = true, VProperty* container = NULL) const; + + //! Sets the value of the property + virtual void setValue(const QVariant& value); + + //! Returns the value of the property as a QVariant + virtual QVariant getValue() const; + +}; + +} + +#endif // VPOINTFPROPERTY_H diff --git a/src/libs/vpropertyexplorer/plugins/vstringproperty.cpp b/src/libs/vpropertyexplorer/plugins/vstringproperty.cpp index 5803dbf61..00cd08061 100644 --- a/src/libs/vpropertyexplorer/plugins/vstringproperty.cpp +++ b/src/libs/vpropertyexplorer/plugins/vstringproperty.cpp @@ -6,18 +6,15 @@ ** ** @brief ** @copyright - ** This program 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, either version 3 of the License, or - ** (at your option) any later version. + ** All rights reserved. This program and the accompanying materials + ** are made available under the terms of the GNU Lesser General Public License + ** (LGPL) version 2.1 which accompanies this distribution, and is available at + ** http://www.gnu.org/licenses/lgpl-2.1.html ** - ** This program is distributed in the hope that it will be useful, + ** 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 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 . + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + ** Lesser General Public License for more details. ** *************************************************************************/ diff --git a/src/libs/vpropertyexplorer/plugins/vstringproperty.h b/src/libs/vpropertyexplorer/plugins/vstringproperty.h index 9edcf74fe..5182e8e69 100644 --- a/src/libs/vpropertyexplorer/plugins/vstringproperty.h +++ b/src/libs/vpropertyexplorer/plugins/vstringproperty.h @@ -6,18 +6,15 @@ ** ** @brief ** @copyright - ** This program 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, either version 3 of the License, or - ** (at your option) any later version. + ** All rights reserved. This program and the accompanying materials + ** are made available under the terms of the GNU Lesser General Public License + ** (LGPL) version 2.1 which accompanies this distribution, and is available at + ** http://www.gnu.org/licenses/lgpl-2.1.html ** - ** This program is distributed in the hope that it will be useful, + ** 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 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 . + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + ** Lesser General Public License for more details. ** *************************************************************************/ diff --git a/src/libs/vpropertyexplorer/vpropertyexplorer.pro b/src/libs/vpropertyexplorer/vpropertyexplorer.pro index d87858fe8..8e41c380a 100644 --- a/src/libs/vpropertyexplorer/vpropertyexplorer.pro +++ b/src/libs/vpropertyexplorer/vpropertyexplorer.pro @@ -47,7 +47,8 @@ SOURCES += \ plugins/vnumberproperty.cpp \ plugins/Vector3d/vvector3dproperty.cpp \ vstandardpropertyfactory.cpp \ - plugins/vstringproperty.cpp + plugins/vstringproperty.cpp \ + plugins/vpointfproperty.cpp HEADERS +=\ vpropertyexplorer_global.h \ @@ -83,7 +84,8 @@ HEADERS +=\ plugins/Vector3d/vvector3dproperty.h \ vpropertyfactorymanager.h \ vserializedproperty.h \ - plugins/vstringproperty.h + plugins/vstringproperty.h \ + plugins/vpointfproperty.h unix { target.path = /usr/lib diff --git a/src/libs/vpropertyexplorer/vpropertyformview.cpp b/src/libs/vpropertyexplorer/vpropertyformview.cpp index a11061f70..a443ee250 100644 --- a/src/libs/vpropertyexplorer/vpropertyformview.cpp +++ b/src/libs/vpropertyexplorer/vpropertyformview.cpp @@ -121,7 +121,7 @@ void VPropertyFormView::dataSubmitted(VProperty *property) if(tmpModel && d_ptr->UpdateEditors) { static_cast(d_ptr)->IgnoreDataChangedSignal = true; - //tmpModel->onDataChangedByModel(property); + tmpModel->onDataChangedByModel(property); tmpModel->showDataChangedByEditor(property); static_cast(d_ptr)->IgnoreDataChangedSignal = false;