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
27#include <IceGrid/Admin.h>
28
29class AdapterInfoModel : public QAbstractTableModel
30{
31 Q_OBJECT
32public:
34 {
35 }
36
37 AdapterInfoModel(IceGrid::AdapterDynamicInfoSeq adapterInfo) : adapterInfo(adapterInfo)
38 {
39 }
40
41 int
42 rowCount(const QModelIndex& parent = QModelIndex()) const override
43 {
44 return adapterInfo.size();
45 }
46
47 int
48 columnCount(const QModelIndex& parent = QModelIndex()) const override
49 {
50 return 2;
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() >= (int)adapterInfo.size())
62 {
63 return QVariant();
64 }
65
66 if (role == Qt::DisplayRole)
67 {
68 switch (index.column())
69 {
70 case 0:
71 return QString::fromStdString(adapterInfo.at(index.row()).id);
72 break;
73
74 case 1:
75 {
76 // A null proxy means the adapter is deactivated; guard the deref.
77 const auto& proxy = adapterInfo.at(index.row()).proxy;
78 return proxy ? QString::fromStdString(proxy->ice_toString()) : QString();
79 }
80
81 default:
82 return QVariant();
83 }
84 }
85
86 return QVariant();
87 }
88
89 QVariant
90 headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override
91 {
92 if (role != Qt::DisplayRole)
93 {
94 return QVariant();
95 }
96
97 if (orientation == Qt::Horizontal)
98 {
99 switch (section)
100 {
101 case 0:
102 return QString("ID");
103 break;
104
105 case 1:
106 return QString("Proxy");
107 break;
108
109 default:
110 return QString("");
111 break;
112 }
113 }
114
115 return QVariant();
116 }
117
118 Qt::ItemFlags
119 flags(const QModelIndex& index) const override
120 {
121 return Qt::ItemFlags(0);
122 }
123
124 bool
125 setData(IceGrid::AdapterDynamicInfoSeq newInfo)
126 {
127 // GUI-thread only (see ServerInfoModel): no mutex, and endResetModel() already
128 // notifies the views so the out-of-range post-reset dataChanged() is gone
129 // (issues #64.12b/#64.12c/#64.13b).
130 beginResetModel();
131 adapterInfo = newInfo;
132 endResetModel();
133 return true;
134 }
135
136protected:
137 IceGrid::AdapterDynamicInfoSeq adapterInfo;
138};
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
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
int columnCount(const QModelIndex &parent=QModelIndex()) const override