From 57ffdc3ff02172c3b2cf5ccce8a0accad45b8046 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Fri, 17 Feb 2023 10:09:41 -0600 Subject: [PATCH] adding proxy models and search to all sql models --- src/cpp/imagesqlmodel.cpp | 12 ++++++++++++ src/cpp/imagesqlmodel.h | 12 ++++++++++++ src/cpp/presentationsqlmodel.cpp | 11 +++++++++++ src/cpp/presentationsqlmodel.h | 11 +++++++++++ src/cpp/videosqlmodel.cpp | 12 ++++++++++++ src/cpp/videosqlmodel.h | 11 +++++++++++ src/main.cpp | 6 +++--- src/qml/presenter/Library.qml | 6 +++--- 8 files changed, 75 insertions(+), 6 deletions(-) diff --git a/src/cpp/imagesqlmodel.cpp b/src/cpp/imagesqlmodel.cpp index 4bce13f..3f6e0b4 100644 --- a/src/cpp/imagesqlmodel.cpp +++ b/src/cpp/imagesqlmodel.cpp @@ -202,3 +202,15 @@ QVariantMap ImageSqlModel::getImage(const int &row) { } return data; } + +// ImageProxyModel + +ImageProxyModel::ImageProxyModel(QObject *parent) + :QSortFilterProxyModel(parent) +{ + ImageSqlModel *imageModel = new ImageSqlModel; + setSourceModel(imageModel); + setDynamicSortFilter(true); + setFilterRole(Qt::UserRole + 1); + setFilterCaseSensitivity(Qt::CaseInsensitive); +} diff --git a/src/cpp/imagesqlmodel.h b/src/cpp/imagesqlmodel.h index 2b9893a..82f9ee7 100644 --- a/src/cpp/imagesqlmodel.h +++ b/src/cpp/imagesqlmodel.h @@ -2,6 +2,7 @@ #define IMAGESQLMODEL_H #include +#include #include #include #include @@ -46,4 +47,15 @@ private: QUrl m_filePath; }; +class ImageProxyModel : public QSortFilterProxyModel +{ + Q_OBJECT + +public: + explicit ImageProxyModel(QObject *parent = nullptr); + + +}; + + #endif //IMAGESQLMODEL_H diff --git a/src/cpp/presentationsqlmodel.cpp b/src/cpp/presentationsqlmodel.cpp index bf41fa3..f2e3424 100644 --- a/src/cpp/presentationsqlmodel.cpp +++ b/src/cpp/presentationsqlmodel.cpp @@ -238,3 +238,14 @@ QVariantMap PresentationSqlModel::getPresentation(const int &row) { } return data; } +// PresentationProxyModel + +PresentationProxyModel::PresentationProxyModel(QObject *parent) + :QSortFilterProxyModel(parent) +{ + PresentationSqlModel *presentationModel = new PresentationSqlModel; + setSourceModel(presentationModel); + setDynamicSortFilter(true); + setFilterRole(Qt::UserRole + 1); + setFilterCaseSensitivity(Qt::CaseInsensitive); +} diff --git a/src/cpp/presentationsqlmodel.h b/src/cpp/presentationsqlmodel.h index 06e297a..cdbdced 100644 --- a/src/cpp/presentationsqlmodel.h +++ b/src/cpp/presentationsqlmodel.h @@ -2,6 +2,7 @@ #define PRESENTATIONSQLMODEL_H #include +#include #include #include #include @@ -52,4 +53,14 @@ private: int m_pageCount; }; +class PresentationProxyModel : public QSortFilterProxyModel +{ + Q_OBJECT + +public: + explicit PresentationProxyModel(QObject *parent = nullptr); + + +}; + #endif //PRESENTATIONSQLMODEL_H diff --git a/src/cpp/videosqlmodel.cpp b/src/cpp/videosqlmodel.cpp index 532ada4..5293c4a 100644 --- a/src/cpp/videosqlmodel.cpp +++ b/src/cpp/videosqlmodel.cpp @@ -314,3 +314,15 @@ QVariantMap VideoSqlModel::getVideo(const int &row) { return data; } + +// VideoProxyModel + +VideoProxyModel::VideoProxyModel(QObject *parent) + :QSortFilterProxyModel(parent) +{ + VideoSqlModel *videoModel = new VideoSqlModel; + setSourceModel(videoModel); + setDynamicSortFilter(true); + setFilterRole(Qt::UserRole + 1); + setFilterCaseSensitivity(Qt::CaseInsensitive); +} diff --git a/src/cpp/videosqlmodel.h b/src/cpp/videosqlmodel.h index edf1c1e..e0e49fe 100644 --- a/src/cpp/videosqlmodel.h +++ b/src/cpp/videosqlmodel.h @@ -2,6 +2,7 @@ #define VIDEOSQLMODEL_H #include +#include #include #include #include @@ -64,4 +65,14 @@ private: bool m_loop; }; +class VideoProxyModel : public QSortFilterProxyModel +{ + Q_OBJECT + +public: + explicit VideoProxyModel(QObject *parent = nullptr); + + +}; + #endif //VIDEOSQLMODEL_H diff --git a/src/main.cpp b/src/main.cpp index 86b30cc..bccc6f7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -173,9 +173,9 @@ int main(int argc, char *argv[]) //register our models qmlRegisterType("org.presenter", 1, 0, "SongSqlModel"); - qmlRegisterType("org.presenter", 1, 0, "VideoSqlModel"); - qmlRegisterType("org.presenter", 1, 0, "ImageSqlModel"); - qmlRegisterType("org.presenter", 1, 0, "PresentationSqlModel"); + qmlRegisterType("org.presenter", 1, 0, "VideoSqlModel"); + qmlRegisterType("org.presenter", 1, 0, "ImageSqlModel"); + qmlRegisterType("org.presenter", 1, 0, "PresentationSqlModel"); qmlRegisterType("org.presenter", 1, 0, "FileHelper"); qmlRegisterType("org.presenter", 1, 0, "ServiceThing"); qmlRegisterSingletonInstance("org.presenter", 1, 0, diff --git a/src/qml/presenter/Library.qml b/src/qml/presenter/Library.qml index 466dab5..51c9577 100644 --- a/src/qml/presenter/Library.qml +++ b/src/qml/presenter/Library.qml @@ -429,7 +429,7 @@ Item { id: searchField height: parent.height width: parent.width - 40 - onAccepted: showPassiveNotification(searchField.text, 3000) + onAccepted: videosqlmodel.setFilterRegExp(searchField.text) } } /* visible: selectedLibrary == "videos" */ @@ -712,7 +712,7 @@ Item { id: searchField height: parent.height width: parent.width - 40 - onAccepted: showPassiveNotification(searchField.text, 3000) + onAccepted: imagesqlmodel.setFilterRegExp(searchField.text) } } /* visible: selectedLibrary == "images" */ @@ -994,7 +994,7 @@ Item { id: searchField height: parent.height width: parent.width - 40 - onAccepted: showPassiveNotification(searchField.text, 3000) + onAccepted: pressqlmodel.setFilterRegExp(searchField.text) } } /* visible: selectedLibrary == "presentations" */