IceGridModel.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 "IceGridModel.h"
24 #include <QApplication>
25 #include <QPainter>
26 #include <QProgressBar>
27 
28 namespace armarx
29 {
30  IceGridModel::IceGridModel(QObject* parent) :
31  QAbstractTableModel(parent)
32  {
33  }
34 
35 
37  {
38  }
39 
40 
41  int IceGridModel::rowCount(const QModelIndex& parent) const
42  {
43  return gridNodeItemsList.size();
44  }
45 
46 
47  int IceGridModel::columnCount(const QModelIndex& parent) const
48  {
49  return 2;
50  }
51 
52 
53  QVariant IceGridModel::data(const QModelIndex& index, int role) const
54  {
55  const unsigned int& row = index.row();
56  const unsigned int& column = index.column();
57  std::unique_lock lock(gridNodeListsMutex);
58 
59  if (row >= gridNodeItemsList.size())
60  {
61  return QVariant();
62  }
63 
64  switch (role)
65  {
66  case Qt::DisplayRole:
67  case Qt::ToolTipRole:
68  switch (column)
69  {
70  case 0:
71  return QString(row);
72  break;
73 
74  case 1:
75  return QString::fromStdString(gridNodeItemsList.at(row));
76  break;
77 
78  default:
79  return QVariant();
80  }
81 
82  break;
83 
84  default:
85  return QVariant();
86  }
87 
88  return QVariant();
89  }
90 
91 
92  QVariant IceGridModel::headerData(int section, Qt::Orientation orientation, int role) const
93  {
94  switch (role)
95  {
96  case Qt::DisplayRole:
97  case Qt::ToolTipRole:
98  if (orientation == Qt::Horizontal)
99  {
100  switch (section)
101  {
102  case 0:
103  return "Item";
104 
105  case 1:
106  return "Name";
107  }
108  }
109 
110  break;
111  }
112 
113  return QAbstractTableModel::headerData(section, orientation, role);
114  }
115 
116 
117  void IceGridModel::setData(const std::vector<std::string>& gridNodeItemsList)
118  {
119  beginResetModel();
120  std::unique_lock lock(gridNodeListsMutex);
121  this->gridNodeItemsList = gridNodeItemsList;
122  endResetModel();
123  emit dataChanged(index(0, 0), index(rowCount(), columnCount()));
124  }
125 }
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::IceGridModel::IceGridModel
IceGridModel(QObject *parent=0)
Definition: IceGridModel.cpp:30
armarx::IceGridModel::setData
void setData(const std::vector< std::string > &gridNodeItemsList)
Definition: IceGridModel.cpp:117
armarx::IceGridModel::headerData
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
Definition: IceGridModel.cpp:92
armarx::IceGridModel::rowCount
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: IceGridModel.cpp:41
armarx::IceGridModel::data
QVariant data(const QModelIndex &index, int role) const override
Definition: IceGridModel.cpp:53
IceGridModel.h
armarx::IceGridModel::columnCount
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition: IceGridModel.cpp:47
armarx::IceGridModel::~IceGridModel
~IceGridModel() override
Definition: IceGridModel.cpp:36
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28