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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
#include "models.h"
#include "../dive.h"
CylindersModel::CylindersModel(QObject* parent): QAbstractTableModel(parent)
{
}
QVariant CylindersModel::headerData(int section, Qt::Orientation orientation, int role) const
{
QVariant ret;
if (orientation == Qt::Vertical) {
return ret;
}
if (role == Qt::DisplayRole) {
switch(section) {
case TYPE:
ret = tr("Type");
break;
case SIZE:
ret = tr("Size");
break;
case MAXPRESS:
ret = tr("MaxPress");
break;
case START:
ret = tr("Start");
break;
case END:
ret = tr("End");
break;
case O2:
ret = tr("O2%");
break;
case HE:
ret = tr("He%");
break;
}
}
return ret;
}
int CylindersModel::columnCount(const QModelIndex& parent) const
{
return 7;
}
QVariant CylindersModel::data(const QModelIndex& index, int role) const
{
QVariant ret;
if (!index.isValid() || index.row() >= MAX_CYLINDERS) {
return ret;
}
dive *d = get_dive(selected_dive);
cylinder_t& cyl = d->cylinder[index.row()];
if (role == Qt::DisplayRole) {
switch(index.column()) {
case TYPE:
ret = QString(cyl.type.description);
break;
case SIZE:
ret = cyl.type.size.mliter;
break;
case MAXPRESS:
ret = cyl.type.workingpressure.mbar;
break;
case START:
ret = cyl.start.mbar;
break;
case END:
ret = cyl.end.mbar;
break;
case O2:
ret = cyl.gasmix.o2.permille;
break;
case HE:
ret = cyl.gasmix.he.permille;
break;
}
}
return ret;
}
int CylindersModel::rowCount(const QModelIndex& parent) const
{
return usedRows[currentDive];
}
void CylindersModel::add(cylinder_t* cyl)
{
if (usedRows[currentDive] >= MAX_CYLINDERS) {
free(cyl);
}
int row = usedRows[currentDive];
cylinder_t& cylinder = currentDive->cylinder[row];
cylinder.end.mbar = cyl->end.mbar;
cylinder.start.mbar = cyl->start.mbar;
beginInsertRows(QModelIndex(), row, row);
usedRows[currentDive]++;
endInsertRows();
}
void CylindersModel::update()
{
if (usedRows[currentDive] > 0) {
beginRemoveRows(QModelIndex(), 0, usedRows[currentDive]-1);
endRemoveRows();
}
currentDive = get_dive(selected_dive);
if (usedRows[currentDive] > 0) {
beginInsertRows(QModelIndex(), 0, usedRows[currentDive]-1);
endInsertRows();
}
}
void CylindersModel::clear()
{
if (usedRows[currentDive] > 0) {
beginRemoveRows(QModelIndex(), 0, usedRows[currentDive]-1);
usedRows[currentDive] = 0;
endRemoveRows();
}
}
void WeightModel::clear()
{
}
int WeightModel::columnCount(const QModelIndex& parent) const
{
return 0;
}
QVariant WeightModel::data(const QModelIndex& index, int role) const
{
return QVariant();
}
int WeightModel::rowCount(const QModelIndex& parent) const
{
return rows;
}
QVariant WeightModel::headerData(int section, Qt::Orientation orientation, int role) const
{
QVariant ret;
if (orientation == Qt::Vertical) {
return ret;
}
switch(section){
case TYPE:
ret = tr("Type");
break;
case WEIGHT:
ret = tr("Weight");
break;
}
return ret;
}
void WeightModel::add(weight_t* weight)
{
}
void WeightModel::update()
{
}
|