FilterableTreeView.cpp
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
19  * @author
20  * @date
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 #include "FilterableTreeView.h"
25 #include "InfixFilterModel.h"
26 
27 #include <QLineEdit>
28 #include <QMouseEvent>
29 #include <QStandardItem>
30 
32 
33 #define DEFAULT_FILTER_CONTENT "Click&type to filter"
35 #define FILTER_HEIGHT 22
36 FilterableTreeView::FilterableTreeView(QWidget* parent, bool hideChildren) :
37  QTreeView(parent),
38  hideChildren(hideChildren)
39 {
40  filterLineEdit = new QLineEdit(this);
41  filterLineEdit->setPlaceholderText(DefaultFilterStr);
42  filterLineEdit->resize(this->width(), FILTER_HEIGHT);
43  filterExpansionTimer.setSingleShot(true);
44  connect(&filterExpansionTimer, SIGNAL(timeout()), this, SLOT(delayedFilterExpansion()));
45  setStyleSheet("QTreeView{margin-top: " + QString::number(filterLineEdit->height()) + "px}");
46 
47 }
48 
49 void FilterableTreeView::resizeEvent(QResizeEvent* event)
50 {
51  filterLineEdit->resize(event->size().width(), FILTER_HEIGHT);
52  QTreeView::resizeEvent(event);
53 }
54 
56 {
57  return proxyModel;
58 }
59 
60 void FilterableTreeView::setModel(QAbstractItemModel* model)
61 {
62  proxyModel = new armarx::InfixFilterModel(this);
63  proxyModel->setSourceModel(model);
64  QTreeView::setModel(proxyModel);
65  // connect(filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(applyFilter(QString)));
66  connect(filterLineEdit, SIGNAL(textChanged(QString)), proxyModel, SLOT(setFilterFixedString(QString)));
67  connect(filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(expandFilterSelection(QString)), Qt::QueuedConnection);
68 
69 
70 }
71 
73 {
74  //ARMARX_INFO_S << VAROUT(filterStr);
75  if (filterStr.length() == 0)
76  {
77  collapseAll();
78  // ui.monitoredManagersTree->expandToDepth(1);
79  }
80  else
81  {
82  filterExpansionTimer.start(500);
83  }
84 }
85 
87 {
89 }
FILTER_HEIGHT
#define FILTER_HEIGHT
Definition: FilterableTreeView.cpp:35
FilterableTreeView::delayedFilterExpansion
void delayedFilterExpansion()
Definition: FilterableTreeView.cpp:86
FilterableTreeView.h
InfixFilterModel.h
FilterableTreeView::FilterableTreeView
FilterableTreeView(QWidget *parent=0, bool hideChildren=true)
Definition: FilterableTreeView.cpp:36
FilterableTreeView::setModel
void setModel(QAbstractItemModel *model) override
Definition: FilterableTreeView.cpp:60
FilterableTreeView::DefaultFilterStr
static const QString DefaultFilterStr
Definition: FilterableTreeView.h:48
FilterableTreeView::expandFilterSelection
void expandFilterSelection(QString filterStr)
Definition: FilterableTreeView.cpp:72
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
DEFAULT_FILTER_CONTENT
#define DEFAULT_FILTER_CONTENT
Definition: FilterableTreeView.cpp:33
armarx::InfixFilterModel
This proxy model reimplements the filterAcceptsRow function with a new behavior: All elements that fi...
Definition: InfixFilterModel.h:41
Exception.h
FilterableTreeView::getProxyModel
armarx::InfixFilterModel * getProxyModel() const
Definition: FilterableTreeView.cpp:55