-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainviewcontroller.cpp
49 lines (37 loc) · 1.39 KB
/
mainviewcontroller.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <QDebug>
#include <QQuickItem>
#include "mainviewcontroller.h"
#include "common.h"
MainviewController::MainviewController(): m_settings(APP_SETTINGS_PATH, QSettings::NativeFormat) {
m_settings.beginGroup("Qml");
//for debug purposes
QUrl Foo = QUrl::fromLocalFile(m_settings.value("main_view").value < QString > ());
qDebug() << "Loading " << Foo.toString() << " < ...";
//the real stuff
this->load(QUrl::fromLocalFile(m_settings.value("main_view").value < QString > ()));
m_settings.endGroup();
}
void MainviewController::updateView(QStringList msg) {
qDebug() << "UpdateView: " << msg << " <--";
QStringList props = msg[0].split(".");
if (props.length() != 2) {
qDebug() << "Invalid prop format, expect prop.value " << msg[0];
return;
}
QList < QObject * > roots = this->rootObjects();
if (roots.empty() == true) {
qDebug() << "rootObject is NULL! -- Check the QML file for errors.";
}
/* We expect the root object to be a ApplicationWindow element */
QObject * rootObject = this->rootObjects().first();
QQuickItem * item = rootObject->findChild < QQuickItem * > (props[0]);
if (item == nullptr) {
qDebug() << "View does not contain: " << props[0];
QObject::dumpObjectTree();
return;
}
bool found = item->setProperty(props[1].toUtf8(), msg[1].toUtf8());
if (!found) {
qDebug() << "No property on objectName:" << (msg[1]);
}
}