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