ObjectExplorerWidget.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2012-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 MemoryX::gui-plugins::SceneEditor
19 * @date 2015
20 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
21 * GNU General Public License
22 */
23
24/* Qt headers */
25#include <QIcon>
26#include <QImage>
27#include <QLabel>
28#include <QPixmap>
29#include <QString>
30#include <QTreeView>
31
32/* C++ headers */
33#include <iostream>
34
35#include "ClearableLineEdit.h"
37#include "OverrideAction.h"
38#include <MemoryX/gui-plugins/SceneEditor/ui_ObjectExplorerWidget.h>
39
41 QWidget* parent) :
42 QWidget(parent),
43 ui(new Ui::ObjectExplorerWidget),
45 sourceModel(new ObjectExplorerModel(control, this))
46{
47 ui->setupUi(this);
48
49 ui->objectExplorerTreeView->setModel(sourceModel);
50
51 std::shared_ptr<gui::ShortcutController> shortcutController = control->getShortcutController();
52 QPointer<QAction> searchAction(
53 new OverrideAction("Object Explorer: Set Focus on Search Field", this));
54 this->addAction(searchAction);
55 shortcutController->registerAction(searchAction->text(), searchAction);
56
57 setMinimumWidth(200);
58
59 connect(searchAction, SIGNAL(triggered()), ui->filterObjectClassesLineEdit, SLOT(setFocus()));
60 connect(ui->filterObjectClassesLineEdit,
61 SIGNAL(textChanged(QString)),
62 this,
63 SLOT(filterFixedString()));
64 connect(ui->objectExplorerTreeView,
65 SIGNAL(clicked(QModelIndex)),
66 this,
67 SLOT(getSelectedObject(QModelIndex)));
68}
69
70void
71gui::ObjectExplorerWidget::filterFixedString()
72{
73 QString searchPattern(ui->filterObjectClassesLineEdit->text());
74 sourceModel->setFilterFixedString(searchPattern);
75
76 if (searchPattern.isEmpty())
77 {
78 ui->objectExplorerTreeView->collapseAll();
79 }
80 else
81 {
82 ui->objectExplorerTreeView->expandAll();
83 }
84}
85
86void
87gui::ObjectExplorerWidget::getSelectedObject(const QModelIndex& index)
88{
89 std::pair<std::string, std::string> object = sourceModel->getItemInformation(index);
90
91 if (!object.first.empty() && !object.second.empty())
92 {
93 if (controller::ControllerPtr controller = control.lock())
94 {
95 controller->triggerObjectClassSelected(object.first, object.second);
96 }
97 }
98}
99
100void
102{
103 sourceModel->onConnect();
104 ui->objectExplorerTreeView->setModel(sourceModel);
105}
106
111
112void
114{
115 ui->retranslateUi(this);
116}
uint8_t index
This class provides a model for storing classes from memoryxcontroller::PriorKnowledgeController and ...
void onConnect()
Populates the gui::ObjectExplorerModel with data and sets up all child widgets.
ObjectExplorerWidget(const controller::ControllerPtr &control, QWidget *parent=0)
Constructor.
void retranslate()
Translates all translatable strings in this dialog.
ArmarX Headers.
This file is part of ArmarX.
std::shared_ptr< Controller > ControllerPtr