mirror of
https://github.com/subsurface/subsurface.git
synced 2024-12-11 03:21:29 +00:00
10fc3bfd47
Fix an issue introduced in #4148. Essentially the refactoring missed the fact that in the imperial system tank size is tracked as the free gas volume, but in the metric system (which is the one used in most of Subsurface's calculations) tank size is tracked as water capacity. So when updating a tank template tracking imperial measurements, the given (metric) volume in l has to be multiplied by the working pressure, and vice versa. This also combines all the logic dealing with `tank_info` data in one place, hopefully making it less likely that this will be broken by inconsistencies in the future. Fixes #4239. Signed-off-by: Michael Keller <github@ike.ch>
40 lines
1 KiB
C++
40 lines
1 KiB
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() >= tank_info_table.nr)
|
|
return QVariant();
|
|
if (role == Qt::FontRole)
|
|
return defaultModelFont();
|
|
if (role == Qt::DisplayRole || role == Qt::EditRole) {
|
|
const struct tank_info &info = tank_info_table.infos[index.row()];
|
|
volume_t size = {0};
|
|
pressure_t pressure = {0};
|
|
extract_tank_info(&info, &size, &pressure);
|
|
|
|
switch (index.column()) {
|
|
case BAR:
|
|
return pressure.mbar;
|
|
case ML:
|
|
return size.mliter;
|
|
case DESCRIPTION:
|
|
return info.name;
|
|
}
|
|
}
|
|
return QVariant();
|
|
}
|
|
|
|
int TankInfoModel::rowCount(const QModelIndex&) const
|
|
{
|
|
return tank_info_table.nr;
|
|
}
|
|
|
|
TankInfoModel::TankInfoModel(QObject *parent) : CleanerTableModel(parent)
|
|
{
|
|
setHeaderDataStrings(QStringList() << tr("Description") << tr("ml") << tr("bar"));
|
|
}
|