feat: implement soft reloading

This commit is contained in:
outfoxxed 2024-02-01 01:29:45 -08:00
parent ba1e18a125
commit 362789fc46
Signed by untrusted user: outfoxxed
GPG key ID: 4C88A185FB89301E
11 changed files with 385 additions and 21 deletions

View file

@ -8,11 +8,12 @@
#include <qqmlengine.h>
#include <qurl.h>
#include "scavenge.hpp"
#include "shell.hpp"
RootWrapper::RootWrapper(QUrl rootUrl):
QObject(nullptr), rootUrl(std::move(rootUrl)), engine(this) {
this->reloadGraph();
this->reloadGraph(true);
if (this->activeRoot == nullptr) {
qCritical() << "could not create scene graph, exiting";
@ -20,20 +21,24 @@ RootWrapper::RootWrapper(QUrl rootUrl):
}
}
void RootWrapper::reloadGraph() {
void RootWrapper::reloadGraph(bool hard) {
if (this->activeRoot != nullptr) {
this->engine.clearComponentCache();
}
auto component = QQmlComponent(&this->engine, this->rootUrl);
SCAVENGE_PARENT = hard ? nullptr : this;
auto* obj = component.beginCreate(this->engine.rootContext());
SCAVENGE_PARENT = nullptr;
if (obj == nullptr) {
qWarning() << "failed to create root component";
return;
}
auto* qtsobj = qobject_cast<QtShell*>(obj);
if (qtsobj == nullptr) {
auto* newRoot = qobject_cast<QtShell*>(obj);
if (newRoot == nullptr) {
qWarning() << "root component was not a QtShell";
delete obj;
return;
@ -46,7 +51,7 @@ void RootWrapper::reloadGraph() {
this->activeRoot = nullptr;
}
this->activeRoot = qtsobj;
this->activeRoot = newRoot;
}
void RootWrapper::changeRoot(QtShell* newRoot) {
@ -61,4 +66,6 @@ void RootWrapper::changeRoot(QtShell* newRoot) {
}
}
QObject* RootWrapper::scavengeTargetFor(QObject* /* child */) { return this->activeRoot; }
void RootWrapper::destroy() { this->deleteLater(); }