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 #include <ArmarXGui/gui-plugins/SystemStateMonitorPlugin/ui_ArmarXManagerRepositoryDialog.h>
27 
28 #include <ArmarXCore/interface/core/ArmarXManagerInterface.h>
29 
30 #include <string>
31 #include <iostream>
32 #include <vector>
33 
34 #include <QList>
35 #include <QInputDialog>
36 #include <QStandardItem>
37 #include <QItemSelectionModel>
38 #include <QPersistentModelIndex>
39 #include <QMessageBox>
40 
41 namespace armarx
42 {
44  ArmarXManagerModel* managerRepositoryModel,
45  ArmarXManagerModel* monitoredManagerModel,
46  QWidget* parent):
47  QDialog(parent),
49  parent(parent)
50  {
51  this->managerRepositoryModel = managerRepositoryModel->clone();
52  this->monitoredManagerModel = monitoredManagerModel->clone();
53 
54  setupView();
55  }
56 
57 
59  {
60  delete ui;
61  }
62 
63 
65  {
66  ui->setupUi(this);
67 
68  ui->managerRepository->setModel(managerRepositoryModel);
69  ui->monitoredManagers->setModel(monitoredManagerModel);
70 
71  connect(ui->addNewManager, SIGNAL(clicked()), this, SLOT(addNewManager()));
72  connect(ui->cancelOkBox, SIGNAL(accepted()), this, SLOT(accept()));
73  connect(ui->cancelOkBox, SIGNAL(rejected()), this, SLOT(reject()));
74 
75  connect(ui->moveToMonitoredManagersButton, SIGNAL(clicked()), this, SLOT(moveToMonitoredManagers()));
76  connect(ui->moveToManagerRepositoryButton, SIGNAL(clicked()), this, SLOT(moveToManagerRepository()));
77  connect(ui->removeSelectedManagersButton, SIGNAL(clicked()), this, SLOT(removeSelectedManagers()));
78 
79  connect(ui->scanButton, SIGNAL(clicked()), this, SLOT(scanForManagers()));
80 
81  connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clearRepository()));
82  }
83 
84 
85  void ArmarXManagerRepositoryDialog::addOnlineManagers(const QStringList& managers)
86  {
87  QStringList::ConstIterator it = managers.begin();
88 
89  QBrush brush;
90  brush.setColor(QColor(78, 238, 148));
91  brush.setStyle(Qt::SolidPattern);
92 
93  while (it != managers.end())
94  {
95  ArmarXManagerItem* item = managerRepositoryModel->getManagerItemByName(*it);
96  if (!item)
97  {
98  item = monitoredManagerModel->getManagerItemByName(*it);
99  }
100 
101  if (!item)
102  {
103  item = new ArmarXManagerItem(*it);
104 
105  // ScopedLock lock(managerRepositoryModel->getMutex());
106  managerRepositoryModel->appendRow(item);
107  }
108 
109  // ScopedLock lock(item->getMutex());
110  item->setBackground(brush);
111 
112  ++it;
113  }
114  }
115 
116 
118  {
119  bool ok;
120  QString managerName = QInputDialog::getText(parent,
121  tr("New ArmarXManager"),
122  tr("Manager name"),
123  QLineEdit::Normal,
124  tr("SampleApplicationManager"),
125  &ok);
126 
127  if (ok)
128  {
129  ArmarXManagerItem* item = managerRepositoryModel->getManagerItemByName(managerName);
130 
131  if (!item)
132  {
133  //ScopedLock lock(managerRepositoryModel->getMutex());
134  managerRepositoryModel->appendRow(new ArmarXManagerItem(managerName));
135  }
136  else
137  {
138  QMessageBox::information(parent,
139  "Add new manager",
140  managerName + " manager already in repository",
141  QMessageBox::Ok);
142  }
143  }
144  }
145 
146 
148  {
149  monitoredManagerModel->takeSelectionFrom(
150  ui->managerRepository->selectionModel(),
151  managerRepositoryModel);
152  }
153 
154 
156  {
157  monitoredManagerModel->moveSelectionTo(
158  ui->monitoredManagers->selectionModel(),
159  managerRepositoryModel);
160  }
161 
162 
164  {
165  emit requestedManagerScan();
166  }
167 
168 
170  {
171  managerRepositoryModel->clear();
172  }
173 
174 
176  {
177  return managerRepositoryModel;
178  }
179 
180 
182  {
183  return monitoredManagerModel;
184  }
185 
186 
188  {
189  managerRepositoryModel->deleteSelection(ui->managerRepository->selectionModel());
190  }
191 }
armarx::ArmarXManagerModel::getManagerItemByName
ArmarXManagerItem * getManagerItemByName(const QString &name)
Returns the requested manager item by its name.
Definition: ArmarXManagerModel.cpp:65
armarx::ArmarXManagerRepositoryDialog::clearRepository
void clearRepository()
Definition: ArmarXManagerRepositoryDialog.cpp:169
armarx::ArmarXManagerRepositoryDialog::ArmarXManagerRepositoryDialog
ArmarXManagerRepositoryDialog(ArmarXManagerModel *managerRepositoryModel, ArmarXManagerModel *monitoredManagerModel, QWidget *parent=0)
Definition: ArmarXManagerRepositoryDialog.cpp:43
ArmarXManagerRepositoryDialog.h
armarx::ArmarXManagerRepositoryDialog::moveToManagerRepository
void moveToManagerRepository()
Definition: ArmarXManagerRepositoryDialog.cpp:155
armarx::ArmarXManagerModel
Definition: ArmarXManagerModel.h:47
armarx::ArmarXManagerModel::clone
ArmarXManagerModel * clone()
Returns a clone of this ArmarXManagerModel.
Definition: ArmarXManagerModel.cpp:677
armarx::ArmarXManagerRepositoryDialog
Definition: ArmarXManagerRepositoryDialog.h:46
armarx::ArmarXManagerRepositoryDialog::getManagerRepositoryModel
ArmarXManagerModel * getManagerRepositoryModel()
Definition: ArmarXManagerRepositoryDialog.cpp:175
armarx::ArmarXManagerRepositoryDialog::addNewManager
void addNewManager()
Definition: ArmarXManagerRepositoryDialog.cpp:117
armarx::ArmarXManagerRepositoryDialog::removeSelectedManagers
void removeSelectedManagers()
Definition: ArmarXManagerRepositoryDialog.cpp:187
visionx::imrecman::ok
@ ok
Definition: ImageRecordingManagerInterface.ice:46
armarx::ArmarXManagerRepositoryDialog::~ArmarXManagerRepositoryDialog
~ArmarXManagerRepositoryDialog() override
Definition: ArmarXManagerRepositoryDialog.cpp:58
armarx::ArmarXManagerRepositoryDialog::moveToMonitoredManagers
void moveToMonitoredManagers()
Definition: ArmarXManagerRepositoryDialog.cpp:147
armarx::ArmarXManagerRepositoryDialog::getMonitoredManagersModel
ArmarXManagerModel * getMonitoredManagersModel()
Definition: ArmarXManagerRepositoryDialog.cpp:181
armarx::ArmarXManagerModel::deleteSelection
void deleteSelection(QItemSelectionModel *selectionModel)
Deletes the selected set of rows from this model.
Definition: ArmarXManagerModel.cpp:563
Ui
ArmarX Headers.
Definition: ArmarXMainWindow.h:54
armarx::ArmarXManagerRepositoryDialog::scanForManagers
void scanForManagers()
Definition: ArmarXManagerRepositoryDialog.cpp:163
armarx::ArmarXManagerRepositoryDialog::setupView
void setupView()
Definition: ArmarXManagerRepositoryDialog.cpp:64
armarx::ArmarXManagerRepositoryDialog::addOnlineManagers
void addOnlineManagers(const QStringList &managers)
Definition: ArmarXManagerRepositoryDialog.cpp:85
armarx::ArmarXManagerItem
Definition: ArmarXManagerItem.h:41
armarx::ArmarXManagerRepositoryDialog::requestedManagerScan
void requestedManagerScan()
armarx::ArmarXManagerModel::moveSelectionTo
void moveSelectionTo(QItemSelectionModel *selectionModel, ArmarXManagerModel *destinationModel)
Takes the specified selected rows via the selection model from this and appends the rows to the given...
Definition: ArmarXManagerModel.cpp:524
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::ArmarXManagerModel::takeSelectionFrom
void takeSelectionFrom(QItemSelectionModel *selectionModel, ArmarXManagerModel *sourceModel)
Takes the specified selected rows via the selection model from the source model and appends the rows ...
Definition: ArmarXManagerModel.cpp:532