Added FloatPropertyBind class
This allows to easily bind a Qml property to a FloatNode, synchronizing values both ways.
This commit is contained in:
parent
9a177352ba
commit
9d077d78f5
12 changed files with 137 additions and 58 deletions
|
@ -55,6 +55,12 @@ void DiffManager::undo()
|
||||||
// Obtain the node by path and reverse apply diff on it
|
// Obtain the node by path and reverse apply diff on it
|
||||||
DefinitionNode *node = tree->findByPath(diff->getPath());
|
DefinitionNode *node = tree->findByPath(diff->getPath());
|
||||||
node->applyDiff(diff, true);
|
node->applyDiff(diff, true);
|
||||||
|
|
||||||
|
for (auto watcher: watchers[node])
|
||||||
|
{
|
||||||
|
// FIXME Reverse diff
|
||||||
|
watcher->nodeChanged(node, diff);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,6 +74,11 @@ void DiffManager::redo()
|
||||||
// Obtain the node by path and re-apply diff on it
|
// Obtain the node by path and re-apply diff on it
|
||||||
DefinitionNode *node = tree->findByPath(diff->getPath());
|
DefinitionNode *node = tree->findByPath(diff->getPath());
|
||||||
node->applyDiff(diff);
|
node->applyDiff(diff);
|
||||||
|
|
||||||
|
for (auto watcher: watchers[node])
|
||||||
|
{
|
||||||
|
watcher->nodeChanged(node, diff);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,28 +3,14 @@
|
||||||
#include "MainModelerWindow.h"
|
#include "MainModelerWindow.h"
|
||||||
#include "Scenery.h"
|
#include "Scenery.h"
|
||||||
#include "AtmosphereDefinition.h"
|
#include "AtmosphereDefinition.h"
|
||||||
#include "OpenGLRenderer.h"
|
#include "FloatPropertyBind.h"
|
||||||
#include "OpenGLSkybox.h"
|
|
||||||
#include "OpenGLTerrain.h"
|
|
||||||
#include "FloatNode.h"
|
|
||||||
|
|
||||||
AtmosphereModeler::AtmosphereModeler(MainModelerWindow *main):
|
AtmosphereModeler::AtmosphereModeler(MainModelerWindow *main)
|
||||||
main(main)
|
|
||||||
{
|
{
|
||||||
QObject *item = main->findQmlObject("atmosphere_daytime");
|
prop_daytime = new FloatPropertyBind(main, "atmosphere_daytime", "value", main->getScenery()->getAtmosphere()->propDayTime());
|
||||||
if (item)
|
|
||||||
{
|
|
||||||
item->setProperty("value", propDayTime()->getValue());
|
|
||||||
connect(item, SIGNAL(changed(double)), this, SLOT(daytimeChanged(double)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AtmosphereModeler::daytimeChanged(double value)
|
AtmosphereModeler::~AtmosphereModeler()
|
||||||
{
|
{
|
||||||
propDayTime()->setValue(value);
|
delete prop_daytime;
|
||||||
}
|
|
||||||
|
|
||||||
FloatNode *AtmosphereModeler::propDayTime() const
|
|
||||||
{
|
|
||||||
return main->getScenery()->getAtmosphere()->propDayTime();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,24 +3,17 @@
|
||||||
|
|
||||||
#include "modeler_global.h"
|
#include "modeler_global.h"
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
namespace paysages {
|
namespace paysages {
|
||||||
namespace modeler {
|
namespace modeler {
|
||||||
|
|
||||||
class AtmosphereModeler : public QObject
|
class AtmosphereModeler
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
public:
|
public:
|
||||||
AtmosphereModeler(MainModelerWindow *main);
|
AtmosphereModeler(MainModelerWindow *main);
|
||||||
|
~AtmosphereModeler();
|
||||||
public slots:
|
|
||||||
void daytimeChanged(double value);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FloatNode *propDayTime() const;
|
FloatPropertyBind *prop_daytime;
|
||||||
|
|
||||||
MainModelerWindow *main;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
40
src/interface/modeler/quickapp/FloatPropertyBind.cpp
Normal file
40
src/interface/modeler/quickapp/FloatPropertyBind.cpp
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
#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);
|
||||||
|
}
|
||||||
|
}
|
37
src/interface/modeler/quickapp/FloatPropertyBind.h
Normal file
37
src/interface/modeler/quickapp/FloatPropertyBind.h
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
#ifndef FLOATPROPERTYBIND_H
|
||||||
|
#define FLOATPROPERTYBIND_H
|
||||||
|
|
||||||
|
#include "modeler_global.h"
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include "DefinitionWatcher.h"
|
||||||
|
|
||||||
|
namespace paysages {
|
||||||
|
namespace modeler {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bind a float Qml property to a FloatNode.
|
||||||
|
*
|
||||||
|
* The FloatNode must exist through this object lifetime.
|
||||||
|
*/
|
||||||
|
class FloatPropertyBind : public QObject, public DefinitionWatcher
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
FloatPropertyBind(MainModelerWindow *window, const QString &object_name, const QString &property_name, FloatNode *node);
|
||||||
|
|
||||||
|
virtual void nodeChanged(const DefinitionNode *node, const DefinitionDiff *diff) override;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void propertyChanged(double value);
|
||||||
|
|
||||||
|
private:
|
||||||
|
FloatNode *node;
|
||||||
|
QString property;
|
||||||
|
QObject *item;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // FLOATPROPERTYBIND_H
|
7
src/interface/modeler/quickapp/PropertyBind.cpp
Normal file
7
src/interface/modeler/quickapp/PropertyBind.cpp
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
#include "PropertyBind.h"
|
||||||
|
|
||||||
|
PropertyBind::PropertyBind(QObject *parent) : QObject(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
17
src/interface/modeler/quickapp/PropertyBind.h
Normal file
17
src/interface/modeler/quickapp/PropertyBind.h
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
#ifndef PROPERTYBIND_H
|
||||||
|
#define PROPERTYBIND_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class PropertyBind : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit PropertyBind(QObject *parent = 0);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PROPERTYBIND_H
|
|
@ -3,26 +3,14 @@
|
||||||
#include "MainModelerWindow.h"
|
#include "MainModelerWindow.h"
|
||||||
#include "Scenery.h"
|
#include "Scenery.h"
|
||||||
#include "TerrainDefinition.h"
|
#include "TerrainDefinition.h"
|
||||||
#include "FloatNode.h"
|
#include "FloatPropertyBind.h"
|
||||||
#include "Logs.h"
|
|
||||||
|
|
||||||
WaterModeler::WaterModeler(MainModelerWindow *main):
|
WaterModeler::WaterModeler(MainModelerWindow *main)
|
||||||
main(main)
|
|
||||||
{
|
{
|
||||||
QObject *item = main->findQmlObject("water_level");
|
prop_water_height = new FloatPropertyBind(main, "water_height", "value", main->getScenery()->getTerrain()->propWaterHeight());
|
||||||
if (item)
|
|
||||||
{
|
|
||||||
item->setProperty("value", propWaterHeight()->getValue() * 0.5 + 0.5);
|
|
||||||
connect(item, SIGNAL(changed(double)), this, SLOT(waterLevelChanged(double)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaterModeler::waterLevelChanged(double value)
|
WaterModeler::~WaterModeler()
|
||||||
{
|
{
|
||||||
propWaterHeight()->setValue(value * 2.0 - 1.0);
|
delete prop_water_height;
|
||||||
}
|
|
||||||
|
|
||||||
FloatNode *WaterModeler::propWaterHeight() const
|
|
||||||
{
|
|
||||||
return main->getScenery()->getTerrain()->propWaterHeight();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,23 +3,17 @@
|
||||||
|
|
||||||
#include "modeler_global.h"
|
#include "modeler_global.h"
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
namespace paysages {
|
namespace paysages {
|
||||||
namespace modeler {
|
namespace modeler {
|
||||||
|
|
||||||
class WaterModeler: public QObject
|
class WaterModeler
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
public:
|
public:
|
||||||
WaterModeler(MainModelerWindow *main);
|
WaterModeler(MainModelerWindow *main);
|
||||||
|
~WaterModeler();
|
||||||
public slots:
|
|
||||||
void waterLevelChanged(double value);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FloatNode *propWaterHeight() const;
|
FloatPropertyBind *prop_water_height;
|
||||||
MainModelerWindow *main;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,8 @@ namespace modeler {
|
||||||
class RenderProcess;
|
class RenderProcess;
|
||||||
|
|
||||||
class ModelerCameras;
|
class ModelerCameras;
|
||||||
|
|
||||||
|
class FloatPropertyBind;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,9 @@ BasePanel {
|
||||||
width: 20
|
width: 20
|
||||||
|
|
||||||
BaseSlider {
|
BaseSlider {
|
||||||
objectName: "water_level"
|
objectName: "water_height"
|
||||||
|
minimumValue: -1
|
||||||
|
maximumValue: 1
|
||||||
orientation: Qt.Vertical
|
orientation: Qt.Vertical
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,8 @@ SOURCES += main.cpp \
|
||||||
AtmosphereModeler.cpp \
|
AtmosphereModeler.cpp \
|
||||||
RenderPreviewProvider.cpp \
|
RenderPreviewProvider.cpp \
|
||||||
RenderProcess.cpp \
|
RenderProcess.cpp \
|
||||||
ModelerCameras.cpp
|
ModelerCameras.cpp \
|
||||||
|
FloatPropertyBind.cpp
|
||||||
|
|
||||||
RESOURCES += \
|
RESOURCES += \
|
||||||
qml/app.qrc
|
qml/app.qrc
|
||||||
|
@ -32,7 +33,8 @@ HEADERS += \
|
||||||
AtmosphereModeler.h \
|
AtmosphereModeler.h \
|
||||||
RenderPreviewProvider.h \
|
RenderPreviewProvider.h \
|
||||||
RenderProcess.h \
|
RenderProcess.h \
|
||||||
ModelerCameras.h
|
ModelerCameras.h \
|
||||||
|
FloatPropertyBind.h
|
||||||
|
|
||||||
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../../system/release/ -lpaysages_system
|
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../../system/release/ -lpaysages_system
|
||||||
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../../../system/debug/ -lpaysages_system
|
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../../../system/debug/ -lpaysages_system
|
||||||
|
|
Loading…
Reference in a new issue