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 "ArmarXManagerItem.h"
29 
30 #include <QMap>
31 #include <QThread>
32 #include <QStringList>
33 #include <QStandardItemModel>
34 #include <QItemSelectionModel>
35 #include <QPointer>
36 
40 
41 #include <mutex>
42 
43 namespace armarx
44 {
45  using StateUpdateMap = std::map<QString, QPair<bool, ArmarXManagerItem::ObjectMap> >;
46  using ManagerPrxMap = std::map<QString, ArmarXManagerInterfacePrx>;
48  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  */
67  void updateManagerDetails(const ArmarXManagerItem::ManagerDataMap& managerDataMap, bool deactivateIfMissing = true);
69  /**
70  * Takes the specified selected rows via the selection model from this
71  * and appends the rows to the given destination model.
72  *
73  * @param selectionModel The selected rows
74  * @param destinationModel Manager destination model
75  */
76  void moveSelectionTo(QItemSelectionModel* selectionModel,
77  ArmarXManagerModel* destinationModel);
78 
79  /**
80  * Takes the specified selected rows via the selection model from the
81  * source model and appends the rows to this one.
82  *
83  * @param selectionModel The selected rows
84  * @param sourceModel Manager source model
85  */
86  void takeSelectionFrom(QItemSelectionModel* selectionModel,
87  ArmarXManagerModel* sourceModel);
88 
89  /**
90  * Deletes the selected set of rows from this model.
91  *
92  * @param selectionModel The selected rows
93  */
94  void deleteSelection(QItemSelectionModel* selectionModel);
95 
96  public:
97  /**
98  * Returns a requested Model item
99  *
100  * @param row The row index of the item
101  * @param column The column index of the item
102  *
103  * @param Pointer to the ArmarXManagerItem
104  */
105  ArmarXManagerItem* getItem(int row, int column = 0) const;
106 
107  /**
108  * Returns the requested manager item by its name
109  *
110  * @param name Requested manager item name
111  *
112  * @return pointer to the manager item if exists, NULL otherwise
113  */
114  ArmarXManagerItem* getManagerItemByName(const QString& name);
115 
117  ManagerPrxMap getManagerProxyMap(const QStringList& managerNames) const;
118 
119  /**
120  * Returns the model as a string list containing the manager names
121  *
122  * @return Manager names as string list
123  */
124  QStringList toStringList() const;
125  bool empty() const;
126 
127  /**
128  * Populates this model with the given manager name list
129  *
130  * @param managerList The manager names to populate this model with.
131  */
132  void populate(const QStringList& managerList);
133 
134  /**
135  * Returns a clone of this ArmarXManagerModel
136  *
137  * @return pointer to a clone of this model
138  */
140 
141  /**
142  * Copies the source model content to this one. After the copy, this
143  * model is basically a clone of the source model
144  *
145  * @param source Source model to copy all content from
146  */
148 
149  /**
150  * Returns the data header
151  */
152  QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
153 
154  /**
155  * Returns the access mutex
156  */
157  std::mutex& getMutex();
158 
159  void setIceManager(IceManagerPtr iceManager);
161  enum class UserDataRoles : int
162  {
163  ComponentStarted = Qt::UserRole + 1,
165  RowType,
166  End
167  };
169  {
170  Endpoint,
172  Components
173  };
174 
175  public slots:
176  void updateItem(QStandardItem* item);
177 
178  public:
179 
180  /// Returns an instance of state dependent brush.
181  QBrush getBrush(armarx::ManagedIceObjectState state) const;
182 
183 
184  private:
185 
186  /**
187  * Util function: Swaps a selection of rows between a source and a
188  * destination model
189  *
190  * @param sourceModel The source model providing the rows
191  * @param destinationModel The destination model which takes the
192  * selected rows
193  * @param selectionModel Model of the selected rows
194  */
195  void swapSelection(ArmarXManagerModel* sourceModel,
196  ArmarXManagerModel* destinationModel,
197  QItemSelectionModel* selectionModel);
198 
199  /**
200  * Util function: Converts a selection model into a persistent index
201  * model used for swapping and deletion of multiple items.
202  *
203  * @param selectionModel The selection model to convert into
204  * a persistent model index
205  *
206  * @return A list of persistent model index
207  */
208  QList<QPersistentModelIndex> getPersistentModelIndex(
209  QItemSelectionModel* selectionModel);
210 
211 
212  QStandardItem* findItem(const QString& name, QStandardItem* item);
213  QStandardItem* findItemByUserData(Qt::ItemDataRole role, const QVariant& data, QStandardItem* item);
214  void syncStringListChildren(QStandardItem* item, const std::vector<QString>& strings);
215 
216  static std::string GenerateDependencyGraph(const std::map<std::string, DependencyMap>& dependenciesMap);
217  private:
218  /**
219  * Modification access mutex
220  */
221  std::mutex mutex;
222 
223  IceManagerPtr iceManager;
224  std::map<std::string, DependencyMap> dependenciesMap;
225  };
226 
227 
228 }
229 
ArmarXManagerItem.h
armarx::ArmarXManagerModel::getManagerItemByName
ArmarXManagerItem * getManagerItemByName(const QString &name)
Returns the requested manager item by its name.
Definition: ArmarXManagerModel.cpp:65
armarx::ArmarXManagerModel::ApplicationRowType::Components
@ Components
armarx::ArmarXManagerModel::toStringList
QStringList toStringList() const
Returns the model as a string list containing the manager names.
Definition: ArmarXManagerModel.cpp:644
armarx::StateUpdateMap
std::map< QString, QPair< bool, ArmarXManagerItem::ObjectMap > > StateUpdateMap
Definition: ArmarXManagerModel.h:45
armarx::ArmarXManagerModel::updateItem
void updateItem(QStandardItem *item)
Definition: ArmarXManagerModel.cpp:630
GfxTL::Orientation
ScalarT Orientation(const VectorXD< 2, ScalarT > &p1, const VectorXD< 2, ScalarT > &p2, const VectorXD< 2, ScalarT > &c)
Definition: Orientation.h:9
armarx::ArmarXManagerModel::getManagerProxyMap
ManagerPrxMap getManagerProxyMap() const
Definition: ArmarXManagerModel.cpp:84
armarx::ArmarXManagerModel::getMutex
std::mutex & getMutex()
Returns the access mutex.
Definition: ArmarXManagerModel.cpp:624
ArmarXManager.h
armarx::ArmarXManagerModel::empty
bool empty() const
Definition: ArmarXManagerModel.cpp:657
armarx::ArmarXManagerModel
Definition: ArmarXManagerModel.h:47
armarx::ArmarXManagerModel::ApplicationRowType
ApplicationRowType
Definition: ArmarXManagerModel.h:168
armarx::ArmarXManagerModel::clone
ArmarXManagerModel * clone()
Returns a clone of this ArmarXManagerModel.
Definition: ArmarXManagerModel.cpp:677
armarx::ArmarXManagerModel::populate
void populate(const QStringList &managerList)
Populates this model with the given manager name list.
Definition: ArmarXManagerModel.cpp:663
armarx::ArmarXManagerModel::copyFrom
void copyFrom(ArmarXManagerModel *source)
Copies the source model content to this one.
Definition: ArmarXManagerModel.cpp:695
armarx::ArmarXManagerModel::setIceManager
void setIceManager(IceManagerPtr iceManager)
Definition: ArmarXManagerModel.cpp:712
armarx::ArmarXManagerModel::UserDataRoles
UserDataRoles
Definition: ArmarXManagerModel.h:161
armarx::ArmarXManagerModel::ApplicationRowType::ApplicationProperties
@ ApplicationProperties
armarx::ArmarXManagerModel::UserDataRoles::RowType
@ RowType
armarx::ArmarXManagerModel::deleteSelection
void deleteSelection(QItemSelectionModel *selectionModel)
Deletes the selected set of rows from this model.
Definition: ArmarXManagerModel.cpp:563
armarx::ArmarXManagerModel::getIceManager
IceManagerPtr getIceManager() const
Definition: ArmarXManagerModel.cpp:718
ManagedIceObject.h
armarx::ArmarXManagerModel::upsertManagerDetails
void upsertManagerDetails(const ArmarXManagerItem::ManagerData &data)
Definition: ArmarXManagerModel.cpp:501
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::ArmarXManagerModel::UserDataRoles::ComponentStarted
@ ComponentStarted
armarx::ArmarXManagerModel::getBrush
QBrush getBrush(armarx::ManagedIceObjectState state) const
Returns an instance of state dependent brush.
Definition: ArmarXManagerModel.cpp:724
armarx::ArmarXManagerModel::UserDataRoles::ResolvedDependency
@ ResolvedDependency
armarx::ArmarXManagerItem::ManagerDataMap
std::map< QString, ManagerData > ManagerDataMap
Definition: ArmarXManagerItem.h:56
boost::source
Vertex source(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:681
armarx::ArmarXManagerModel::headerData
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
Returns the data header.
Definition: ArmarXManagerModel.cpp:603
armarx::ArmarXManagerModel::ArmarXManagerModel
ArmarXManagerModel()
Constructs an ArmarXManagerModel.
Definition: ArmarXManagerModel.cpp:46
IceUtil::Handle< IceManager >
armarx::ManagerPrxMap
std::map< QString, ArmarXManagerInterfacePrx > ManagerPrxMap
Definition: ArmarXManagerModel.h:46
ManagedIceObjectRegistryInterface.h
armarx::ArmarXManagerItem::ManagerData
Definition: ArmarXManagerItem.h:46
armarx::ArmarXManagerModel::ApplicationRowType::Endpoint
@ Endpoint
armarx::ArmarXManagerModel::updateManagerDetails
void updateManagerDetails(const ArmarXManagerItem::ManagerDataMap &managerDataMap, bool deactivateIfMissing=true)
Definition: ArmarXManagerModel.cpp:138
armarx::ArmarXManagerItem
Definition: ArmarXManagerItem.h:41
armarx::ArmarXManagerModel::getItem
ArmarXManagerItem * getItem(int row, int column=0) const
Returns a requested Model item.
Definition: ArmarXManagerModel.cpp:59
armarx::ArmarXManagerModel::~ArmarXManagerModel
~ArmarXManagerModel() override
Model destructor.
Definition: ArmarXManagerModel.cpp:53
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
armarx::ArmarXManagerModel::UserDataRoles::End
@ End