2013-04-13 20:44:02 -07:00
|
|
|
/*
|
|
|
|
* models.cpp
|
|
|
|
*
|
|
|
|
* classes for the equipment models of Subsurface
|
|
|
|
*
|
|
|
|
*/
|
2013-04-13 10:17:59 -03:00
|
|
|
#include "models.h"
|
2013-11-13 21:45:54 +09:00
|
|
|
#include "diveplanner.h"
|
|
|
|
#include "mainwindow.h"
|
2014-11-03 17:32:12 -08:00
|
|
|
#include "helpers.h"
|
|
|
|
#include "dive.h"
|
|
|
|
#include "device.h"
|
|
|
|
#include "statistics.h"
|
|
|
|
#include "qthelper.h"
|
|
|
|
#include "gettextfromc.h"
|
|
|
|
#include "display.h"
|
2015-02-09 19:51:31 -02:00
|
|
|
#include "color.h"
|
2015-05-28 15:00:58 -03:00
|
|
|
#include "cleanertablemodel.h"
|
2015-05-28 16:52:13 -03:00
|
|
|
#include "weigthsysteminfomodel.h"
|
2013-05-01 23:51:34 -03:00
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QDebug>
|
2013-12-06 14:29:38 -02:00
|
|
|
#include <QDir>
|
|
|
|
#include <QSettings>
|
2013-05-02 14:19:15 -07:00
|
|
|
#include <QColor>
|
|
|
|
#include <QBrush>
|
2013-05-19 10:46:49 -03:00
|
|
|
#include <QFont>
|
2013-05-22 11:00:20 -03:00
|
|
|
#include <QIcon>
|
2013-11-13 21:45:54 +09:00
|
|
|
#include <QMessageBox>
|
2014-02-11 18:50:44 +01:00
|
|
|
#include <QStringListModel>
|
2013-04-24 16:57:30 +01:00
|
|
|
|
2014-10-19 16:15:20 +02:00
|
|
|
// initialize the trash icon if necessary
|
|
|
|
|
2014-10-31 14:28:39 -07:00
|
|
|
const QPixmap &trashIcon()
|
|
|
|
{
|
2015-05-28 16:23:49 -03:00
|
|
|
static QPixmap trash = QPixmap(":trash").scaledToHeight(defaultIconMetrics().sz_small);
|
|
|
|
return trash;
|
2013-05-22 11:00:20 -03:00
|
|
|
}
|
|
|
|
|
2013-06-17 18:59:50 -03:00
|
|
|
/*################################################################
|
|
|
|
*
|
|
|
|
* Implementation of the Dive List.
|
|
|
|
*
|
|
|
|
* ############################################################### */
|
|
|
|
struct TripItem : public TreeItem {
|
2013-05-01 23:51:34 -03:00
|
|
|
virtual QVariant data(int column, int role) const;
|
2014-02-27 20:09:57 -08:00
|
|
|
dive_trip_t *trip;
|
2013-05-01 23:51:34 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
QVariant TripItem::data(int column, int role) const
|
|
|
|
{
|
|
|
|
QVariant ret;
|
2013-04-25 16:04:41 +02:00
|
|
|
|
2013-06-26 19:16:40 -10:00
|
|
|
if (role == DiveTripModel::TRIP_ROLE)
|
2014-02-27 20:09:57 -08:00
|
|
|
return QVariant::fromValue<void *>(trip);
|
2013-06-26 19:16:40 -10:00
|
|
|
|
2013-06-17 18:59:50 -03:00
|
|
|
if (role == DiveTripModel::SORT_ROLE)
|
2013-05-29 14:54:39 +09:00
|
|
|
return (qulonglong)trip->when;
|
|
|
|
|
2013-05-02 09:33:51 -07:00
|
|
|
if (role == Qt::DisplayRole) {
|
|
|
|
switch (column) {
|
2014-02-27 20:09:57 -08:00
|
|
|
case DiveTripModel::NR:
|
2014-11-16 18:46:07 +00:00
|
|
|
QString shownText;
|
|
|
|
struct dive *d = trip->dives;
|
|
|
|
int countShown = 0;
|
|
|
|
while (d) {
|
|
|
|
if (!d->hidden_by_filter)
|
|
|
|
countShown++;
|
|
|
|
d = d->next;
|
|
|
|
}
|
|
|
|
if (countShown < trip->nrdives)
|
|
|
|
shownText = tr(" (%1 shown)").arg(countShown);
|
2013-11-19 14:16:33 -08:00
|
|
|
if (trip->location && *trip->location)
|
2014-11-16 18:46:07 +00:00
|
|
|
ret = QString(trip->location) + ", " + get_trip_date_string(trip->when, trip->nrdives) + shownText;
|
2013-11-19 14:16:33 -08:00
|
|
|
else
|
2014-11-16 18:46:07 +00:00
|
|
|
ret = get_trip_date_string(trip->when, trip->nrdives) + shownText;
|
2013-05-02 09:33:51 -07:00
|
|
|
break;
|
|
|
|
}
|
2013-05-01 23:51:34 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-05-29 14:54:39 +09:00
|
|
|
static int nitrox_sort_value(struct dive *dive)
|
|
|
|
{
|
2015-01-25 18:06:27 +01:00
|
|
|
int o2, he, o2max;
|
|
|
|
get_dive_gas(dive, &o2, &he, &o2max);
|
2014-02-27 20:09:57 -08:00
|
|
|
return he * 1000 + o2;
|
2013-05-29 14:54:39 +09:00
|
|
|
}
|
|
|
|
|
2014-10-30 10:19:39 -07:00
|
|
|
static QVariant dive_table_alignment(int column)
|
2014-09-11 22:59:52 +02:00
|
|
|
{
|
|
|
|
QVariant retVal;
|
|
|
|
switch (column) {
|
|
|
|
case DiveTripModel::DEPTH:
|
|
|
|
case DiveTripModel::DURATION:
|
|
|
|
case DiveTripModel::TEMPERATURE:
|
|
|
|
case DiveTripModel::TOTALWEIGHT:
|
|
|
|
case DiveTripModel::SAC:
|
|
|
|
case DiveTripModel::OTU:
|
|
|
|
case DiveTripModel::MAXCNS:
|
|
|
|
// Right align numeric columns
|
2014-10-30 10:19:39 -07:00
|
|
|
retVal = int(Qt::AlignRight | Qt::AlignVCenter);
|
2014-09-11 22:59:52 +02:00
|
|
|
break;
|
|
|
|
// NR needs to be left aligned becase its the indent marker for trips too
|
|
|
|
case DiveTripModel::NR:
|
|
|
|
case DiveTripModel::DATE:
|
|
|
|
case DiveTripModel::RATING:
|
|
|
|
case DiveTripModel::SUIT:
|
|
|
|
case DiveTripModel::CYLINDER:
|
|
|
|
case DiveTripModel::GAS:
|
|
|
|
case DiveTripModel::LOCATION:
|
|
|
|
retVal = int(Qt::AlignLeft | Qt::AlignVCenter);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
2013-05-01 23:51:34 -03:00
|
|
|
QVariant DiveItem::data(int column, int role) const
|
2013-04-21 22:12:36 -03:00
|
|
|
{
|
2013-05-01 23:51:34 -03:00
|
|
|
QVariant retVal;
|
2014-05-19 06:38:37 +09:00
|
|
|
struct dive *dive = get_dive_by_uniq_id(diveId);
|
2015-01-09 14:55:21 -08:00
|
|
|
if (!dive)
|
|
|
|
return QVariant();
|
2013-05-01 23:51:34 -03:00
|
|
|
|
2013-05-02 14:05:53 -07:00
|
|
|
switch (role) {
|
|
|
|
case Qt::TextAlignmentRole:
|
2014-10-30 10:19:39 -07:00
|
|
|
retVal = dive_table_alignment(column);
|
2013-05-02 14:05:53 -07:00
|
|
|
break;
|
2014-02-27 20:09:57 -08:00
|
|
|
case DiveTripModel::SORT_ROLE:
|
2014-01-07 12:22:22 +08:00
|
|
|
Q_ASSERT(dive != NULL);
|
2013-05-29 14:54:39 +09:00
|
|
|
switch (column) {
|
2014-02-27 20:09:57 -08:00
|
|
|
case NR:
|
|
|
|
retVal = (qulonglong)dive->when;
|
|
|
|
break;
|
|
|
|
case DATE:
|
|
|
|
retVal = (qulonglong)dive->when;
|
|
|
|
break;
|
|
|
|
case RATING:
|
|
|
|
retVal = dive->rating;
|
|
|
|
break;
|
|
|
|
case DEPTH:
|
|
|
|
retVal = dive->maxdepth.mm;
|
|
|
|
break;
|
|
|
|
case DURATION:
|
|
|
|
retVal = dive->duration.seconds;
|
|
|
|
break;
|
|
|
|
case TEMPERATURE:
|
|
|
|
retVal = dive->watertemp.mkelvin;
|
|
|
|
break;
|
|
|
|
case TOTALWEIGHT:
|
|
|
|
retVal = total_weight(dive);
|
|
|
|
break;
|
|
|
|
case SUIT:
|
|
|
|
retVal = QString(dive->suit);
|
|
|
|
break;
|
|
|
|
case CYLINDER:
|
|
|
|
retVal = QString(dive->cylinder[0].type.description);
|
|
|
|
break;
|
2014-07-20 15:07:56 +02:00
|
|
|
case GAS:
|
2014-02-27 20:09:57 -08:00
|
|
|
retVal = nitrox_sort_value(dive);
|
|
|
|
break;
|
|
|
|
case SAC:
|
|
|
|
retVal = dive->sac;
|
|
|
|
break;
|
|
|
|
case OTU:
|
|
|
|
retVal = dive->otu;
|
|
|
|
break;
|
|
|
|
case MAXCNS:
|
|
|
|
retVal = dive->maxcns;
|
|
|
|
break;
|
|
|
|
case LOCATION:
|
2015-02-12 12:54:20 -08:00
|
|
|
retVal = QString(get_dive_location(dive));
|
2014-02-27 20:09:57 -08:00
|
|
|
break;
|
2013-05-29 14:54:39 +09:00
|
|
|
}
|
|
|
|
break;
|
2013-05-02 14:05:53 -07:00
|
|
|
case Qt::DisplayRole:
|
2014-01-07 12:22:22 +08:00
|
|
|
Q_ASSERT(dive != NULL);
|
2013-05-01 23:51:34 -03:00
|
|
|
switch (column) {
|
2014-02-27 20:09:57 -08:00
|
|
|
case NR:
|
|
|
|
retVal = dive->number;
|
|
|
|
break;
|
|
|
|
case DATE:
|
|
|
|
retVal = displayDate();
|
|
|
|
break;
|
|
|
|
case DEPTH:
|
|
|
|
retVal = displayDepth();
|
|
|
|
break;
|
|
|
|
case DURATION:
|
|
|
|
retVal = displayDuration();
|
|
|
|
break;
|
|
|
|
case TEMPERATURE:
|
|
|
|
retVal = displayTemperature();
|
|
|
|
break;
|
|
|
|
case TOTALWEIGHT:
|
|
|
|
retVal = displayWeight();
|
|
|
|
break;
|
|
|
|
case SUIT:
|
|
|
|
retVal = QString(dive->suit);
|
|
|
|
break;
|
|
|
|
case CYLINDER:
|
|
|
|
retVal = QString(dive->cylinder[0].type.description);
|
|
|
|
break;
|
|
|
|
case SAC:
|
|
|
|
retVal = displaySac();
|
|
|
|
break;
|
|
|
|
case OTU:
|
|
|
|
retVal = dive->otu;
|
|
|
|
break;
|
|
|
|
case MAXCNS:
|
|
|
|
retVal = dive->maxcns;
|
|
|
|
break;
|
|
|
|
case LOCATION:
|
2015-02-12 12:54:20 -08:00
|
|
|
retVal = QString(get_dive_location(dive));
|
2014-02-27 20:09:57 -08:00
|
|
|
break;
|
2014-12-18 08:47:43 +01:00
|
|
|
case GAS:
|
|
|
|
const char *gas_string = get_dive_gas_string(dive);
|
|
|
|
retVal = QString(gas_string);
|
|
|
|
free((void*)gas_string);
|
|
|
|
break;
|
2013-05-01 23:51:34 -03:00
|
|
|
}
|
2013-05-02 14:05:53 -07:00
|
|
|
break;
|
2014-10-30 07:40:22 -07:00
|
|
|
case Qt::ToolTipRole:
|
|
|
|
switch (column) {
|
|
|
|
case NR:
|
|
|
|
retVal = tr("#");
|
|
|
|
break;
|
|
|
|
case DATE:
|
|
|
|
retVal = tr("Date");
|
|
|
|
break;
|
|
|
|
case RATING:
|
|
|
|
retVal = tr("Rating");
|
|
|
|
break;
|
|
|
|
case DEPTH:
|
|
|
|
retVal = tr("Depth(%1)").arg((get_units()->length == units::METERS) ? tr("m") : tr("ft"));
|
|
|
|
break;
|
|
|
|
case DURATION:
|
|
|
|
retVal = tr("Duration");
|
|
|
|
break;
|
|
|
|
case TEMPERATURE:
|
|
|
|
retVal = tr("Temp(%1%2)").arg(UTF8_DEGREE).arg((get_units()->temperature == units::CELSIUS) ? "C" : "F");
|
|
|
|
break;
|
|
|
|
case TOTALWEIGHT:
|
|
|
|
retVal = tr("Weight(%1)").arg((get_units()->weight == units::KG) ? tr("kg") : tr("lbs"));
|
|
|
|
break;
|
|
|
|
case SUIT:
|
|
|
|
retVal = tr("Suit");
|
|
|
|
break;
|
|
|
|
case CYLINDER:
|
|
|
|
retVal = tr("Cyl");
|
|
|
|
break;
|
|
|
|
case GAS:
|
|
|
|
retVal = tr("Gas");
|
|
|
|
break;
|
|
|
|
case SAC:
|
|
|
|
const char *unit;
|
|
|
|
get_volume_units(0, NULL, &unit);
|
|
|
|
retVal = tr("SAC(%1)").arg(QString(unit).append(tr("/min")));
|
|
|
|
break;
|
|
|
|
case OTU:
|
|
|
|
retVal = tr("OTU");
|
|
|
|
break;
|
|
|
|
case MAXCNS:
|
|
|
|
retVal = tr("Max CNS");
|
|
|
|
break;
|
|
|
|
case LOCATION:
|
|
|
|
retVal = tr("Location");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2013-05-01 23:51:34 -03:00
|
|
|
}
|
2013-05-02 20:32:57 -03:00
|
|
|
|
2014-01-07 12:22:22 +08:00
|
|
|
if (role == DiveTripModel::STAR_ROLE) {
|
|
|
|
Q_ASSERT(dive != NULL);
|
2013-05-02 20:32:57 -03:00
|
|
|
retVal = dive->rating;
|
2014-01-07 12:22:22 +08:00
|
|
|
}
|
|
|
|
if (role == DiveTripModel::DIVE_ROLE) {
|
2014-02-27 20:09:57 -08:00
|
|
|
retVal = QVariant::fromValue<void *>(dive);
|
2014-01-07 12:22:22 +08:00
|
|
|
}
|
2014-01-16 11:50:56 +07:00
|
|
|
if (role == DiveTripModel::DIVE_IDX) {
|
2014-01-07 12:22:22 +08:00
|
|
|
Q_ASSERT(dive != NULL);
|
2013-11-16 18:41:47 -02:00
|
|
|
retVal = get_divenr(dive);
|
|
|
|
}
|
2013-05-01 23:51:34 -03:00
|
|
|
return retVal;
|
2013-04-21 22:12:36 -03:00
|
|
|
}
|
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
Qt::ItemFlags DiveItem::flags(const QModelIndex &index) const
|
2013-11-18 22:33:01 -02:00
|
|
|
{
|
2014-01-16 11:50:56 +07:00
|
|
|
if (index.column() == NR) {
|
2013-11-18 22:33:01 -02:00
|
|
|
return TreeItem::flags(index) | Qt::ItemIsEditable;
|
|
|
|
}
|
|
|
|
return TreeItem::flags(index);
|
|
|
|
}
|
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
bool DiveItem::setData(const QModelIndex &index, const QVariant &value, int role)
|
2013-11-18 22:33:01 -02:00
|
|
|
{
|
|
|
|
if (role != Qt::EditRole)
|
|
|
|
return false;
|
|
|
|
if (index.column() != NR)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
int v = value.toInt();
|
2013-11-18 22:34:22 -02:00
|
|
|
if (v == 0)
|
|
|
|
return false;
|
|
|
|
|
2013-11-18 22:33:01 -02:00
|
|
|
int i;
|
|
|
|
struct dive *d;
|
2014-05-22 11:40:22 -07:00
|
|
|
for_each_dive (i, d) {
|
2013-11-18 22:33:01 -02:00
|
|
|
if (d->number == v)
|
|
|
|
return false;
|
|
|
|
}
|
2014-05-19 06:38:37 +09:00
|
|
|
d = get_dive_by_uniq_id(diveId);
|
2014-01-07 11:57:20 +08:00
|
|
|
d->number = value.toInt();
|
2014-01-15 09:30:42 +01:00
|
|
|
mark_divelist_changed(true);
|
2013-11-18 22:33:01 -02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-07-11 12:41:50 +03:00
|
|
|
QString DiveItem::displayDate() const
|
|
|
|
{
|
2014-05-19 06:38:37 +09:00
|
|
|
struct dive *dive = get_dive_by_uniq_id(diveId);
|
2013-10-17 01:00:17 +03:00
|
|
|
return get_dive_date_string(dive->when);
|
2013-07-11 12:41:50 +03:00
|
|
|
}
|
|
|
|
|
2013-04-24 16:57:30 +01:00
|
|
|
QString DiveItem::displayDepth() const
|
|
|
|
{
|
2014-05-19 06:38:37 +09:00
|
|
|
struct dive *dive = get_dive_by_uniq_id(diveId);
|
2014-07-11 21:59:21 -07:00
|
|
|
return get_depth_string(dive->maxdepth);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString DiveItem::displayDepthWithUnit() const
|
|
|
|
{
|
|
|
|
struct dive *dive = get_dive_by_uniq_id(diveId);
|
|
|
|
return get_depth_string(dive->maxdepth, true);
|
2013-04-24 16:57:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QString DiveItem::displayDuration() const
|
|
|
|
{
|
2015-05-16 12:42:26 +02:00
|
|
|
int hrs, mins, fullmins, secs;
|
2014-05-19 06:38:37 +09:00
|
|
|
struct dive *dive = get_dive_by_uniq_id(diveId);
|
2014-10-31 14:28:39 -07:00
|
|
|
mins = (dive->duration.seconds + 59) / 60;
|
2015-05-16 12:42:26 +02:00
|
|
|
fullmins = dive->duration.seconds / 60;
|
|
|
|
secs = dive->duration.seconds - 60 * fullmins;
|
2013-04-24 16:03:14 -07:00
|
|
|
hrs = mins / 60;
|
|
|
|
mins -= hrs * 60;
|
2013-04-24 16:57:30 +01:00
|
|
|
|
|
|
|
QString displayTime;
|
2013-04-24 16:03:14 -07:00
|
|
|
if (hrs)
|
2014-10-30 09:49:05 -07:00
|
|
|
displayTime = QString("%1:%2").arg(hrs).arg(mins, 2, 10, QChar('0'));
|
2015-05-16 12:42:26 +02:00
|
|
|
else if (mins < 15 || dive->dc.divemode == FREEDIVE)
|
|
|
|
displayTime = QString("%1m%2s").arg(fullmins).arg(secs, 2, 10, QChar('0'));
|
2013-04-24 16:57:30 +01:00
|
|
|
else
|
2014-10-30 09:49:05 -07:00
|
|
|
displayTime = QString("%1").arg(mins);
|
2013-04-24 16:57:30 +01:00
|
|
|
return displayTime;
|
|
|
|
}
|
|
|
|
|
2013-04-24 23:21:57 -07:00
|
|
|
QString DiveItem::displayTemperature() const
|
|
|
|
{
|
|
|
|
QString str;
|
2014-05-19 06:38:37 +09:00
|
|
|
struct dive *dive = get_dive_by_uniq_id(diveId);
|
2013-05-14 09:45:01 +02:00
|
|
|
if (!dive->watertemp.mkelvin)
|
|
|
|
return str;
|
2013-05-01 22:00:08 -07:00
|
|
|
if (get_units()->temperature == units::CELSIUS)
|
2013-04-25 16:04:41 +02:00
|
|
|
str = QString::number(mkelvin_to_C(dive->watertemp.mkelvin), 'f', 1);
|
2013-05-01 22:00:08 -07:00
|
|
|
else
|
2013-04-25 16:04:41 +02:00
|
|
|
str = QString::number(mkelvin_to_F(dive->watertemp.mkelvin), 'f', 1);
|
2013-04-24 23:21:57 -07:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString DiveItem::displaySac() const
|
|
|
|
{
|
|
|
|
QString str;
|
2014-05-19 06:38:37 +09:00
|
|
|
struct dive *dive = get_dive_by_uniq_id(diveId);
|
2014-08-06 07:38:18 -07:00
|
|
|
if (dive->sac) {
|
|
|
|
const char *unit;
|
|
|
|
int decimal;
|
|
|
|
double value = get_volume_units(dive->sac, &decimal, &unit);
|
2014-08-22 14:41:24 -07:00
|
|
|
return QString::number(value, 'f', decimal);
|
2014-08-06 07:38:18 -07:00
|
|
|
}
|
|
|
|
return QString("");
|
2013-04-24 23:21:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
QString DiveItem::displayWeight() const
|
|
|
|
{
|
2013-10-04 21:39:33 +03:00
|
|
|
QString str = weight_string(weight());
|
2013-04-24 23:21:57 -07:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2013-05-01 23:51:34 -03:00
|
|
|
int DiveItem::weight() const
|
2013-04-21 22:12:36 -03:00
|
|
|
{
|
2014-05-19 06:38:37 +09:00
|
|
|
struct dive *dive = get_dive_by_uniq_id(diveId);
|
2013-05-01 23:51:34 -03:00
|
|
|
weight_t tw = { total_weight(dive) };
|
|
|
|
return tw.grams;
|
2013-04-21 22:12:36 -03:00
|
|
|
}
|
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
DiveTripModel::DiveTripModel(QObject *parent) : TreeModel(parent)
|
2013-05-01 23:51:34 -03:00
|
|
|
{
|
2013-06-17 18:59:50 -03:00
|
|
|
columns = COLUMNS;
|
2013-04-21 22:12:36 -03:00
|
|
|
}
|
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
Qt::ItemFlags DiveTripModel::flags(const QModelIndex &index) const
|
2013-04-21 22:12:36 -03:00
|
|
|
{
|
2013-05-01 23:51:34 -03:00
|
|
|
if (!index.isValid())
|
2013-04-21 22:12:36 -03:00
|
|
|
return 0;
|
2013-05-01 23:51:34 -03:00
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
TripItem *item = static_cast<TripItem *>(index.internalPointer());
|
2013-11-18 22:33:01 -02:00
|
|
|
return item->flags(index);
|
2013-04-21 22:12:36 -03:00
|
|
|
}
|
|
|
|
|
2013-06-17 18:59:50 -03:00
|
|
|
QVariant DiveTripModel::headerData(int section, Qt::Orientation orientation, int role) const
|
2013-04-21 22:12:36 -03:00
|
|
|
{
|
2013-06-17 18:59:50 -03:00
|
|
|
QVariant ret;
|
|
|
|
if (orientation == Qt::Vertical)
|
|
|
|
return ret;
|
2013-04-21 22:12:36 -03:00
|
|
|
|
2014-01-16 11:50:56 +07:00
|
|
|
switch (role) {
|
2014-09-11 22:59:52 +02:00
|
|
|
case Qt::TextAlignmentRole:
|
2014-10-30 10:19:39 -07:00
|
|
|
ret = dive_table_alignment(section);
|
2014-09-11 22:59:52 +02:00
|
|
|
break;
|
2014-02-27 20:09:57 -08:00
|
|
|
case Qt::FontRole:
|
|
|
|
ret = defaultModelFont();
|
|
|
|
break;
|
|
|
|
case Qt::DisplayRole:
|
2014-10-30 07:40:22 -07:00
|
|
|
switch (section) {
|
|
|
|
case NR:
|
|
|
|
ret = tr("#");
|
|
|
|
break;
|
|
|
|
case DATE:
|
|
|
|
ret = tr("Date");
|
|
|
|
break;
|
|
|
|
case RATING:
|
|
|
|
ret = tr("Rating");
|
|
|
|
break;
|
|
|
|
case DEPTH:
|
|
|
|
ret = tr("Depth");
|
|
|
|
break;
|
|
|
|
case DURATION:
|
|
|
|
ret = tr("Duration");
|
|
|
|
break;
|
|
|
|
case TEMPERATURE:
|
|
|
|
ret = tr("Temp");
|
|
|
|
break;
|
|
|
|
case TOTALWEIGHT:
|
|
|
|
ret = tr("Weight");
|
|
|
|
break;
|
|
|
|
case SUIT:
|
|
|
|
ret = tr("Suit");
|
|
|
|
break;
|
|
|
|
case CYLINDER:
|
|
|
|
ret = tr("Cyl");
|
|
|
|
break;
|
|
|
|
case GAS:
|
|
|
|
ret = tr("Gas");
|
|
|
|
break;
|
|
|
|
case SAC:
|
|
|
|
ret = tr("SAC");
|
|
|
|
break;
|
|
|
|
case OTU:
|
|
|
|
ret = tr("OTU");
|
|
|
|
break;
|
|
|
|
case MAXCNS:
|
|
|
|
ret = tr("Max CNS");
|
|
|
|
break;
|
|
|
|
case LOCATION:
|
|
|
|
ret = tr("Location");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Qt::ToolTipRole:
|
2014-02-27 20:09:57 -08:00
|
|
|
switch (section) {
|
|
|
|
case NR:
|
|
|
|
ret = tr("#");
|
|
|
|
break;
|
|
|
|
case DATE:
|
2014-07-11 18:39:04 +01:00
|
|
|
ret = tr("Date");
|
2014-02-27 20:09:57 -08:00
|
|
|
break;
|
|
|
|
case RATING:
|
2014-08-22 14:41:24 -07:00
|
|
|
ret = tr("Rating");
|
2014-02-27 20:09:57 -08:00
|
|
|
break;
|
|
|
|
case DEPTH:
|
2014-08-22 14:41:24 -07:00
|
|
|
ret = tr("Depth(%1)").arg((get_units()->length == units::METERS) ? tr("m") : tr("ft"));
|
2014-02-27 20:09:57 -08:00
|
|
|
break;
|
|
|
|
case DURATION:
|
2014-08-22 14:41:24 -07:00
|
|
|
ret = tr("Duration");
|
2014-02-27 20:09:57 -08:00
|
|
|
break;
|
|
|
|
case TEMPERATURE:
|
2014-08-22 14:41:24 -07:00
|
|
|
ret = tr("Temp(%1%2)").arg(UTF8_DEGREE).arg((get_units()->temperature == units::CELSIUS) ? "C" : "F");
|
2014-02-27 20:09:57 -08:00
|
|
|
break;
|
|
|
|
case TOTALWEIGHT:
|
2014-08-22 14:41:24 -07:00
|
|
|
ret = tr("Weight(%1)").arg((get_units()->weight == units::KG) ? tr("kg") : tr("lbs"));
|
2014-02-27 20:09:57 -08:00
|
|
|
break;
|
|
|
|
case SUIT:
|
2014-07-11 18:39:04 +01:00
|
|
|
ret = tr("Suit");
|
2014-02-27 20:09:57 -08:00
|
|
|
break;
|
|
|
|
case CYLINDER:
|
2014-07-11 18:39:04 +01:00
|
|
|
ret = tr("Cyl");
|
2014-02-27 20:09:57 -08:00
|
|
|
break;
|
2014-07-20 15:07:56 +02:00
|
|
|
case GAS:
|
2014-07-20 15:07:55 +02:00
|
|
|
ret = tr("Gas");
|
2014-02-27 20:09:57 -08:00
|
|
|
break;
|
|
|
|
case SAC:
|
2014-08-22 14:41:24 -07:00
|
|
|
const char *unit;
|
|
|
|
get_volume_units(0, NULL, &unit);
|
|
|
|
ret = tr("SAC(%1)").arg(QString(unit).append(tr("/min")));
|
2014-02-27 20:09:57 -08:00
|
|
|
break;
|
|
|
|
case OTU:
|
|
|
|
ret = tr("OTU");
|
|
|
|
break;
|
|
|
|
case MAXCNS:
|
2014-07-11 18:39:04 +01:00
|
|
|
ret = tr("Max CNS");
|
2014-02-27 20:09:57 -08:00
|
|
|
break;
|
|
|
|
case LOCATION:
|
2014-07-11 18:39:04 +01:00
|
|
|
ret = tr("Location");
|
2014-02-27 20:09:57 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2013-06-16 11:13:32 -03:00
|
|
|
}
|
|
|
|
|
2013-06-17 18:59:50 -03:00
|
|
|
return ret;
|
2013-05-01 23:51:34 -03:00
|
|
|
}
|
2013-04-21 22:12:36 -03:00
|
|
|
|
2013-05-01 23:51:34 -03:00
|
|
|
void DiveTripModel::setupModelData()
|
2013-04-21 22:12:36 -03:00
|
|
|
{
|
2013-05-01 23:51:34 -03:00
|
|
|
int i = dive_table.nr;
|
|
|
|
|
2014-01-16 11:50:56 +07:00
|
|
|
if (rowCount()) {
|
2014-02-27 20:09:57 -08:00
|
|
|
beginRemoveRows(QModelIndex(), 0, rowCount() - 1);
|
2013-05-28 16:56:58 -03:00
|
|
|
endRemoveRows();
|
|
|
|
}
|
|
|
|
|
2013-06-15 13:45:04 -10:00
|
|
|
if (autogroup)
|
|
|
|
autogroup_dives();
|
|
|
|
dive_table.preexisting = dive_table.nr;
|
2013-05-01 23:51:34 -03:00
|
|
|
while (--i >= 0) {
|
2014-02-27 20:09:57 -08:00
|
|
|
struct dive *dive = get_dive(i);
|
2013-05-06 20:36:37 -07:00
|
|
|
update_cylinder_related_info(dive);
|
2014-02-27 20:09:57 -08:00
|
|
|
dive_trip_t *trip = dive->divetrip;
|
2013-05-01 23:51:34 -03:00
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
DiveItem *diveItem = new DiveItem();
|
2014-01-07 11:57:20 +08:00
|
|
|
diveItem->diveId = dive->id;
|
2013-05-01 23:51:34 -03:00
|
|
|
|
2013-05-28 16:56:58 -03:00
|
|
|
if (!trip || currentLayout == LIST) {
|
2013-05-01 23:51:34 -03:00
|
|
|
diveItem->parent = rootItem;
|
2013-05-14 09:28:30 +02:00
|
|
|
rootItem->children.push_back(diveItem);
|
2013-05-01 23:51:34 -03:00
|
|
|
continue;
|
|
|
|
}
|
2013-05-28 16:56:58 -03:00
|
|
|
if (currentLayout == LIST)
|
|
|
|
continue;
|
|
|
|
|
2013-05-01 23:51:34 -03:00
|
|
|
if (!trips.keys().contains(trip)) {
|
2014-02-27 20:09:57 -08:00
|
|
|
TripItem *tripItem = new TripItem();
|
2013-05-01 23:51:34 -03:00
|
|
|
tripItem->trip = trip;
|
|
|
|
tripItem->parent = rootItem;
|
2013-05-14 09:28:30 +02:00
|
|
|
tripItem->children.push_back(diveItem);
|
2013-05-01 23:51:34 -03:00
|
|
|
trips[trip] = tripItem;
|
2013-05-14 09:28:30 +02:00
|
|
|
rootItem->children.push_back(tripItem);
|
2013-05-01 23:51:34 -03:00
|
|
|
continue;
|
|
|
|
}
|
2014-02-27 20:09:57 -08:00
|
|
|
TripItem *tripItem = trips[trip];
|
2013-05-14 09:28:30 +02:00
|
|
|
tripItem->children.push_back(diveItem);
|
2013-04-21 22:12:36 -03:00
|
|
|
}
|
2013-05-28 16:56:58 -03:00
|
|
|
|
2014-01-16 11:50:56 +07:00
|
|
|
if (rowCount()) {
|
2013-05-30 05:43:14 +09:00
|
|
|
beginInsertRows(QModelIndex(), 0, rowCount() - 1);
|
2013-05-28 16:56:58 -03:00
|
|
|
endInsertRows();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DiveTripModel::Layout DiveTripModel::layout() const
|
|
|
|
{
|
|
|
|
return currentLayout;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DiveTripModel::setLayout(DiveTripModel::Layout layout)
|
|
|
|
{
|
|
|
|
currentLayout = layout;
|
|
|
|
setupModelData();
|
2013-04-21 22:12:36 -03:00
|
|
|
}
|
2013-06-07 11:43:45 -03:00
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
bool DiveTripModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
2013-11-18 22:33:01 -02:00
|
|
|
{
|
2014-02-27 20:09:57 -08:00
|
|
|
TreeItem *item = static_cast<TreeItem *>(index.internalPointer());
|
|
|
|
DiveItem *diveItem = dynamic_cast<DiveItem *>(item);
|
2014-01-16 11:50:56 +07:00
|
|
|
if (!diveItem)
|
2013-11-18 22:33:01 -02:00
|
|
|
return false;
|
2014-02-27 20:09:57 -08:00
|
|
|
return diveItem->setData(index, value, role);
|
|
|
|
}
|
2013-11-18 22:33:01 -02:00
|
|
|
|
2013-06-17 19:41:05 -03:00
|
|
|
/*#################################################################
|
|
|
|
* #
|
|
|
|
* # Yearly Statistics Model
|
|
|
|
* #
|
|
|
|
* ################################################################
|
|
|
|
*/
|
|
|
|
|
2013-07-25 12:52:20 +03:00
|
|
|
/*#################################################################
|
|
|
|
* #
|
|
|
|
* # Table Print Model
|
|
|
|
* #
|
|
|
|
* ################################################################
|
|
|
|
*/
|
|
|
|
TablePrintModel::TablePrintModel()
|
|
|
|
{
|
|
|
|
columns = 7;
|
|
|
|
rows = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
TablePrintModel::~TablePrintModel()
|
|
|
|
{
|
|
|
|
for (int i = 0; i < list.size(); i++)
|
|
|
|
delete list.at(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TablePrintModel::insertRow(int index)
|
|
|
|
{
|
|
|
|
struct TablePrintItem *item = new struct TablePrintItem();
|
|
|
|
item->colorBackground = 0xffffffff;
|
|
|
|
if (index == -1) {
|
|
|
|
beginInsertRows(QModelIndex(), rows, rows);
|
|
|
|
list.append(item);
|
|
|
|
} else {
|
|
|
|
beginInsertRows(QModelIndex(), index, index);
|
|
|
|
list.insert(index, item);
|
|
|
|
}
|
|
|
|
endInsertRows();
|
|
|
|
rows++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TablePrintModel::callReset()
|
|
|
|
{
|
2014-01-15 09:30:44 +01:00
|
|
|
beginResetModel();
|
|
|
|
endResetModel();
|
2013-07-25 12:52:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant TablePrintModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
|
|
|
if (!index.isValid())
|
|
|
|
return QVariant();
|
|
|
|
if (role == Qt::BackgroundRole)
|
|
|
|
return QColor(list.at(index.row())->colorBackground);
|
|
|
|
if (role == Qt::DisplayRole)
|
|
|
|
switch (index.column()) {
|
2014-02-27 20:09:57 -08:00
|
|
|
case 0:
|
|
|
|
return list.at(index.row())->number;
|
|
|
|
case 1:
|
|
|
|
return list.at(index.row())->date;
|
|
|
|
case 2:
|
|
|
|
return list.at(index.row())->depth;
|
|
|
|
case 3:
|
|
|
|
return list.at(index.row())->duration;
|
|
|
|
case 4:
|
|
|
|
return list.at(index.row())->divemaster;
|
|
|
|
case 5:
|
|
|
|
return list.at(index.row())->buddy;
|
|
|
|
case 6:
|
|
|
|
return list.at(index.row())->location;
|
2013-07-25 12:52:20 +03:00
|
|
|
}
|
2014-07-11 21:51:44 -07:00
|
|
|
if (role == Qt::FontRole) {
|
|
|
|
QFont font;
|
|
|
|
font.setPointSizeF(7.5);
|
|
|
|
if (index.row() == 0 && index.column() == 0) {
|
|
|
|
font.setBold(true);
|
|
|
|
}
|
|
|
|
return QVariant::fromValue(font);
|
|
|
|
}
|
2013-07-25 12:52:20 +03:00
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TablePrintModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
|
|
|
{
|
|
|
|
if (index.isValid()) {
|
|
|
|
if (role == Qt::DisplayRole) {
|
|
|
|
switch (index.column()) {
|
2014-02-27 20:09:57 -08:00
|
|
|
case 0:
|
|
|
|
list.at(index.row())->number = value.toString();
|
|
|
|
case 1:
|
|
|
|
list.at(index.row())->date = value.toString();
|
|
|
|
case 2:
|
|
|
|
list.at(index.row())->depth = value.toString();
|
|
|
|
case 3:
|
|
|
|
list.at(index.row())->duration = value.toString();
|
|
|
|
case 4:
|
|
|
|
list.at(index.row())->divemaster = value.toString();
|
|
|
|
case 5:
|
|
|
|
list.at(index.row())->buddy = value.toString();
|
2013-12-06 18:24:29 +02:00
|
|
|
case 6: {
|
|
|
|
/* truncate if there are more than N lines of text,
|
|
|
|
* we don't want a row to be larger that a single page! */
|
|
|
|
QString s = value.toString();
|
|
|
|
const int maxLines = 15;
|
|
|
|
int count = 0;
|
|
|
|
for (int i = 0; i < s.length(); i++) {
|
|
|
|
if (s.at(i) != QChar('\n'))
|
|
|
|
continue;
|
|
|
|
count++;
|
|
|
|
if (count > maxLines) {
|
|
|
|
s = s.left(i - 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
list.at(index.row())->location = s;
|
|
|
|
}
|
2013-07-25 12:52:20 +03:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (role == Qt::BackgroundRole) {
|
|
|
|
list.at(index.row())->colorBackground = value.value<unsigned int>();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TablePrintModel::rowCount(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
Q_UNUSED(parent);
|
|
|
|
return rows;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TablePrintModel::columnCount(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
Q_UNUSED(parent);
|
|
|
|
return columns;
|
|
|
|
}
|
2013-10-03 17:50:40 +03:00
|
|
|
|
|
|
|
/*#################################################################
|
|
|
|
* #
|
|
|
|
* # Profile Print Model
|
|
|
|
* #
|
|
|
|
* ################################################################
|
|
|
|
*/
|
|
|
|
|
|
|
|
ProfilePrintModel::ProfilePrintModel(QObject *parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProfilePrintModel::setDive(struct dive *divePtr)
|
|
|
|
{
|
2014-01-07 11:57:20 +08:00
|
|
|
diveId = divePtr->id;
|
2013-10-03 17:50:40 +03:00
|
|
|
// reset();
|
|
|
|
}
|
|
|
|
|
2014-07-11 21:30:40 -07:00
|
|
|
void ProfilePrintModel::setFontsize(double size)
|
|
|
|
{
|
|
|
|
fontSize = size;
|
|
|
|
}
|
|
|
|
|
2013-10-03 17:50:40 +03:00
|
|
|
int ProfilePrintModel::rowCount(const QModelIndex &parent) const
|
|
|
|
{
|
2013-11-30 14:38:54 +02:00
|
|
|
return 12;
|
2013-10-03 17:50:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int ProfilePrintModel::columnCount(const QModelIndex &parent) const
|
|
|
|
{
|
2013-11-30 14:38:54 +02:00
|
|
|
return 5;
|
2013-10-03 17:50:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant ProfilePrintModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
|
|
|
const int row = index.row();
|
|
|
|
const int col = index.column();
|
|
|
|
|
|
|
|
switch (role) {
|
|
|
|
case Qt::DisplayRole: {
|
2014-05-19 06:38:37 +09:00
|
|
|
struct dive *dive = get_dive_by_uniq_id(diveId);
|
2013-10-03 17:50:40 +03:00
|
|
|
struct DiveItem di;
|
2014-01-07 11:57:20 +08:00
|
|
|
di.diveId = diveId;
|
2013-10-11 10:21:04 -03:00
|
|
|
|
|
|
|
const QString unknown = tr("unknown");
|
2013-10-03 17:50:40 +03:00
|
|
|
|
|
|
|
// dive# + date, depth, location, duration
|
|
|
|
if (row == 0) {
|
|
|
|
if (col == 0)
|
2013-10-11 10:21:04 -03:00
|
|
|
return tr("Dive #%1 - %2").arg(dive->number).arg(di.displayDate());
|
2014-07-11 21:40:22 -07:00
|
|
|
if (col == 3) {
|
2013-10-11 10:21:04 -03:00
|
|
|
QString unit = (get_units()->length == units::METERS) ? "m" : "ft";
|
|
|
|
return tr("Max depth: %1 %2").arg(di.displayDepth()).arg(unit);
|
2013-10-03 17:50:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (row == 1) {
|
|
|
|
if (col == 0)
|
2015-02-12 12:54:20 -08:00
|
|
|
return QString(get_dive_location(dive));
|
2014-07-11 21:40:22 -07:00
|
|
|
if (col == 3)
|
2013-10-03 17:50:40 +03:00
|
|
|
return QString(tr("Duration: %1 min")).arg(di.displayDuration());
|
|
|
|
}
|
2013-11-30 16:00:51 +02:00
|
|
|
// headings
|
2013-10-03 17:50:40 +03:00
|
|
|
if (row == 2) {
|
|
|
|
if (col == 0)
|
2014-07-11 09:21:38 +01:00
|
|
|
return tr("Gas used:");
|
2013-10-03 17:50:40 +03:00
|
|
|
if (col == 2)
|
2014-07-11 21:39:44 -07:00
|
|
|
return tr("Tags:");
|
2013-11-30 16:00:51 +02:00
|
|
|
if (col == 3)
|
2014-07-11 21:39:44 -07:00
|
|
|
return tr("SAC:");
|
2013-11-30 16:00:51 +02:00
|
|
|
if (col == 4)
|
|
|
|
return tr("Weights:");
|
2013-10-03 17:50:40 +03:00
|
|
|
}
|
2013-11-30 16:09:54 +02:00
|
|
|
// notes
|
|
|
|
if (col == 0) {
|
|
|
|
if (row == 6)
|
|
|
|
return tr("Notes:");
|
|
|
|
if (row == 7)
|
|
|
|
return QString(dive->notes);
|
|
|
|
}
|
2013-11-30 16:23:19 +02:00
|
|
|
// more headings
|
|
|
|
if (row == 4) {
|
|
|
|
if (col == 0)
|
|
|
|
return tr("Divemaster:");
|
2013-10-03 17:50:40 +03:00
|
|
|
if (col == 1)
|
2013-11-30 16:23:19 +02:00
|
|
|
return tr("Buddy:");
|
2013-10-03 17:50:40 +03:00
|
|
|
if (col == 2)
|
2013-11-30 16:23:19 +02:00
|
|
|
return tr("Suit:");
|
|
|
|
if (col == 3)
|
|
|
|
return tr("Viz:");
|
|
|
|
if (col == 4)
|
|
|
|
return tr("Rating:");
|
2013-10-03 17:50:40 +03:00
|
|
|
}
|
2013-11-30 16:51:28 +02:00
|
|
|
// values for gas, sac, etc...
|
|
|
|
if (row == 3) {
|
|
|
|
if (col == 0) {
|
|
|
|
int added = 0;
|
2014-07-11 21:39:44 -07:00
|
|
|
QString gas, gases;
|
2013-11-30 16:51:28 +02:00
|
|
|
for (int i = 0; i < MAX_CYLINDERS; i++) {
|
2014-08-06 07:08:31 -07:00
|
|
|
if (!is_cylinder_used(dive, i))
|
|
|
|
continue;
|
2014-07-11 21:39:44 -07:00
|
|
|
gas = dive->cylinder[i].type.description;
|
|
|
|
gas += QString(!gas.isEmpty() ? " " : "") + gasname(&dive->cylinder[i].gasmix);
|
2013-11-30 16:51:28 +02:00
|
|
|
// if has a description and if such gas is not already present
|
2014-07-11 21:39:44 -07:00
|
|
|
if (!gas.isEmpty() && gases.indexOf(gas) == -1) {
|
2013-11-30 16:51:28 +02:00
|
|
|
if (added > 0)
|
|
|
|
gases += QString(" / ");
|
2014-07-11 21:39:44 -07:00
|
|
|
gases += gas;
|
2013-11-30 16:51:28 +02:00
|
|
|
added++;
|
|
|
|
}
|
2013-10-03 17:50:40 +03:00
|
|
|
}
|
2013-11-30 16:51:28 +02:00
|
|
|
return gases;
|
2013-10-03 17:50:40 +03:00
|
|
|
}
|
2014-07-11 21:39:44 -07:00
|
|
|
if (col == 2) {
|
|
|
|
char buffer[256];
|
|
|
|
taglist_get_tagstring(dive->tag_list, buffer, 256);
|
|
|
|
return QString(buffer);
|
|
|
|
}
|
2013-11-30 19:10:47 +02:00
|
|
|
if (col == 3)
|
2014-07-11 21:39:44 -07:00
|
|
|
return di.displaySac();
|
2013-11-30 16:51:28 +02:00
|
|
|
if (col == 4) {
|
|
|
|
weight_t tw = { total_weight(dive) };
|
|
|
|
return get_weight_string(tw, true);
|
2013-10-03 17:50:40 +03:00
|
|
|
}
|
|
|
|
}
|
2013-11-30 17:09:10 +02:00
|
|
|
// values for DM, buddy, suit, etc...
|
|
|
|
if (row == 5) {
|
|
|
|
if (col == 0)
|
|
|
|
return QString(dive->divemaster);
|
|
|
|
if (col == 1)
|
|
|
|
return QString(dive->buddy);
|
|
|
|
if (col == 2)
|
|
|
|
return QString(dive->suit);
|
|
|
|
if (col == 3)
|
|
|
|
return (dive->visibility) ? QString::number(dive->visibility).append(" / 5") : QString();
|
|
|
|
if (col == 4)
|
|
|
|
return (dive->rating) ? QString::number(dive->rating).append(" / 5") : QString();
|
2013-10-03 17:50:40 +03:00
|
|
|
}
|
2013-10-11 10:21:04 -03:00
|
|
|
return QString();
|
2013-10-03 17:50:40 +03:00
|
|
|
}
|
|
|
|
case Qt::FontRole: {
|
|
|
|
QFont font;
|
2014-07-11 21:30:40 -07:00
|
|
|
font.setPointSizeF(fontSize);
|
2013-10-03 17:50:40 +03:00
|
|
|
if (row == 0 && col == 0) {
|
|
|
|
font.setBold(true);
|
|
|
|
}
|
|
|
|
return QVariant::fromValue(font);
|
|
|
|
}
|
|
|
|
case Qt::TextAlignmentRole: {
|
2013-11-30 15:41:18 +02:00
|
|
|
// everything is aligned to the left
|
|
|
|
unsigned int align = Qt::AlignLeft;
|
|
|
|
// align depth and duration right
|
|
|
|
if (row < 2 && col == 4)
|
2013-10-03 17:50:40 +03:00
|
|
|
align = Qt::AlignRight | Qt::AlignVCenter;
|
|
|
|
return QVariant::fromValue(align);
|
|
|
|
}
|
|
|
|
} // switch (role)
|
|
|
|
return QVariant();
|
|
|
|
}
|
2013-11-14 17:39:35 -02:00
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
Qt::ItemFlags GasSelectionModel::flags(const QModelIndex &index) const
|
2013-11-14 17:39:35 -02:00
|
|
|
{
|
2013-11-19 18:17:50 -08:00
|
|
|
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
2013-11-14 17:39:35 -02:00
|
|
|
}
|
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
GasSelectionModel *GasSelectionModel::instance()
|
2013-11-14 17:39:35 -02:00
|
|
|
{
|
2013-11-30 09:18:04 -08:00
|
|
|
static QScopedPointer<GasSelectionModel> self(new GasSelectionModel());
|
|
|
|
return self.data();
|
2013-11-14 17:39:35 -02:00
|
|
|
}
|
|
|
|
|
2015-05-28 16:23:49 -03:00
|
|
|
//TODO: Remove this #include here when the issue below is fixed.
|
|
|
|
#include "diveplannermodel.h"
|
2013-11-14 17:39:35 -02:00
|
|
|
void GasSelectionModel::repopulate()
|
|
|
|
{
|
2015-05-28 16:23:49 -03: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-19 18:17:50 -08:00
|
|
|
setStringList(DivePlannerPointsModel::instance()->getGasList());
|
2013-11-14 17:39:35 -02:00
|
|
|
}
|
2013-11-14 17:43:28 -02:00
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
QVariant GasSelectionModel::data(const QModelIndex &index, int role) const
|
2013-11-14 17:43:28 -02:00
|
|
|
{
|
2014-01-16 11:50:56 +07:00
|
|
|
if (role == Qt::FontRole) {
|
2013-11-14 17:43:28 -02:00
|
|
|
return defaultModelFont();
|
|
|
|
}
|
|
|
|
return QStringListModel::data(index, role);
|
|
|
|
}
|
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
|
|
|
{
|
|
|
|
QSettings s;
|
2013-12-06 18:30:05 -02:00
|
|
|
QDir d(getSubsurfaceDataPath("translations"));
|
2014-07-15 14:43:20 -03:00
|
|
|
Q_FOREACH (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: {
|
2014-02-27 20:09:57 -08:00
|
|
|
QLocale l(currentString.remove("subsurface_"));
|
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:
|
|
|
|
return currentString == "English" ? "en_US" : currentString.remove("subsurface_");
|
2013-12-06 14:29:38 -02:00
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
int LanguageModel::rowCount(const QModelIndex &parent) const
|
2013-12-06 14:29:38 -02:00
|
|
|
{
|
|
|
|
return languages.count();
|
|
|
|
}
|