-
Notifications
You must be signed in to change notification settings - Fork 0
/
tablemodel.cpp
113 lines (103 loc) · 2.88 KB
/
tablemodel.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "tablemodel.h"
TableModel::TableModel(QObject *parent) : QAbstractTableModel(parent)
{
}
// Create a method to populate the model with data:
void TableModel::populateData(const QList<QString> &id,
const QList<QString> &description,
const QList<QString> &tgl,
const QList<QString> &tal,
const QList<QString> &tfl,
const QList<QString> &tcounter)
{
list_ID.clear();
list_ID = id;
list_Description.clear();
list_Description = description;
list_TGL.clear();
list_TGL = tgl;
list_TAL.clear();
list_TAL = tal;
list_TFL.clear();
list_TFL = tfl;
list_Counter.clear();
list_Counter = tcounter;
return;
}
int TableModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return list_ID.length();
}
int TableModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return 6;
}
QVariant TableModel::data(const QModelIndex &index, int role) const
{
int row = index.row();
int col = index.column();
switch (role)
{
case Qt::DisplayRole:
if(col == 0) return list_Counter[row];
if(col == 1) return list_ID[row];
if(col == 2) return list_TGL[row];
if(col == 3) return list_TAL[row];
if(col == 4) return list_TFL[row];
if(col == 5) return list_Description[row];
case Qt::FontRole:
if(row == 0 ||
list_Description[row].contains("EINLAGERN") ||
list_Description[row].contains("AUSLAGERN"))
{
QFont boldFont;
boldFont.setBold(true);
return boldFont;
}
case Qt::BackgroundRole:
if (row == 0 ||
list_Description[row].contains("EINLAGERN") ||
list_Description[row].contains("AUSLAGERN"))
return QBrush(Qt::darkGray);
//if(list_ID[row].contains("_X"))
// return QBrush(Qt::red);
break;
// break;
//default:
// break;
}
return QVariant();
}
QVariant TableModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (role == Qt::DisplayRole && orientation == Qt::Horizontal)
{
if (section == 0)
{
return QString("Nr");
}
else if (section == 1)
{
return QString("Tool ID");
}
else if (section == 2)
{
return QString("GL");
}
else if (section == 3)
{
return QString("AL");
}
else if (section == 4)
{
return QString("FL");
}
else if (section == 5)
{
return QString("Beschreibung");
}
}
return QVariant();
}