diff options
author | Arno <arno@disconnect.de> | 2018-02-17 19:29:41 +0100 |
---|---|---|
committer | Arno <arno@disconnect.de> | 2018-02-17 19:29:41 +0100 |
commit | 280c75090cb518f0f1a4e2b470a7722f95b9c9ab (patch) | |
tree | 466cb4a6ea3dedb02a944fa9378fa5fa0355a206 /collectionwidgetproxy.cpp | |
parent | b49d5333119239cf32f873d25a3d46d788f9747e (diff) | |
download | BeetPlayer-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.cpp | 20 |
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()); +} |