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 <QAction>
29#include <QComboBox>
30#include <QHeaderView>
31
33
34#include <ArmarXGui/gui-plugins/ScenarioManager/gui/ui_scenariolistview.h>
35
36#include "scenarioitem.h"
37#include "treeitem.h"
38
39using namespace ScenarioManager;
40using namespace Data_Structure;
41using namespace armarx;
42
44 QWidget(parent),
45 ui(new Ui::ScenarioListView),
46 startButtonDelegate(this),
47 stopButtonDelegate(this),
48 restartButtonDelegate(this),
49 removeAction("Remove", &contextMenu),
50 expandAction("Expand", &contextMenu),
51 collapseAction("Collapse", &contextMenu)
52{
53 ui->setupUi(this);
54
55 ui->treeView->setModel(model.get());
56 ui->treeView->setSortingEnabled(true);
57 ui->treeView->setItemDelegateForColumn(1, &startButtonDelegate);
58 ui->treeView->setItemDelegateForColumn(2, &stopButtonDelegate);
59 ui->treeView->setItemDelegateForColumn(3, &restartButtonDelegate);
60
61
62 contextMenu.setParent(ui->treeView);
63 ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu);
64 QObject::connect(ui->treeView,
65 SIGNAL(customContextMenuRequested(const QPoint&)),
66 this,
67 SLOT(onCustomContextMenu(const QPoint&)));
68
69 ui->treeView->addAction(&removeAction);
70
71 ui->treeView->setDragEnabled(true);
72 ui->treeView->setDefaultDropAction(Qt::CopyAction);
73 ui->treeView->setAcceptDrops(true);
74 ui->treeView->setDropIndicatorShown(true);
75
76 QObject::connect(&removeAction, SIGNAL(triggered()), this, SLOT(removeItemTriggered()));
77 QObject::connect(&expandAction, SIGNAL(triggered()), this, SLOT(expandItemTriggered()));
78 QObject::connect(&collapseAction, SIGNAL(triggered()), this, SLOT(collapseItemTriggered()));
79
80 QObject::connect(&startButtonDelegate,
81 SIGNAL(buttonClicked(int, int, QModelIndex)),
82 this,
83 SLOT(startButtonClicked(int, int, QModelIndex)));
84
85
86 QObject::connect(&stopButtonDelegate,
87 SIGNAL(buttonClicked(int, int, QModelIndex)),
88 this,
89 SLOT(stopButtonClicked(int, int, QModelIndex)));
90
91 QObject::connect(&restartButtonDelegate,
92 SIGNAL(buttonClicked(int, int, QModelIndex)),
93 this,
94 SLOT(restartButtonClicked(int, int, QModelIndex)));
95}
96
98{
99 delete ui;
100}
101
102void
104{
105 this->model = treeModel;
106 ui->treeView->setModel(model.get());
107
108 QHeaderView* header = ui->treeView->header();
109 header->setStretchLastSection(false);
110 header->setSectionResizeMode(0, QHeaderView::Stretch);
111 header->setSectionResizeMode(1, QHeaderView::Fixed);
112 header->setSectionResizeMode(2, QHeaderView::Fixed);
113 header->setSectionResizeMode(3, QHeaderView::Fixed);
114 header->setSectionResizeMode(4, QHeaderView::ResizeToContents);
115 const int buttonWidth = 60;
116 header->resizeSection(1, buttonWidth);
117 header->resizeSection(2, buttonWidth);
118 header->resizeSection(3, buttonWidth);
119}
120
121void
122ScenarioListView::on_searchBar_textEdited(const QString& text)
123{
124 model->setFilterRegExp(QRegExp(text, Qt::CaseInsensitive, QRegExp::FixedString));
125 ui->treeView->expandAll();
126}
127
128void
129ScenarioListView::startButtonClicked(int row, int column, QModelIndex parent)
130{
131 emit startApplication(row, column, parent);
132}
133
134void
135ScenarioListView::stopButtonClicked(int row, int column, QModelIndex parent)
136{
137 emit stopApplication(row, column, parent);
138}
139
140void
141ScenarioListView::restartButtonClicked(int row, int column, QModelIndex parent)
142{
143 emit restartApplication(row, column, parent);
144}
145
146void
147ScenarioListView::on_newButton_clicked()
148{
149 emit createScenario();
150}
151
152void
153ScenarioListView::on_openButton_clicked()
154{
155 emit showOpenDialog();
156}
157
158void
159ScenarioListView::on_expandAllButton_clicked()
160{
161 ui->treeView->expandAll();
162}
163
164void
165ScenarioListView::on_collapseAllButton_clicked()
166{
167 ui->treeView->collapseAll();
168}
169
170void
171ScenarioListView::removeItemTriggered()
172{
173 QModelIndex index = ui->treeView->currentIndex();
174 emit removeItem(index);
175}
176
177void
178ScenarioListView::on_treeView_clicked(const QModelIndex& index)
179{
180 emit itemClicked(index);
181}
182
183void
184ScenarioListView::onCustomContextMenu(const QPoint& point)
185{
186 QModelIndex index = ui->treeView->currentIndex();
187
188 QList<QAction*> actions;
189 actions.append(&expandAction);
190 actions.append(&collapseAction);
191 QAction separator;
192 separator.setSeparator(true);
193 actions.append(&separator);
194 actions.append(&removeAction);
195
196 QMenu::exec(actions, ui->treeView->mapToGlobal(point));
197}
198
199// Generated by ChatGPT
200inline void
201expandRecursively(QTreeView* view, const QModelIndex& index)
202{
203 if (!index.isValid())
204 {
205 return;
206 }
207
208 view->expand(index);
209
210 const QAbstractItemModel* model = index.model();
211 int rows = model->rowCount(index);
212 int cols = model->columnCount(index);
213
214 for (int r = 0; r < rows; ++r)
215 {
216 for (int c = 0; c < cols; ++c)
217 {
218 QModelIndex child = model->index(r, c, index);
219 if (child.isValid())
220 {
221 expandRecursively(view, child);
222 }
223 }
224 }
225}
226
227void
228ScenarioListView::expandItemTriggered()
229{
230 QModelIndex index = ui->treeView->currentIndex();
231
232 // Support for Ubuntu 18 with older Qt version (>=5.9.5)
233 #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
234 ui->treeView->expandRecursively(index);
235 #else
236 expandRecursively(ui->treeView, index);
237 #endif
238}
239
240void
241ScenarioListView::collapseItemTriggered()
242{
243 QModelIndex index = ui->treeView->currentIndex();
244 ui->treeView->collapse(index);
245}
uint8_t index
constexpr T c
~ScenarioListView() override
Destructor.
void itemClicked(const QModelIndex &index)
ScenarioListView(QWidget *parent=0)
Constructor that sets up the ui and behaviour of this view.
void stopApplication(int row, int column, QModelIndex parent)
void setModel(FilterableTreeModelSortFilterProxyModelPtr model)
Sets the model of this view.
void restartApplication(int row, int column, QModelIndex parent)
void startApplication(int row, int column, QModelIndex parent)
void removeItem(QModelIndex index)
std::shared_ptr< FilterableTreeModelSortFilterProxyModel > FilterableTreeModelSortFilterProxyModelPtr
ArmarX Headers.
bool buttonClicked(RemoteGui::ValueMap const &newValues, RemoteGui::ValueMap const &oldValues, std::string const &name)
Definition Storage.cpp:7
This file offers overloads of toIce() and fromIce() functions for STL container types.
void expandRecursively(QTreeView *view, const QModelIndex &index)