scenariolistview.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 ArmarXCore::core
19  * @author Cedric Seehausen (usdnr at kit dot edu)
20  * @date 2016
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 
26 #include "scenariolistview.h"
27 
28 #include <QComboBox>
29 
31 
32 #include <ArmarXGui/gui-plugins/ScenarioManager/gui/ui_scenariolistview.h>
33 
34 #include "scenarioitem.h"
35 #include "treeitem.h"
36 
37 using namespace ScenarioManager;
38 using namespace Data_Structure;
39 using namespace armarx;
40 
42  QWidget(parent),
43  ui(new Ui::ScenarioListView),
44  startButtonDelegate(this),
45  stopButtonDelegate(this),
46  restartButtonDelegate(this),
47  removeAction("Remove", &contextMenu)
48 {
49  ui->setupUi(this);
50 
51  ui->treeView->setModel(model.get());
52  ui->treeView->setSortingEnabled(true);
53  ui->treeView->setItemDelegateForColumn(1, &startButtonDelegate);
54  ui->treeView->setItemDelegateForColumn(2, &stopButtonDelegate);
55  ui->treeView->setItemDelegateForColumn(3, &restartButtonDelegate);
56 
57 
58  contextMenu.setParent(ui->treeView);
59  ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu);
60  QObject::connect(ui->treeView,
61  SIGNAL(customContextMenuRequested(const QPoint&)),
62  this,
63  SLOT(onCustomContextMenu(const QPoint&)));
64 
65  ui->treeView->addAction(&removeAction);
66 
67  ui->treeView->setDragEnabled(true);
68  ui->treeView->setDefaultDropAction(Qt::CopyAction);
69  ui->treeView->setAcceptDrops(true);
70  ui->treeView->setDropIndicatorShown(true);
71 
72  QObject::connect(&removeAction, SIGNAL(triggered()), this, SLOT(removeItemTriggered()));
73 
74  QObject::connect(&startButtonDelegate,
75  SIGNAL(buttonClicked(int, int, QModelIndex)),
76  this,
77  SLOT(startButtonClicked(int, int, QModelIndex)));
78 
79 
80  QObject::connect(&stopButtonDelegate,
81  SIGNAL(buttonClicked(int, int, QModelIndex)),
82  this,
83  SLOT(stopButtonClicked(int, int, QModelIndex)));
84 
85  QObject::connect(&restartButtonDelegate,
86  SIGNAL(buttonClicked(int, int, QModelIndex)),
87  this,
88  SLOT(restartButtonClicked(int, int, QModelIndex)));
89 }
90 
92 {
93  delete ui;
94 }
95 
96 void
98 {
99  this->model = treeModel;
100  ui->treeView->setModel(model.get());
101 
102  ui->treeView->setColumnWidth(0, 200);
103  ui->treeView->setColumnWidth(1, 90);
104  ui->treeView->setColumnWidth(2, 50);
105  ui->treeView->setColumnWidth(3, 60);
106 }
107 
108 void
109 ScenarioListView::on_searchBar_textEdited(const QString& text)
110 {
111  model->setFilterRegExp(QRegExp(text, Qt::CaseInsensitive, QRegExp::FixedString));
112  ui->treeView->expandAll();
113 }
114 
115 void
116 ScenarioListView::startButtonClicked(int row, int column, QModelIndex parent)
117 {
118  emit startApplication(row, column, parent);
119 }
120 
121 void
122 ScenarioListView::stopButtonClicked(int row, int column, QModelIndex parent)
123 {
124  emit stopApplication(row, column, parent);
125 }
126 
127 void
128 ScenarioListView::restartButtonClicked(int row, int column, QModelIndex parent)
129 {
130  emit restartApplication(row, column, parent);
131 }
132 
133 void
134 ScenarioListView::on_newButton_clicked()
135 {
136  emit createScenario();
137 }
138 
139 void
140 ScenarioListView::on_openButton_clicked()
141 {
142  emit showOpenDialog();
143 }
144 
145 void
146 ScenarioListView::removeItemTriggered()
147 {
148  QModelIndex index = ui->treeView->currentIndex();
149  emit removeItem(index);
150 }
151 
152 void
153 ScenarioListView::on_treeView_clicked(const QModelIndex& index)
154 {
155  emit itemClicked(index);
156 }
157 
158 void
159 ScenarioListView::onCustomContextMenu(const QPoint& point)
160 {
161  QModelIndex index = ui->treeView->currentIndex();
162 
163  removeAction.setText("Remove " + index.data().toString());
164 
165  QList<QAction*> actions;
166  actions.append(&removeAction);
167 
168  QMenu::exec(actions, ui->treeView->mapToGlobal(point));
169 }
ScenarioListView::setModel
void setModel(FilterableTreeModelSortFilterProxyModelPtr model)
Sets the model of this view.
Definition: scenariolistview.cpp:97
scenariolistview.h
ScenarioListView::ScenarioListView
ScenarioListView(QWidget *parent=0)
Constructor that sets up the ui and behaviour of this view.
Definition: scenariolistview.cpp:41
index
uint8_t index
Definition: EtherCATFrame.h:59
treeitem.h
ScenarioListView::showOpenDialog
void showOpenDialog()
scenarioitem.h
ScenarioListView::startApplication
void startApplication(int row, int column, QModelIndex parent)
ScenarioListView::createScenario
void createScenario()
ScenarioListView::stopApplication
void stopApplication(int row, int column, QModelIndex parent)
Ui
ArmarX Headers.
Definition: ArmarXMainWindow.h:54
ScenarioListView::removeItem
void removeItem(QModelIndex index)
FilterableTreeModelSortFilterProxyModelPtr
std::shared_ptr< FilterableTreeModelSortFilterProxyModel > FilterableTreeModelSortFilterProxyModelPtr
Definition: filterabletreemodelsortfilterproxymodel.h:68
ScenarioManager
Definition: Application.cpp:180
ScenarioListView::~ScenarioListView
~ScenarioListView() override
Destructor.
Definition: scenariolistview.cpp:91
ScenarioListView
View that shows a list of Scenarios. Allows to start, stop, restart Applications and Scenarios....
Definition: scenariolistview.h:52
ScenarioListView::itemClicked
void itemClicked(const QModelIndex &index)
ScenarioListView::restartApplication
void restartApplication(int row, int column, QModelIndex parent)
Logging.h
armarx::RemoteGui::buttonClicked
bool buttonClicked(RemoteGui::ValueMap const &newValues, RemoteGui::ValueMap const &oldValues, std::string const &name)
Definition: Storage.cpp:7
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27