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"
|
2020-10-25 12:28:55 +00:00
|
|
|
#include "core/divecomputer.h"
|
2016-04-05 05:02:03 +00:00
|
|
|
#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();
|
2024-05-18 19:04:58 +00:00
|
|
|
const extra_data &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:
|
2024-05-18 19:04:58 +00:00
|
|
|
return QString::fromStdString(item.key);
|
2015-05-28 20:29:58 +00:00
|
|
|
case VALUE:
|
2024-05-18 19:04:58 +00:00
|
|
|
return QString::fromStdString(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();
|
2024-05-18 19:04:58 +00:00
|
|
|
if (dc)
|
|
|
|
items = dc->extra_data;
|
|
|
|
else
|
|
|
|
items.clear();
|
2020-05-06 20:11:41 +00:00
|
|
|
endResetModel();
|
2015-05-28 20:29:58 +00:00
|
|
|
}
|