2015-09-08 21:52:34 +00:00
|
|
|
#include "IntPropertyBind.h"
|
|
|
|
|
|
|
|
#include "IntNode.h"
|
|
|
|
#include "Logs.h"
|
2016-07-23 20:58:32 +00:00
|
|
|
#include "MainModelerWindow.h"
|
2015-09-08 21:52:34 +00:00
|
|
|
|
2015-12-29 23:20:20 +00:00
|
|
|
IntPropertyBind::IntPropertyBind(MainModelerWindow *window, const string &object_name, const string &property_name,
|
2015-11-09 21:30:46 +00:00
|
|
|
IntNode *node)
|
2016-01-21 22:02:22 +00:00
|
|
|
: QObject(window), DefinitionWatcher("IntPropertyBind " + object_name + "." + property_name), node(node),
|
|
|
|
property(property_name) {
|
2015-09-08 21:52:34 +00:00
|
|
|
item = window->findQmlObject(object_name);
|
2015-11-09 21:30:46 +00:00
|
|
|
if (item) {
|
2016-01-21 22:02:22 +00:00
|
|
|
startWatching(node);
|
2015-12-29 23:20:20 +00:00
|
|
|
string signal_name("2" + property_name + "Changed()");
|
|
|
|
connect(item, signal_name.c_str(), this, SLOT(propertyChanged()));
|
2015-11-09 21:30:46 +00:00
|
|
|
} else {
|
2015-09-08 21:52:34 +00:00
|
|
|
item = NULL;
|
2015-12-29 23:20:20 +00:00
|
|
|
Logs::error("UI") << "Can't find object :" << object_name << endl;
|
2015-09-08 21:52:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-16 15:21:02 +00:00
|
|
|
void IntPropertyBind::nodeChanged(const DefinitionNode *, const DefinitionDiff *, const DefinitionNode *) {
|
2015-11-09 21:30:46 +00:00
|
|
|
if (item) {
|
2015-12-29 23:20:20 +00:00
|
|
|
item->setProperty(property.c_str(), node->getValue());
|
2015-09-08 21:52:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-29 23:20:20 +00:00
|
|
|
void IntPropertyBind::propertyChanged() {
|
|
|
|
bool ok;
|
|
|
|
int value = item->property(property.c_str()).toInt(&ok);
|
|
|
|
if (ok and value != node->getValue()) {
|
2015-09-08 21:52:34 +00:00
|
|
|
node->setValue(value);
|
|
|
|
}
|
|
|
|
}
|