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"
36 #include "ObjectExplorerWidget.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 
70 void
71 gui::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 
86 void
87 gui::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  {
94  {
95  controller->triggerObjectClassSelected(object.first, object.second);
96  }
97  }
98 }
99 
100 void
102 {
103  sourceModel->onConnect();
104  ui->objectExplorerTreeView->setModel(sourceModel);
105 }
106 
108 {
109  delete ui;
110 }
111 
112 void
114 {
115  ui->retranslateUi(this);
116 }
gui::ObjectExplorerWidget::retranslate
void retranslate()
Translates all translatable strings in this dialog.
Definition: ObjectExplorerWidget.cpp:113
gui::OverrideAction
Definition: OverrideAction.h:31
gui::ObjectExplorerWidget::~ObjectExplorerWidget
~ObjectExplorerWidget() override
Definition: ObjectExplorerWidget.cpp:107
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:101
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.