AdapterInfoModel.h
Go to the documentation of this file.
1 /*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package ArmarX::
17 * @author Manfred Kroehnert ( manfred.kroehnert at kit dot edu)
18 * @date 2013
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 
23 #pragma once
24 
25 #include <QAbstractTableModel>
26 #include <IceGrid/Admin.h>
27 
28 #include <mutex>
29 
31  public QAbstractTableModel
32 {
33  Q_OBJECT
34 public:
36  {
37  }
38 
39 
40  AdapterInfoModel(IceGrid::AdapterDynamicInfoSeq adapterInfo) :
42  {
43  }
44 
45 
46  int rowCount(const QModelIndex& parent = QModelIndex()) const override
47  {
48  return adapterInfo.size();
49  }
50 
51 
52  int columnCount(const QModelIndex& parent = QModelIndex()) const override
53  {
54  return 2;
55  }
56 
57 
58  QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override
59  {
60  if (!index.isValid())
61  {
62  return QVariant();
63  }
64 
65  if (index.row() >= (int)adapterInfo.size())
66  {
67  return QVariant();
68  }
69 
70  if (role == Qt::DisplayRole)
71  {
72  std::unique_lock guard(adapterInfoMutex);
73 
74  switch (index.column())
75  {
76  case 0:
77  return QString::fromStdString(adapterInfo.at(index.row()).id);
78  break;
79 
80  case 1:
81  return QString::fromStdString(adapterInfo.at(index.row()).proxy->ice_toString());
82  break;
83 
84  default:
85  return QVariant();
86  }
87  }
88 
89  return QVariant();
90  }
91 
92 
93  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override
94  {
95  if (role != Qt::DisplayRole)
96  {
97  return QVariant();
98  }
99 
100  if (orientation == Qt::Horizontal)
101  {
102  switch (section)
103  {
104  case 0:
105  return QString("ID");
106  break;
107 
108  case 1:
109  return QString("Proxy");
110  break;
111 
112  default:
113  return QString("");
114  break;
115  }
116  }
117 
118  return QVariant();
119  }
120 
121 
122  Qt::ItemFlags flags(const QModelIndex& index) const override
123  {
124  return Qt::ItemFlags(0);
125  }
126 
127 
128  bool setData(IceGrid::AdapterDynamicInfoSeq newInfo)
129  {
130  std::unique_lock guard(adapterInfoMutex);
131  beginResetModel();
132  adapterInfo = newInfo;
133  endResetModel();
134  emit dataChanged(index(0, 0), index(rowCount(), columnCount()));
135  return true;
136  }
137 
138 protected:
139  IceGrid::AdapterDynamicInfoSeq adapterInfo;
140  mutable std::mutex adapterInfoMutex;
141 };
142 
AdapterInfoModel::rowCount
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: AdapterInfoModel.h:46
AdapterInfoModel::setData
bool setData(IceGrid::AdapterDynamicInfoSeq newInfo)
Definition: AdapterInfoModel.h:128
GfxTL::Orientation
ScalarT Orientation(const VectorXD< 2, ScalarT > &p1, const VectorXD< 2, ScalarT > &p2, const VectorXD< 2, ScalarT > &c)
Definition: Orientation.h:9
index
uint8_t index
Definition: EtherCATFrame.h:59
AdapterInfoModel::adapterInfoMutex
std::mutex adapterInfoMutex
Definition: AdapterInfoModel.h:140
AdapterInfoModel::adapterInfo
IceGrid::AdapterDynamicInfoSeq adapterInfo
Definition: AdapterInfoModel.h:139
AdapterInfoModel::columnCount
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition: AdapterInfoModel.h:52
AdapterInfoModel::AdapterInfoModel
AdapterInfoModel()
Definition: AdapterInfoModel.h:35
AdapterInfoModel::data
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Definition: AdapterInfoModel.h:58
AdapterInfoModel::AdapterInfoModel
AdapterInfoModel(IceGrid::AdapterDynamicInfoSeq adapterInfo)
Definition: AdapterInfoModel.h:40
AdapterInfoModel
Definition: AdapterInfoModel.h:30
AdapterInfoModel::headerData
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Definition: AdapterInfoModel.h:93
AdapterInfoModel::flags
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: AdapterInfoModel.h:122