mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
		
			
				
	
	
		
			113 lines
		
	
	
	
		
			2.7 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			113 lines
		
	
	
	
		
			2.7 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
/*
 | 
						|
 * models.cpp
 | 
						|
 *
 | 
						|
 * classes for the equipment models of Subsurface
 | 
						|
 *
 | 
						|
 */
 | 
						|
#include "models.h"
 | 
						|
#include "diveplanner.h"
 | 
						|
#include "mainwindow.h"
 | 
						|
#include "helpers.h"
 | 
						|
#include "dive.h"
 | 
						|
#include "device.h"
 | 
						|
#include "statistics.h"
 | 
						|
#include "qthelper.h"
 | 
						|
#include "gettextfromc.h"
 | 
						|
#include "display.h"
 | 
						|
#include "color.h"
 | 
						|
#include "divetripmodel.h"
 | 
						|
 | 
						|
#include "cleanertablemodel.h"
 | 
						|
#include "weigthsysteminfomodel.h"
 | 
						|
#include <QCoreApplication>
 | 
						|
#include <QDebug>
 | 
						|
#include <QDir>
 | 
						|
#include <QSettings>
 | 
						|
#include <QColor>
 | 
						|
#include <QBrush>
 | 
						|
#include <QFont>
 | 
						|
#include <QIcon>
 | 
						|
#include <QMessageBox>
 | 
						|
#include <QStringListModel>
 | 
						|
 | 
						|
// initialize the trash icon if necessary
 | 
						|
 | 
						|
const QPixmap &trashIcon()
 | 
						|
{
 | 
						|
	static QPixmap trash = QPixmap(":trash").scaledToHeight(defaultIconMetrics().sz_small);
 | 
						|
	return trash;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
Qt::ItemFlags GasSelectionModel::flags(const QModelIndex &index) const
 | 
						|
{
 | 
						|
	return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
 | 
						|
}
 | 
						|
 | 
						|
GasSelectionModel *GasSelectionModel::instance()
 | 
						|
{
 | 
						|
	static QScopedPointer<GasSelectionModel> self(new GasSelectionModel());
 | 
						|
	return self.data();
 | 
						|
}
 | 
						|
 | 
						|
//TODO: Remove this #include here when the issue below is fixed.
 | 
						|
#include "diveplannermodel.h"
 | 
						|
void GasSelectionModel::repopulate()
 | 
						|
{
 | 
						|
	/* 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.
 | 
						|
	 */
 | 
						|
	setStringList(DivePlannerPointsModel::instance()->getGasList());
 | 
						|
}
 | 
						|
 | 
						|
QVariant GasSelectionModel::data(const QModelIndex &index, int role) const
 | 
						|
{
 | 
						|
	if (role == Qt::FontRole) {
 | 
						|
		return defaultModelFont();
 | 
						|
	}
 | 
						|
	return QStringListModel::data(index, role);
 | 
						|
}
 | 
						|
 | 
						|
// Language Model, The Model to populate the list of possible Languages.
 | 
						|
 | 
						|
LanguageModel *LanguageModel::instance()
 | 
						|
{
 | 
						|
	static LanguageModel *self = new LanguageModel();
 | 
						|
	QLocale l;
 | 
						|
	return self;
 | 
						|
}
 | 
						|
 | 
						|
LanguageModel::LanguageModel(QObject *parent) : QAbstractListModel(parent)
 | 
						|
{
 | 
						|
	QSettings s;
 | 
						|
	QDir d(getSubsurfaceDataPath("translations"));
 | 
						|
	Q_FOREACH (const QString &s, d.entryList()) {
 | 
						|
		if (s.startsWith("subsurface_") && s.endsWith(".qm")) {
 | 
						|
			languages.push_back((s == "subsurface_source.qm") ? "English" : s);
 | 
						|
		}
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
QVariant LanguageModel::data(const QModelIndex &index, int role) const
 | 
						|
{
 | 
						|
	QLocale loc;
 | 
						|
	QString currentString = languages.at(index.row());
 | 
						|
	if (!index.isValid())
 | 
						|
		return QVariant();
 | 
						|
	switch (role) {
 | 
						|
	case Qt::DisplayRole: {
 | 
						|
		QLocale l(currentString.remove("subsurface_"));
 | 
						|
		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_");
 | 
						|
	}
 | 
						|
	return QVariant();
 | 
						|
}
 | 
						|
 | 
						|
int LanguageModel::rowCount(const QModelIndex &parent) const
 | 
						|
{
 | 
						|
	return languages.count();
 | 
						|
}
 |