forked from quickshell/quickshell
feat: implement soft reloading
This commit is contained in:
parent
ba1e18a125
commit
362789fc46
11 changed files with 385 additions and 21 deletions
40
src/cpp/scavenge.cpp
Normal file
40
src/cpp/scavenge.cpp
Normal 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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue