mirror of
https://github.com/subsurface/subsurface.git
synced 2024-12-12 12:01:30 +00:00
0d011231e6
The combo-boxes (cylinder type, weightsystem, etc.) were controlled by global models. Keeping these models up-to-date was very combersome and buggy. Create a new model everytime a combobox is opened. Ultimately it might even be better to create a copy of the strings and switch to simple QStringListModel. Set data in the core directly and don't do this via the models. The result is much simpler and easier to handle. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
42 lines
1.1 KiB
C++
42 lines
1.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()];
|
|
int ml = info.ml;
|
|
double bar = (info.psi) ? psi_to_bar(info.psi) : info.bar;
|
|
|
|
if (info.cuft && info.psi)
|
|
ml = lrint(cuft_to_l(info.cuft) * 1000 / bar_to_atm(bar));
|
|
|
|
switch (index.column()) {
|
|
case BAR:
|
|
return bar * 1000;
|
|
case ML:
|
|
return ml;
|
|
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"));
|
|
}
|