ArmarXManagerRepositoryDialog.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 ArmarX::Gui
19 * @author Jan Issac ( jan.issac at gmail dot com)
20 * @date 2012
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
26
27#include <iostream>
28#include <string>
29#include <vector>
30
31#include <QInputDialog>
32#include <QItemSelectionModel>
33#include <QList>
34#include <QMessageBox>
35#include <QPersistentModelIndex>
36#include <QStandardItem>
37
38#include <ArmarXCore/interface/core/ArmarXManagerInterface.h>
39
40#include <ArmarXGui/gui-plugins/SystemStateMonitorPlugin/ui_ArmarXManagerRepositoryDialog.h>
41
42namespace armarx
43{
45 ArmarXManagerModel* managerRepositoryModel,
46 ArmarXManagerModel* monitoredManagerModel,
47 QWidget* parent) :
48 QDialog(parent), ui(new Ui::ArmarXManagerRepositoryDialog), parent(parent)
49 {
50 this->managerRepositoryModel = managerRepositoryModel->clone();
51 this->monitoredManagerModel = monitoredManagerModel->clone();
52
53 setupView();
54 }
55
57 {
58 // The two cloned models were never deleted; delete them here (issue #64.16).
59 // Views still bound to them detach safely via Qt's model destroyed() handling.
60 delete ui;
61 delete managerRepositoryModel;
62 delete monitoredManagerModel;
63 }
64
65 void
67 {
68 ui->setupUi(this);
69
70 ui->managerRepository->setModel(managerRepositoryModel);
71 ui->monitoredManagers->setModel(monitoredManagerModel);
72
73 connect(ui->addNewManager, SIGNAL(clicked()), this, SLOT(addNewManager()));
74 connect(ui->cancelOkBox, SIGNAL(accepted()), this, SLOT(accept()));
75 connect(ui->cancelOkBox, SIGNAL(rejected()), this, SLOT(reject()));
76
77 connect(ui->moveToMonitoredManagersButton,
78 SIGNAL(clicked()),
79 this,
81 connect(ui->moveToManagerRepositoryButton,
82 SIGNAL(clicked()),
83 this,
85 connect(ui->removeSelectedManagersButton,
86 SIGNAL(clicked()),
87 this,
89
90 connect(ui->scanButton, SIGNAL(clicked()), this, SLOT(scanForManagers()));
91
92 connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clearRepository()));
93 }
94
95 void
97 {
98 QBrush brush;
99 brush.setColor(QColor(78, 238, 148));
100 brush.setStyle(Qt::SolidPattern);
101
102 // Build a name -> item index once. The old code called getManagerItemByName() -
103 // a linear scan of the model - twice for every online manager, i.e. O(n^2)
104 // (issue #64.18). Insert monitored first, then repository, so a repository item
105 // wins on a duplicate name (matching the old lookup precedence).
106 QHash<QString, ArmarXManagerItem*> itemByName;
107 for (int i = 0; i < monitoredManagerModel->rowCount(); ++i)
108 {
109 ArmarXManagerItem* item = monitoredManagerModel->getItem(i);
110 itemByName.insert(item->getName(), item);
111 }
112 for (int i = 0; i < managerRepositoryModel->rowCount(); ++i)
113 {
114 ArmarXManagerItem* item = managerRepositoryModel->getItem(i);
115 itemByName.insert(item->getName(), item);
116 }
117
118 for (const QString& name : managers)
119 {
120 ArmarXManagerItem* item = itemByName.value(name, nullptr);
121 if (!item)
122 {
123 item = new ArmarXManagerItem(name);
124 managerRepositoryModel->appendRow(item);
125 itemByName.insert(name, item);
126 }
127
128 item->setBackground(brush);
129 }
130 }
131
132 void
134 {
135 bool ok;
136 QString managerName = QInputDialog::getText(parent,
137 tr("New ArmarXManager"),
138 tr("Manager name"),
139 QLineEdit::Normal,
140 tr("SampleApplicationManager"),
141 &ok);
142
143 if (ok)
144 {
145 ArmarXManagerItem* item = managerRepositoryModel->getManagerItemByName(managerName);
146
147 if (!item)
148 {
149 //ScopedLock lock(managerRepositoryModel->getMutex());
150 managerRepositoryModel->appendRow(new ArmarXManagerItem(managerName));
151 }
152 else
153 {
154 QMessageBox::information(parent,
155 "Add new manager",
156 managerName + " manager already in repository",
157 QMessageBox::Ok);
158 }
159 }
160 }
161
162 void
164 {
165 monitoredManagerModel->takeSelectionFrom(ui->managerRepository->selectionModel(),
166 managerRepositoryModel);
167 }
168
169 void
171 {
172 monitoredManagerModel->moveSelectionTo(ui->monitoredManagers->selectionModel(),
173 managerRepositoryModel);
174 }
175
176 void
181
182 void
184 {
185 managerRepositoryModel->clear();
186 }
187
190 {
191 return managerRepositoryModel;
192 }
193
196 {
197 return monitoredManagerModel;
198 }
199
200 void
202 {
203 managerRepositoryModel->deleteSelection(ui->managerRepository->selectionModel());
204 }
205} // namespace armarx
ArmarXManagerModel * clone()
Returns a clone of this ArmarXManagerModel.
void deleteSelection(QItemSelectionModel *selectionModel)
Deletes the selected set of rows from this model.
ArmarXManagerRepositoryDialog(ArmarXManagerModel *managerRepositoryModel, ArmarXManagerModel *monitoredManagerModel, QWidget *parent=0)
void addOnlineManagers(const QStringList &managers)
ArmarX Headers.
This file offers overloads of toIce() and fromIce() functions for STL container types.