Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
RegistryNotifier.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3#pragma once
4
5#include <PhosphorRegistry/phosphorregistry_export.h>
6
7#include <QObject>
8#include <QString>
9#include <QtCore/qtclasshelpermacros.h> // Q_DISABLE_COPY_MOVE
10
11namespace PhosphorRegistry {
12
13// QObject-derived signal carrier for Registry<T>. The Registry itself
14// is a template, and Qt's moc cannot template-process a Q_OBJECT
15// class. The standard workaround is to put Q_OBJECT machinery on a
16// non-template helper that the template owns and forwards through.
17//
18// Registry<T> calls notifyRegistered / notifyUnregistered (the public
19// emit forwarders below) rather than emitting the signals directly.
20// Qt's `Q_SIGNALS:` access level (currently `public:` in Qt 6) is an
21// implementation detail Qt does not commit to keep public, so a
22// template invoking Q_EMIT m_notifier.factoryRegistered(...) would be
23// fragile under future Qt strictness. The forwarder pattern keeps
24// the access-level contract under our control.
25//
26// Consumers connect to factoryRegistered / factoryUnregistered via
27// registry.notifier(), with the factory id as the payload. The
28// concrete factory instance is looked up via factory(id) if needed
29// (passing the typed pointer through a QObject signal would require
30// Q_DECLARE_METATYPE for every factory subclass).
31class PHOSPHORREGISTRY_EXPORT RegistryNotifier : public QObject
32{
33 Q_OBJECT
34public:
35 explicit RegistryNotifier(QObject* parent = nullptr);
37 Q_DISABLE_COPY_MOVE(RegistryNotifier)
38
39 // Public emit forwarders. Registry<T> calls these from its template
40 // body so the Q_EMIT macro lives next to the signal declaration
41 // (whose access level Qt controls), not inside a template
42 // (whose Q_EMIT call would be fragile against future Qt access-
43 // level tightening of `Q_SIGNALS:`).
44 void notifyRegistered(const QString& id)
45 {
46 Q_EMIT factoryRegistered(id);
47 }
48 void notifyUnregistered(const QString& id)
49 {
50 Q_EMIT factoryUnregistered(id);
51 }
52
53Q_SIGNALS:
54 // Fired after a factory has been added to the registry.
55 void factoryRegistered(const QString& id);
56
57 // Fired after a factory has been removed from the registry. On a plain
58 // unregister the factory is gone — factory(id) returns null. On a Replace
59 // (DuplicatePolicy::Replace overwrites an existing id) this fires for the
60 // OLD factory immediately before factoryRegistered(id) for the new one,
61 // and the replacement is ALREADY in place — so factory(id) returns the new
62 // factory here, not null. Consumers that key teardown on factory(id)==null
63 // must account for the Replace case.
64 void factoryUnregistered(const QString& id);
65};
66
67} // namespace PhosphorRegistry
void factoryUnregistered(const QString &id)
RegistryNotifier(QObject *parent=nullptr)
void notifyUnregistered(const QString &id)
Definition RegistryNotifier.h:48
void factoryRegistered(const QString &id)
void notifyRegistered(const QString &id)
Definition RegistryNotifier.h:44
Definition IBarWidgetFactory.h:16