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
26#include <QLineEdit>
27#include <QMouseEvent>
28#include <QStandardItem>
29
31
32#include "InfixFilterModel.h"
33
34#define DEFAULT_FILTER_CONTENT "Click&type to filter"
36#define FILTER_HEIGHT 22
37
38FilterableTreeView::FilterableTreeView(QWidget* parent, bool hideChildren) :
39 QTreeView(parent), hideChildren(hideChildren)
40{
41 filterLineEdit = new QLineEdit(this);
42 filterLineEdit->setPlaceholderText(DefaultFilterStr);
43 filterLineEdit->resize(this->width(), FILTER_HEIGHT);
44 filterExpansionTimer.setSingleShot(true);
45 connect(&filterExpansionTimer, SIGNAL(timeout()), this, SLOT(delayedFilterExpansion()));
46 setStyleSheet("QTreeView{margin-top: " + QString::number(filterLineEdit->height()) + "px}");
47}
48
49void
50FilterableTreeView::resizeEvent(QResizeEvent* event)
51{
52 filterLineEdit->resize(event->size().width(), FILTER_HEIGHT);
53 QTreeView::resizeEvent(event);
54}
55
58{
59 return proxyModel;
60}
61
62void
63FilterableTreeView::setModel(QAbstractItemModel* model)
64{
65 proxyModel = new armarx::InfixFilterModel(this);
66 proxyModel->setSourceModel(model);
67 QTreeView::setModel(proxyModel);
68 // connect(filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(applyFilter(QString)));
69 connect(filterLineEdit,
70 SIGNAL(textChanged(QString)),
71 proxyModel,
72 SLOT(setFilterFixedString(QString)));
73 connect(filterLineEdit,
74 SIGNAL(textChanged(QString)),
75 this,
76 SLOT(expandFilterSelection(QString)),
77 Qt::QueuedConnection);
78}
79
80void
82{
83 //ARMARX_INFO_S << VAROUT(filterStr);
84 if (filterStr.length() == 0)
85 {
86 collapseAll();
87 // ui.monitoredManagersTree->expandToDepth(1);
88 }
89 else
90 {
91 filterExpansionTimer.start(500);
92 }
93}
94
95void
#define FILTER_HEIGHT
#define DEFAULT_FILTER_CONTENT
FilterableTreeView(QWidget *parent=0, bool hideChildren=true)
void setModel(QAbstractItemModel *model) override
static const QString DefaultFilterStr
void expandFilterSelection(QString filterStr)
armarx::InfixFilterModel * getProxyModel() const
This proxy model reimplements the filterAcceptsRow function with a new behavior: All elements that fi...
static void ExpandFilterResults(QTreeView *treeView)
Expands the treeview that all items that match the filterstring are expanded and directly visible.