2024-01-25 12:33:02 +00:00
|
|
|
#pragma once
|
|
|
|
|
2024-02-01 02:35:51 +00:00
|
|
|
#include <qcontainerfwd.h>
|
2024-02-01 09:29:45 +00:00
|
|
|
#include <qlist.h>
|
2024-01-25 12:33:02 +00:00
|
|
|
#include <qobject.h>
|
|
|
|
#include <qqmlengine.h>
|
|
|
|
#include <qqmllist.h>
|
2024-02-01 02:35:51 +00:00
|
|
|
#include <qtmetamacros.h>
|
2024-01-25 12:33:02 +00:00
|
|
|
|
2024-02-01 09:29:45 +00:00
|
|
|
#include "scavenge.hpp"
|
|
|
|
|
2024-02-05 07:00:59 +00:00
|
|
|
class ShellConfig {
|
|
|
|
Q_GADGET;
|
|
|
|
Q_PROPERTY(bool watchFiles MEMBER mWatchFiles);
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool mWatchFiles = true;
|
|
|
|
};
|
|
|
|
|
2024-02-12 12:21:24 +00:00
|
|
|
///! Root config element
|
2024-02-05 07:00:59 +00:00
|
|
|
class ShellRoot: public Scavenger, virtual public Scavengeable {
|
2024-01-25 12:33:02 +00:00
|
|
|
Q_OBJECT;
|
2024-02-12 12:21:24 +00:00
|
|
|
/// If `config.watchFiles` is true the configuration will be reloaded whenever it changes.
|
|
|
|
/// Defaults to true.
|
2024-02-05 07:00:59 +00:00
|
|
|
Q_PROPERTY(ShellConfig config READ config WRITE setConfig);
|
2024-02-12 12:21:24 +00:00
|
|
|
Q_PROPERTY(QQmlListProperty<QObject> components READ components);
|
2024-01-25 12:33:02 +00:00
|
|
|
Q_CLASSINFO("DefaultProperty", "components");
|
|
|
|
QML_ELEMENT;
|
|
|
|
|
|
|
|
public:
|
2024-02-05 07:00:59 +00:00
|
|
|
explicit ShellRoot(QObject* parent = nullptr): Scavenger(parent) {}
|
2024-02-01 09:29:45 +00:00
|
|
|
|
|
|
|
void earlyInit(QObject* old) override;
|
|
|
|
QObject* scavengeTargetFor(QObject* child) override;
|
2024-01-25 12:33:02 +00:00
|
|
|
|
2024-02-05 07:00:59 +00:00
|
|
|
void setConfig(ShellConfig config);
|
|
|
|
[[nodiscard]] ShellConfig config() const;
|
|
|
|
|
2024-02-01 02:35:51 +00:00
|
|
|
QQmlListProperty<QObject> components();
|
2024-01-25 12:33:02 +00:00
|
|
|
|
2024-02-05 07:00:59 +00:00
|
|
|
signals:
|
|
|
|
void configChanged();
|
|
|
|
|
2024-01-25 12:33:02 +00:00
|
|
|
private:
|
2024-02-01 02:35:51 +00:00
|
|
|
static void appendComponent(QQmlListProperty<QObject>* list, QObject* component);
|
2024-02-01 09:29:45 +00:00
|
|
|
|
2024-02-05 07:00:59 +00:00
|
|
|
ShellConfig mConfig;
|
|
|
|
|
2024-02-01 09:29:45 +00:00
|
|
|
// track only the children assigned to `components` in order
|
|
|
|
QList<QObject*> children;
|
|
|
|
QList<QObject*> scavengeableChildren;
|
2024-01-25 12:33:02 +00:00
|
|
|
};
|