ArmarXManagerModel.h
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
25
26#pragma once
27
28#include <mutex>
29
30#include <QItemSelectionModel>
31#include <QMap>
32#include <QPointer>
33#include <QStandardItemModel>
34#include <QStringList>
35#include <QThread>
36
40
41#include "ArmarXManagerItem.h"
42
43namespace armarx
44{
45 using StateUpdateMap = std::map<QString, QPair<bool, ArmarXManagerItem::ObjectMap>>;
46 using ManagerPrxMap = std::map<QString, ArmarXManagerInterfacePrx>;
47
48 class ArmarXManagerModel : public QStandardItemModel
49 {
50 Q_OBJECT
51
52 public:
53 /**
54 * Constructs an ArmarXManagerModel
55 */
57
58 /**
59 * Model destructor
60 */
61 ~ArmarXManagerModel() override;
62
63 public slots:
64 /**
65 *
66 */
68 bool deactivateIfMissing = true);
70 /**
71 * Takes the specified selected rows via the selection model from this
72 * and appends the rows to the given destination model.
73 *
74 * @param selectionModel The selected rows
75 * @param destinationModel Manager destination model
76 */
77 void moveSelectionTo(QItemSelectionModel* selectionModel,
78 ArmarXManagerModel* destinationModel);
79
80 /**
81 * Takes the specified selected rows via the selection model from the
82 * source model and appends the rows to this one.
83 *
84 * @param selectionModel The selected rows
85 * @param sourceModel Manager source model
86 */
87 void takeSelectionFrom(QItemSelectionModel* selectionModel,
88 ArmarXManagerModel* sourceModel);
89
90 /**
91 * Deletes the selected set of rows from this model.
92 *
93 * @param selectionModel The selected rows
94 */
95 void deleteSelection(QItemSelectionModel* selectionModel);
96
97 public:
98 /**
99 * Returns a requested Model item
100 *
101 * @param row The row index of the item
102 * @param column The column index of the item
103 *
104 * @param Pointer to the ArmarXManagerItem
105 */
106 ArmarXManagerItem* getItem(int row, int column = 0) const;
107
108 /**
109 * Returns the requested manager item by its name
110 *
111 * @param name Requested manager item name
112 *
113 * @return pointer to the manager item if exists, NULL otherwise
114 */
115 ArmarXManagerItem* getManagerItemByName(const QString& name);
116
118 ManagerPrxMap getManagerProxyMap(const QStringList& managerNames) const;
119
120 /**
121 * Returns the model as a string list containing the manager names
122 *
123 * @return Manager names as string list
124 */
125 QStringList toStringList() const;
126 bool empty() const;
127
128 /**
129 * Populates this model with the given manager name list
130 *
131 * @param managerList The manager names to populate this model with.
132 */
133 void populate(const QStringList& managerList);
134
135 /**
136 * Returns a clone of this ArmarXManagerModel
137 *
138 * @return pointer to a clone of this model
139 */
141
142 /**
143 * Copies the source model content to this one. After the copy, this
144 * model is basically a clone of the source model
145 *
146 * @param source Source model to copy all content from
147 */
148 void copyFrom(ArmarXManagerModel* source);
149
150 /**
151 * Returns the data header
152 */
153 QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
154
155 /**
156 * Returns the access mutex
157 */
158 std::mutex& getMutex();
159
160 void setIceManager(IceManagerPtr iceManager);
162 enum class UserDataRoles : int
163 {
164 ComponentStarted = Qt::UserRole + 1,
168 };
175
176 public slots:
177 void updateItem(QStandardItem* item);
178
179 public:
180 /// Returns an instance of state dependent brush.
181 QBrush getBrush(armarx::ManagedIceObjectState state) const;
182
183
184 private:
185 /**
186 * Util function: Swaps a selection of rows between a source and a
187 * destination model
188 *
189 * @param sourceModel The source model providing the rows
190 * @param destinationModel The destination model which takes the
191 * selected rows
192 * @param selectionModel Model of the selected rows
193 */
194 void swapSelection(ArmarXManagerModel* sourceModel,
195 ArmarXManagerModel* destinationModel,
196 QItemSelectionModel* selectionModel);
197
198 /**
199 * Util function: Converts a selection model into a persistent index
200 * model used for swapping and deletion of multiple items.
201 *
202 * @param selectionModel The selection model to convert into
203 * a persistent model index
204 *
205 * @return A list of persistent model index
206 */
207 QList<QPersistentModelIndex> getPersistentModelIndex(QItemSelectionModel* selectionModel);
208
209
210 QStandardItem* findItem(const QString& name, QStandardItem* item);
211 QStandardItem*
212 findItemByUserData(Qt::ItemDataRole role, const QVariant& data, QStandardItem* item);
213 void syncStringListChildren(QStandardItem* item, const std::vector<QString>& strings);
214
215 static std::string
216 GenerateDependencyGraph(const std::map<std::string, DependencyMap>& dependenciesMap);
217
218 private:
219 /**
220 * Modification access mutex
221 */
222 std::mutex mutex;
223
224 IceManagerPtr iceManager;
225 std::map<std::string, DependencyMap> dependenciesMap;
226 };
227
228
229} // namespace armarx
std::map< QString, ManagerData > ManagerDataMap
void upsertManagerDetails(const ArmarXManagerItem::ManagerData &data)
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
Returns the data header.
ArmarXManagerModel * clone()
Returns a clone of this ArmarXManagerModel.
void moveSelectionTo(QItemSelectionModel *selectionModel, ArmarXManagerModel *destinationModel)
Takes the specified selected rows via the selection model from this and appends the rows to the given...
void setIceManager(IceManagerPtr iceManager)
QStringList toStringList() const
Returns the model as a string list containing the manager names.
ArmarXManagerItem * getItem(int row, int column=0) const
Returns a requested Model item.
QBrush getBrush(armarx::ManagedIceObjectState state) const
Returns an instance of state dependent brush.
void takeSelectionFrom(QItemSelectionModel *selectionModel, ArmarXManagerModel *sourceModel)
Takes the specified selected rows via the selection model from the source model and appends the rows ...
std::mutex & getMutex()
Returns the access mutex.
ArmarXManagerModel()
Constructs an ArmarXManagerModel.
ManagerPrxMap getManagerProxyMap() const
~ArmarXManagerModel() override
Model destructor.
ArmarXManagerItem * getManagerItemByName(const QString &name)
Returns the requested manager item by its name.
IceManagerPtr getIceManager() const
void updateManagerDetails(const ArmarXManagerItem::ManagerDataMap &managerDataMap, bool deactivateIfMissing=true)
void deleteSelection(QItemSelectionModel *selectionModel)
Deletes the selected set of rows from this model.
void populate(const QStringList &managerList)
Populates this model with the given manager name list.
void updateItem(QStandardItem *item)
void copyFrom(ArmarXManagerModel *source)
Copies the source model content to this one.
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::map< QString, QPair< bool, ArmarXManagerItem::ObjectMap > > StateUpdateMap
std::map< QString, ArmarXManagerInterfacePrx > ManagerPrxMap
IceUtil::Handle< IceManager > IceManagerPtr
IceManager smart pointer.
Definition ArmarXFwd.h:39