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 <QString>
26 #include <QTreeView>
27 #include <QImage>
28 #include <QPixmap>
29 #include <QIcon>
30 #include <QLabel>
31 
32 /* C++ headers */
33 #include <iostream>
34 
35 #include "ObjectExplorerWidget.h"
36 #include <MemoryX/gui-plugins/SceneEditor/ui_ObjectExplorerWidget.h>
37 #include "ClearableLineEdit.h"
38 #include "OverrideAction.h"
39 
41  QWidget(parent),
42  ui(new Ui::ObjectExplorerWidget),
44  sourceModel(new ObjectExplorerModel(control, this))
45 {
46  ui->setupUi(this);
47 
48  ui->objectExplorerTreeView->setModel(sourceModel);
49 
50  std::shared_ptr<gui::ShortcutController> shortcutController = control->getShortcutController();
51  QPointer<QAction> searchAction(new OverrideAction("Object Explorer: Set Focus on Search Field", this));
52  this->addAction(searchAction);
53  shortcutController->registerAction(searchAction->text(), searchAction);
54 
55  setMinimumWidth(200);
56 
57  connect(searchAction, SIGNAL(triggered()), ui->filterObjectClassesLineEdit, SLOT(setFocus()));
58  connect(ui->filterObjectClassesLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterFixedString()));
59  connect(ui->objectExplorerTreeView, SIGNAL(clicked(QModelIndex)), this, SLOT(getSelectedObject(QModelIndex)));
60 }
61 
62 void gui::ObjectExplorerWidget::filterFixedString()
63 {
64  QString searchPattern(ui->filterObjectClassesLineEdit->text());
65  sourceModel->setFilterFixedString(searchPattern);
66 
67  if (searchPattern.isEmpty())
68  {
69  ui->objectExplorerTreeView->collapseAll();
70  }
71  else
72  {
73  ui->objectExplorerTreeView->expandAll();
74  }
75 
76 }
77 
78 void gui::ObjectExplorerWidget::getSelectedObject(const QModelIndex& index)
79 {
80  std::pair<std::string, std::string> object = sourceModel->getItemInformation(index);
81 
82  if (!object.first.empty() && !object.second.empty())
83  {
85  {
86  controller->triggerObjectClassSelected(object.first, object.second);
87  }
88  }
89 }
90 
92 {
93  sourceModel->onConnect();
94  ui->objectExplorerTreeView->setModel(sourceModel);
95 }
96 
98 {
99  delete ui;
100 }
101 
103 {
104  ui->retranslateUi(this);
105 }
gui::ObjectExplorerWidget::retranslate
void retranslate()
Translates all translatable strings in this dialog.
Definition: ObjectExplorerWidget.cpp:102
gui::OverrideAction
Definition: OverrideAction.h:31
gui::ObjectExplorerWidget::~ObjectExplorerWidget
~ObjectExplorerWidget() override
Definition: ObjectExplorerWidget.cpp:97
index
uint8_t index
Definition: EtherCATFrame.h:59
ClearableLineEdit.h
ObjectExplorerWidget.h
gui::ObjectExplorerWidget::ObjectExplorerWidget
ObjectExplorerWidget(const controller::ControllerPtr &control, QWidget *parent=0)
Constructor.
Definition: ObjectExplorerWidget.cpp:40
controller
Definition: AddOperation.h:39
Ui
ArmarX Headers.
Definition: ArmarXMainWindow.h:54
controller::ControllerPtr
std::shared_ptr< Controller > ControllerPtr
Definition: ClassDefinitions.h:41
OverrideAction.h
gui::ObjectExplorerWidget
This class provides a QWidget which displays all object classes from PriorKnowledge in their collecti...
Definition: ObjectExplorerWidget.h:51
gui::ObjectExplorerWidget::onConnect
void onConnect()
Populates the gui::ObjectExplorerModel with data and sets up all child widgets.
Definition: ObjectExplorerWidget.cpp:91
gui::ObjectExplorerModel
This class provides a model for storing classes from memoryxcontroller::PriorKnowledgeController and ...
Definition: ObjectExplorerModel.h:44
control
This file is part of ArmarX.