mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
For the "CleanerHeaderModel" to work, the deriving class has to set the header descriptions. Failing to do so led to bug #4294. To avoid that in the future force the deriving class to pass the headers in the constructor. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
54 lines
1.2 KiB
C++
54 lines
1.2 KiB
C++
// SPDX-License-Identifier: GPL-2.0
|
|
#include "qt-models/divecomputerextradatamodel.h"
|
|
#include "core/divecomputer.h"
|
|
#include "core/metrics.h"
|
|
|
|
ExtraDataModel::ExtraDataModel(QObject *parent) :
|
|
CleanerTableModel(QStringList { tr("Key"), tr("Value") }, parent)
|
|
{
|
|
}
|
|
|
|
void ExtraDataModel::clear()
|
|
{
|
|
beginResetModel();
|
|
items.clear();
|
|
endResetModel();
|
|
}
|
|
|
|
QVariant ExtraDataModel::data(const QModelIndex &index, int role) const
|
|
{
|
|
if (!index.isValid() || index.row() > (int)items.size())
|
|
return QVariant();
|
|
const extra_data &item = items[index.row()];
|
|
|
|
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 QString::fromStdString(item.key);
|
|
case VALUE:
|
|
return QString::fromStdString(item.value);
|
|
}
|
|
return QVariant();
|
|
}
|
|
return QVariant();
|
|
}
|
|
|
|
int ExtraDataModel::rowCount(const QModelIndex&) const
|
|
{
|
|
return (int)items.size();
|
|
}
|
|
|
|
void ExtraDataModel::updateDiveComputer(const struct divecomputer *dc)
|
|
{
|
|
beginResetModel();
|
|
if (dc)
|
|
items = dc->extra_data;
|
|
else
|
|
items.clear();
|
|
endResetModel();
|
|
}
|