summaryrefslogtreecommitdiffstats
path: root/beetplayerproxy.cpp
diff options
context:
space:
mode:
authorArno <arno@disconnect.de>2017-02-25 18:45:49 +0100
committerArno <arno@disconnect.de>2017-02-25 18:45:49 +0100
commita169ca87cbe7b3ebe6f9ef24335f65ca64791116 (patch)
treeda37dd590ac329bb36229702017cd76daf4b12a3 /beetplayerproxy.cpp
parentffa50a24296688d1c6e9f4de2315bbd494f86cf6 (diff)
downloadBeetPlayer-a169ca87cbe7b3ebe6f9ef24335f65ca64791116.tar.gz
BeetPlayer-a169ca87cbe7b3ebe6f9ef24335f65ca64791116.tar.bz2
BeetPlayer-a169ca87cbe7b3ebe6f9ef24335f65ca64791116.zip
Implement filtering
Well, as it turns out, QSortFilterProxyModel isn't the weapon of choice for this. Implement it by creating a separate model which is populated by SQL-Queries.
Diffstat (limited to 'beetplayerproxy.cpp')
-rw-r--r--beetplayerproxy.cpp43
1 files changed, 40 insertions, 3 deletions
diff --git a/beetplayerproxy.cpp b/beetplayerproxy.cpp
index 115bd3a..574713f 100644
--- a/beetplayerproxy.cpp
+++ b/beetplayerproxy.cpp
@@ -7,13 +7,50 @@ BeetPlayerProxy::BeetPlayerProxy(QObject *parent) : QSortFilterProxyModel(parent
}
bool BeetPlayerProxy::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const{
+ if(filterRegExp().isEmpty()){
+ return true;
+ }
QRegExp filter = filterRegExp();
QModelIndex curIdx = sourceModel()->index(source_row, 0, source_parent);
- while(curIdx.isValid()){
- if(curIdx.data().toString().contains(filter)){
+ return recurseChildren(curIdx);
+}
+
+bool BeetPlayerProxy::recurseChildren(QModelIndex parent) const{
+ static bool retval = false;
+ if(parent.data().toString().contains(filterRegExp())){
+ qDebug() << "found:" << parent.data();
+ retval = true;
+ }else{
+ retval = false;
+ }
+ for(int i = 0; i < sourceModel()->rowCount(parent); ++i){
+ QModelIndex cur = sourceModel()->index(i, 0, parent);
+ //qDebug() << cur.data();
+ if(cur.data().toString().contains(filterRegExp())){
+ retval = true;
+ }
+ if(sourceModel()->hasChildren(cur)){
+ recurseChildren(cur);
+ }
+ }
+ return retval;
+}
+
+bool BeetPlayerProxy::hasValidChild(QModelIndex parent) const{
+ QModelIndex curIdx = parent;
+ if(curIdx.isValid()){
+ if(curIdx.data().toString().contains(filterRegExp())){
+ qDebug() << "found:" << curIdx.data();
return true;
}
- curIdx = curIdx.parent();
+ qDebug() << parent.data() << sourceModel()->rowCount(curIdx);
+ for(int i = 0; i < sourceModel()->rowCount(curIdx); ++i){
+ curIdx = sourceModel()->index(i, 0, curIdx);
+ //qDebug() << "in for:" << curIdx.data() << i;
+ if(sourceModel()->hasChildren(curIdx)){
+ hasValidChild(curIdx);
+ }
+ }
}
return false;
}