InfixFilterModel.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package ArmarX
19 * @author Mirko Waechter( mirko.waechter at kit dot edu)
20 * @date 2016
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24#pragma once
25
26#include <functional>
27
28#include <QObject>
29#include <QSortFilterProxyModel>
30
31class QTreeView;
32
33namespace armarx
34{
35
36 /**
37 * @brief This proxy model reimplements the filterAcceptsRow function with a new behavior:
38 * All elements that fit the filter string are shown alongside with all their parents as well as all their children.
39 * This means the full sub-tree which contains matching elements is shown.
40 *
41 */
42 class InfixFilterModel : public QSortFilterProxyModel
43 {
44 Q_OBJECT
45 public:
46 using FilterFunc = std::function<bool(QAbstractItemModel*, int, const QModelIndex&)>;
47 InfixFilterModel(QObject* parent = 0);
48 // QSortFilterProxyModel interface
49 /**
50 * @brief Expands the treeview that all items that match the filterstring are expanded and directly visible.
51 * Anything else is collapsed.
52 * @param treeView
53 */
54 static void ExpandFilterResults(QTreeView* treeView);
55 static bool containsAll(const QString& text, const QStringList& searchParts);
56 void addCustomFilter(FilterFunc function);
57
58 protected:
59 bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override;
60 bool filterAcceptsRow(int source_row,
61 const QModelIndex& source_parent,
62 bool considerParents) const;
63 std::vector<FilterFunc> customFilters;
64 };
65
66} // namespace armarx
void addCustomFilter(FilterFunc function)
std::function< bool(QAbstractItemModel *, int, const QModelIndex &)> FilterFunc
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override
std::vector< FilterFunc > customFilters
InfixFilterModel(QObject *parent=0)
static void ExpandFilterResults(QTreeView *treeView)
Expands the treeview that all items that match the filterstring are expanded and directly visible.
static bool containsAll(const QString &text, const QStringList &searchParts)
This file offers overloads of toIce() and fromIce() functions for STL container types.