2013-04-14 03:44:02 +00:00
|
|
|
/*
|
|
|
|
* models.cpp
|
|
|
|
*
|
|
|
|
* classes for the equipment models of Subsurface
|
|
|
|
*
|
|
|
|
*/
|
2013-04-13 13:17:59 +00:00
|
|
|
#include "models.h"
|
|
|
|
#include "../dive.h"
|
2013-04-22 01:12:36 +00:00
|
|
|
#include "../divelist.h"
|
2013-04-13 13:17:59 +00:00
|
|
|
|
2013-04-24 15:57:30 +00:00
|
|
|
#include <QtDebug>
|
|
|
|
|
2013-04-15 18:04:35 +00:00
|
|
|
extern struct tank_info tank_info[100];
|
|
|
|
|
2013-04-13 13:17:59 +00:00
|
|
|
CylindersModel::CylindersModel(QObject* parent): QAbstractTableModel(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant CylindersModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
|
|
{
|
|
|
|
QVariant ret;
|
|
|
|
if (orientation == Qt::Vertical) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (role == Qt::DisplayRole) {
|
|
|
|
switch(section) {
|
|
|
|
case TYPE:
|
2013-04-14 13:44:29 +00:00
|
|
|
ret = tr("Type");
|
2013-04-13 13:17:59 +00:00
|
|
|
break;
|
|
|
|
case SIZE:
|
2013-04-14 13:44:29 +00:00
|
|
|
ret = tr("Size");
|
2013-04-13 13:17:59 +00:00
|
|
|
break;
|
|
|
|
case MAXPRESS:
|
2013-04-14 13:44:29 +00:00
|
|
|
ret = tr("MaxPress");
|
2013-04-13 13:17:59 +00:00
|
|
|
break;
|
|
|
|
case START:
|
2013-04-14 13:44:29 +00:00
|
|
|
ret = tr("Start");
|
2013-04-13 13:17:59 +00:00
|
|
|
break;
|
|
|
|
case END:
|
2013-04-14 13:44:29 +00:00
|
|
|
ret = tr("End");
|
2013-04-13 13:17:59 +00:00
|
|
|
break;
|
|
|
|
case O2:
|
2013-04-14 13:44:29 +00:00
|
|
|
ret = tr("O2%");
|
2013-04-13 13:17:59 +00:00
|
|
|
break;
|
|
|
|
case HE:
|
2013-04-14 13:44:29 +00:00
|
|
|
ret = tr("He%");
|
2013-04-13 13:17:59 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CylindersModel::columnCount(const QModelIndex& parent) const
|
|
|
|
{
|
|
|
|
return 7;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant CylindersModel::data(const QModelIndex& index, int role) const
|
|
|
|
{
|
|
|
|
QVariant ret;
|
|
|
|
if (!index.isValid() || index.row() >= MAX_CYLINDERS) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-04-25 07:50:01 +00:00
|
|
|
struct dive *d = get_dive(selected_dive);
|
2013-04-13 13:17:59 +00:00
|
|
|
cylinder_t& cyl = d->cylinder[index.row()];
|
|
|
|
|
|
|
|
if (role == Qt::DisplayRole) {
|
|
|
|
switch(index.column()) {
|
|
|
|
case TYPE:
|
|
|
|
ret = QString(cyl.type.description);
|
|
|
|
break;
|
|
|
|
case SIZE:
|
|
|
|
ret = cyl.type.size.mliter;
|
|
|
|
break;
|
|
|
|
case MAXPRESS:
|
|
|
|
ret = cyl.type.workingpressure.mbar;
|
|
|
|
break;
|
|
|
|
case START:
|
|
|
|
ret = cyl.start.mbar;
|
|
|
|
break;
|
|
|
|
case END:
|
|
|
|
ret = cyl.end.mbar;
|
|
|
|
break;
|
|
|
|
case O2:
|
|
|
|
ret = cyl.gasmix.o2.permille;
|
|
|
|
break;
|
|
|
|
case HE:
|
|
|
|
ret = cyl.gasmix.he.permille;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CylindersModel::rowCount(const QModelIndex& parent) const
|
|
|
|
{
|
|
|
|
return usedRows[currentDive];
|
|
|
|
}
|
|
|
|
|
|
|
|
void CylindersModel::add(cylinder_t* cyl)
|
|
|
|
{
|
|
|
|
if (usedRows[currentDive] >= MAX_CYLINDERS) {
|
|
|
|
free(cyl);
|
|
|
|
}
|
|
|
|
|
|
|
|
int row = usedRows[currentDive];
|
|
|
|
|
|
|
|
cylinder_t& cylinder = currentDive->cylinder[row];
|
|
|
|
|
|
|
|
cylinder.end.mbar = cyl->end.mbar;
|
|
|
|
cylinder.start.mbar = cyl->start.mbar;
|
|
|
|
|
|
|
|
beginInsertRows(QModelIndex(), row, row);
|
|
|
|
usedRows[currentDive]++;
|
|
|
|
endInsertRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CylindersModel::update()
|
|
|
|
{
|
|
|
|
if (usedRows[currentDive] > 0) {
|
|
|
|
beginRemoveRows(QModelIndex(), 0, usedRows[currentDive]-1);
|
|
|
|
endRemoveRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
currentDive = get_dive(selected_dive);
|
|
|
|
if (usedRows[currentDive] > 0) {
|
|
|
|
beginInsertRows(QModelIndex(), 0, usedRows[currentDive]-1);
|
|
|
|
endInsertRows();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CylindersModel::clear()
|
|
|
|
{
|
|
|
|
if (usedRows[currentDive] > 0) {
|
|
|
|
beginRemoveRows(QModelIndex(), 0, usedRows[currentDive]-1);
|
|
|
|
usedRows[currentDive] = 0;
|
|
|
|
endRemoveRows();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WeightModel::clear()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int WeightModel::columnCount(const QModelIndex& parent) const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant WeightModel::data(const QModelIndex& index, int role) const
|
|
|
|
{
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
int WeightModel::rowCount(const QModelIndex& parent) const
|
|
|
|
{
|
|
|
|
return rows;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant WeightModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
|
|
{
|
|
|
|
QVariant ret;
|
|
|
|
if (orientation == Qt::Vertical) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-04-15 18:04:35 +00:00
|
|
|
switch(section) {
|
2013-04-13 13:17:59 +00:00
|
|
|
case TYPE:
|
2013-04-14 13:44:29 +00:00
|
|
|
ret = tr("Type");
|
2013-04-13 13:17:59 +00:00
|
|
|
break;
|
|
|
|
case WEIGHT:
|
2013-04-14 13:44:29 +00:00
|
|
|
ret = tr("Weight");
|
2013-04-13 13:17:59 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WeightModel::add(weight_t* weight)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void WeightModel::update()
|
|
|
|
{
|
|
|
|
}
|
2013-04-15 18:04:35 +00:00
|
|
|
|
|
|
|
void TankInfoModel::add(const QString& description)
|
|
|
|
{
|
|
|
|
// When the user `creates` a new one on the combobox.
|
|
|
|
// for now, empty till dirk cleans the GTK code.
|
|
|
|
}
|
|
|
|
|
|
|
|
void TankInfoModel::clear()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int TankInfoModel::columnCount(const QModelIndex& parent) const
|
|
|
|
{
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant TankInfoModel::data(const QModelIndex& index, int role) const
|
|
|
|
{
|
|
|
|
QVariant ret;
|
|
|
|
if (!index.isValid()) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
struct tank_info *info = &tank_info[index.row()];
|
|
|
|
|
|
|
|
int ml = info->ml;
|
|
|
|
|
|
|
|
int bar = ((info->psi) ? psi_to_bar(info->psi) : info->bar) * 1000 + 0.5;
|
|
|
|
|
|
|
|
if (info->cuft) {
|
|
|
|
double airvolume = cuft_to_l(info->cuft) * 1000.0;
|
|
|
|
ml = airvolume / bar_to_atm(bar) + 0.5;
|
|
|
|
}
|
|
|
|
if (role == Qt::DisplayRole) {
|
|
|
|
switch(index.column()) {
|
|
|
|
case BAR: ret = bar;
|
|
|
|
break;
|
|
|
|
case ML: ret = ml;
|
|
|
|
break;
|
|
|
|
case DESCRIPTION:
|
|
|
|
ret = QString(info->name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant TankInfoModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
|
|
{
|
|
|
|
QVariant ret;
|
|
|
|
|
|
|
|
if (orientation != Qt::Horizontal)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (role == Qt::DisplayRole) {
|
|
|
|
switch(section) {
|
|
|
|
case BAR:
|
|
|
|
ret = tr("Bar");
|
|
|
|
break;
|
|
|
|
case ML:
|
|
|
|
ret = tr("Ml");
|
|
|
|
break;
|
|
|
|
case DESCRIPTION:
|
|
|
|
ret = tr("Description");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TankInfoModel::rowCount(const QModelIndex& parent) const
|
|
|
|
{
|
|
|
|
return rows+1;
|
|
|
|
}
|
|
|
|
|
|
|
|
TankInfoModel::TankInfoModel() : QAbstractTableModel(), rows(-1)
|
|
|
|
{
|
|
|
|
struct tank_info *info = tank_info;
|
|
|
|
for (info = tank_info ; info->name; info++, rows++);
|
|
|
|
|
|
|
|
if (rows > -1) {
|
|
|
|
beginInsertRows(QModelIndex(), 0, rows);
|
|
|
|
endInsertRows();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TankInfoModel::update()
|
|
|
|
{
|
|
|
|
if(rows > -1) {
|
|
|
|
beginRemoveRows(QModelIndex(), 0, rows);
|
|
|
|
endRemoveRows();
|
|
|
|
}
|
|
|
|
struct tank_info *info = tank_info;
|
|
|
|
for (info = tank_info ; info->name; info++, rows++);
|
|
|
|
|
|
|
|
if (rows > -1) {
|
|
|
|
beginInsertRows(QModelIndex(), 0, rows);
|
|
|
|
endInsertRows();
|
|
|
|
}
|
|
|
|
}
|
2013-04-22 01:12:36 +00:00
|
|
|
|
|
|
|
/*! A DiveItem for use with a DiveTripModel
|
|
|
|
*
|
|
|
|
* A simple class which wraps basic stats for a dive (e.g. duration, depth) and
|
|
|
|
* tidies up after it's children. This is done manually as we don't inherit from
|
|
|
|
* QObject.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class DiveItem
|
|
|
|
{
|
|
|
|
public:
|
2013-04-25 15:38:58 +00:00
|
|
|
DiveItem(): dive(NULL), parentItem(NULL) {}
|
2013-04-25 07:50:01 +00:00
|
|
|
|
2013-04-25 15:38:58 +00:00
|
|
|
DiveItem(struct dive *d, DiveItem *parent = NULL);
|
2013-04-25 07:50:01 +00:00
|
|
|
|
2013-04-22 01:12:36 +00:00
|
|
|
~DiveItem() { qDeleteAll(childlist); }
|
|
|
|
|
2013-04-25 14:04:41 +00:00
|
|
|
int diveNumber() const { return dive->number; }
|
2013-04-26 04:10:05 +00:00
|
|
|
const QString diveDateTime() const { return get_dive_date_string(dive->when); }
|
2013-04-25 14:04:41 +00:00
|
|
|
int diveDuration() const { return dive->duration.seconds; }
|
|
|
|
int diveDepth() const { return dive->maxdepth.mm; }
|
|
|
|
int diveSac() const { return dive->sac; }
|
|
|
|
int diveOtu() const { return dive->otu; }
|
|
|
|
int diveMaxcns() const { return dive->maxcns; }
|
|
|
|
|
|
|
|
int diveWeight() const
|
|
|
|
{
|
|
|
|
weight_t tw = { total_weight(dive) };
|
|
|
|
return tw.grams;
|
|
|
|
}
|
|
|
|
|
2013-04-24 15:57:30 +00:00
|
|
|
QString displayDuration() const;
|
|
|
|
QString displayDepth() const;
|
2013-04-25 06:21:57 +00:00
|
|
|
QString displayTemperature() const;
|
|
|
|
QString displayWeight() const;
|
|
|
|
QString displaySac() const;
|
2013-04-26 04:10:05 +00:00
|
|
|
const QString diveLocation() const { return dive->location; }
|
2013-04-25 14:04:41 +00:00
|
|
|
const QString diveSuit() const { return dive->suit; }
|
2013-04-22 01:12:36 +00:00
|
|
|
DiveItem *parent() const { return parentItem; }
|
|
|
|
const QList<DiveItem *>& children() const { return childlist; }
|
|
|
|
|
|
|
|
void addChild(DiveItem* item) {
|
|
|
|
item->parentItem = this;
|
|
|
|
childlist.push_back(item);
|
|
|
|
} /* parent = self */
|
|
|
|
|
|
|
|
private:
|
2013-04-25 14:04:41 +00:00
|
|
|
struct dive *dive;
|
2013-04-22 01:12:36 +00:00
|
|
|
DiveItem *parentItem;
|
|
|
|
QList <DiveItem*> childlist;
|
|
|
|
};
|
|
|
|
|
2013-04-25 07:50:01 +00:00
|
|
|
DiveItem::DiveItem(struct dive *d, DiveItem *p):
|
2013-04-25 14:04:41 +00:00
|
|
|
dive(d),
|
2013-04-25 07:50:01 +00:00
|
|
|
parentItem(p)
|
2013-04-22 01:12:36 +00:00
|
|
|
{
|
|
|
|
if (parentItem)
|
|
|
|
parentItem->addChild(this);
|
|
|
|
}
|
|
|
|
|
2013-04-24 15:57:30 +00:00
|
|
|
QString DiveItem::displayDepth() const
|
|
|
|
{
|
|
|
|
const int scale = 1000;
|
|
|
|
QString fract, str;
|
|
|
|
if (get_units()->length == units::METERS) {
|
2013-04-25 14:04:41 +00:00
|
|
|
fract = QString::number((unsigned)(dive->maxdepth.mm % scale) / 10);
|
|
|
|
str = QString("%1.%2").arg((unsigned)(dive->maxdepth.mm / scale)).arg(fract, 2, QChar('0'));
|
2013-04-24 15:57:30 +00:00
|
|
|
}
|
|
|
|
if (get_units()->length == units::FEET) {
|
2013-04-25 14:04:41 +00:00
|
|
|
str = QString::number(mm_to_feet(dive->maxdepth.mm),'f',0);
|
2013-04-24 15:57:30 +00:00
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString DiveItem::displayDuration() const
|
|
|
|
{
|
2013-04-24 23:03:14 +00:00
|
|
|
int hrs, mins, secs;
|
2013-04-24 15:57:30 +00:00
|
|
|
|
2013-04-25 14:04:41 +00:00
|
|
|
secs = dive->duration.seconds % 60;
|
|
|
|
mins = dive->duration.seconds / 60;
|
2013-04-24 23:03:14 +00:00
|
|
|
hrs = mins / 60;
|
|
|
|
mins -= hrs * 60;
|
2013-04-24 15:57:30 +00:00
|
|
|
|
|
|
|
QString displayTime;
|
2013-04-24 23:03:14 +00:00
|
|
|
if (hrs)
|
|
|
|
displayTime = QString("%1:%2:").arg(hrs).arg(mins, 2, 10, QChar('0'));
|
2013-04-24 15:57:30 +00:00
|
|
|
else
|
2013-04-24 23:03:14 +00:00
|
|
|
displayTime = QString("%1:").arg(mins);
|
|
|
|
displayTime += QString("%1").arg(secs, 2, 10, QChar('0'));
|
2013-04-24 15:57:30 +00:00
|
|
|
return displayTime;
|
|
|
|
}
|
|
|
|
|
2013-04-25 06:21:57 +00:00
|
|
|
QString DiveItem::displayTemperature() const
|
|
|
|
{
|
|
|
|
QString str;
|
|
|
|
|
|
|
|
if (get_units()->temperature == units::CELSIUS) {
|
2013-04-25 14:04:41 +00:00
|
|
|
str = QString::number(mkelvin_to_C(dive->watertemp.mkelvin), 'f', 1);
|
2013-04-25 06:21:57 +00:00
|
|
|
} else {
|
2013-04-25 14:04:41 +00:00
|
|
|
str = QString::number(mkelvin_to_F(dive->watertemp.mkelvin), 'f', 1);
|
2013-04-25 06:21:57 +00:00
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString DiveItem::displaySac() const
|
|
|
|
{
|
|
|
|
QString str;
|
|
|
|
|
|
|
|
if (get_units()->volume == units::LITER) {
|
2013-04-25 14:04:41 +00:00
|
|
|
str = QString::number(dive->sac / 1000, 'f', 1);
|
2013-04-25 06:21:57 +00:00
|
|
|
} else {
|
2013-04-25 14:04:41 +00:00
|
|
|
str = QString::number(ml_to_cuft(dive->sac), 'f', 2);
|
2013-04-25 06:21:57 +00:00
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString DiveItem::displayWeight() const
|
|
|
|
{
|
|
|
|
QString str;
|
|
|
|
|
|
|
|
if (get_units()->weight == units::KG) {
|
2013-04-25 14:04:41 +00:00
|
|
|
int gr = diveWeight() % 1000;
|
|
|
|
int kg = diveWeight() / 1000;
|
2013-04-25 06:21:57 +00:00
|
|
|
str = QString("%1.%2").arg(kg).arg((unsigned)(gr + 500) / 100);
|
|
|
|
} else {
|
2013-04-25 14:04:41 +00:00
|
|
|
str = QString("%1").arg((unsigned)(grams_to_lbs(diveWeight()) + 0.5));
|
2013-04-25 06:21:57 +00:00
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2013-04-22 01:12:36 +00:00
|
|
|
DiveTripModel::DiveTripModel(QObject *parent) : QAbstractItemModel(parent)
|
|
|
|
{
|
|
|
|
rootItem = new DiveItem;
|
|
|
|
int i;
|
|
|
|
struct dive *d;
|
|
|
|
|
|
|
|
for_each_dive(i, d) {
|
2013-04-25 07:50:01 +00:00
|
|
|
new DiveItem(d, rootItem);
|
2013-04-22 01:12:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Qt::ItemFlags DiveTripModel::flags(const QModelIndex &index) const
|
|
|
|
{
|
|
|
|
Qt::ItemFlags diveFlags = QAbstractItemModel::flags(index);
|
|
|
|
if (index.isValid()) {
|
|
|
|
diveFlags |= Qt::ItemIsSelectable|Qt::ItemIsEnabled;
|
|
|
|
}
|
|
|
|
return diveFlags;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QVariant DiveTripModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
|
|
|
if (!index.isValid())
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
DiveItem *item = static_cast<DiveItem*>(index.internalPointer());
|
|
|
|
|
|
|
|
QVariant retVal;
|
2013-04-24 15:57:30 +00:00
|
|
|
if (role == Qt::TextAlignmentRole) {
|
|
|
|
switch (index.column()) {
|
2013-04-25 06:21:57 +00:00
|
|
|
case DATE: /* fall through */
|
|
|
|
case SUIT: /* fall through */
|
|
|
|
case LOCATION:
|
|
|
|
retVal = Qt::AlignLeft;
|
2013-04-24 15:57:30 +00:00
|
|
|
break;
|
|
|
|
default:
|
2013-04-25 06:21:57 +00:00
|
|
|
retVal = Qt::AlignRight;
|
|
|
|
break;
|
2013-04-24 15:57:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (role == Qt::DisplayRole) {
|
2013-04-22 01:12:36 +00:00
|
|
|
switch (index.column()) {
|
|
|
|
case NR:
|
|
|
|
retVal = item->diveNumber();
|
|
|
|
break;
|
|
|
|
case DATE:
|
|
|
|
retVal = item->diveDateTime();
|
|
|
|
break;
|
2013-04-25 06:21:57 +00:00
|
|
|
case DEPTH:
|
|
|
|
retVal = item->displayDepth();
|
|
|
|
break;
|
2013-04-22 01:12:36 +00:00
|
|
|
case DURATION:
|
2013-04-24 15:57:30 +00:00
|
|
|
retVal = item->displayDuration();
|
2013-04-22 01:12:36 +00:00
|
|
|
break;
|
2013-04-25 06:21:57 +00:00
|
|
|
case TEMPERATURE:
|
|
|
|
retVal = item->displayTemperature();
|
|
|
|
break;
|
|
|
|
case TOTALWEIGHT:
|
|
|
|
retVal = item->displayWeight();
|
|
|
|
break;
|
|
|
|
case SUIT:
|
|
|
|
retVal = item->diveSuit();
|
|
|
|
break;
|
|
|
|
case SAC:
|
|
|
|
retVal = item->displaySac();
|
|
|
|
break;
|
|
|
|
case OTU:
|
|
|
|
retVal = item->diveOtu();
|
|
|
|
break;
|
|
|
|
case MAXCNS:
|
|
|
|
retVal = item->diveMaxcns();
|
2013-04-22 01:12:36 +00:00
|
|
|
break;
|
|
|
|
case LOCATION:
|
|
|
|
retVal = item->diveLocation();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QVariant DiveTripModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
|
|
{
|
|
|
|
QVariant ret;
|
2013-04-24 15:57:30 +00:00
|
|
|
if (orientation != Qt::Horizontal)
|
2013-04-22 01:12:36 +00:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (role == Qt::DisplayRole) {
|
2013-04-24 15:57:30 +00:00
|
|
|
switch(section) {
|
2013-04-22 01:12:36 +00:00
|
|
|
case NR:
|
|
|
|
ret = tr("#");
|
|
|
|
break;
|
|
|
|
case DATE:
|
|
|
|
ret = tr("Date");
|
|
|
|
break;
|
|
|
|
case RATING:
|
2013-04-26 04:10:05 +00:00
|
|
|
ret = UTF8_BLACKSTAR;
|
2013-04-22 01:12:36 +00:00
|
|
|
break;
|
|
|
|
case DEPTH:
|
2013-04-24 15:57:30 +00:00
|
|
|
if (get_units()->length == units::METERS)
|
2013-04-24 23:02:41 +00:00
|
|
|
ret = tr("m");
|
2013-04-24 15:57:30 +00:00
|
|
|
else
|
2013-04-24 23:02:41 +00:00
|
|
|
ret = tr("ft");
|
2013-04-22 01:12:36 +00:00
|
|
|
break;
|
|
|
|
case DURATION:
|
2013-04-24 23:02:41 +00:00
|
|
|
ret = tr("min");
|
2013-04-22 01:12:36 +00:00
|
|
|
break;
|
|
|
|
case TEMPERATURE:
|
2013-04-24 15:57:30 +00:00
|
|
|
if (get_units()->temperature == units::CELSIUS)
|
2013-04-26 04:10:05 +00:00
|
|
|
ret = QString("%1%2").arg(UTF8_DEGREE).arg("C");
|
2013-04-24 15:57:30 +00:00
|
|
|
else
|
2013-04-26 04:10:05 +00:00
|
|
|
ret = QString("%1%2").arg(UTF8_DEGREE).arg("F");
|
2013-04-22 01:12:36 +00:00
|
|
|
break;
|
|
|
|
case TOTALWEIGHT:
|
2013-04-24 15:57:30 +00:00
|
|
|
if (get_units()->weight == units::KG)
|
2013-04-24 23:02:41 +00:00
|
|
|
ret = tr("kg");
|
2013-04-24 15:57:30 +00:00
|
|
|
else
|
2013-04-24 23:02:41 +00:00
|
|
|
ret = tr("lbs");
|
2013-04-22 01:12:36 +00:00
|
|
|
break;
|
|
|
|
case SUIT:
|
|
|
|
ret = tr("Suit");
|
|
|
|
break;
|
|
|
|
case CYLINDER:
|
|
|
|
ret = tr("Cyl");
|
|
|
|
break;
|
|
|
|
case NITROX:
|
2013-04-26 04:10:05 +00:00
|
|
|
ret = QString("O%1%").arg(UTF8_SUBSCRIPT_2);
|
2013-04-22 01:12:36 +00:00
|
|
|
break;
|
|
|
|
case SAC:
|
|
|
|
ret = tr("SAC");
|
|
|
|
break;
|
|
|
|
case OTU:
|
|
|
|
ret = tr("OTU");
|
|
|
|
break;
|
|
|
|
case MAXCNS:
|
|
|
|
ret = tr("maxCNS");
|
|
|
|
break;
|
|
|
|
case LOCATION:
|
|
|
|
ret = tr("Location");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DiveTripModel::rowCount(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
/* only allow kids in column 0 */
|
2013-04-24 15:57:30 +00:00
|
|
|
if (parent.isValid() && parent.column() > 0)
|
2013-04-22 01:12:36 +00:00
|
|
|
return 0;
|
|
|
|
DiveItem *item = itemForIndex(parent);
|
|
|
|
return item ? item->children().count() : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int DiveTripModel::columnCount(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
return parent.isValid() && parent.column() != 0 ? 0 : COLUMNS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QModelIndex DiveTripModel::index(int row, int column, const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!rootItem || row < 0 || column < 0 || column >= COLUMNS ||
|
|
|
|
(parent.isValid() && parent.column() != 0))
|
|
|
|
return QModelIndex();
|
|
|
|
|
|
|
|
DiveItem *parentItem = itemForIndex(parent);
|
|
|
|
Q_ASSERT(parentItem);
|
2013-04-24 15:57:30 +00:00
|
|
|
if (DiveItem *item = parentItem->children().at(row))
|
2013-04-22 01:12:36 +00:00
|
|
|
return createIndex(row, column, item);
|
|
|
|
return QModelIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QModelIndex DiveTripModel::parent(const QModelIndex &childIndex) const
|
|
|
|
{
|
|
|
|
if (!childIndex.isValid())
|
|
|
|
return QModelIndex();
|
|
|
|
|
|
|
|
DiveItem *child = static_cast<DiveItem*>(childIndex.internalPointer());
|
|
|
|
DiveItem *parent = child->parent();
|
|
|
|
|
|
|
|
if (parent == rootItem)
|
|
|
|
return QModelIndex();
|
|
|
|
|
|
|
|
return createIndex(parent->children().indexOf(child), 0, parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DiveItem* DiveTripModel::itemForIndex(const QModelIndex &index) const
|
|
|
|
{
|
|
|
|
if (index.isValid()) {
|
|
|
|
DiveItem *item = static_cast<DiveItem*>(index.internalPointer());
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
return rootItem;
|
|
|
|
}
|