RunningTaskModel.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 Adil Orhan ( ubdnw at student dot kit dot edu)
18* @date 2015
19* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20* GNU General Public License
21*/
22
23#include "RunningTaskModel.h"
24
25namespace armarx
26{
27 RunningTaskModel::RunningTaskModel(QObject* parent) : QAbstractTableModel(parent)
28 {
29 }
30
34
35 int
36 RunningTaskModel::rowCount(const QModelIndex& parent) const
37 {
38 if (parent.isValid())
39 {
40 return 0;
41 }
42 return runningTaskList.size();
43 }
44
45 int
46 RunningTaskModel::columnCount(const QModelIndex& parent) const
47 {
48 if (parent.isValid())
49 {
50 return 0;
51 }
52 return 6;
53 }
54
55 QVariant
56 RunningTaskModel::data(const QModelIndex& index, int role) const
57 {
58 const int row = index.row();
59 const int column = index.column();
60 std::unique_lock lock(taskListsMutex);
61
62 if (row < 0 || row >= static_cast<int>(runningTaskList.size()))
63 {
64 return QVariant();
65 }
66
67 const RunningTaskIceBase& entry = runningTaskList.at(row);
68
69 switch (role)
70 {
71 case Qt::DisplayRole:
72 case Qt::ToolTipRole:
73 switch (column)
74 {
75 case 0:
76 return QString::fromStdString(entry.name);
77 break;
78
79 case 1:
80 if (entry.running)
81 {
82 return "Yes";
83 }
84 else
85 {
86 return "No";
87 }
88
89 break;
90
91 case 2:
92 return entry.workload * 100.0f;
93 break;
94
95 case 3:
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 4:
104 {
105 QString date = QString::fromStdString(
106 IceUtil::Time::microSeconds(entry.lastFeedbackTime).toDateTime());
107 return date.remove(0, date.indexOf(' ') + 1); // remove date
108 }
109 break;
110
111 case 5:
112 {
113 return QString::number(entry.threadId);
114 }
115 break;
116
117
118 default:
119 return QVariant();
120 }
121
122 break;
123
124 default:
125
126 return QVariant();
127 }
128
129 return QVariant();
130 }
131
132 QVariant
133 RunningTaskModel::headerData(int section, Qt::Orientation orientation, int role) const
134 {
135 switch (role)
136 {
137 case Qt::DisplayRole:
138 case Qt::ToolTipRole:
139 if (orientation == Qt::Horizontal)
140 {
141 switch (section)
142 {
143 case 0:
144 return "ThreadName";
145
146 case 1:
147 return "Running?";
148
149 case 2:
150 return "Workload";
151
152 case 3:
153 return "Starttime";
154
155 case 4:
156 return "lastFeedbackTime";
157
158 case 5:
159 return "Thread Id";
160 }
161 }
162
163 break;
164 }
165
166 return QAbstractTableModel::headerData(section, orientation, role);
167 }
168
169 void
170 RunningTaskModel::setRunningTaskListData(const RunningTaskList& runningTaskList)
171 {
172 beginResetModel();
173 {
174 // Hold taskListsMutex only around the assignment; see ThreadViewerModel for
175 // why holding it across endResetModel() risks a self-deadlock now that the
176 // setter runs on the GUI thread (issues #64.12c/#64.14a/#64.13b).
177 std::unique_lock lock(taskListsMutex);
178 this->runningTaskList = runningTaskList;
179 }
180 endResetModel();
181 }
182} // namespace armarx
uint8_t index
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
void setRunningTaskListData(const RunningTaskList &runningTaskList)
RunningTaskModel(QObject *parent=0)
int columnCount(const QModelIndex &parent=QModelIndex()) const override
QVariant data(const QModelIndex &index, int role) const override
This file offers overloads of toIce() and fromIce() functions for STL container types.