NodeInfoModel.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  NodeInfoModel(IceGrid::NodeInfo nodeInfo) :
41  {
42  }
43 
44  int rowCount(const QModelIndex& parent = QModelIndex()) const override
45  {
46  return 1;
47  }
48 
49  int columnCount(const QModelIndex& parent = QModelIndex()) const override
50  {
51  return 8;
52  }
53 
54  QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override
55  {
56  if (!index.isValid())
57  {
58  return QVariant();
59  }
60 
61  if (index.row() >= rowCount() || index.column() >= columnCount())
62  {
63  return QVariant();
64  }
65 
66  if (role == Qt::DisplayRole)
67  {
68  std::unique_lock guard(nodeInfoMutex);
69 
70  switch (index.column())
71  {
72  case 0:
73  return QString::fromStdString(nodeInfo.name);
74  break;
75 
76  case 1:
77  return QString::fromStdString(nodeInfo.os);
78  break;
79 
80  case 2:
81  return QString::fromStdString(nodeInfo.hostname);
82  break;
83 
84  case 3:
85  return QString::fromStdString(nodeInfo.release);
86  break;
87 
88  case 4:
89  return QString::fromStdString(nodeInfo.version);
90  break;
91 
92  case 5:
93  return QString::fromStdString(nodeInfo.machine);
94  break;
95 
96  case 6:
97  return QString::number(nodeInfo.nProcessors);
98  break;
99 
100  case 7:
101  return QString::fromStdString(nodeInfo.dataDir);
102  break;
103 
104  default:
105  return QVariant();
106  }
107  }
108 
109  return QVariant();
110  }
111 
112  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override
113  {
114  if (role != Qt::DisplayRole)
115  {
116  return QVariant();
117  }
118 
119  if (orientation == Qt::Horizontal)
120  {
121  switch (section)
122  {
123  case 0:
124  return QString("Name");
125  break;
126 
127  case 1:
128  return QString("OS");
129  break;
130 
131  case 2:
132  return QString("Hostname");
133  break;
134 
135  case 3:
136  return QString("Release");
137  break;
138 
139  case 4:
140  return QString("Version");
141  break;
142 
143  case 5:
144  return QString("Machine");
145  break;
146 
147  case 6:
148  return QString("#CPUs");
149  break;
150 
151  case 7:
152  return QString("DataDir");
153  break;
154 
155  default:
156  return QString("");
157  break;
158  }
159  }
160 
161  return QVariant();
162  }
163 
164  Qt::ItemFlags flags(const QModelIndex& index) const override
165  {
166  return Qt::ItemFlags(0);
167  }
168 
169  bool setData(IceGrid::NodeInfo newInfo)
170  {
171  std::unique_lock guard(nodeInfoMutex);
172  beginResetModel();
173  nodeInfo = newInfo;
174  endResetModel();
175  emit dataChanged(index(0, 0), index(rowCount(), columnCount()));
176  return true;
177  }
178 
179 protected:
180  IceGrid::NodeInfo nodeInfo;
181  mutable std::mutex nodeInfoMutex;
182 };
183 
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
NodeInfoModel::NodeInfoModel
NodeInfoModel(IceGrid::NodeInfo nodeInfo)
Definition: NodeInfoModel.h:39
NodeInfoModel::setData
bool setData(IceGrid::NodeInfo newInfo)
Definition: NodeInfoModel.h:169
NodeInfoModel::nodeInfoMutex
std::mutex nodeInfoMutex
Definition: NodeInfoModel.h:181
NodeInfoModel::headerData
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Definition: NodeInfoModel.h:112
NodeInfoModel::NodeInfoModel
NodeInfoModel()
Definition: NodeInfoModel.h:35
NodeInfoModel
Definition: NodeInfoModel.h:30
NodeInfoModel::columnCount
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition: NodeInfoModel.h:49
NodeInfoModel::flags
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: NodeInfoModel.h:164
NodeInfoModel::nodeInfo
IceGrid::NodeInfo nodeInfo
Definition: NodeInfoModel.h:180
NodeInfoModel::data
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Definition: NodeInfoModel.h:54
NodeInfoModel::rowCount
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: NodeInfoModel.h:44