blob: e322a70a847813bf61ee80a179a2c32650b53f34 (
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
|
// SPDX-License-Identifier: GPL-2.0
#include "qt-models/divecomputerextradatamodel.h"
#include "core/dive.h"
#include "core/metrics.h"
ExtraDataModel::ExtraDataModel(QObject *parent) : CleanerTableModel(parent),
rows(0)
{
//enum Column {KEY, VALUE};
setHeaderDataStrings(QStringList() << tr("Key") << tr("Value"));
}
void ExtraDataModel::clear()
{
beginResetModel();
rows = 0;
endResetModel();
}
QVariant ExtraDataModel::data(const QModelIndex &index, int role) const
{
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 QVariant();
switch (role) {
case Qt::FontRole:
return defaultModelFont();
case Qt::TextAlignmentRole:
return static_cast<int>(Qt::AlignLeft | Qt::AlignVCenter);
case Qt::DisplayRole:
switch (index.column()) {
case KEY:
return ed->key;
case VALUE:
return ed->value;
}
return QVariant();
}
return QVariant();
}
int ExtraDataModel::rowCount(const QModelIndex&) const
{
return rows;
}
void ExtraDataModel::updateDive()
{
beginResetModel();
rows = 0;
struct extra_data *ed = get_dive_dc(&displayed_dive, dc_number)->extra_data;
while (ed) {
rows++;
ed = ed->next;
}
endResetModel();
}
|