Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
SearchController.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
7#include "phosphorcontrol_export.h"
8
9#include <QHash>
10#include <QObject>
11#include <QPointer>
12#include <QSet>
13#include <QString>
14#include <QStringList>
15#include <QVariantList>
16#include <QVector>
17
18namespace PhosphorControl {
19
21class ISearchProvider;
22
49class PHOSPHORCONTROL_EXPORT SearchController : public QObject
50{
51 Q_OBJECT
52 Q_PROPERTY(QString query READ query WRITE setQuery NOTIFY queryChanged)
53 Q_PROPERTY(QVariantList results READ results NOTIFY resultsChanged)
54 Q_PROPERTY(int resultCount READ resultCount NOTIFY resultsChanged)
55 Q_PROPERTY(QString suggestion READ suggestion NOTIFY resultsChanged)
56 Q_PROPERTY(int limit READ limit WRITE setLimit NOTIFY limitChanged)
57
58public:
59 explicit SearchController(ApplicationController* app, QObject* parent = nullptr);
61
62 QString query() const;
63 void setQuery(const QString& q);
64
65 QVariantList results() const;
66 int resultCount() const;
67 QString suggestion() const;
68
69 int limit() const;
71 void setLimit(int n);
72
76 void setPageKeywords(const QString& pageId, const QStringList& keywords);
78 void addEntry(const SearchEntry& entry);
86
88 Q_INVOKABLE void invalidate();
89
100
101Q_SIGNALS:
105
106private:
107 void recompute();
108 QVector<SearchEntry> buildIndex();
109
110 QPointer<ApplicationController> m_app = nullptr;
111 QString m_query;
112 int m_limit = 24;
113
114 QHash<QString, QStringList> m_pageKeywords;
115 QVector<SearchEntry> m_staticEntries;
116 QVector<ISearchProvider*> m_providers;
117
130 QSet<QString> m_warnedEntryKeys;
131
132 bool m_indexDirty = true;
135 bool m_building = false;
137 int m_updateHolds = 0;
138 QVector<SearchEntry> m_index;
139 QVariantList m_resultsVariant;
140 QString m_suggestion;
141};
142
143} // namespace PhosphorControl
Top-level orchestrator for a phosphor-control application.
Definition ApplicationController.h:47
Source of dynamic (content) search entries — rules, shaders, layouts, virtual screens,...
Definition ISearchProvider.h:23
void registerProvider(ISearchProvider *provider)
Register a dynamic content source.
void setLimit(int n)
Max results. n < 0 = uncapped; n == 0 = no results.
void invalidate()
Mark the index stale; the next query (or the current one) rebuilds it.
void setPageKeywords(const QString &pageId, const QStringList &keywords)
Sets the synonyms for the auto-derived page entry for pageId (the ranker weighs them alongside the pa...
void unregisterProvider(ISearchProvider *provider)
Stop asking provider, and refresh the results of a live query.
void setQuery(const QString &q)
SearchController(ApplicationController *app, QObject *parent=nullptr)
void holdUpdates()
Hold back the rebuild a live query makes on every change, until the matching releaseUpdates(),...
void addEntry(const SearchEntry &entry)
A static section / setting anchor entry (or any extra entry).
void releaseUpdates()
End a holdUpdates().
QVariantList results() const
Definition ApplicationController.h:21
One searchable item in the global settings search index.
Definition SearchEntry.h:25