subsurface/qt-models/tankinfomodel.cpp
Berthold Stoeger c0e8ea5188 models: pass header descriptions in CleanerTableModel constructor
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>
2024-08-31 07:36:38 +02:00

38 lines
1,016 B
C++

// SPDX-License-Identifier: GPL-2.0
#include "qt-models/tankinfomodel.h"
#include "core/dive.h"
#include "core/subsurface-qt/divelistnotifier.h"
#include "core/gettextfromc.h"
#include "core/metrics.h"
QVariant TankInfoModel::data(const QModelIndex &index, int role) const
{
if (index.row() < 0 || index.row() >= (int)tank_info_table.size())
return QVariant();
if (role == Qt::FontRole)
return defaultModelFont();
if (role == Qt::DisplayRole || role == Qt::EditRole) {
const struct tank_info &info = tank_info_table[index.row()];
auto [size, pressure] = extract_tank_info(info);
switch (index.column()) {
case BAR:
return pressure.mbar;
case ML:
return size.mliter;
case DESCRIPTION:
return QString::fromStdString(info.name);
}
}
return QVariant();
}
int TankInfoModel::rowCount(const QModelIndex&) const
{
return (int)tank_info_table.size();
}
TankInfoModel::TankInfoModel(QObject *parent) :
CleanerTableModel(QStringList{ tr("Description"), tr("ml"), tr("bar") }, parent)
{
}