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/appdb.cpp | |
| 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/appdb.cpp')
| -rw-r--r-- | plugin/src/Caelestia/appdb.cpp | 49 |
1 files changed, 28 insertions, 21 deletions
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() { |