diff options
Diffstat (limited to 'mappingtreeproxy.cpp')
-rw-r--r-- | mappingtreeproxy.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/mappingtreeproxy.cpp b/mappingtreeproxy.cpp new file mode 100644 index 0000000..077d72a --- /dev/null +++ b/mappingtreeproxy.cpp @@ -0,0 +1,25 @@ +/* + 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){ + mFilter = QRegExp(filter); + invalidateFilter(); +} + +bool MappingTreeProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const{ + if(mFilter.isEmpty()){ + return true; + } + QModelIndex nameIdx = sourceModel()->index(sourceRow, MappingTreeModel::Name, sourceParent); + MappingTreeModel *model = qobject_cast<MappingTreeModel*>(sourceModel()); + return model->matchRecursive(nameIdx, mFilter); +} |