From 13c8704bdcf99946f1be78454d584634e939e844 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Fri, 17 Feb 2023 09:38:20 -0600 Subject: [PATCH] adding a proxyModel --- src/cpp/songsqlmodel.cpp | 11 +++++++++++ src/cpp/songsqlmodel.h | 12 ++++++++++++ src/main.cpp | 2 +- src/qml/presenter/Library.qml | 2 +- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/cpp/songsqlmodel.cpp b/src/cpp/songsqlmodel.cpp index ceaaf07..3c3bc9e 100644 --- a/src/cpp/songsqlmodel.cpp +++ b/src/cpp/songsqlmodel.cpp @@ -709,3 +709,14 @@ void SongSqlModel::updateFontSize(const int &row, const int &fontSize) { submitAll(); emit fontSizeChanged(); } +// SongProxyModel + +SongProxyModel::SongProxyModel(QObject *parent) + :QSortFilterProxyModel(parent) +{ + SongSqlModel songModel = new SongSqlModel; + setSourceModel(songModel); + setDynamicSortFilter(true); + setFilterRole(Qt::UserRole + 1); + setFilterCaseSensitivity(Qt::CaseInsensitive); +} diff --git a/src/cpp/songsqlmodel.h b/src/cpp/songsqlmodel.h index 9c09252..c2997c3 100644 --- a/src/cpp/songsqlmodel.h +++ b/src/cpp/songsqlmodel.h @@ -2,6 +2,7 @@ #define SONGSQLMODEL_H #include +#include #include #include #include @@ -107,4 +108,15 @@ private: int m_fontSize; }; +class SongProxyModel : public QSortFilterProxyModel +{ + Q_OBJECT + +public: + explicit SongProxyModel(QObject *parent = nullptr); + + +}; + + #endif //SONGSQLMODEL_H diff --git a/src/main.cpp b/src/main.cpp index 8b28a59..86b30cc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -172,7 +172,7 @@ int main(int argc, char *argv[]) qmlRegisterType("mpv", 1, 0, "MpvObject"); //register our models - qmlRegisterType("org.presenter", 1, 0, "SongSqlModel"); + qmlRegisterType("org.presenter", 1, 0, "SongSqlModel"); qmlRegisterType("org.presenter", 1, 0, "VideoSqlModel"); qmlRegisterType("org.presenter", 1, 0, "ImageSqlModel"); qmlRegisterType("org.presenter", 1, 0, "PresentationSqlModel"); diff --git a/src/qml/presenter/Library.qml b/src/qml/presenter/Library.qml index 8db5154..466dab5 100644 --- a/src/qml/presenter/Library.qml +++ b/src/qml/presenter/Library.qml @@ -125,7 +125,7 @@ Item { id: searchField height: parent.height width: parent.width - 40 - onAccepted: showPassiveNotification(searchField.text, 3000) + onAccepted: songsqlmodel.setFilterRegExp(searchField.text) } } /* visible: selectedLibrary == "songs" */