paysages3d/src/interface/modeler/IntPropertyBind.cpp

33 lines
1.1 KiB
C++

#include "IntPropertyBind.h"
#include "MainModelerWindow.h"
#include "IntNode.h"
#include "Logs.h"
IntPropertyBind::IntPropertyBind(MainModelerWindow *window, const string &object_name, const string &property_name,
IntNode *node)
: QObject(window), node(node), property(property_name) {
item = window->findQmlObject(object_name);
if (item) {
node->addWatcher(this, true);
string signal_name("2" + property_name + "Changed()");
connect(item, signal_name.c_str(), this, SLOT(propertyChanged()));
} else {
item = NULL;
Logs::error("UI") << "Can't find object :" << object_name << endl;
}
}
void IntPropertyBind::nodeChanged(const DefinitionNode *, const DefinitionDiff *, const DefinitionNode *) {
if (item) {
item->setProperty(property.c_str(), node->getValue());
}
}
void IntPropertyBind::propertyChanged() {
bool ok;
int value = item->property(property.c_str()).toInt(&ok);
if (ok and value != node->getValue()) {
node->setValue(value);
}
}