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 <mutex>
26
27#include <QAbstractTableModel>
28
29#include <IceGrid/Admin.h>
30
31class AdapterInfoModel : public QAbstractTableModel
32{
33 Q_OBJECT
34public:
36 {
37 }
38
39 AdapterInfoModel(IceGrid::AdapterDynamicInfoSeq adapterInfo) : adapterInfo(adapterInfo)
40 {
41 }
42
43 int
44 rowCount(const QModelIndex& parent = QModelIndex()) const override
45 {
46 return adapterInfo.size();
47 }
48
49 int
50 columnCount(const QModelIndex& parent = QModelIndex()) const override
51 {
52 return 2;
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() >= (int)adapterInfo.size())
64 {
65 return QVariant();
66 }
67
68 if (role == Qt::DisplayRole)
69 {
70 std::unique_lock guard(adapterInfoMutex);
71
72 switch (index.column())
73 {
74 case 0:
75 return QString::fromStdString(adapterInfo.at(index.row()).id);
76 break;
77
78 case 1:
79 return QString::fromStdString(
80 adapterInfo.at(index.row()).proxy->ice_toString());
81 break;
82
83 default:
84 return QVariant();
85 }
86 }
87
88 return QVariant();
89 }
90
91 QVariant
92 headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override
93 {
94 if (role != Qt::DisplayRole)
95 {
96 return QVariant();
97 }
98
99 if (orientation == Qt::Horizontal)
100 {
101 switch (section)
102 {
103 case 0:
104 return QString("ID");
105 break;
106
107 case 1:
108 return QString("Proxy");
109 break;
110
111 default:
112 return QString("");
113 break;
114 }
115 }
116
117 return QVariant();
118 }
119
120 Qt::ItemFlags
121 flags(const QModelIndex& index) const override
122 {
123 return Qt::ItemFlags(0);
124 }
125
126 bool
127 setData(IceGrid::AdapterDynamicInfoSeq newInfo)
128 {
129 std::unique_lock guard(adapterInfoMutex);
130 beginResetModel();
131 adapterInfo = newInfo;
132 endResetModel();
133 emit dataChanged(index(0, 0), index(rowCount(), columnCount()));
134 return true;
135 }
136
137protected:
138 IceGrid::AdapterDynamicInfoSeq adapterInfo;
139 mutable std::mutex adapterInfoMutex;
140};
uint8_t index
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
AdapterInfoModel(IceGrid::AdapterDynamicInfoSeq adapterInfo)
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Qt::ItemFlags flags(const QModelIndex &index) const override
bool setData(IceGrid::AdapterDynamicInfoSeq newInfo)
IceGrid::AdapterDynamicInfoSeq adapterInfo
std::mutex adapterInfoMutex
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
int columnCount(const QModelIndex &parent=QModelIndex()) const override