summaryrefslogtreecommitdiffstats
path: root/collectionwidgetproxy.cpp
blob: b3427b2f96bba9af896af753debdfc8ba7f84ab6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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());
}