paysages3d/src/interface/modeler/quickapp/FloatPropertyBind.cpp
Michaël Lemaire 9d077d78f5 Added FloatPropertyBind class
This allows to easily bind a Qml property to a FloatNode,
synchronizing values both ways.
2015-08-19 01:17:49 +02:00

41 lines
1,010 B
C++

#include "FloatPropertyBind.h"
#include "MainModelerWindow.h"
#include "FloatNode.h"
#include "Logs.h"
#include <cassert>
#include <cmath>
FloatPropertyBind::FloatPropertyBind(MainModelerWindow *window, const QString &object_name, const QString &property_name, FloatNode *node):
QObject(window), node(node), property(property_name)
{
item = window->findQmlObject(object_name);
if (item)
{
node->addWatcher(this, true);
connect(item, SIGNAL(changed(double)), this, SLOT(propertyChanged(double)));
}
else
{
item = NULL;
Logs::error() << "Can't find object :" << object_name.toStdString() << std::endl;
}
}
void FloatPropertyBind::nodeChanged(const DefinitionNode *, const DefinitionDiff *)
{
if (item)
{
item->setProperty(property.toLocal8Bit(), node->getValue());
}
}
void FloatPropertyBind::propertyChanged(double value)
{
if (fabs(value - node->getValue()) > 0.00000001)
{
node->setValue(value);
}
}