2014-09-10 17:27:45 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vnumberproperty.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 "vnumberproperty.h"
|
|
|
|
|
|
|
|
#include <QDoubleSpinBox>
|
|
|
|
#include <QSpinBox>
|
|
|
|
#include <QSizePolicy>
|
|
|
|
#include <QCoreApplication>
|
|
|
|
|
|
|
|
#include "vproperty_p.h"
|
|
|
|
|
|
|
|
using namespace VPE;
|
|
|
|
|
|
|
|
|
|
|
|
const int VIntegerProperty::StandardMin = -1000000;
|
|
|
|
const int VIntegerProperty::StandardMax = 1000000;
|
|
|
|
|
|
|
|
VIntegerProperty::VIntegerProperty(const QString& name, const QMap<QString, QVariant>& settings)
|
2014-09-10 19:57:08 +02:00
|
|
|
: VProperty(name, QVariant::Int), minValue(StandardMin), maxValue(StandardMax), singleStep(1.0)
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
|
|
|
VProperty::setSettings(settings);
|
|
|
|
VProperty::d_ptr->VariantValue.setValue(0);
|
|
|
|
VProperty::d_ptr->VariantValue.convert(QVariant::Int);
|
|
|
|
}
|
|
|
|
|
|
|
|
VIntegerProperty::VIntegerProperty(const QString &name)
|
2014-09-10 19:57:08 +02:00
|
|
|
: VProperty(name), minValue(StandardMin), maxValue(StandardMax)
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
|
|
|
VProperty::d_ptr->VariantValue.setValue(0);
|
|
|
|
VProperty::d_ptr->VariantValue.convert(QVariant::Int);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Returns an editor widget, or NULL if it doesn't supply one
|
2014-09-10 19:57:08 +02:00
|
|
|
QWidget* VIntegerProperty::createEditor(QWidget * parent, const QStyleOptionViewItem& options,
|
|
|
|
const QAbstractItemDelegate* delegate)
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
|
|
|
Q_UNUSED(options);
|
|
|
|
Q_UNUSED(delegate);
|
|
|
|
|
|
|
|
QSpinBox* tmpEditor = new QSpinBox(parent);
|
2014-09-10 19:57:08 +02:00
|
|
|
tmpEditor->setMinimum(minValue);
|
|
|
|
tmpEditor->setMaximum(maxValue);
|
2014-09-10 17:27:45 +02:00
|
|
|
tmpEditor->setSingleStep(singleStep);
|
|
|
|
tmpEditor->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
|
|
tmpEditor->setValue(VProperty::d_ptr->VariantValue.toInt());
|
|
|
|
connect(tmpEditor, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
|
|
|
|
&VIntegerProperty::valueChanged);
|
|
|
|
|
|
|
|
VProperty::d_ptr->editor = tmpEditor;
|
|
|
|
return VProperty::d_ptr->editor;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Gets the data from the widget
|
|
|
|
QVariant VIntegerProperty::getEditorData(QWidget* editor) const
|
|
|
|
{
|
|
|
|
QSpinBox* tmpEditor = qobject_cast<QSpinBox*>(editor);
|
2014-09-10 19:57:08 +02:00
|
|
|
if (tmpEditor)
|
|
|
|
{
|
2014-09-10 17:27:45 +02:00
|
|
|
return tmpEditor->value();
|
2014-09-10 19:57:08 +02:00
|
|
|
}
|
2014-09-10 17:27:45 +02:00
|
|
|
|
|
|
|
return QVariant(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VIntegerProperty::setSettings(int minimum, int maxiumum, int singleStep)
|
|
|
|
{
|
2014-09-10 19:57:08 +02:00
|
|
|
minValue = minimum;
|
|
|
|
maxValue = maxiumum;
|
2014-09-10 17:27:45 +02:00
|
|
|
this->singleStep = singleStep;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VIntegerProperty::setSetting(const QString& key, const QVariant& value)
|
|
|
|
{
|
2014-09-10 19:57:08 +02:00
|
|
|
if (key == QLatin1String("Min"))
|
|
|
|
{
|
|
|
|
setSettings(value.toInt(), maxValue);
|
|
|
|
}
|
|
|
|
else if (key == QLatin1String("Max"))
|
|
|
|
{
|
|
|
|
setSettings(minValue, value.toInt());
|
|
|
|
}
|
|
|
|
else if (key == QLatin1String("Step"))
|
|
|
|
{
|
2014-09-10 17:27:45 +02:00
|
|
|
setSettings(singleStep, value.toInt());
|
2014-09-10 19:57:08 +02:00
|
|
|
}
|
2014-09-10 17:27:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant VIntegerProperty::getSetting(const QString& key) const
|
|
|
|
{
|
2014-09-10 19:57:08 +02:00
|
|
|
if (key == QLatin1String("Min"))
|
|
|
|
{
|
|
|
|
return minValue;
|
|
|
|
}
|
|
|
|
if (key == QLatin1String("Max"))
|
|
|
|
{
|
|
|
|
return maxValue;
|
|
|
|
}
|
|
|
|
if (key == QLatin1String("Step"))
|
|
|
|
{
|
2014-09-10 17:27:45 +02:00
|
|
|
return singleStep;
|
2014-09-10 19:57:08 +02:00
|
|
|
}
|
2014-09-10 17:27:45 +02:00
|
|
|
else
|
|
|
|
return VProperty::getSetting(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList VIntegerProperty::getSettingKeys() const
|
|
|
|
{
|
|
|
|
return (QStringList("Min") << "Max" << "Step");
|
|
|
|
}
|
|
|
|
|
|
|
|
QString VIntegerProperty::type() const
|
|
|
|
{
|
|
|
|
return "integer";
|
|
|
|
}
|
|
|
|
|
|
|
|
VProperty* VIntegerProperty::clone(bool include_children, VProperty* container) const
|
|
|
|
{
|
|
|
|
return VProperty::clone(include_children, container ? container : new VIntegerProperty(getName()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void VIntegerProperty::valueChanged(int i)
|
|
|
|
{
|
|
|
|
Q_UNUSED(i)
|
|
|
|
UserChangeEvent *event = new UserChangeEvent();
|
|
|
|
QCoreApplication::postEvent ( VProperty::d_ptr->editor, event );
|
|
|
|
}
|
|
|
|
|
|
|
|
const double VDoubleProperty::StandardPrecision = 5;
|
|
|
|
|
|
|
|
VDoubleProperty::VDoubleProperty(const QString& name, const QMap<QString, QVariant>& settings)
|
|
|
|
: VIntegerProperty(name), Precision(StandardPrecision)
|
|
|
|
{
|
|
|
|
VProperty::setSettings(settings);
|
|
|
|
VProperty::d_ptr->VariantValue.setValue(0);
|
|
|
|
VProperty::d_ptr->VariantValue.convert(QVariant::Double);
|
|
|
|
VProperty::d_ptr->PropertyVariantType = QVariant::Double;
|
|
|
|
}
|
|
|
|
|
|
|
|
VDoubleProperty::VDoubleProperty(const QString &name)
|
|
|
|
: VIntegerProperty(name), Precision(StandardPrecision)
|
|
|
|
{
|
|
|
|
VProperty::d_ptr->VariantValue.setValue(0);
|
|
|
|
VProperty::d_ptr->VariantValue.convert(QVariant::Double);
|
|
|
|
VProperty::d_ptr->PropertyVariantType = QVariant::Double;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Returns an editor widget, or NULL if it doesn't supply one
|
2014-09-10 19:57:08 +02:00
|
|
|
QWidget* VDoubleProperty::createEditor(QWidget * parent, const QStyleOptionViewItem& options,
|
|
|
|
const QAbstractItemDelegate* delegate)
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
|
|
|
Q_UNUSED(options);
|
|
|
|
Q_UNUSED(delegate);
|
|
|
|
QDoubleSpinBox* tmpEditor = new QDoubleSpinBox(parent);
|
2014-09-10 19:57:08 +02:00
|
|
|
tmpEditor->setMinimum(minValue);
|
|
|
|
tmpEditor->setMaximum(maxValue);
|
2014-09-10 17:27:45 +02:00
|
|
|
tmpEditor->setDecimals(Precision);
|
|
|
|
tmpEditor->setSingleStep(singleStep);
|
|
|
|
tmpEditor->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
|
|
tmpEditor->setValue(VProperty::d_ptr->VariantValue.toDouble());
|
|
|
|
connect(tmpEditor, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this,
|
|
|
|
&VIntegerProperty::valueChanged);
|
|
|
|
|
|
|
|
VProperty::d_ptr->editor = tmpEditor;
|
|
|
|
return VProperty::d_ptr->editor;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Gets the data from the widget
|
|
|
|
QVariant VDoubleProperty::getEditorData(QWidget* editor) const
|
|
|
|
{
|
|
|
|
QDoubleSpinBox* tmpEditor = qobject_cast<QDoubleSpinBox*>(editor);
|
2014-09-10 19:57:08 +02:00
|
|
|
if (tmpEditor)
|
|
|
|
{
|
2014-09-10 17:27:45 +02:00
|
|
|
return tmpEditor->value();
|
2014-09-10 19:57:08 +02:00
|
|
|
}
|
2014-09-10 17:27:45 +02:00
|
|
|
|
|
|
|
return QVariant(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VDoubleProperty::setSettings(double minimum, double maxiumum, double singleStep, int precision)
|
|
|
|
{
|
2014-09-10 19:57:08 +02:00
|
|
|
minValue = minimum;
|
|
|
|
maxValue = maxiumum;
|
2014-09-10 17:27:45 +02:00
|
|
|
this->singleStep = singleStep;
|
|
|
|
Precision = precision;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VDoubleProperty::setSetting(const QString& key, const QVariant& value)
|
|
|
|
{
|
2014-09-10 19:57:08 +02:00
|
|
|
if (key == QLatin1String("Min"))
|
|
|
|
{
|
|
|
|
setSettings(value.toDouble(), maxValue, singleStep, Precision);
|
|
|
|
}
|
|
|
|
else if (key == QLatin1String("Max"))
|
|
|
|
{
|
|
|
|
setSettings(minValue, value.toDouble(), singleStep, Precision);
|
|
|
|
}
|
|
|
|
else if (key == QLatin1String("Step"))
|
|
|
|
{
|
|
|
|
setSettings(minValue, maxValue, value.toDouble(), Precision);
|
|
|
|
}
|
|
|
|
else if (key == QLatin1String("Precision"))
|
|
|
|
{
|
|
|
|
setSettings(minValue, maxValue, singleStep, value.toDouble());
|
|
|
|
}
|
2014-09-10 17:27:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant VDoubleProperty::getSetting(const QString& key) const
|
|
|
|
{
|
2014-09-10 19:57:08 +02:00
|
|
|
if (key == QLatin1String("Min"))
|
|
|
|
{
|
|
|
|
return minValue;
|
|
|
|
}
|
|
|
|
if (key == QLatin1String("Max"))
|
|
|
|
{
|
|
|
|
return maxValue;
|
|
|
|
}
|
|
|
|
if (key == QLatin1String("Step"))
|
|
|
|
{
|
2014-09-10 17:27:45 +02:00
|
|
|
return singleStep;
|
2014-09-10 19:57:08 +02:00
|
|
|
}
|
|
|
|
if (key == QLatin1String("Precision"))
|
|
|
|
{
|
2014-09-10 17:27:45 +02:00
|
|
|
return Precision;
|
2014-09-10 19:57:08 +02:00
|
|
|
}
|
2014-09-10 17:27:45 +02:00
|
|
|
else
|
|
|
|
return VProperty::getSetting(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList VDoubleProperty::getSettingKeys() const
|
|
|
|
{
|
|
|
|
return (QStringList("Min") << "Max" << "Step" << "Precision");
|
|
|
|
}
|
|
|
|
|
|
|
|
QString VDoubleProperty::type() const
|
|
|
|
{
|
|
|
|
return "double";
|
|
|
|
}
|
|
|
|
|
|
|
|
VProperty* VDoubleProperty::clone(bool include_children, VProperty* container) const
|
|
|
|
{
|
|
|
|
return VIntegerProperty::clone(include_children, container ? container : new VDoubleProperty(getName()));
|
|
|
|
}
|