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
|
@ -2,22 +2,26 @@
|
|||
|
||||
#include <qcontainerfwd.h>
|
||||
#include <qlist.h>
|
||||
#include <qlogging.h>
|
||||
#include <qmap.h>
|
||||
#include <qobject.h>
|
||||
#include <qqmlcomponent.h>
|
||||
#include <qqmlparserstatus.h>
|
||||
|
||||
#include "scavenge.hpp"
|
||||
|
||||
// extremely inefficient map
|
||||
template <typename K, typename V>
|
||||
class AwfulMap {
|
||||
public:
|
||||
[[nodiscard]] bool contains(const K& key) const;
|
||||
[[nodiscard]] V* get(const K& key);
|
||||
void insert(K key, V value); // assumes no duplicates
|
||||
bool remove(const K& key); // returns true if anything was removed
|
||||
QList<QPair<K, V>> values;
|
||||
};
|
||||
|
||||
class Variants: public QObject, public QQmlParserStatus {
|
||||
class Variants: public Scavenger, virtual public Scavengeable {
|
||||
Q_OBJECT;
|
||||
Q_PROPERTY(QQmlComponent* component MEMBER mComponent);
|
||||
Q_PROPERTY(QVariantList variants MEMBER mVariants WRITE setVariants);
|
||||
|
@ -25,9 +29,11 @@ class Variants: public QObject, public QQmlParserStatus {
|
|||
QML_ELEMENT;
|
||||
|
||||
public:
|
||||
explicit Variants(QObject* parent = nullptr): QObject(parent) {}
|
||||
explicit Variants(QObject* parent = nullptr): Scavenger(parent) {}
|
||||
|
||||
void earlyInit(QObject* old) override;
|
||||
QObject* scavengeTargetFor(QObject* child) override;
|
||||
|
||||
void classBegin() override {};
|
||||
void componentComplete() override;
|
||||
|
||||
private:
|
||||
|
@ -37,4 +43,8 @@ private:
|
|||
QQmlComponent* mComponent = nullptr;
|
||||
QVariantList mVariants;
|
||||
AwfulMap<QVariantMap, QObject*> instances;
|
||||
|
||||
// pointers may die post componentComplete.
|
||||
AwfulMap<QVariantMap, QObject*> scavengeableInstances;
|
||||
QVariantMap* activeScavengeVariant = nullptr;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue