From 27953a89d1110d6cc82ff198e1c28f698104d554 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Tue, 14 Oct 2025 16:00:17 +1100 Subject: internal: use QQmlListProperty Fix lsp errors --- plugin/src/Caelestia/Internal/hyprdevices.cpp | 4 +- plugin/src/Caelestia/Internal/hyprdevices.hpp | 6 ++- plugin/src/Caelestia/Internal/hyprextras.hpp | 2 +- plugin/src/Caelestia/Models/filesystemmodel.cpp | 4 +- plugin/src/Caelestia/Models/filesystemmodel.hpp | 5 ++- plugin/src/Caelestia/appdb.cpp | 49 ++++++++++++++----------- plugin/src/Caelestia/appdb.hpp | 15 +++++--- plugin/src/Caelestia/toaster.cpp | 4 +- plugin/src/Caelestia/toaster.hpp | 5 ++- 9 files changed, 54 insertions(+), 40 deletions(-) (limited to 'plugin') diff --git a/plugin/src/Caelestia/Internal/hyprdevices.cpp b/plugin/src/Caelestia/Internal/hyprdevices.cpp index 3eba7e4..1ac7d25 100644 --- a/plugin/src/Caelestia/Internal/hyprdevices.cpp +++ b/plugin/src/Caelestia/Internal/hyprdevices.cpp @@ -85,8 +85,8 @@ bool HyprKeyboard::updateLastIpcObject(QJsonObject object) { HyprDevices::HyprDevices(QObject* parent) : QObject(parent) {} -QList HyprDevices::keyboards() const { - return m_keyboards; +QQmlListProperty HyprDevices::keyboards() { + return QQmlListProperty(this, &m_keyboards); } bool HyprDevices::updateLastIpcObject(QJsonObject object) { diff --git a/plugin/src/Caelestia/Internal/hyprdevices.hpp b/plugin/src/Caelestia/Internal/hyprdevices.hpp index e10df46..da18063 100644 --- a/plugin/src/Caelestia/Internal/hyprdevices.hpp +++ b/plugin/src/Caelestia/Internal/hyprdevices.hpp @@ -3,6 +3,7 @@ #include #include #include +#include namespace caelestia::internal::hypr { @@ -53,12 +54,13 @@ class HyprDevices : public QObject { QML_ELEMENT QML_UNCREATABLE("HyprDevices instances can only be retrieved from a HyprExtras") - Q_PROPERTY(QList keyboards READ keyboards NOTIFY keyboardsChanged) + Q_PROPERTY( + QQmlListProperty keyboards READ keyboards NOTIFY keyboardsChanged) public: explicit HyprDevices(QObject* parent = nullptr); - [[nodiscard]] QList keyboards() const; + [[nodiscard]] QQmlListProperty keyboards(); bool updateLastIpcObject(QJsonObject object); diff --git a/plugin/src/Caelestia/Internal/hyprextras.hpp b/plugin/src/Caelestia/Internal/hyprextras.hpp index 9f9e1ad..14563c0 100644 --- a/plugin/src/Caelestia/Internal/hyprextras.hpp +++ b/plugin/src/Caelestia/Internal/hyprextras.hpp @@ -12,7 +12,7 @@ class HyprExtras : public QObject { QML_ELEMENT Q_PROPERTY(QVariantHash options READ options NOTIFY optionsChanged) - Q_PROPERTY(HyprDevices* devices READ devices CONSTANT) + Q_PROPERTY(caelestia::internal::hypr::HyprDevices* devices READ devices CONSTANT) public: explicit HyprExtras(QObject* parent = nullptr); diff --git a/plugin/src/Caelestia/Models/filesystemmodel.cpp b/plugin/src/Caelestia/Models/filesystemmodel.cpp index 3ceb1dd..e387ecd 100644 --- a/plugin/src/Caelestia/Models/filesystemmodel.cpp +++ b/plugin/src/Caelestia/Models/filesystemmodel.cpp @@ -211,8 +211,8 @@ void FileSystemModel::setNameFilters(const QStringList& nameFilters) { update(); } -QList FileSystemModel::entries() const { - return m_entries; +QQmlListProperty FileSystemModel::entries() { + return QQmlListProperty(this, &m_entries); } void FileSystemModel::watchDirIfRecursive(const QString& path) { diff --git a/plugin/src/Caelestia/Models/filesystemmodel.hpp b/plugin/src/Caelestia/Models/filesystemmodel.hpp index cead43f..cf8eae8 100644 --- a/plugin/src/Caelestia/Models/filesystemmodel.hpp +++ b/plugin/src/Caelestia/Models/filesystemmodel.hpp @@ -8,6 +8,7 @@ #include #include #include +#include namespace caelestia::models { @@ -71,7 +72,7 @@ class FileSystemModel : public QAbstractListModel { Q_PROPERTY(Filter filter READ filter WRITE setFilter NOTIFY filterChanged) Q_PROPERTY(QStringList nameFilters READ nameFilters WRITE setNameFilters NOTIFY nameFiltersChanged) - Q_PROPERTY(QList entries READ entries NOTIFY entriesChanged) + Q_PROPERTY(QQmlListProperty entries READ entries NOTIFY entriesChanged) public: enum Filter { @@ -109,7 +110,7 @@ public: [[nodiscard]] QStringList nameFilters() const; void setNameFilters(const QStringList& nameFilters); - [[nodiscard]] QList entries() const; + [[nodiscard]] QQmlListProperty entries(); signals: void pathChanged(); diff --git a/plugin/src/Caelestia/appdb.cpp b/plugin/src/Caelestia/appdb.cpp index 16077b7..6e37e16 100644 --- a/plugin/src/Caelestia/appdb.cpp +++ b/plugin/src/Caelestia/appdb.cpp @@ -147,11 +147,11 @@ void AppDb::setPath(const QString& path) { updateAppFrequencies(); } -QList AppDb::entries() const { +QObjectList AppDb::entries() const { return m_entries; } -void AppDb::setEntries(const QList& entries) { +void AppDb::setEntries(const QObjectList& entries) { if (m_entries == entries) { return; } @@ -162,15 +162,8 @@ void AppDb::setEntries(const QList& entries) { m_timer->start(); } -QList AppDb::apps() const { - auto apps = m_apps.values(); - std::sort(apps.begin(), apps.end(), [](AppEntry* a, AppEntry* b) { - if (a->frequency() != b->frequency()) { - return a->frequency() > b->frequency(); - } - return a->name().localeAwareCompare(b->name()) < 0; - }); - return apps; +QQmlListProperty AppDb::apps() { + return QQmlListProperty(this, &getSortedApps()); } void AppDb::incrementFrequency(const QString& id) { @@ -183,21 +176,29 @@ void AppDb::incrementFrequency(const QString& id) { query.bindValue(":id", id); query.exec(); - for (auto* app : std::as_const(m_apps)) { - if (app->id() == id) { - const auto before = apps(); - - app->incrementFrequency(); + auto* app = m_apps.value(id); + if (app) { + const auto before = getSortedApps(); - if (before != apps()) { - emit appsChanged(); - } + app->incrementFrequency(); - return; + if (before != getSortedApps()) { + emit appsChanged(); } + } else { + qWarning() << "AppDb::incrementFrequency: could not find app with id" << id; } +} - qWarning() << "AppDb::incrementFrequency: could not find app with id" << id; +QList& AppDb::getSortedApps() const { + m_sortedApps = m_apps.values(); + std::sort(m_sortedApps.begin(), m_sortedApps.end(), [](AppEntry* a, AppEntry* b) { + if (a->frequency() != b->frequency()) { + return a->frequency() > b->frequency(); + } + return a->name().localeAwareCompare(b->name()) < 0; + }); + return m_sortedApps; } quint32 AppDb::getFrequency(const QString& id) const { @@ -215,9 +216,15 @@ quint32 AppDb::getFrequency(const QString& id) const { } void AppDb::updateAppFrequencies() { + const auto before = getSortedApps(); + for (auto* app : std::as_const(m_apps)) { app->setFrequency(getFrequency(app->id())); } + + if (before != getSortedApps()) { + emit appsChanged(); + } } void AppDb::updateApps() { diff --git a/plugin/src/Caelestia/appdb.hpp b/plugin/src/Caelestia/appdb.hpp index bb1a3f1..5f9b960 100644 --- a/plugin/src/Caelestia/appdb.hpp +++ b/plugin/src/Caelestia/appdb.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include namespace caelestia { @@ -64,8 +65,8 @@ class AppDb : public QObject { Q_PROPERTY(QString uuid READ uuid CONSTANT) Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged REQUIRED) - Q_PROPERTY(QList entries READ entries WRITE setEntries NOTIFY entriesChanged REQUIRED) - Q_PROPERTY(QList apps READ apps NOTIFY appsChanged) + Q_PROPERTY(QObjectList entries READ entries WRITE setEntries NOTIFY entriesChanged REQUIRED) + Q_PROPERTY(QQmlListProperty apps READ apps NOTIFY appsChanged) public: explicit AppDb(QObject* parent = nullptr); @@ -75,10 +76,10 @@ public: [[nodiscard]] QString path() const; void setPath(const QString& path); - [[nodiscard]] QList entries() const; - void setEntries(const QList& entries); + [[nodiscard]] QObjectList entries() const; + void setEntries(const QObjectList& entries); - [[nodiscard]] QList apps() const; + [[nodiscard]] QQmlListProperty apps(); Q_INVOKABLE void incrementFrequency(const QString& id); @@ -92,9 +93,11 @@ private: const QString m_uuid; QString m_path; - QList m_entries; + QObjectList m_entries; QHash m_apps; + mutable QList m_sortedApps; + QList& getSortedApps() const; quint32 getFrequency(const QString& id) const; void updateAppFrequencies(); void updateApps(); diff --git a/plugin/src/Caelestia/toaster.cpp b/plugin/src/Caelestia/toaster.cpp index 4e2acd5..978805d 100644 --- a/plugin/src/Caelestia/toaster.cpp +++ b/plugin/src/Caelestia/toaster.cpp @@ -97,8 +97,8 @@ void Toast::unlock(QObject* sender) { Toaster::Toaster(QObject* parent) : QObject(parent) {} -QList Toaster::toasts() const { - return m_toasts; +QQmlListProperty Toaster::toasts() { + return QQmlListProperty(this, &m_toasts); } void Toaster::toast(const QString& title, const QString& message, const QString& icon, Toast::Type type, int timeout) { diff --git a/plugin/src/Caelestia/toaster.hpp b/plugin/src/Caelestia/toaster.hpp index 0197aa1..1f61734 100644 --- a/plugin/src/Caelestia/toaster.hpp +++ b/plugin/src/Caelestia/toaster.hpp @@ -2,6 +2,7 @@ #include #include +#include #include namespace caelestia { @@ -61,12 +62,12 @@ class Toaster : public QObject { QML_ELEMENT QML_SINGLETON - Q_PROPERTY(QList toasts READ toasts NOTIFY toastsChanged) + Q_PROPERTY(QQmlListProperty toasts READ toasts NOTIFY toastsChanged) public: explicit Toaster(QObject* parent = nullptr); - [[nodiscard]] QList toasts() const; + [[nodiscard]] QQmlListProperty toasts(); Q_INVOKABLE void toast(const QString& title, const QString& message, const QString& icon = QString(), caelestia::Toast::Type type = Toast::Type::Info, int timeout = 5000); -- cgit v1.2.3-freya