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 
25 namespace armarx
26 {
28  QAbstractTableModel(parent)
29  {
30 
31  }
32 
34  {
35  }
36 
37 
38 
39  int ThreadViewerModel::rowCount(const QModelIndex& parent) const
40  {
41  return periodicTaskList.size();
42  }
43 
44  int ThreadViewerModel::columnCount(const QModelIndex& parent) const
45  {
46  return 8;
47  }
48 
49  QVariant ThreadViewerModel::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 >= periodicTaskList.size())
56  {
57  return QVariant();
58  }
59 
60  const PeriodicTaskIceBase& entry = periodicTaskList.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.intervalMs;
86  break;
87 
88  case 3:
89  return *entry.workloadList.rbegin() * 100.0f;
90  break;
91 
92  case 4:
93  return QString::number(0.001 * entry.lastCycleDuration, 'f', 1);
94  break;
95 
96  case 5:
97  {
98  QString date = QString::fromStdString(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(IceUtil::Time::microSeconds(entry.lastCycleStartTime).toDateTime());
106  return date.remove(0, date.indexOf(' ') + 1); // remove date
107  }
108  break;
109 
110  case 7:
111  {
112  return QString::number(entry.threadId);
113  }
114  break;
115 
116  default:
117  return QVariant();
118 
119 
120  }
121 
122  break;
123 
124  default:
125 
126  return QVariant();
127  }
128 
129  return QVariant();
130  }
131 
132  QVariant 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 
169  break;
170  }
171 
172  return QAbstractTableModel::headerData(section, orientation, role);
173  }
174 
175  void 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 }
armarx::ThreadViewerModel::data
QVariant data(const QModelIndex &index, int role) const override
Definition: ThreadViewerModel.cpp:49
armarx::ThreadViewerModel::~ThreadViewerModel
~ThreadViewerModel() override
Definition: ThreadViewerModel.cpp:33
armarx::ThreadViewerModel::setPeriodicTaskListData
void setPeriodicTaskListData(const PeriodicTaskList &periodicTaskList)
Definition: ThreadViewerModel.cpp:175
GfxTL::Orientation
ScalarT Orientation(const VectorXD< 2, ScalarT > &p1, const VectorXD< 2, ScalarT > &p2, const VectorXD< 2, ScalarT > &c)
Definition: Orientation.h:9
ThreadViewerModel.h
armarx::ThreadViewerModel::ThreadViewerModel
ThreadViewerModel(QObject *parent=0)
Definition: ThreadViewerModel.cpp:27
index
uint8_t index
Definition: EtherCATFrame.h:59
armarx::ThreadViewerModel::rowCount
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: ThreadViewerModel.cpp:39
armarx::ThreadViewerModel::headerData
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
Definition: ThreadViewerModel.cpp:132
armarx::ThreadViewerModel::columnCount
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition: ThreadViewerModel.cpp:44
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28