core: convert dive computer extra data to C++

Use std::string and std::vector. Much simpler code.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-05-18 21:04:58 +02:00 committed by bstoeger
parent b9a2eff3c9
commit bc761344d4
14 changed files with 101 additions and 161 deletions

View file

@ -1,7 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
#include "qt-models/divecomputerextradatamodel.h"
#include "core/divecomputer.h"
#include "core/extradata.h"
#include "core/metrics.h"
ExtraDataModel::ExtraDataModel(QObject *parent) : CleanerTableModel(parent)
@ -21,7 +20,7 @@ QVariant ExtraDataModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || index.row() > (int)items.size())
return QVariant();
const Item &item = items[index.row()];
const extra_data &item = items[index.row()];
switch (role) {
case Qt::FontRole:
@ -31,9 +30,9 @@ QVariant ExtraDataModel::data(const QModelIndex &index, int role) const
case Qt::DisplayRole:
switch (index.column()) {
case KEY:
return item.key;
return QString::fromStdString(item.key);
case VALUE:
return item.value;
return QString::fromStdString(item.value);
}
return QVariant();
}
@ -48,11 +47,9 @@ int ExtraDataModel::rowCount(const QModelIndex&) const
void ExtraDataModel::updateDiveComputer(const struct divecomputer *dc)
{
beginResetModel();
struct extra_data *ed = dc ? dc->extra_data : nullptr;
items.clear();
while (ed) {
items.push_back({ ed->key, ed->value });
ed = ed->next;
}
if (dc)
items = dc->extra_data;
else
items.clear();
endResetModel();
}

View file

@ -3,6 +3,7 @@
#define DIVECOMPUTEREXTRADATAMODEL_H
#include "cleanertablemodel.h"
#include "core/extradata.h"
struct divecomputer;
@ -22,11 +23,7 @@ public:
void updateDiveComputer(const struct divecomputer *dc);
private:
struct Item {
QString key;
QString value;
};
std::vector<Item> items;
std::vector<extra_data> items;
};
#endif