2017-04-27 20:25:32 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2013-04-13 20:44:02 -07:00
|
|
|
/*
|
|
|
|
* models.cpp
|
|
|
|
*
|
|
|
|
* classes for the equipment models of Subsurface
|
|
|
|
*
|
|
|
|
*/
|
2016-04-04 22:02:03 -07:00
|
|
|
#include "qt-models/models.h"
|
2018-06-03 22:15:19 +02:00
|
|
|
#include "core/qthelper.h"
|
2019-07-15 23:44:39 +02:00
|
|
|
#include "core/dive.h"
|
2018-06-17 08:48:54 +02:00
|
|
|
#include "core/gettextfromc.h"
|
2015-05-28 18:33:51 -03:00
|
|
|
|
2020-12-28 14:30:57 +01:00
|
|
|
#include <QDir>
|
2015-05-29 14:19:56 -03:00
|
|
|
#include <QLocale>
|
2013-04-24 16:57:30 +01:00
|
|
|
|
2024-05-15 17:23:39 +12:00
|
|
|
GasSelectionModel::GasSelectionModel(const dive &d, int dcNr, QObject *parent)
|
|
|
|
: QAbstractListModel(parent)
|
2013-11-14 17:39:35 -02:00
|
|
|
{
|
2024-05-15 17:23:39 +12:00
|
|
|
gasNames = get_dive_gas_list(&d, dcNr, true);
|
2013-11-14 17:39:35 -02:00
|
|
|
}
|
|
|
|
|
2024-05-15 17:23:39 +12:00
|
|
|
QVariant GasSelectionModel::data(const QModelIndex &index, int role) const
|
2013-11-14 17:39:35 -02:00
|
|
|
{
|
2024-05-15 17:23:39 +12:00
|
|
|
if (!index.isValid())
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
switch (role) {
|
|
|
|
case Qt::FontRole:
|
|
|
|
return defaultModelFont();
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
return gasNames.at(index.row()).second;
|
|
|
|
case Qt::UserRole:
|
|
|
|
return gasNames.at(index.row()).first;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QVariant();
|
2013-11-14 17:39:35 -02:00
|
|
|
}
|
2013-11-14 17:43:28 -02:00
|
|
|
|
2024-05-15 17:23:39 +12:00
|
|
|
int GasSelectionModel::rowCount(const QModelIndex&) const
|
2013-11-14 17:43:28 -02:00
|
|
|
{
|
2024-05-15 17:23:39 +12:00
|
|
|
return gasNames.size();
|
2013-11-14 17:43:28 -02:00
|
|
|
}
|
2022-11-08 07:48:49 +01:00
|
|
|
|
2018-05-08 17:26:48 +02:00
|
|
|
// Dive Type Model for the divetype combo box
|
|
|
|
|
2024-05-15 17:23:39 +12:00
|
|
|
DiveTypeSelectionModel::DiveTypeSelectionModel(const dive &d, int dcNr, QObject *parent) : QAbstractListModel(parent)
|
2018-05-08 17:26:48 +02:00
|
|
|
{
|
2024-05-15 17:23:39 +12:00
|
|
|
divemode_t mode = d.get_dc(dcNr)->divemode;
|
|
|
|
for (int i = 0; i < FREEDIVE; i++) {
|
|
|
|
switch (mode) {
|
|
|
|
case OC:
|
|
|
|
default:
|
|
|
|
if (i != OC)
|
|
|
|
continue;
|
2018-05-08 17:26:48 +02:00
|
|
|
|
2024-05-15 17:23:39 +12:00
|
|
|
break;
|
|
|
|
case CCR:
|
|
|
|
if (i != OC && i != CCR)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
break;
|
|
|
|
case PSCR:
|
|
|
|
if (i != OC && i != PSCR)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
diveTypes.push_back(std::pair(i, gettextFromC::tr(divemode_text_ui[i])));
|
|
|
|
}
|
2018-05-08 17:26:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant DiveTypeSelectionModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
2024-05-15 17:23:39 +12:00
|
|
|
if (!index.isValid())
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
switch (role) {
|
|
|
|
case Qt::FontRole:
|
2018-05-08 17:26:48 +02:00
|
|
|
return defaultModelFont();
|
2024-05-15 17:23:39 +12:00
|
|
|
case Qt::DisplayRole:
|
|
|
|
return diveTypes.at(index.row()).second;
|
|
|
|
case Qt::UserRole:
|
|
|
|
return diveTypes.at(index.row()).first;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
int DiveTypeSelectionModel::rowCount(const QModelIndex&) const
|
|
|
|
{
|
|
|
|
return diveTypes.size();
|
2018-05-08 17:26:48 +02:00
|
|
|
}
|
|
|
|
|
2013-12-06 14:29:38 -02:00
|
|
|
// Language Model, The Model to populate the list of possible Languages.
|
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
LanguageModel *LanguageModel::instance()
|
2013-12-06 14:29:38 -02:00
|
|
|
{
|
|
|
|
static LanguageModel *self = new LanguageModel();
|
|
|
|
QLocale l;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
LanguageModel::LanguageModel(QObject *parent) : QAbstractListModel(parent)
|
2013-12-06 14:29:38 -02:00
|
|
|
{
|
2013-12-06 18:30:05 -02:00
|
|
|
QDir d(getSubsurfaceDataPath("translations"));
|
2024-03-16 16:50:43 +01:00
|
|
|
for (const QString &s: d.entryList()) {
|
2014-02-27 20:09:57 -08:00
|
|
|
if (s.startsWith("subsurface_") && s.endsWith(".qm")) {
|
|
|
|
languages.push_back((s == "subsurface_source.qm") ? "English" : s);
|
2013-12-06 14:29:38 -02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
QVariant LanguageModel::data(const QModelIndex &index, int role) const
|
2013-12-06 14:29:38 -02:00
|
|
|
{
|
|
|
|
QLocale loc;
|
2013-12-06 17:48:38 -02:00
|
|
|
QString currentString = languages.at(index.row());
|
2014-01-16 11:50:56 +07:00
|
|
|
if (!index.isValid())
|
2013-12-06 14:29:38 -02:00
|
|
|
return QVariant();
|
2014-01-16 11:50:56 +07:00
|
|
|
switch (role) {
|
2014-02-12 06:18:15 -08:00
|
|
|
case Qt::DisplayRole: {
|
2016-09-20 12:47:31 -07:00
|
|
|
QLocale l(currentString.remove("subsurface_").remove(".qm"));
|
2014-02-12 06:18:15 -08:00
|
|
|
return currentString == "English" ? currentString : QString("%1 (%2)").arg(l.languageToString(l.language())).arg(l.countryToString(l.country()));
|
|
|
|
}
|
|
|
|
case Qt::UserRole:
|
2016-09-20 12:47:31 -07:00
|
|
|
return currentString == "English" ? "en_US" : currentString.remove("subsurface_").remove(".qm");
|
2013-12-06 14:29:38 -02:00
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
2018-05-21 17:53:42 +02:00
|
|
|
int LanguageModel::rowCount(const QModelIndex&) const
|
2013-12-06 14:29:38 -02:00
|
|
|
{
|
|
|
|
return languages.count();
|
|
|
|
}
|