ThreadViewerModel.cpp
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 Mirko Waechter ( mirko.waechter 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#include "ThreadViewerModel.h"
24
25namespace armarx
26{
27 ThreadViewerModel::ThreadViewerModel(QObject* parent) : QAbstractTableModel(parent)
28 {
29 }
30
34
35 int
36 ThreadViewerModel::rowCount(const QModelIndex& parent) const
37 {
38 return periodicTaskList.size();
39 }
40
41 int
42 ThreadViewerModel::columnCount(const QModelIndex& parent) const
43 {
44 return 8;
45 }
46
47 QVariant
48 ThreadViewerModel::data(const QModelIndex& index, int role) const
49 {
50 const unsigned int& row = index.row();
51 const unsigned int& column = index.column();
52 std::unique_lock lock(taskListsMutex);
53
54 if (row >= periodicTaskList.size())
55 {
56 return QVariant();
57 }
58
59 const PeriodicTaskIceBase& entry = periodicTaskList.at(row);
60
61 switch (role)
62 {
63 case Qt::DisplayRole:
64 case Qt::ToolTipRole:
65 switch (column)
66 {
67 case 0:
68 return QString::fromStdString(entry.name);
69 break;
70
71 case 1:
72 if (entry.running)
73 {
74 return "Yes";
75 }
76 else
77 {
78 return "No";
79 }
80
81 break;
82
83 case 2:
84 return entry.intervalMs;
85 break;
86
87 case 3:
88 return *entry.workloadList.rbegin() * 100.0f;
89 break;
90
91 case 4:
92 return QString::number(0.001 * entry.lastCycleDuration, 'f', 1);
93 break;
94
95 case 5:
96 {
97 QString date = QString::fromStdString(
98 IceUtil::Time::microSeconds(entry.startTime).toDateTime());
99 return date.remove(0, date.indexOf(' ') + 1); // remove date
100 }
101 break;
102
103 case 6:
104 {
105 QString date = QString::fromStdString(
106 IceUtil::Time::microSeconds(entry.lastCycleStartTime).toDateTime());
107 return date.remove(0, date.indexOf(' ') + 1); // remove date
108 }
109 break;
110
111 case 7:
112 {
113 return QString::number(entry.threadId);
114 }
115 break;
116
117 default:
118 return QVariant();
119 }
120
121 break;
122
123 default:
124
125 return QVariant();
126 }
127
128 return QVariant();
129 }
130
131 QVariant
132 ThreadViewerModel::headerData(int section, Qt::Orientation orientation, int role) const
133 {
134 switch (role)
135 {
136 case Qt::DisplayRole:
137 case Qt::ToolTipRole:
138 if (orientation == Qt::Horizontal)
139 {
140 switch (section)
141 {
142 case 0:
143 return "ThreadName";
144
145 case 1:
146 return "Running?";
147
148 case 2:
149 return "Interval (ms)";
150
151 case 3:
152 return "Workload";
153
154 case 4:
155 return "Last cycle duration (ms)";
156
157 case 5:
158 return "Starttime";
159
160 case 6:
161 return "Last cycle start";
162
163 case 7:
164 return "Thread Id";
165 }
166 }
167
168 break;
169 }
170
171 return QAbstractTableModel::headerData(section, orientation, role);
172 }
173
174 void
175 ThreadViewerModel::setPeriodicTaskListData(const PeriodicTaskList& periodicTaskList)
176 {
177 beginResetModel();
178
179 std::unique_lock lock(taskListsMutex);
180 this->periodicTaskList = periodicTaskList;
181 endResetModel();
182 emit dataChanged(index(0, 0), index(rowCount(), columnCount()));
183 }
184} // namespace armarx
uint8_t index
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
ThreadViewerModel(QObject *parent=0)
int columnCount(const QModelIndex &parent=QModelIndex()) const override
void setPeriodicTaskListData(const PeriodicTaskList &periodicTaskList)
QVariant data(const QModelIndex &index, int role) const override
This file offers overloads of toIce() and fromIce() functions for STL container types.