New property for point type.

--HG--
branch : feature
This commit is contained in:
dismine 2014-08-27 15:39:54 +03:00
parent 0d0bcb9005
commit c48c627682
8 changed files with 240 additions and 50 deletions

View File

@ -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 <QDockWidget>
#include <QHBoxLayout>
@ -88,19 +89,27 @@ void VToolOptionsPropertyBrowser::itemClicked(QGraphicsItem *item)
//---------------------------------------------------------------------------------------------------------------------
void VToolOptionsPropertyBrowser::userChangedData(VProperty *property)
{
if (!propertyToId.contains(property))
VProperty *prop = property;
if (!propertyToId.contains(prop))
{
if (!propertyToId.contains(prop->getParent()))// Maybe we know parent
{
return;
}
else
{
prop = prop->getParent();
}
}
if (!currentItem)
{
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<VToolSinglePoint *>(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:

View File

@ -31,8 +31,7 @@ public:
Q_DECLARE_METATYPE(QPE::Vector3D) // todo
namespace QPE{*/
*/
class VPROPERTYEXPLORERSHARED_EXPORT QVector3DProperty : public VProperty
{

View File

@ -0,0 +1,129 @@
/************************************************************************
**
** @file vpointfproperty.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @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 <QPointF>
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<VProperty*> 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()));
}

View File

@ -0,0 +1,71 @@
/************************************************************************
**
** @file vpointfproperty.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @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

View File

@ -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 <http://www.gnu.org/licenses/>.
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details.
**
*************************************************************************/

View File

@ -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 <http://www.gnu.org/licenses/>.
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details.
**
*************************************************************************/

View File

@ -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

View File

@ -121,7 +121,7 @@ void VPropertyFormView::dataSubmitted(VProperty *property)
if(tmpModel && d_ptr->UpdateEditors) {
static_cast<VPropertyFormViewPrivate*>(d_ptr)->IgnoreDataChangedSignal = true;
//tmpModel->onDataChangedByModel(property);
tmpModel->onDataChangedByModel(property);
tmpModel->showDataChangedByEditor(property);
static_cast<VPropertyFormViewPrivate*>(d_ptr)->IgnoreDataChangedSignal = false;