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 <QObject>
27 #include <QSortFilterProxyModel>
28 #include <functional>
29 
30 class QTreeView;
31 
32 namespace armarx
33 {
34 
35  /**
36  * @brief This proxy model reimplements the filterAcceptsRow function with a new behavior:
37  * All elements that fit the filter string are shown alongside with all their parents as well as all their children.
38  * This means the full sub-tree which contains matching elements is shown.
39  *
40  */
42  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  protected:
58  bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override;
59  bool filterAcceptsRow(int source_row, const QModelIndex& source_parent, bool considerParents) const;
60  std::vector<FilterFunc> customFilters;
61  };
62 
63 }
64 
armarx::InfixFilterModel::FilterFunc
std::function< bool(QAbstractItemModel *, int, const QModelIndex &)> FilterFunc
Definition: InfixFilterModel.h:46
armarx::InfixFilterModel::addCustomFilter
void addCustomFilter(FilterFunc function)
Definition: InfixFilterModel.cpp:58
armarx::InfixFilterModel::ExpandFilterResults
static void ExpandFilterResults(QTreeView *treeView)
Expands the treeview that all items that match the filterstring are expanded and directly visible.
Definition: InfixFilterModel.cpp:63
armarx::InfixFilterModel::InfixFilterModel
InfixFilterModel(QObject *parent=0)
Definition: InfixFilterModel.cpp:32
armarx::InfixFilterModel
This proxy model reimplements the filterAcceptsRow function with a new behavior: All elements that fi...
Definition: InfixFilterModel.h:41
armarx::InfixFilterModel::filterAcceptsRow
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override
Definition: InfixFilterModel.cpp:109
armarx::InfixFilterModel::customFilters
std::vector< FilterFunc > customFilters
Definition: InfixFilterModel.h:60
armarx::InfixFilterModel::containsAll
static bool containsAll(const QString &text, const QStringList &searchParts)
Definition: InfixFilterModel.cpp:46
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28