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
37using namespace ScenarioManager;
38using namespace Data_Structure;
39using 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
95
96void
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
108void
109ScenarioListView::on_searchBar_textEdited(const QString& text)
110{
111 model->setFilterRegExp(QRegExp(text, Qt::CaseInsensitive, QRegExp::FixedString));
112 ui->treeView->expandAll();
113}
114
115void
116ScenarioListView::startButtonClicked(int row, int column, QModelIndex parent)
117{
118 emit startApplication(row, column, parent);
119}
120
121void
122ScenarioListView::stopButtonClicked(int row, int column, QModelIndex parent)
123{
124 emit stopApplication(row, column, parent);
125}
126
127void
128ScenarioListView::restartButtonClicked(int row, int column, QModelIndex parent)
129{
130 emit restartApplication(row, column, parent);
131}
132
133void
134ScenarioListView::on_newButton_clicked()
135{
136 emit createScenario();
137}
138
139void
140ScenarioListView::on_openButton_clicked()
141{
142 emit showOpenDialog();
143}
144
145void
146ScenarioListView::removeItemTriggered()
147{
148 QModelIndex index = ui->treeView->currentIndex();
149 emit removeItem(index);
150}
151
152void
153ScenarioListView::on_treeView_clicked(const QModelIndex& index)
154{
155 emit itemClicked(index);
156}
157
158void
159ScenarioListView::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}
uint8_t index
~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.