summaryrefslogtreecommitdiffstats
path: root/collectionwidgetproxy.cpp
diff options
context:
space:
mode:
authorArno <arno@disconnect.de>2018-02-17 19:29:41 +0100
committerArno <arno@disconnect.de>2018-02-17 19:29:41 +0100
commit280c75090cb518f0f1a4e2b470a7722f95b9c9ab (patch)
tree466cb4a6ea3dedb02a944fa9378fa5fa0355a206 /collectionwidgetproxy.cpp
parentb49d5333119239cf32f873d25a3d46d788f9747e (diff)
downloadBeetPlayer-280c75090cb518f0f1a4e2b470a7722f95b9c9ab.tar.gz
BeetPlayer-280c75090cb518f0f1a4e2b470a7722f95b9c9ab.tar.bz2
BeetPlayer-280c75090cb518f0f1a4e2b470a7722f95b9c9ab.zip
Make filtering useful
Add a custom QSortFilterProxyModel which filterAcceptsRow() returns true if the uppermost parent matches the filter RegExp.
Diffstat (limited to 'collectionwidgetproxy.cpp')
-rw-r--r--collectionwidgetproxy.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/collectionwidgetproxy.cpp b/collectionwidgetproxy.cpp
new file mode 100644
index 0000000..b3427b2
--- /dev/null
+++ b/collectionwidgetproxy.cpp
@@ -0,0 +1,20 @@
+#include <QStandardItemModel>
+
+#include "collectionwidgetproxy.h"
+
+CollectionWidgetProxy::CollectionWidgetProxy(QObject *parent) : QSortFilterProxyModel(parent) {
+}
+
+bool CollectionWidgetProxy::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const {
+ const QStandardItemModel *srcM = qobject_cast<const QStandardItemModel*>(sourceModel());
+ QModelIndex rootIdx = srcM->invisibleRootItem()->index();
+ QModelIndex curIdx = srcM->index(source_row, 0, source_parent);
+ if(curIdx == rootIdx){
+ return true;
+ }
+ while(curIdx.parent() != rootIdx){
+ curIdx = curIdx.parent();
+ }
+ QString cur = curIdx.data().toString();
+ return cur.contains(filterRegExp());
+}