2013-04-14 03:44:02 +00:00
|
|
|
/*
|
|
|
|
* models.cpp
|
|
|
|
*
|
|
|
|
* classes for the equipment models of Subsurface
|
|
|
|
*
|
|
|
|
*/
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "qt-models/models.h"
|
|
|
|
#include "core/helpers.h"
|
2015-05-28 21:33:51 +00:00
|
|
|
|
2015-05-29 17:19:56 +00:00
|
|
|
#include <QLocale>
|
2013-12-06 16:29:38 +00:00
|
|
|
#include <QSettings>
|
2013-04-24 15:57:30 +00:00
|
|
|
|
2014-10-19 14:15:20 +00:00
|
|
|
// initialize the trash icon if necessary
|
|
|
|
|
2014-10-31 21:28:39 +00:00
|
|
|
const QPixmap &trashIcon()
|
|
|
|
{
|
2015-05-28 19:23:49 +00:00
|
|
|
static QPixmap trash = QPixmap(":trash").scaledToHeight(defaultIconMetrics().sz_small);
|
|
|
|
return trash;
|
2013-05-22 14:00:20 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 22:27:49 +00:00
|
|
|
const QPixmap &trashForbiddenIcon()
|
|
|
|
{
|
|
|
|
static QPixmap trash = QPixmap(":trashForbidden").scaledToHeight(defaultIconMetrics().sz_small);
|
|
|
|
return trash;
|
|
|
|
}
|
2013-11-14 19:39:35 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
Qt::ItemFlags GasSelectionModel::flags(const QModelIndex &index) const
|
2013-11-14 19:39:35 +00:00
|
|
|
{
|
2016-03-08 05:27:43 +00:00
|
|
|
Q_UNUSED(index);
|
2013-11-20 02:17:50 +00:00
|
|
|
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
2013-11-14 19:39:35 +00:00
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
GasSelectionModel *GasSelectionModel::instance()
|
2013-11-14 19:39:35 +00:00
|
|
|
{
|
2013-11-30 17:18:04 +00:00
|
|
|
static QScopedPointer<GasSelectionModel> self(new GasSelectionModel());
|
|
|
|
return self.data();
|
2013-11-14 19:39:35 +00:00
|
|
|
}
|
|
|
|
|
2015-05-28 19:23:49 +00:00
|
|
|
//TODO: Remove this #include here when the issue below is fixed.
|
|
|
|
#include "diveplannermodel.h"
|
2013-11-14 19:39:35 +00:00
|
|
|
void GasSelectionModel::repopulate()
|
|
|
|
{
|
2015-05-28 19:23:49 +00:00
|
|
|
/* TODO:
|
|
|
|
* getGasList shouldn't be a member of DivePlannerPointsModel,
|
|
|
|
* it has nothing to do with the current plain being calculated:
|
|
|
|
* it's internal to the current_dive.
|
|
|
|
*/
|
2013-11-20 02:17:50 +00:00
|
|
|
setStringList(DivePlannerPointsModel::instance()->getGasList());
|
2013-11-14 19:39:35 +00:00
|
|
|
}
|
2013-11-14 19:43:28 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
QVariant GasSelectionModel::data(const QModelIndex &index, int role) const
|
2013-11-14 19:43:28 +00:00
|
|
|
{
|
2014-01-16 04:50:56 +00:00
|
|
|
if (role == Qt::FontRole) {
|
2013-11-14 19:43:28 +00:00
|
|
|
return defaultModelFont();
|
|
|
|
}
|
|
|
|
return QStringListModel::data(index, role);
|
|
|
|
}
|
2013-12-06 16:29:38 +00:00
|
|
|
|
|
|
|
// Language Model, The Model to populate the list of possible Languages.
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
LanguageModel *LanguageModel::instance()
|
2013-12-06 16:29:38 +00:00
|
|
|
{
|
|
|
|
static LanguageModel *self = new LanguageModel();
|
|
|
|
QLocale l;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
LanguageModel::LanguageModel(QObject *parent) : QAbstractListModel(parent)
|
2013-12-06 16:29:38 +00:00
|
|
|
{
|
|
|
|
QSettings s;
|
2013-12-06 20:30:05 +00:00
|
|
|
QDir d(getSubsurfaceDataPath("translations"));
|
2014-07-15 17:43:20 +00:00
|
|
|
Q_FOREACH (const QString &s, d.entryList()) {
|
2014-02-28 04:09:57 +00:00
|
|
|
if (s.startsWith("subsurface_") && s.endsWith(".qm")) {
|
|
|
|
languages.push_back((s == "subsurface_source.qm") ? "English" : s);
|
2013-12-06 16:29:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
QVariant LanguageModel::data(const QModelIndex &index, int role) const
|
2013-12-06 16:29:38 +00:00
|
|
|
{
|
|
|
|
QLocale loc;
|
2013-12-06 19:48:38 +00:00
|
|
|
QString currentString = languages.at(index.row());
|
2014-01-16 04:50:56 +00:00
|
|
|
if (!index.isValid())
|
2013-12-06 16:29:38 +00:00
|
|
|
return QVariant();
|
2014-01-16 04:50:56 +00:00
|
|
|
switch (role) {
|
2014-02-12 14:18:15 +00:00
|
|
|
case Qt::DisplayRole: {
|
2014-02-28 04:09:57 +00:00
|
|
|
QLocale l(currentString.remove("subsurface_"));
|
2014-02-12 14:18:15 +00:00
|
|
|
return currentString == "English" ? currentString : QString("%1 (%2)").arg(l.languageToString(l.language())).arg(l.countryToString(l.country()));
|
|
|
|
}
|
|
|
|
case Qt::UserRole:
|
|
|
|
return currentString == "English" ? "en_US" : currentString.remove("subsurface_");
|
2013-12-06 16:29:38 +00:00
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
int LanguageModel::rowCount(const QModelIndex &parent) const
|
2013-12-06 16:29:38 +00:00
|
|
|
{
|
2016-03-08 05:27:43 +00:00
|
|
|
Q_UNUSED(parent);
|
2013-12-06 16:29:38 +00:00
|
|
|
return languages.count();
|
|
|
|
}
|