From 731097bca3c1815867a32ef7283e08a229fc0bab Mon Sep 17 00:00:00 2001 From: James Turner Date: Tue, 28 Nov 2017 16:20:10 +0000 Subject: [PATCH] Remote canvas: fix snapshot loading Visibility prop was being saved incorrectly. --- utils/fgqcanvas/canvasdisplay.cpp | 2 ++ utils/fgqcanvas/canvasitem.cpp | 3 ++- utils/fgqcanvas/fgcanvaselement.cpp | 7 ++----- utils/fgqcanvas/localprop.cpp | 13 ++++++++++--- utils/fgqcanvas/localprop.h | 4 ++-- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/utils/fgqcanvas/canvasdisplay.cpp b/utils/fgqcanvas/canvasdisplay.cpp index 946ba3f39..71179ffc3 100644 --- a/utils/fgqcanvas/canvasdisplay.cpp +++ b/utils/fgqcanvas/canvasdisplay.cpp @@ -109,6 +109,8 @@ void CanvasDisplay::onConnectionStatusChanged() if (m_connection->status() == CanvasConnection::Snapshot) { m_connection->propertyRoot()->recursiveNotifyRestored(); + m_rootElement->polish(); + update(); } } } diff --git a/utils/fgqcanvas/canvasitem.cpp b/utils/fgqcanvas/canvasitem.cpp index 71e7194ab..4b68d765f 100644 --- a/utils/fgqcanvas/canvasitem.cpp +++ b/utils/fgqcanvas/canvasitem.cpp @@ -30,7 +30,8 @@ public: transform = t; update(); } - void applyTo(QMatrix4x4 *matrix) const Q_DECL_OVERRIDE { + void applyTo(QMatrix4x4 *matrix) const override + { *matrix *= transform; } private: diff --git a/utils/fgqcanvas/fgcanvaselement.cpp b/utils/fgqcanvas/fgcanvaselement.cpp index 6534e75b5..748e6bda9 100644 --- a/utils/fgqcanvas/fgcanvaselement.cpp +++ b/utils/fgqcanvas/fgcanvaselement.cpp @@ -85,11 +85,8 @@ FGCanvasElement::FGCanvasElement(FGCanvasGroup* pr, LocalProp* prop) : _propertyRoot(prop), _parent(pr) { - connect(prop->getOrCreateWithPath("visible"), &LocalProp::valueChanged, - [this](QVariant val) { - _visible = val.toBool(); - requestPolish(); - }); + connect(prop->getOrCreateWithPath("visible", true), &LocalProp::valueChanged, + this, &FGCanvasElement::onVisibleChanged); connect(prop, &LocalProp::childAdded, this, &FGCanvasElement::onChildAdded); connect(prop, &LocalProp::childRemoved, this, &FGCanvasElement::onChildRemoved); diff --git a/utils/fgqcanvas/localprop.cpp b/utils/fgqcanvas/localprop.cpp index 66bd3ddde..69ad2f1d8 100644 --- a/utils/fgqcanvas/localprop.cpp +++ b/utils/fgqcanvas/localprop.cpp @@ -32,7 +32,7 @@ QDataStream& operator>>(QDataStream& stream, NameIndexTuple& nameIndex) return stream; } -LocalProp *LocalProp::getOrCreateWithPath(const QByteArray &path) +LocalProp *LocalProp::getOrCreateWithPath(const QByteArray &path, QVariant defaultValue) { if (path.isEmpty()) { return this; @@ -40,12 +40,17 @@ LocalProp *LocalProp::getOrCreateWithPath(const QByteArray &path) QList segments = path.split('/'); LocalProp* result = this; - while (!segments.empty()) { + while (segments.size() > 1) { QByteArray nameIndex = segments.front(); result = result->getOrCreateChildWithNameAndIndex(nameIndex); segments.pop_front(); } + // for the final segment, pass the default value + if (!segments.empty()) { + result = result->getOrCreateChildWithNameAndIndex(segments.front(), defaultValue); + } + return result; } @@ -167,7 +172,8 @@ void LocalProp::recursiveNotifyRestored() } } -LocalProp *LocalProp::getOrCreateChildWithNameAndIndex(const NameIndexTuple& ni) +LocalProp *LocalProp::getOrCreateChildWithNameAndIndex(const NameIndexTuple& ni, + QVariant defaultValue) { auto it = std::lower_bound(_children.begin(), _children.end(), ni, lessThanPropNameIndex); if ((it != _children.end()) && ((*it)->id() == ni)) { @@ -175,6 +181,7 @@ LocalProp *LocalProp::getOrCreateChildWithNameAndIndex(const NameIndexTuple& ni) } LocalProp* newChild = new LocalProp(this, ni); + newChild->_value = defaultValue; _children.insert(it, newChild); emit childAdded(newChild); return newChild; diff --git a/utils/fgqcanvas/localprop.h b/utils/fgqcanvas/localprop.h index a2c9e06e3..b0e21da8b 100644 --- a/utils/fgqcanvas/localprop.h +++ b/utils/fgqcanvas/localprop.h @@ -90,11 +90,11 @@ public: QByteArray path() const; - LocalProp* getOrCreateWithPath(const QByteArray& path); + LocalProp* getOrCreateWithPath(const QByteArray& path, QVariant defaultValue = {}); LocalProp* childWithNameAndIndex(const NameIndexTuple& ni) const; - LocalProp* getOrCreateChildWithNameAndIndex(const NameIndexTuple& ni); + LocalProp* getOrCreateChildWithNameAndIndex(const NameIndexTuple& ni, QVariant defaultValue = {}); LocalProp* getOrCreateWithPath(const char* name);