summaryrefslogtreecommitdiffstats
path: root/mappingtreeproxy.cpp
blob: 6758f5582629a6c275f7513378d1c79ee76ffd78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License
  as published by the Free Software Foundation; either version
  2 of the License, or (at your option) any later version.
*/

#include "mappingtreeproxy.h"
#include "mappingtreemodel.h"

MappingTreeProxy::MappingTreeProxy(QObject *parent) : QSortFilterProxyModel(parent) {}

void MappingTreeProxy::setFilter(const QString &filter){
    if(!filter.isEmpty()){
        mFilter = QRegularExpression(filter);
    }else{
        mFilter = QRegularExpression();
    }
    invalidateFilter();
}

bool MappingTreeProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const{
    if(mFilter == QRegularExpression()){
        return true;
    }
    QModelIndex nameIdx = sourceModel()->index(sourceRow, MappingTreeModel::Name, sourceParent);
    MappingTreeModel *model = qobject_cast<MappingTreeModel*>(sourceModel());
    return model->matchRecursive(nameIdx, mFilter);
}