quickshell/src/core/singleton.hpp
outfoxxed 0416032a7c
core/reloader: trigger postReload with a signal
A signal is now used over the previous tree-searching method as some
QML components such as Repeater fail to reparent created children to
themselves, which breaks the tree.
2025-07-26 17:52:06 -07:00

32 lines
632 B
C++

#pragma once
#include <qhash.h>
#include <qobject.h>
#include <qqmlengine.h>
#include <qqmlintegration.h>
#include <qtmetamacros.h>
#include <qtypes.h>
#include <qurl.h>
#include "reload.hpp"
///! The root component for reloadable singletons.
/// All singletons should inherit from this type.
class Singleton: public ReloadPropagator {
Q_OBJECT;
QML_ELEMENT;
public:
void componentComplete() override;
};
class SingletonRegistry {
public:
SingletonRegistry() = default;
void registerSingleton(const QUrl& url, Singleton* singleton);
void onReload(SingletonRegistry* old);
private:
QHash<QUrl, Singleton*> registry;
};