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