feat: implement soft reloading

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

40
src/cpp/scavenge.cpp Normal file
View file

@ -0,0 +1,40 @@
#include "scavenge.hpp"
#include <qcontainerfwd.h>
#include <qobject.h>
#include <qqmlcomponent.h>
#include <qqmlengine.h>
QObject* SCAVENGE_PARENT = nullptr; // NOLINT
void Scavenger::classBegin() {
// prayers
if (this->parent() == nullptr) {
this->setParent(SCAVENGE_PARENT);
SCAVENGE_PARENT = nullptr;
}
auto* parent = dynamic_cast<Scavengeable*>(this->parent());
QObject* old = nullptr;
if (parent != nullptr) {
old = parent->scavengeTargetFor(this);
}
this->earlyInit(old);
}
QObject* createComponentScavengeable(
QObject& parent,
QQmlComponent& component,
QVariantMap& initialProperties
) {
SCAVENGE_PARENT = &parent;
auto* instance = component.beginCreate(QQmlEngine::contextForObject(&parent));
SCAVENGE_PARENT = nullptr;
if (instance == nullptr) return nullptr;
if (instance->parent() != nullptr) instance->setParent(&parent);
component.setInitialProperties(instance, initialProperties);
component.completeCreate();
return instance;
}