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