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