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 
43 namespace 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  */
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,
166  RowType,
167  End
168  };
170  {
171  Endpoint,
173  Components
174  };
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
ArmarXManagerItem.h
armarx::ArmarXManagerModel::getManagerItemByName
ArmarXManagerItem * getManagerItemByName(const QString &name)
Returns the requested manager item by its name.
Definition: ArmarXManagerModel.cpp:64
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:675
armarx::StateUpdateMap
std::map< QString, QPair< bool, ArmarXManagerItem::ObjectMap > > StateUpdateMap
Definition: ArmarXManagerModel.h:45
armarx::ArmarXManagerModel::updateItem
void updateItem(QStandardItem *item)
Definition: ArmarXManagerModel.cpp:661
GfxTL::Orientation
ScalarT Orientation(const VectorXD< 2, ScalarT > &p1, const VectorXD< 2, ScalarT > &p2, const VectorXD< 2, ScalarT > &c)
Definition: Orientation.h:10
armarx::ArmarXManagerModel::getManagerProxyMap
ManagerPrxMap getManagerProxyMap() const
Definition: ArmarXManagerModel.cpp:84
armarx::ArmarXManagerModel::getMutex
std::mutex & getMutex()
Returns the access mutex.
Definition: ArmarXManagerModel.cpp:655
ArmarXManager.h
armarx::ArmarXManagerModel::empty
bool empty() const
Definition: ArmarXManagerModel.cpp:689
armarx::ArmarXManagerModel
Definition: ArmarXManagerModel.h:48
armarx::ArmarXManagerModel::ApplicationRowType
ApplicationRowType
Definition: ArmarXManagerModel.h:169
armarx::ArmarXManagerModel::clone
ArmarXManagerModel * clone()
Returns a clone of this ArmarXManagerModel.
Definition: ArmarXManagerModel.cpp:709
armarx::ArmarXManagerModel::populate
void populate(const QStringList &managerList)
Populates this model with the given manager name list.
Definition: ArmarXManagerModel.cpp:695
armarx::ArmarXManagerModel::copyFrom
void copyFrom(ArmarXManagerModel *source)
Copies the source model content to this one.
Definition: ArmarXManagerModel.cpp:727
armarx::ArmarXManagerModel::setIceManager
void setIceManager(IceManagerPtr iceManager)
Definition: ArmarXManagerModel.cpp:744
armarx::ArmarXManagerModel::UserDataRoles
UserDataRoles
Definition: ArmarXManagerModel.h:162
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:594
armarx::ArmarXManagerModel::getIceManager
IceManagerPtr getIceManager() const
Definition: ArmarXManagerModel.cpp:750
ManagedIceObject.h
armarx::ArmarXManagerModel::upsertManagerDetails
void upsertManagerDetails(const ArmarXManagerItem::ManagerData &data)
Definition: ArmarXManagerModel.cpp:533
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:756
armarx::ArmarXManagerModel::UserDataRoles::ResolvedDependency
@ ResolvedDependency
armarx::ArmarXManagerItem::ManagerDataMap
std::map< QString, ManagerData > ManagerDataMap
Definition: ArmarXManagerItem.h:57
boost::source
Vertex source(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:661
armarx::ArmarXManagerModel::headerData
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
Returns the data header.
Definition: ArmarXManagerModel.cpp:633
armarx::ArmarXManagerModel::ArmarXManagerModel
ArmarXManagerModel()
Constructs an ArmarXManagerModel.
Definition: ArmarXManagerModel.cpp:48
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:140
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:58
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: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
armarx::ArmarXManagerModel::UserDataRoles::End
@ End