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 #include <ArmarXGui/gui-plugins/ScenarioManager/gui/ui_scenariolistview.h>
28 #include "scenarioitem.h"
29 #include "treeitem.h"
30 #include "comboboxbutton.h"
31 
33 
34 #include <QComboBox>
35 
36 using namespace ScenarioManager;
37 using namespace Data_Structure;
38 using namespace armarx;
39 
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, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(onCustomContextMenu(const QPoint&)));
61 
62  ui->treeView->addAction(&removeAction);
63 
64  ui->treeView->setDragEnabled(true);
65  ui->treeView->setDefaultDropAction(Qt::CopyAction);
66  ui->treeView->setAcceptDrops(true);
67  ui->treeView->setDropIndicatorShown(true);
68 
69  QObject::connect(&removeAction, SIGNAL(triggered()),
70  this, SLOT(removeItemTriggered()));
71 
72  QObject::connect(&startButtonDelegate, SIGNAL(comboBoxButtonClicked(int, int, QModelIndex, QString)),
73  this, SLOT(startComboBoxClicked(int, int, QModelIndex, QString)));
74  QObject::connect(&startButtonDelegate, SIGNAL(buttonClicked(int, int, QModelIndex)),
75  this, SLOT(startButtonClicked(int, int, QModelIndex)));
76 
77 
78  QObject::connect(&stopButtonDelegate, SIGNAL(buttonClicked(int, int, QModelIndex)),
79  this, SLOT(stopButtonClicked(int, int, QModelIndex)));
80 
81  QObject::connect(&restartButtonDelegate, SIGNAL(buttonClicked(int, int, QModelIndex)),
82  this, SLOT(restartButtonClicked(int, int, QModelIndex)));
83 }
84 
86 {
87  delete ui;
88 }
89 
91 {
92  this->model = model;
93  ui->treeView->setModel(model.get());
94  QObject::connect(this->model.get(), SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(onModelDataChange(QModelIndex, QModelIndex)));
95 
96  ui->treeView->setColumnWidth(0, 200);
97  ui->treeView->setColumnWidth(1, 90);
98  ui->treeView->setColumnWidth(2, 50);
99  ui->treeView->setColumnWidth(3, 60);
100 }
101 
102 
103 void ScenarioListView::on_searchBar_textEdited(const QString& text)
104 {
105  model->setFilterRegExp(QRegExp(text, Qt::CaseInsensitive, QRegExp::FixedString));
106  ui->treeView->expandAll();
107 }
108 
109 void ScenarioListView::startComboBoxClicked(int row, int column, QModelIndex parent, QString text)
110 {
111  emit startApplication(row, column, parent, LocalStart);
112 }
113 
114 void ScenarioListView::startButtonClicked(int row, int column, QModelIndex parent)
115 {
116  emit startApplication(row, column, parent, LocalStart);
117 }
118 
119 void ScenarioListView::stopButtonClicked(int row, int column, QModelIndex parent)
120 {
121  emit stopApplication(row, column, parent);
122 }
123 
124 void ScenarioListView::restartButtonClicked(int row, int column, QModelIndex parent)
125 {
126  emit restartApplication(row, column, parent);
127 }
128 
129 void ScenarioListView::on_newButton_clicked()
130 {
131  emit createScenario();
132 }
133 
134 void ScenarioListView::on_openButton_clicked()
135 {
136  emit showOpenDialog();
137 }
138 
139 void ScenarioListView::updateScenarioIndices()
140 {
141  for (int i = 0; i < this->model->rowCount(); ++i)
142  {
143  auto index = this->model->index(i, 1);
144  ui->treeView->openPersistentEditor(index);
145  // auto w = ui->treeView->indexWidget(index);
146  // ComboBoxButton* cb = qobject_cast<ComboBoxButton*>(w);
147  // if (cb)
148  // {
149  // cb->setScenarioIndex(index);
150  // }
151  }
152 }
153 
154 void ScenarioListView::removeItemTriggered()
155 {
156  QModelIndex index = ui->treeView->currentIndex();
157  emit removeItem(index);
158  updateScenarioIndices();
159 
160 }
161 
162 void ScenarioListView::on_treeView_clicked(const QModelIndex& index)
163 {
164  emit itemClicked(index);
165 }
166 
167 void ScenarioListView::onCustomContextMenu(const QPoint& point)
168 {
169  QModelIndex index = ui->treeView->currentIndex();
170 
171  removeAction.setText("Remove " + index.data().toString());
172 
173  QList<QAction*> actions;
174  actions.append(&removeAction);
175 
176  QMenu::exec(actions, ui->treeView->mapToGlobal(point));
177 }
178 
179 void ScenarioListView::onModelDataChange(QModelIndex start, QModelIndex end)
180 {
181  updateScenarioIndices();
182 }
ScenarioListView::setModel
void setModel(FilterableTreeModelSortFilterProxyModelPtr model)
Sets the model of this view.
Definition: scenariolistview.cpp:90
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
LocalStart
@ LocalStart
Definition: scenariolistview.h:46
ScenarioListView::showOpenDialog
void showOpenDialog()
scenarioitem.h
ScenarioListView::createScenario
void createScenario()
comboboxbutton.h
ScenarioListView::stopApplication
void stopApplication(int row, int column, QModelIndex parent)
Ui
ArmarX Headers.
Definition: ArmarXMainWindow.h:58
ScenarioListView::removeItem
void removeItem(QModelIndex index)
FilterableTreeModelSortFilterProxyModelPtr
std::shared_ptr< FilterableTreeModelSortFilterProxyModel > FilterableTreeModelSortFilterProxyModelPtr
Definition: filterabletreemodelsortfilterproxymodel.h:65
ScenarioListView::startApplication
void startApplication(int row, int column, QModelIndex parent, ScenarioStartModes startMode)
ScenarioManager
Definition: Application.cpp:166
ScenarioListView::~ScenarioListView
~ScenarioListView() override
Destructor.
Definition: scenariolistview.cpp:85
ScenarioListView
View that shows a list of Scenarios. Allows to start, stop, restart Applications and Scenarios....
Definition: scenariolistview.h:54
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:6
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28