2017-04-27 18:25:32 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "qt-models/divecomputerextradatamodel.h"
|
|
|
|
#include "core/dive.h"
|
|
|
|
#include "core/metrics.h"
|
2015-05-28 20:29:58 +00:00
|
|
|
|
|
|
|
|
2020-05-06 20:25:48 +00:00
|
|
|
ExtraDataModel::ExtraDataModel(QObject *parent) : CleanerTableModel(parent)
|
2015-05-28 20:29:58 +00:00
|
|
|
{
|
|
|
|
//enum Column {KEY, VALUE};
|
|
|
|
setHeaderDataStrings(QStringList() << tr("Key") << tr("Value"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtraDataModel::clear()
|
|
|
|
{
|
2020-05-06 20:11:41 +00:00
|
|
|
beginResetModel();
|
2020-05-06 20:25:48 +00:00
|
|
|
items.clear();
|
2020-05-06 20:11:41 +00:00
|
|
|
endResetModel();
|
2015-05-28 20:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant ExtraDataModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
2020-05-06 20:25:48 +00:00
|
|
|
if (!index.isValid() || index.row() > (int)items.size())
|
2020-05-06 20:16:37 +00:00
|
|
|
return QVariant();
|
2020-05-06 20:25:48 +00:00
|
|
|
const Item &item = items[index.row()];
|
2015-05-28 20:29:58 +00:00
|
|
|
|
|
|
|
switch (role) {
|
|
|
|
case Qt::FontRole:
|
2020-05-06 20:16:37 +00:00
|
|
|
return defaultModelFont();
|
2015-05-28 20:29:58 +00:00
|
|
|
case Qt::TextAlignmentRole:
|
2020-05-06 20:16:37 +00:00
|
|
|
return static_cast<int>(Qt::AlignLeft | Qt::AlignVCenter);
|
2015-05-28 20:29:58 +00:00
|
|
|
case Qt::DisplayRole:
|
|
|
|
switch (index.column()) {
|
|
|
|
case KEY:
|
2020-05-06 20:25:48 +00:00
|
|
|
return item.key;
|
2015-05-28 20:29:58 +00:00
|
|
|
case VALUE:
|
2020-05-06 20:25:48 +00:00
|
|
|
return item.value;
|
2015-05-28 20:29:58 +00:00
|
|
|
}
|
2020-05-06 20:16:37 +00:00
|
|
|
return QVariant();
|
2015-05-28 20:29:58 +00:00
|
|
|
}
|
2020-05-06 20:16:37 +00:00
|
|
|
return QVariant();
|
2015-05-28 20:29:58 +00:00
|
|
|
}
|
|
|
|
|
2018-05-21 15:53:42 +00:00
|
|
|
int ExtraDataModel::rowCount(const QModelIndex&) const
|
2015-05-28 20:29:58 +00:00
|
|
|
{
|
2020-05-06 20:25:48 +00:00
|
|
|
return (int)items.size();
|
2015-05-28 20:29:58 +00:00
|
|
|
}
|
|
|
|
|
2020-05-06 20:25:48 +00:00
|
|
|
void ExtraDataModel::updateDiveComputer(const struct divecomputer *dc)
|
2015-05-28 20:29:58 +00:00
|
|
|
{
|
2020-05-06 20:11:41 +00:00
|
|
|
beginResetModel();
|
2020-05-06 20:25:48 +00:00
|
|
|
struct extra_data *ed = dc ? dc->extra_data : nullptr;
|
|
|
|
items.clear();
|
2015-05-28 20:29:58 +00:00
|
|
|
while (ed) {
|
2020-05-06 20:25:48 +00:00
|
|
|
items.push_back({ ed->key, ed->value });
|
2015-05-28 20:29:58 +00:00
|
|
|
ed = ed->next;
|
|
|
|
}
|
2020-05-06 20:11:41 +00:00
|
|
|
endResetModel();
|
2015-05-28 20:29:58 +00:00
|
|
|
}
|