aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Teichmann <daniel.teichmann@das-netzwerkteam.de>2021-07-12 13:02:24 +0200
committerDaniel Teichmann <daniel.teichmann@das-netzwerkteam.de>2021-07-12 13:02:24 +0200
commit18c2b837d33c040a21f84c444d8c554769f1dc58 (patch)
treea540a8c3448261c3bb07a2adeabd031d40b7ce81
parentc8dc8bda03b27a76d31c358e4b642a5687611178 (diff)
downloadRWA.Support.DesktopApp-18c2b837d33c040a21f84c444d8c554769f1dc58.tar.gz
RWA.Support.DesktopApp-18c2b837d33c040a21f84c444d8c554769f1dc58.tar.bz2
RWA.Support.DesktopApp-18c2b837d33c040a21f84c444d8c554769f1dc58.zip
Don't just reset the _rwaHostModel everytime but add and remove specific items.
TODO: Use QSet subtraction feature instead of manual for loops!!!
-rw-r--r--src/main_qmladaptor.cpp83
1 files changed, 76 insertions, 7 deletions
diff --git a/src/main_qmladaptor.cpp b/src/main_qmladaptor.cpp
index a89d085..6d3a60c 100644
--- a/src/main_qmladaptor.cpp
+++ b/src/main_qmladaptor.cpp
@@ -121,6 +121,7 @@ void MainQMLAdaptor::get_web_app_hosts_response(QJsonDocument *doc) {
// Building host_objects
QJsonArray host_objects = jObject.value("hosts").toArray();
+ QList<RWAHost*> *all_rwa_hosts = new QList<RWAHost*>;
foreach (const QJsonValue &host_object, host_objects) {
QString host_uuid = host_object["uuid"].toString();
QString host_alias = host_object["alias"].toString();
@@ -142,12 +143,46 @@ void MainQMLAdaptor::get_web_app_hosts_response(QJsonDocument *doc) {
host_alias = host_url;
}
+
// Now built RWAHost object.
RWAHost *rwa_host = new RWAHost(host_uuid, host_alias, host_url);
- addRWAHost(rwa_host);
+ all_rwa_hosts->append(rwa_host);
+
+ bool found = false;
+ for (int i = 0; i < this->_rwaHostModel->size(); i++) {
+ RWAHost* old_host = qobject_cast<RWAHost*>(_rwaHostModel->value(i));
+ Q_ASSERT(old_host != nullptr);
+
+ if (rwa_host->uuid() == old_host->uuid()) {
+ found = true;
+ break;
+ }
+ }
+
atLeastOneHostAvailable = true;
- qInfo().noquote() << QString(tr("Successfully added new RWAHost '%0'")).arg(rwa_host->alias());
+ if (!found) {
+ qInfo().noquote() << QString(tr("Successfully added new RWAHost '%0'")).arg(rwa_host->alias());
+ addRWAHost(rwa_host);
+ }
+ }
+
+ for (int i = 0; i < this->_rwaHostModel->size(); i++) {
+ RWAHost* old_host = qobject_cast<RWAHost*>(_rwaHostModel->value(i));
+ Q_ASSERT(old_host != nullptr);
+
+ bool found = false;
+ for (RWAHost *host : *all_rwa_hosts) {
+ if (host->uuid() == old_host->uuid()) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found) {
+ removeRWAHost(old_host);
+ qInfo().noquote() << QString(tr("Removed RWAHost '%0'")).arg(old_host->alias());
+ }
}
} else {
QString reason = tr("An error occured while adding a new host:");
@@ -176,16 +211,40 @@ void MainQMLAdaptor::get_web_app_hosts_response(QJsonDocument *doc) {
void MainQMLAdaptor::main_content_push(QString scene) {
// Find item via 'objectName'
+ QObject *window = _engine->rootObjects().takeFirst();
+ Q_ASSERT(window != nullptr);
+
QObject *main_content = _engine->rootObjects().takeFirst()->findChild<QObject*>("main_content");
Q_ASSERT(main_content != nullptr);
- QMetaObject::invokeMethod(main_content, "push", Q_ARG(QString, scene));
+
+ QVariant to_cast = main_content->property("currentItem");
+ QObject *obj = qvariant_cast<QObject *>(to_cast);
+ if (obj) {
+ if (!(scene.contains(obj->objectName()))) {
+ QVariant arg = QVariant::fromValue(scene);
+ if(!QMetaObject::invokeMethod(window, "main_content_push", Q_ARG(QVariant, arg)))
+ qDebug() << "Failed to invoke push";
+ }
+ }
}
void MainQMLAdaptor::main_content_pop(QString scene) {
// Find item via 'objectName'
+ QObject *window = _engine->rootObjects().takeFirst();
+ Q_ASSERT(window != nullptr);
+
QObject *main_content = _engine->rootObjects().takeFirst()->findChild<QObject*>("main_content");
Q_ASSERT(main_content != nullptr);
- QMetaObject::invokeMethod(main_content, "pop", Q_ARG(QString, scene));
+
+ QVariant to_cast = main_content->property("currentItem");
+ QObject *obj = qvariant_cast<QObject *>(to_cast);
+ if (obj) {
+ if (!(scene.contains(obj->objectName()))) {
+ QVariant arg = QVariant::fromValue(scene);
+ if(!QMetaObject::invokeMethod(window, "main_content_pop", Q_ARG(QVariant, arg)))
+ qDebug() << "Failed to invoke pop";
+ }
+ }
}
void MainQMLAdaptor::main_content_replace(QString scene) {
@@ -193,9 +252,19 @@ void MainQMLAdaptor::main_content_replace(QString scene) {
QObject *window = _engine->rootObjects().takeFirst();
Q_ASSERT(window != nullptr);
- QVariant arg = QVariant::fromValue(scene);
- if(!QMetaObject::invokeMethod(window, "main_content_replace", Q_ARG(QVariant, arg)))
- qDebug() << "Failed to invoke push";
+ QObject *main_content = _engine->rootObjects().takeFirst()->findChild<QObject*>("main_content");
+ Q_ASSERT(main_content != nullptr);
+
+ QVariant to_cast = main_content->property("currentItem");
+ QObject *obj = qvariant_cast<QObject *>(to_cast);
+ if (obj) {
+ QString scene_add_server_wizard = "Scene_step_1";
+ if (!(scene.contains(obj->objectName()) || scene_add_server_wizard.contains(obj->objectName()))) {
+ QVariant arg = QVariant::fromValue(scene);
+ if(!QMetaObject::invokeMethod(window, "main_content_replace", Q_ARG(QVariant, arg)))
+ qDebug() << "Failed to invoke replace";
+ }
+ }
}
bool MainQMLAdaptor::setConnectButtonEnabled(bool enabled) {