blob: 8c0c828e31d16d0ad7b27c120821cede81c82f10 (
plain) (
blame)
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
|
#include "divecomputerextradatamodel.h"
#include "dive.h"
#include "metrics.h"
ExtraDataModel::ExtraDataModel(QObject *parent) : CleanerTableModel(parent),
rows(0)
{
//enum Column {KEY, VALUE};
setHeaderDataStrings(QStringList() << tr("Key") << tr("Value"));
}
void ExtraDataModel::clear()
{
if (rows > 0) {
beginRemoveRows(QModelIndex(), 0, rows - 1);
endRemoveRows();
}
}
QVariant ExtraDataModel::data(const QModelIndex &index, int role) const
{
QVariant ret;
struct extra_data *ed = get_dive_dc(&displayed_dive, dc_number)->extra_data;
int i = -1;
while (ed && ++i < index.row())
ed = ed->next;
if (!ed)
return ret;
switch (role) {
case Qt::FontRole:
ret = defaultModelFont();
break;
case Qt::TextAlignmentRole:
ret = int(Qt::AlignLeft | Qt::AlignVCenter);
break;
case Qt::DisplayRole:
switch (index.column()) {
case KEY:
ret = QString(ed->key);
break;
case VALUE:
ret = QString(ed->value);
break;
}
break;
}
return ret;
}
int ExtraDataModel::rowCount(const QModelIndex &parent) const
{
return rows;
}
void ExtraDataModel::updateDive()
{
clear();
rows = 0;
struct extra_data *ed = get_dive_dc(&displayed_dive, dc_number)->extra_data;
while (ed) {
rows++;
ed = ed->next;
}
if (rows > 0) {
beginInsertRows(QModelIndex(), 0, rows - 1);
endInsertRows();
}
}
|