[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [elisa] src: bring back AlbumFilterProxyModel and uses it again to filter albums
From: Matthieu Gallien <matthieu_gallien () yahoo ! fr>
Date: 2016-12-06 22:10:58
Message-ID: E1cENww-00046P-7N () code ! kde ! org
[Download RAW message or body]
Git commit 8b38aee02a452cc9df8a1f20453ae18a28622a27 by Matthieu Gallien.
Committed on 06/12/2016 at 22:10.
Pushed by mgallien into branch 'master'.
bring back AlbumFilterProxyModel and uses it again to filter albums
M +1 -0 src/CMakeLists.txt
M +7 -4 src/MediaAllAlbumView.qml
A +73 -0 src/albumfilterproxymodel.cpp [License: LGPL (v3+)]
A +64 -0 src/albumfilterproxymodel.h [License: LGPL (v3+)]
M +2 -0 src/upnpControl.cpp
https://commits.kde.org/elisa/8b38aee02a452cc9df8a1f20453ae18a28622a27
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index fda00f7..114fd36 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -18,6 +18,7 @@ if (Qt5Quick_FOUND AND Qt5Widgets_FOUND)
managemediaplayercontrol.cpp
manageheaderbar.cpp
manageaudioplayer.cpp
+ albumfilterproxymodel.cpp
MediaServer.qml
diff --git a/src/MediaAllAlbumView.qml b/src/MediaAllAlbumView.qml
index fda3698..05a5086 100644
--- a/src/MediaAllAlbumView.qml
+++ b/src/MediaAllAlbumView.qml
@@ -108,11 +108,14 @@ Item {
model: DelegateModel {
id: delegateContentModel
- model: AllAlbumsModel {
- id: contentDirectoryModel
+ model: AlbumFilterProxyModel {
+ sourceModel: AllAlbumsModel {
+ id: contentDirectoryModel
- databaseInterface: rootElement.musicDatabase
- artist: filterTextInput.text
+ databaseInterface: rootElement.musicDatabase
+ }
+
+ filterText: filterTextInput.text
}
delegate: MediaAlbumDelegate {
diff --git a/src/albumfilterproxymodel.cpp b/src/albumfilterproxymodel.cpp
new file mode 100644
index 0000000..f302e9e
--- /dev/null
+++ b/src/albumfilterproxymodel.cpp
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2016 Matthieu Gallien <matthieu_gallien@yahoo.fr>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "albumfilterproxymodel.h"
+
+#include "allalbumsmodel.h"
+
+AlbumFilterProxyModel::AlbumFilterProxyModel(QObject *parent) : \
QSortFilterProxyModel(parent), mFilterText() +{
+ setFilterCaseSensitivity(Qt::CaseInsensitive);
+}
+
+AlbumFilterProxyModel::~AlbumFilterProxyModel()
+{
+}
+
+QString AlbumFilterProxyModel::filterText() const
+{
+ return mFilterText;
+}
+
+void AlbumFilterProxyModel::setFilterText(QString filterText)
+{
+ if (mFilterText == filterText)
+ return;
+
+ mFilterText = filterText;
+
+ mFilterExpression.setPattern(mFilterText);
+ mFilterExpression.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
+ mFilterExpression.optimize();
+
+ invalidate();
+
+ Q_EMIT filterTextChanged(mFilterText);
+}
+
+bool AlbumFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex \
&source_parent) const +{
+ bool result = true;
+
+ for (int column = 0, columnCount = sourceModel()->columnCount(source_parent); \
result && column < columnCount; ++column) { + auto currentIndex = \
sourceModel()->index(source_row, column, source_parent); +
+ const auto &titleValue = sourceModel()->data(currentIndex, \
AllAlbumsModel::TitleRole).toString(); + const auto &artistValue = \
sourceModel()->data(currentIndex, AllAlbumsModel::ArtistRole).toString(); +
+ if (!mFilterExpression.match(titleValue).hasMatch() && \
!mFilterExpression.match(artistValue).hasMatch()) { + result = false;
+ }
+ }
+
+ return result;
+}
+
+
+#include "moc_albumfilterproxymodel.cpp"
diff --git a/src/albumfilterproxymodel.h b/src/albumfilterproxymodel.h
new file mode 100644
index 0000000..6ba742b
--- /dev/null
+++ b/src/albumfilterproxymodel.h
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2016 Matthieu Gallien <matthieu_gallien@yahoo.fr>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef ALBUMFILTERPROXYMODEL_H
+#define ALBUMFILTERPROXYMODEL_H
+
+#include <QtCore/QSortFilterProxyModel>
+#include <QtCore/QRegularExpression>
+
+class AlbumFilterProxyModel : public QSortFilterProxyModel
+{
+
+ Q_OBJECT
+
+ Q_PROPERTY(QString filterText
+ READ filterText
+ WRITE setFilterText
+ NOTIFY filterTextChanged)
+
+public:
+
+ explicit AlbumFilterProxyModel(QObject *parent = 0);
+
+ virtual ~AlbumFilterProxyModel();
+
+ QString filterText() const;
+
+public Q_SLOTS:
+
+ void setFilterText(QString filterText);
+
+Q_SIGNALS:
+
+ void filterTextChanged(QString filterText);
+
+protected:
+
+ bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const \
override; +
+private:
+
+ QString mFilterText;
+
+ QRegularExpression mFilterExpression;
+
+};
+
+#endif // ALBUMFILTERPROXYMODEL_H
diff --git a/src/upnpControl.cpp b/src/upnpControl.cpp
index 737eb03..219371a 100644
--- a/src/upnpControl.cpp
+++ b/src/upnpControl.cpp
@@ -50,6 +50,7 @@
#include "allartistsmodel.h"
#include "musicaudiotrack.h"
#include "musiclistenersmanager.h"
+#include "albumfilterproxymodel.h"
#if defined Qt5DBus_FOUND && Qt5DBus_FOUND
#include "mpris2/mpris2.h"
@@ -123,6 +124,7 @@ int __attribute__((visibility("default"))) main(int argc, char \
*argv[])
qmlRegisterType<AlbumModel>("org.mgallien.QmlExtension", 1, 0, "AlbumModel");
qmlRegisterType<MusicListenersManager>("org.mgallien.QmlExtension", 1, 0, \
"MusicListenersManager");
qmlRegisterType<QSortFilterProxyModel>("org.mgallien.QmlExtension", 1, 0, \
"SortFilterProxyModel"); + \
qmlRegisterType<AlbumFilterProxyModel>("org.mgallien.QmlExtension", 1, 0, \
"AlbumFilterProxyModel");
#if defined Qt5DBus_FOUND && Qt5DBus_FOUND
qmlRegisterType<Mpris2>("org.mgallien.QmlExtension", 1, 0, "Mpris2");
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic