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

@ -1,4 +1,5 @@
#include "shell.hpp"
#include <utility>
#include <qlogging.h>
#include <qobject.h>
@ -8,7 +9,7 @@
#include "rootwrapper.hpp"
void QtShell::reload() {
void QtShell::reload(bool hard) {
auto* rootobj = QQmlEngine::contextForObject(this)->engine()->parent();
auto* root = qobject_cast<RootWrapper*>(rootobj);
@ -17,7 +18,23 @@ void QtShell::reload() {
return;
}
root->reloadGraph();
root->reloadGraph(hard);
}
void QtShell::earlyInit(QObject* old) {
auto* oldshell = qobject_cast<QtShell*>(old);
if (oldshell != nullptr) {
this->scavengeableChildren = std::move(oldshell->children);
}
}
QObject* QtShell::scavengeTargetFor(QObject* /* child */) {
if (this->scavengeableChildren.length() > this->children.length()) {
return this->scavengeableChildren[this->children.length()];
}
return nullptr;
}
QQmlListProperty<QObject> QtShell::components() {
@ -36,4 +53,5 @@ QQmlListProperty<QObject> QtShell::components() {
void QtShell::appendComponent(QQmlListProperty<QObject>* list, QObject* component) {
auto* shell = static_cast<QtShell*>(list->object); // NOLINT
component->setParent(shell);
shell->children.append(component);
}