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 return runningTaskList.size();
39 }
40
41 int
42 RunningTaskModel::columnCount(const QModelIndex& parent) const
43 {
44 return 6;
45 }
46
47 QVariant
48 RunningTaskModel::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 >= runningTaskList.size())
55 {
56 return QVariant();
57 }
58
59 const RunningTaskIceBase& entry = runningTaskList.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.workload * 100.0f;
85 break;
86
87 case 3:
88 {
89 QString date = QString::fromStdString(
90 IceUtil::Time::microSeconds(entry.startTime).toDateTime());
91 return date.remove(0, date.indexOf(' ') + 1); // remove date
92 }
93 break;
94
95 case 4:
96 {
97 QString date = QString::fromStdString(
98 IceUtil::Time::microSeconds(entry.lastFeedbackTime).toDateTime());
99 return date.remove(0, date.indexOf(' ') + 1); // remove date
100 }
101 break;
102
103 case 5:
104 {
105 return QString::number(entry.threadId);
106 }
107 break;
108
109
110 default:
111 return QVariant();
112 }
113
114 break;
115
116 default:
117
118 return QVariant();
119 }
120
121 return QVariant();
122 }
123
124 QVariant
125 RunningTaskModel::headerData(int section, Qt::Orientation orientation, int role) const
126 {
127 switch (role)
128 {
129 case Qt::DisplayRole:
130 case Qt::ToolTipRole:
131 if (orientation == Qt::Horizontal)
132 {
133 switch (section)
134 {
135 case 0:
136 return "ThreadName";
137
138 case 1:
139 return "Running?";
140
141 case 2:
142 return "Workload";
143
144 case 3:
145 return "Starttime";
146
147 case 4:
148 return "lastFeedbackTime";
149
150 case 5:
151 return "Thread Id";
152 }
153 }
154
155 break;
156 }
157
158 return QAbstractTableModel::headerData(section, orientation, role);
159 }
160
161 void
162 RunningTaskModel::setRunningTaskListData(const RunningTaskList& runningTaskList)
163 {
164 beginResetModel();
165
166 std::unique_lock lock(taskListsMutex);
167 this->runningTaskList = runningTaskList;
168 endResetModel();
169 emit dataChanged(index(0, 0), index(rowCount(), columnCount()));
170 }
171} // 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.