Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
AlgorithmRegistry.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
6#include <phosphortiles_export.h>
8#include "AutotileConstants.h"
10#include <QHash>
11#include <QLatin1String>
12#include <QList>
13#include <QMutex>
14#include <QMutexLocker>
15#include <QObject>
16#include <QPointer>
17#include <QRect>
18#include <QString>
19#include <QStringList>
20#include <QVariantList>
21#include <QVariantMap>
22#include <functional>
23
24namespace PhosphorTiles {
25
26class TilingAlgorithm;
27
52class PHOSPHORTILES_EXPORT AlgorithmRegistry : public ITileAlgorithmRegistry
53{
54 Q_OBJECT
55 Q_DISABLE_COPY_MOVE(AlgorithmRegistry)
56
57public:
78 void cleanup();
79
80 // ─── ITileAlgorithmRegistry implementation ─────────────────────────────
81
82 void registerAlgorithm(const QString& id, TilingAlgorithm* algorithm) override;
83 bool unregisterAlgorithm(const QString& id) override;
84 TilingAlgorithm* algorithm(const QString& id) const override;
85 QStringList availableAlgorithms() const override;
86 QList<TilingAlgorithm*> allAlgorithms() const override;
87 bool hasAlgorithm(const QString& id) const override;
89
102 QString defaultAlgorithmId() const override
103 {
104 return staticDefaultAlgorithmId();
105 }
106
110 static QString staticDefaultAlgorithmId();
111
112 // ═══════════════════════════════════════════════════════════════════════════
113 // Preview utilities for unified layout model (shared by zone selector,
114 // overlay service, daemon OSD, and KCM algorithm preview)
115 // ═══════════════════════════════════════════════════════════════════════════
116
121 static constexpr int PreviewCanvasSize = 1000;
122
123 // ─── Preview params (ITileAlgorithmRegistry overrides) ─────────────────
124
125 void setPreviewParams(const AlgorithmPreviewParams& params) override;
126 const AlgorithmPreviewParams& previewParams() const noexcept override;
127
131 explicit AlgorithmRegistry(QObject* parent = nullptr);
132 ~AlgorithmRegistry() override;
133
134private:
140 void registerBuiltInAlgorithms();
141
151 TilingAlgorithm* removeAlgorithmInternal(const QString& id);
152
161 void safeDeleteAlgorithm(TilingAlgorithm* algo);
162
163 QHash<QString, TilingAlgorithm*> m_algorithms;
164 QStringList m_registrationOrder;
165
172 QList<QPointer<TilingAlgorithm>> m_pendingDeletes;
173
174 AlgorithmPreviewParams m_previewParams;
175};
176
180struct PHOSPHORTILES_EXPORT PendingAlgorithmRegistration
181{
182 QString id;
184 std::function<TilingAlgorithm*()> factory;
185};
186
201PHOSPHORTILES_EXPORT QList<PendingAlgorithmRegistration>& pendingAlgorithmRegistrations();
202
207PHOSPHORTILES_EXPORT class QMutex& pendingAlgorithmRegistrationsMutex();
208
226template<typename T>
228{
229public:
236 explicit AlgorithmRegistrar(const QString& id, int priority = 100)
237 {
238 // Store in the global (non-template) pending list. Locked so
239 // multiple algorithm libraries' static-init can run concurrently
240 // (Qt plugin loader on a worker thread, parallel test binaries
241 // sharing a process) without corrupting the QList.
242 QMutexLocker locker(&pendingAlgorithmRegistrationsMutex());
243 pendingAlgorithmRegistrations().append({id, priority, []() {
244 return new T();
245 }});
246 }
247};
248
249} // namespace PhosphorTiles
Algorithm-layer constants for the autotile/tile primitives.
Helper for static self-registration of built-in algorithms.
Definition AlgorithmRegistry.h:228
AlgorithmRegistrar(const QString &id, int priority=100)
Register an algorithm at static initialization time.
Definition AlgorithmRegistry.h:236
Concrete tiling-algorithm registry.
Definition AlgorithmRegistry.h:53
bool hasAlgorithm(const QString &id) const override
Whether an algorithm is registered under id.
void cleanup()
Early cleanup of all registered algorithms.
void setPreviewParams(const AlgorithmPreviewParams &params) override
Apply the user-configured tiling parameters.
QStringList availableAlgorithms() const override
All registered algorithm ids, in registration order.
QString defaultAlgorithmId() const override
Get the library's recommended default algorithm ID.
Definition AlgorithmRegistry.h:102
TilingAlgorithm * defaultAlgorithm() const override
Convenience: the registry's recommended default algorithm.
bool unregisterAlgorithm(const QString &id) override
Unregister and delete the algorithm with id.
const AlgorithmPreviewParams & previewParams() const noexcept override
The currently-configured preview parameters.
TilingAlgorithm * algorithm(const QString &id) const override
Resolve an algorithm by its stable id.
void registerAlgorithm(const QString &id, TilingAlgorithm *algorithm) override
Register an algorithm under id.
static QString staticDefaultAlgorithmId()
Static accessor for the same id defaultAlgorithmId() returns.
QList< TilingAlgorithm * > allAlgorithms() const override
Every registered algorithm pointer.
Abstract contract for a tiling-algorithm registry.
Definition ITileAlgorithmRegistry.h:41
Abstract base class for tiling algorithms.
Definition TilingAlgorithm.h:56
Definition AutotileEngine.h:71
PHOSPHORTILES_EXPORT QList< PendingAlgorithmRegistration > & pendingAlgorithmRegistrations()
Global list of pending algorithm registrations.
PHOSPHORTILES_EXPORT class QMutex & pendingAlgorithmRegistrationsMutex()
Mutex protecting pendingAlgorithmRegistrations().
User-configured tiling parameters that affect algorithm preview generation.
Definition AlgorithmPreviewParams.h:20
Pending algorithm registration data.
Definition AlgorithmRegistry.h:181
QString id
Definition AlgorithmRegistry.h:182
int priority
Definition AlgorithmRegistry.h:183