2014-09-10 17:27:45 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vvector3dproperty.cpp
|
|
|
|
** @author hedgeware <internal(at)hedgeware.net>
|
|
|
|
** @date
|
|
|
|
**
|
|
|
|
** @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 "vvector3dproperty.h"
|
|
|
|
|
|
|
|
using namespace VPE;
|
|
|
|
|
|
|
|
#include "vproperty_p.h"
|
|
|
|
#include "../vnumberproperty.h"
|
|
|
|
#include <QStringList>
|
|
|
|
|
|
|
|
QVector3DProperty::QVector3DProperty(const QString& name)
|
2014-09-10 19:57:08 +02:00
|
|
|
: VProperty(name, QVariant::String) // todo: QVariant::Vector3D??
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
|
|
|
QVariant tmpFloat(0); tmpFloat.convert(QVariant::Double);
|
|
|
|
VDoubleProperty* tmpX = new VDoubleProperty("X"); addChild(tmpX); tmpX->setUpdateBehaviour(true, false);
|
|
|
|
VDoubleProperty* tmpY = new VDoubleProperty("Y"); addChild(tmpY); tmpY->setUpdateBehaviour(true, false);
|
|
|
|
VDoubleProperty* tmpZ = new VDoubleProperty("Z"); addChild(tmpZ); tmpZ->setUpdateBehaviour(true, false);
|
|
|
|
setVector(Vector3D());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! Get the data how it should be displayed
|
|
|
|
QVariant QVector3DProperty::data (int column, int role) const
|
|
|
|
{
|
2014-09-10 19:57:08 +02:00
|
|
|
if (column == DPC_Data && Qt::DisplayRole == role)
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
|
|
|
Vector3D tmpVect = getVector();
|
|
|
|
return QString("(%1, %2, %3)").arg(QString::number(tmpVect.X),
|
|
|
|
QString::number(tmpVect.Y),
|
|
|
|
QString::number(tmpVect.Z));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return VProperty::data(column, role);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Returns item flags
|
|
|
|
Qt::ItemFlags QVector3DProperty::flags(int column) const
|
|
|
|
{
|
2014-09-10 19:57:08 +02:00
|
|
|
if (column == DPC_Name || column == DPC_Data)
|
|
|
|
{
|
2014-09-10 17:27:45 +02:00
|
|
|
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
2014-09-10 19:57:08 +02:00
|
|
|
}
|
2014-09-10 17:27:45 +02:00
|
|
|
else
|
|
|
|
return Qt::NoItemFlags;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! Returns the Vector3d
|
|
|
|
Vector3D QVector3DProperty::getVector() const
|
|
|
|
{
|
|
|
|
Vector3D tmpVect;
|
|
|
|
|
2014-09-10 19:57:08 +02:00
|
|
|
if (d_ptr->Children.count() < 3)
|
|
|
|
{
|
2014-09-10 17:27:45 +02:00
|
|
|
return tmpVect;
|
2014-09-10 19:57:08 +02:00
|
|
|
}
|
2014-09-10 17:27:45 +02:00
|
|
|
|
|
|
|
tmpVect.X = d_ptr->Children.at(0)->getValue().toFloat();
|
|
|
|
tmpVect.Y = d_ptr->Children.at(1)->getValue().toFloat();
|
|
|
|
tmpVect.Z = d_ptr->Children.at(2)->getValue().toFloat();
|
|
|
|
|
|
|
|
return tmpVect;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Sets the Vector3d
|
|
|
|
void QVector3DProperty::setVector(const Vector3D &vect)
|
|
|
|
{
|
|
|
|
setVector(vect.X, vect.Y, vect.Z);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QVector3DProperty::setVector(float x, float y, float z)
|
|
|
|
{
|
2014-09-10 19:57:08 +02:00
|
|
|
if (d_ptr->Children.count() < 3)
|
|
|
|
{
|
2014-09-10 17:27:45 +02:00
|
|
|
return;
|
2014-09-10 19:57:08 +02:00
|
|
|
}
|
2014-09-10 17:27:45 +02:00
|
|
|
|
|
|
|
QVariant tmpX(x); tmpX.convert(QVariant::Double);
|
|
|
|
QVariant tmpY(y); tmpY.convert(QVariant::Double);
|
|
|
|
QVariant tmpZ(z); tmpZ.convert(QVariant::Double);
|
|
|
|
d_ptr->Children.at(0)->setValue(tmpX);
|
|
|
|
d_ptr->Children.at(1)->setValue(tmpY);
|
|
|
|
d_ptr->Children.at(2)->setValue(tmpZ);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString QVector3DProperty::type() const
|
|
|
|
{
|
|
|
|
return "vector3d";
|
|
|
|
}
|
|
|
|
|
|
|
|
VProperty* QVector3DProperty::clone(bool include_children, VProperty* container) const
|
|
|
|
{
|
2014-09-10 19:57:08 +02:00
|
|
|
if (!container)
|
|
|
|
{
|
2014-09-10 17:27:45 +02:00
|
|
|
container = new QVector3DProperty(getName());
|
|
|
|
|
2014-09-10 19:57:08 +02:00
|
|
|
if (!include_children)
|
|
|
|
{
|
2014-09-10 17:27:45 +02:00
|
|
|
QList<VProperty*> tmpChildren = container->getChildren();
|
2014-09-10 19:57:08 +02:00
|
|
|
foreach (VProperty* tmpChild, tmpChildren)
|
|
|
|
{
|
2014-09-10 17:27:45 +02:00
|
|
|
container->removeChild(tmpChild);
|
|
|
|
delete tmpChild;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-10 19:57:08 +02:00
|
|
|
return VProperty::clone(false, container); // Child
|
2014-09-10 17:27:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void QVector3DProperty::setValue(const QVariant &value)
|
|
|
|
{
|
|
|
|
QStringList tmpStrings = value.toString().split(",");
|
2014-09-10 19:57:08 +02:00
|
|
|
if (tmpStrings.count() == 3)
|
|
|
|
{
|
2014-09-10 17:27:45 +02:00
|
|
|
setVector(tmpStrings[0].toDouble(), tmpStrings[1].toDouble(), tmpStrings[2].toDouble());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant QVector3DProperty::getValue() const
|
|
|
|
{
|
|
|
|
Vector3D tmpVect = getVector();
|
|
|
|
return QString("%1,%2,%3").arg(QString::number(tmpVect.X), QString::number(tmpVect.Y), QString::number(tmpVect.Z));
|
|
|
|
}
|