core/window: fix reloads breaking for indirect window children

This commit is contained in:
outfoxxed 2024-04-07 14:17:57 -07:00
parent 6214ac1002
commit c0847366dd
Signed by: outfoxxed
GPG Key ID: 4C88A185FB89301E
1 changed files with 15 additions and 1 deletions

View File

@ -17,6 +17,7 @@
#include "qmlscreen.hpp"
#include "region.hpp"
#include "reload.hpp"
#include "windowinterface.hpp"
ProxyWindowBase::ProxyWindowBase(QObject* parent)
: Reloadable(parent)
@ -47,7 +48,20 @@ void ProxyWindowBase::onReload(QObject* oldInstance) {
auto wasVisible = this->window != nullptr && this->window->isVisible();
if (this->window == nullptr) this->window = new QQuickWindow();
Reloadable::reloadRecursive(this->mContentItem, oldInstance);
// The qml engine will leave the WindowInterface as owner of everything
// nested in an item, so we have to make sure the interface's children
// are also reloaded.
// Reparenting from the interface does not work reliably, so instead
// we check if the parent is one, as it proxies reloads to here.
if (auto* w = qobject_cast<WindowInterface*>(this->parent())) {
for (auto* child: w->children()) {
if (child == this) continue;
auto* oldInterfaceParent = oldInstance == nullptr ? nullptr : oldInstance->parent();
Reloadable::reloadRecursive(child, oldInterfaceParent);
}
}
Reloadable::reloadChildrenRecursive(this, oldInstance);
this->connectWindow();
this->completeWindow();