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 
32 
33 #include <QComboBox>
34 
35 using namespace ScenarioManager;
36 using namespace Data_Structure;
37 using namespace armarx;
38 
39 
41  QWidget(parent),
42  ui(new Ui::ScenarioListView),
43  startButtonDelegate(this),
44  stopButtonDelegate(this),
45  restartButtonDelegate(this),
46  removeAction("Remove", &contextMenu)
47 {
48  ui->setupUi(this);
49 
50  ui->treeView->setModel(model.get());
51  ui->treeView->setSortingEnabled(true);
52  ui->treeView->setItemDelegateForColumn(1, &startButtonDelegate);
53  ui->treeView->setItemDelegateForColumn(2, &stopButtonDelegate);
54  ui->treeView->setItemDelegateForColumn(3, &restartButtonDelegate);
55 
56 
57  contextMenu.setParent(ui->treeView);
58  ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu);
59  QObject::connect(ui->treeView, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(onCustomContextMenu(const QPoint&)));
60 
61  ui->treeView->addAction(&removeAction);
62 
63  ui->treeView->setDragEnabled(true);
64  ui->treeView->setDefaultDropAction(Qt::CopyAction);
65  ui->treeView->setAcceptDrops(true);
66  ui->treeView->setDropIndicatorShown(true);
67 
68  QObject::connect(&removeAction, SIGNAL(triggered()),
69  this, SLOT(removeItemTriggered()));
70 
71  QObject::connect(&startButtonDelegate, SIGNAL(buttonClicked(int, int, QModelIndex)),
72  this, SLOT(startButtonClicked(int, int, QModelIndex)));
73 
74 
75  QObject::connect(&stopButtonDelegate, SIGNAL(buttonClicked(int, int, QModelIndex)),
76  this, SLOT(stopButtonClicked(int, int, QModelIndex)));
77 
78  QObject::connect(&restartButtonDelegate, SIGNAL(buttonClicked(int, int, QModelIndex)),
79  this, SLOT(restartButtonClicked(int, int, QModelIndex)));
80 }
81 
83 {
84  delete ui;
85 }
86 
88 {
89  this->model = treeModel;
90  ui->treeView->setModel(model.get());
91 
92  ui->treeView->setColumnWidth(0, 200);
93  ui->treeView->setColumnWidth(1, 90);
94  ui->treeView->setColumnWidth(2, 50);
95  ui->treeView->setColumnWidth(3, 60);
96 }
97 
98 
99 void ScenarioListView::on_searchBar_textEdited(const QString& text)
100 {
101  model->setFilterRegExp(QRegExp(text, Qt::CaseInsensitive, QRegExp::FixedString));
102  ui->treeView->expandAll();
103 }
104 
105 void ScenarioListView::startButtonClicked(int row, int column, QModelIndex parent)
106 {
107  emit startApplication(row, column, parent);
108 }
109 
110 void ScenarioListView::stopButtonClicked(int row, int column, QModelIndex parent)
111 {
112  emit stopApplication(row, column, parent);
113 }
114 
115 void ScenarioListView::restartButtonClicked(int row, int column, QModelIndex parent)
116 {
117  emit restartApplication(row, column, parent);
118 }
119 
120 void ScenarioListView::on_newButton_clicked()
121 {
122  emit createScenario();
123 }
124 
125 void ScenarioListView::on_openButton_clicked()
126 {
127  emit showOpenDialog();
128 }
129 
130 void ScenarioListView::removeItemTriggered()
131 {
132  QModelIndex index = ui->treeView->currentIndex();
133  emit removeItem(index);
134 }
135 
136 void ScenarioListView::on_treeView_clicked(const QModelIndex& index)
137 {
138  emit itemClicked(index);
139 }
140 
141 void ScenarioListView::onCustomContextMenu(const QPoint& point)
142 {
143  QModelIndex index = ui->treeView->currentIndex();
144 
145  removeAction.setText("Remove " + index.data().toString());
146 
147  QList<QAction*> actions;
148  actions.append(&removeAction);
149 
150  QMenu::exec(actions, ui->treeView->mapToGlobal(point));
151 }
ScenarioListView::setModel
void setModel(FilterableTreeModelSortFilterProxyModelPtr model)
Sets the model of this view.
Definition: scenariolistview.cpp:87
scenariolistview.h
ScenarioListView::ScenarioListView
ScenarioListView(QWidget *parent=0)
Constructor that sets up the ui and behaviour of this view.
Definition: scenariolistview.cpp:40
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:58
ScenarioListView::removeItem
void removeItem(QModelIndex index)
FilterableTreeModelSortFilterProxyModelPtr
std::shared_ptr< FilterableTreeModelSortFilterProxyModel > FilterableTreeModelSortFilterProxyModelPtr
Definition: filterabletreemodelsortfilterproxymodel.h:65
ScenarioManager
Definition: Application.cpp:166
ScenarioListView::~ScenarioListView
~ScenarioListView() override
Destructor.
Definition: scenariolistview.cpp:82
ScenarioListView
View that shows a list of Scenarios. Allows to start, stop, restart Applications and Scenarios....
Definition: scenariolistview.h:49
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