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

@ -2,9 +2,7 @@
#include <qcontainerfwd.h>
#include <qlist.h>
#include <qobject.h>
#include <qqmlengine.h>
#include <qqmllist.h>
#include <qtmetamacros.h>
#include "scavenge.hpp"
@ -18,35 +16,22 @@ public:
};
///! Root config element
class ShellRoot: public Scavenger, virtual public Scavengeable {
class ShellRoot: public ScavengeableScope {
Q_OBJECT;
/// If `config.watchFiles` is true the configuration will be reloaded whenever it changes.
/// Defaults to true.
Q_PROPERTY(ShellConfig config READ config WRITE setConfig);
Q_PROPERTY(QQmlListProperty<QObject> components READ components);
Q_CLASSINFO("DefaultProperty", "components");
QML_ELEMENT;
public:
explicit ShellRoot(QObject* parent = nullptr): Scavenger(parent) {}
void earlyInit(QObject* old) override;
QObject* scavengeTargetFor(QObject* child) override;
explicit ShellRoot(QObject* parent = nullptr): ScavengeableScope(parent) {}
void setConfig(ShellConfig config);
[[nodiscard]] ShellConfig config() const;
QQmlListProperty<QObject> components();
signals:
void configChanged();
private:
static void appendComponent(QQmlListProperty<QObject>* list, QObject* component);
ShellConfig mConfig;
// track only the children assigned to `components` in order
QList<QObject*> children;
QList<QObject*> scavengeableChildren;
};