diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-10-14 16:00:17 +1100 |
|---|---|---|
| committer | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-10-14 16:00:17 +1100 |
| commit | 27953a89d1110d6cc82ff198e1c28f698104d554 (patch) | |
| tree | 69b302d1f8c0150c9a61e57dad9b0dd80ff11e48 /plugin/src/Caelestia | |
| parent | toasts: add toast for kb layout change (diff) | |
| download | caelestia-shell-27953a89d1110d6cc82ff198e1c28f698104d554.tar.gz caelestia-shell-27953a89d1110d6cc82ff198e1c28f698104d554.tar.bz2 caelestia-shell-27953a89d1110d6cc82ff198e1c28f698104d554.zip | |
internal: use QQmlListProperty
Fix lsp errors
Diffstat (limited to 'plugin/src/Caelestia')
| -rw-r--r-- | plugin/src/Caelestia/Internal/hyprdevices.cpp | 4 | ||||
| -rw-r--r-- | plugin/src/Caelestia/Internal/hyprdevices.hpp | 6 | ||||
| -rw-r--r-- | plugin/src/Caelestia/Internal/hyprextras.hpp | 2 | ||||
| -rw-r--r-- | plugin/src/Caelestia/Models/filesystemmodel.cpp | 4 | ||||
| -rw-r--r-- | plugin/src/Caelestia/Models/filesystemmodel.hpp | 5 | ||||
| -rw-r--r-- | plugin/src/Caelestia/appdb.cpp | 49 | ||||
| -rw-r--r-- | plugin/src/Caelestia/appdb.hpp | 15 | ||||
| -rw-r--r-- | plugin/src/Caelestia/toaster.cpp | 4 | ||||
| -rw-r--r-- | plugin/src/Caelestia/toaster.hpp | 5 |
9 files changed, 54 insertions, 40 deletions
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<HyprKeyboard*> HyprDevices::keyboards() const { - return m_keyboards; +QQmlListProperty<HyprKeyboard> HyprDevices::keyboards() { + return QQmlListProperty<HyprKeyboard>(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 <qjsonobject.h> #include <qobject.h> #include <qqmlintegration.h> +#include <qqmllist.h> 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<HyprKeyboard*> keyboards READ keyboards NOTIFY keyboardsChanged) + Q_PROPERTY( + QQmlListProperty<caelestia::internal::hypr::HyprKeyboard> keyboards READ keyboards NOTIFY keyboardsChanged) public: explicit HyprDevices(QObject* parent = nullptr); - [[nodiscard]] QList<HyprKeyboard*> keyboards() const; + [[nodiscard]] QQmlListProperty<HyprKeyboard> 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<FileSystemEntry*> FileSystemModel::entries() const { - return m_entries; +QQmlListProperty<FileSystemEntry> FileSystemModel::entries() { + return QQmlListProperty<FileSystemEntry>(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 <qmimedatabase.h> #include <qobject.h> #include <qqmlintegration.h> +#include <qqmllist.h> 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<FileSystemEntry*> entries READ entries NOTIFY entriesChanged) + Q_PROPERTY(QQmlListProperty<caelestia::models::FileSystemEntry> entries READ entries NOTIFY entriesChanged) public: enum Filter { @@ -109,7 +110,7 @@ public: [[nodiscard]] QStringList nameFilters() const; void setNameFilters(const QStringList& nameFilters); - [[nodiscard]] QList<FileSystemEntry*> entries() const; + [[nodiscard]] QQmlListProperty<FileSystemEntry> 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<QObject*> AppDb::entries() const { +QObjectList AppDb::entries() const { return m_entries; } -void AppDb::setEntries(const QList<QObject*>& entries) { +void AppDb::setEntries(const QObjectList& entries) { if (m_entries == entries) { return; } @@ -162,15 +162,8 @@ void AppDb::setEntries(const QList<QObject*>& entries) { m_timer->start(); } -QList<AppEntry*> 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<AppEntry> AppDb::apps() { + return QQmlListProperty<AppEntry>(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<AppEntry*>& 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 <qhash.h> #include <qobject.h> #include <qqmlintegration.h> +#include <qqmllist.h> #include <qtimer.h> 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<QObject*> entries READ entries WRITE setEntries NOTIFY entriesChanged REQUIRED) - Q_PROPERTY(QList<AppEntry*> apps READ apps NOTIFY appsChanged) + Q_PROPERTY(QObjectList entries READ entries WRITE setEntries NOTIFY entriesChanged REQUIRED) + Q_PROPERTY(QQmlListProperty<caelestia::AppEntry> 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<QObject*> entries() const; - void setEntries(const QList<QObject*>& entries); + [[nodiscard]] QObjectList entries() const; + void setEntries(const QObjectList& entries); - [[nodiscard]] QList<AppEntry*> apps() const; + [[nodiscard]] QQmlListProperty<AppEntry> apps(); Q_INVOKABLE void incrementFrequency(const QString& id); @@ -92,9 +93,11 @@ private: const QString m_uuid; QString m_path; - QList<QObject*> m_entries; + QObjectList m_entries; QHash<QString, AppEntry*> m_apps; + mutable QList<AppEntry*> m_sortedApps; + QList<AppEntry*>& 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<Toast*> Toaster::toasts() const { - return m_toasts; +QQmlListProperty<Toast> Toaster::toasts() { + return QQmlListProperty<Toast>(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 <qobject.h> #include <qqmlintegration.h> +#include <qqmllist.h> #include <qset.h> namespace caelestia { @@ -61,12 +62,12 @@ class Toaster : public QObject { QML_ELEMENT QML_SINGLETON - Q_PROPERTY(QList<Toast*> toasts READ toasts NOTIFY toastsChanged) + Q_PROPERTY(QQmlListProperty<caelestia::Toast> toasts READ toasts NOTIFY toastsChanged) public: explicit Toaster(QObject* parent = nullptr); - [[nodiscard]] QList<Toast*> toasts() const; + [[nodiscard]] QQmlListProperty<Toast> 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); |