internal: use QQmlListProperty
Fix lsp errors
This commit is contained in:
parent
73aa3e32de
commit
27953a89d1
9 changed files with 54 additions and 40 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
auto* app = m_apps.value(id);
|
||||
if (app) {
|
||||
const auto before = getSortedApps();
|
||||
|
||||
app->incrementFrequency();
|
||||
app->incrementFrequency();
|
||||
|
||||
if (before != apps()) {
|
||||
emit appsChanged();
|
||||
}
|
||||
|
||||
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() {
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue