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 
25 namespace armarx
26 {
28  QAbstractTableModel(parent)
29  {
30 
31  }
32 
34  {
35  }
36 
37 
38 
39  int RunningTaskModel::rowCount(const QModelIndex& parent) const
40  {
41  return runningTaskList.size();
42  }
43 
44  int RunningTaskModel::columnCount(const QModelIndex& parent) const
45  {
46  return 6;
47  }
48 
49  QVariant RunningTaskModel::data(const QModelIndex& index, int role) const
50  {
51  const unsigned int& row = index.row();
52  const unsigned int& column = index.column();
53  std::unique_lock lock(taskListsMutex);
54 
55  if (row >= runningTaskList.size())
56  {
57  return QVariant();
58  }
59 
60  const RunningTaskIceBase& entry = runningTaskList.at(row);
61 
62  switch (role)
63  {
64  case Qt::DisplayRole:
65  case Qt::ToolTipRole:
66  switch (column)
67  {
68  case 0:
69  return QString::fromStdString(entry.name);
70  break;
71 
72  case 1:
73  if (entry.running)
74  {
75  return "Yes";
76  }
77  else
78  {
79  return "No";
80  }
81 
82  break;
83 
84  case 2:
85  return entry.workload * 100.0f;
86  break;
87 
88  case 3:
89  {
90  QString date = QString::fromStdString(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(IceUtil::Time::microSeconds(entry.lastFeedbackTime).toDateTime());
98  return date.remove(0, date.indexOf(' ') + 1); // remove date
99  }
100  break;
101 
102  case 5:
103  {
104  return QString::number(entry.threadId);
105  }
106  break;
107 
108 
109  default:
110  return QVariant();
111  }
112 
113  break;
114 
115  default:
116 
117  return QVariant();
118  }
119 
120  return QVariant();
121  }
122 
123  QVariant RunningTaskModel::headerData(int section, Qt::Orientation orientation, int role) const
124  {
125  switch (role)
126  {
127  case Qt::DisplayRole:
128  case Qt::ToolTipRole:
129  if (orientation == Qt::Horizontal)
130  {
131  switch (section)
132  {
133  case 0:
134  return "ThreadName";
135 
136  case 1:
137  return "Running?";
138 
139  case 2:
140  return "Workload";
141 
142  case 3:
143  return "Starttime";
144 
145  case 4:
146  return "lastFeedbackTime";
147 
148  case 5:
149  return "Thread Id";
150 
151  }
152  }
153 
154  break;
155  }
156 
157  return QAbstractTableModel::headerData(section, orientation, role);
158  }
159 
160  void RunningTaskModel::setRunningTaskListData(const RunningTaskList& runningTaskList)
161  {
162  beginResetModel();
163 
164  std::unique_lock lock(taskListsMutex);
165  this->runningTaskList = runningTaskList;
166  endResetModel();
167  emit dataChanged(index(0, 0), index(rowCount(), columnCount()));
168  }
169 }
armarx::RunningTaskModel::data
QVariant data(const QModelIndex &index, int role) const override
Definition: RunningTaskModel.cpp:49
GfxTL::Orientation
ScalarT Orientation(const VectorXD< 2, ScalarT > &p1, const VectorXD< 2, ScalarT > &p2, const VectorXD< 2, ScalarT > &c)
Definition: Orientation.h:9
index
uint8_t index
Definition: EtherCATFrame.h:59
armarx::RunningTaskModel::RunningTaskModel
RunningTaskModel(QObject *parent=0)
Definition: RunningTaskModel.cpp:27
armarx::RunningTaskModel::rowCount
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: RunningTaskModel.cpp:39
armarx::RunningTaskModel::columnCount
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition: RunningTaskModel.cpp:44
armarx::RunningTaskModel::~RunningTaskModel
~RunningTaskModel() override
Definition: RunningTaskModel.cpp:33
armarx::RunningTaskModel::setRunningTaskListData
void setRunningTaskListData(const RunningTaskList &runningTaskList)
Definition: RunningTaskModel.cpp:160
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::RunningTaskModel::headerData
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
Definition: RunningTaskModel.cpp:123
RunningTaskModel.h