feat: abstract out scavenger scopes

This commit is contained in:
outfoxxed 2024-02-14 03:03:41 -08:00
parent 82aa7d45d3
commit d6ed717c39
Signed by untrusted user: outfoxxed
GPG key ID: 4C88A185FB89301E
4 changed files with 74 additions and 56 deletions

View file

@ -1,26 +1,7 @@
#include "shell.hpp"
#include <utility>
#include <qobject.h>
#include <qqmllist.h>
#include <qtmetamacros.h>
void ShellRoot::earlyInit(QObject* old) {
auto* oldshell = qobject_cast<ShellRoot*>(old);
if (oldshell != nullptr) {
this->scavengeableChildren = std::move(oldshell->children);
}
}
QObject* ShellRoot::scavengeTargetFor(QObject* /* child */) {
if (this->scavengeableChildren.length() > this->children.length()) {
return this->scavengeableChildren[this->children.length()];
}
return nullptr;
}
void ShellRoot::setConfig(ShellConfig config) {
this->mConfig = config;
@ -28,22 +9,3 @@ void ShellRoot::setConfig(ShellConfig config) {
}
ShellConfig ShellRoot::config() const { return this->mConfig; }
QQmlListProperty<QObject> ShellRoot::components() {
return QQmlListProperty<QObject>(
this,
nullptr,
&ShellRoot::appendComponent,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr
);
}
void ShellRoot::appendComponent(QQmlListProperty<QObject>* list, QObject* component) {
auto* shell = static_cast<ShellRoot*>(list->object); // NOLINT
component->setParent(shell);
shell->children.append(component);
}