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
|
|
|
|
}
|
|
|
|
|
|
2014-11-04 15:05:35 -08:00
|
|
|
|
WeightModel::WeightModel(QObject *parent) : CleanerTableModel(parent),
|
2014-11-08 14:11:06 +01:00
|
|
|
|
changed(false),
|
|
|
|
|
rows(0)
|
2013-05-23 18:40:16 -07:00
|
|
|
|
{
|
2013-10-11 11:04:27 -03:00
|
|
|
|
//enum Column {REMOVE, TYPE, WEIGHT};
|
|
|
|
|
setHeaderDataStrings(QStringList() << tr("") << tr("Type") << tr("Weight"));
|
2013-05-23 18:40:16 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
|
weightsystem_t *WeightModel::weightSystemAt(const QModelIndex &index)
|
2013-07-18 11:53:47 -03:00
|
|
|
|
{
|
2014-07-02 22:38:08 -07:00
|
|
|
|
return &displayed_dive.weightsystem[index.row()];
|
2013-07-18 11:53:47 -03:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
|
void WeightModel::remove(const QModelIndex &index)
|
2013-05-22 11:00:20 -03:00
|
|
|
|
{
|
2013-05-22 21:25:05 -07:00
|
|
|
|
if (index.column() != REMOVE) {
|
2013-05-22 11:00:20 -03:00
|
|
|
|
return;
|
|
|
|
|
}
|
2013-05-22 11:40:57 -03:00
|
|
|
|
beginRemoveRows(QModelIndex(), index.row(), index.row()); // yah, know, ugly.
|
2013-05-22 10:02:28 -07:00
|
|
|
|
rows--;
|
2014-07-02 22:38:08 -07:00
|
|
|
|
remove_weightsystem(&displayed_dive, index.row());
|
2013-09-25 14:23:51 -03:00
|
|
|
|
changed = true;
|
2013-05-22 11:40:57 -03:00
|
|
|
|
endRemoveRows();
|
2013-05-22 11:00:20 -03:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-13 10:17:59 -03:00
|
|
|
|
void WeightModel::clear()
|
|
|
|
|
{
|
2013-05-21 09:59:41 -03:00
|
|
|
|
if (rows > 0) {
|
2014-02-27 20:09:57 -08:00
|
|
|
|
beginRemoveRows(QModelIndex(), 0, rows - 1);
|
2013-05-01 09:04:14 -07:00
|
|
|
|
endRemoveRows();
|
|
|
|
|
}
|
2013-04-13 10:17:59 -03:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
|
QVariant WeightModel::data(const QModelIndex &index, int role) const
|
2013-04-13 10:17:59 -03:00
|
|
|
|
{
|
2013-05-01 10:11:46 -07:00
|
|
|
|
QVariant ret;
|
2013-05-01 22:00:08 -07:00
|
|
|
|
if (!index.isValid() || index.row() >= MAX_WEIGHTSYSTEMS)
|
2013-05-01 10:11:46 -07:00
|
|
|
|
return ret;
|
2013-05-01 22:00:08 -07:00
|
|
|
|
|
2014-07-02 22:38:08 -07:00
|
|
|
|
weightsystem_t *ws = &displayed_dive.weightsystem[index.row()];
|
2013-05-01 10:11:46 -07:00
|
|
|
|
|
2013-05-25 20:04:31 -07:00
|
|
|
|
switch (role) {
|
|
|
|
|
case Qt::FontRole:
|
2013-06-16 11:13:32 -03:00
|
|
|
|
ret = defaultModelFont();
|
2013-05-25 20:04:31 -07:00
|
|
|
|
break;
|
|
|
|
|
case Qt::TextAlignmentRole:
|
2013-11-21 23:36:39 -02:00
|
|
|
|
ret = Qt::AlignCenter;
|
2014-02-27 20:09:57 -08:00
|
|
|
|
break;
|
2013-05-25 20:04:31 -07:00
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
|
case Qt::EditRole:
|
2014-01-16 11:50:56 +07:00
|
|
|
|
switch (index.column()) {
|
2013-05-01 10:11:46 -07:00
|
|
|
|
case TYPE:
|
2013-12-02 10:10:55 -08:00
|
|
|
|
ret = gettextFromC::instance()->tr(ws->description);
|
2013-05-01 10:11:46 -07:00
|
|
|
|
break;
|
|
|
|
|
case WEIGHT:
|
2014-01-15 09:30:42 +01:00
|
|
|
|
ret = get_weight_string(ws->weight, true);
|
2013-05-01 10:11:46 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
2013-05-25 20:04:31 -07:00
|
|
|
|
break;
|
|
|
|
|
case Qt::DecorationRole:
|
2013-05-22 21:25:05 -07:00
|
|
|
|
if (index.column() == REMOVE)
|
2014-10-19 16:15:20 +02:00
|
|
|
|
ret = trashIcon();
|
|
|
|
|
break;
|
|
|
|
|
case Qt::SizeHintRole:
|
|
|
|
|
if (index.column() == REMOVE)
|
|
|
|
|
ret = trashIcon().size();
|
2013-05-25 20:04:31 -07:00
|
|
|
|
break;
|
2013-11-21 23:32:11 -02:00
|
|
|
|
case Qt::ToolTipRole:
|
|
|
|
|
if (index.column() == REMOVE)
|
2014-07-11 09:21:38 +01:00
|
|
|
|
ret = tr("Clicking here will remove this weight system.");
|
2013-11-21 23:32:11 -02:00
|
|
|
|
break;
|
2013-05-22 11:00:20 -03:00
|
|
|
|
}
|
2013-05-01 10:11:46 -07:00
|
|
|
|
return ret;
|
2013-04-13 10:17:59 -03:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-23 18:40:16 -07:00
|
|
|
|
// this is our magic 'pass data in' function that allows the delegate to get
|
|
|
|
|
// the data here without silly unit conversions;
|
|
|
|
|
// so we only implement the two columns we care about
|
2014-02-27 20:09:57 -08:00
|
|
|
|
void WeightModel::passInData(const QModelIndex &index, const QVariant &value)
|
2013-05-23 18:40:16 -07:00
|
|
|
|
{
|
2014-07-02 22:38:08 -07:00
|
|
|
|
weightsystem_t *ws = &displayed_dive.weightsystem[index.row()];
|
2013-05-23 18:40:16 -07:00
|
|
|
|
if (index.column() == WEIGHT) {
|
|
|
|
|
if (ws->weight.grams != value.toInt()) {
|
|
|
|
|
ws->weight.grams = value.toInt();
|
2013-07-16 19:13:58 -03:00
|
|
|
|
dataChanged(index, index);
|
2013-05-23 18:40:16 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-04-16 23:56:42 -03:00
|
|
|
|
//TODO: Move to C
|
2014-01-08 14:51:22 +08:00
|
|
|
|
weight_t string_to_weight(const char *str)
|
2014-01-02 20:52:47 -08:00
|
|
|
|
{
|
2014-01-08 14:51:22 +08:00
|
|
|
|
const char *end;
|
2014-01-02 20:52:47 -08:00
|
|
|
|
double value = strtod_flags(str, &end, 0);
|
2014-01-03 11:22:37 -08:00
|
|
|
|
QString rest = QString(end).trimmed();
|
2014-07-15 20:27:32 -03:00
|
|
|
|
QString local_kg = QObject::tr("kg");
|
|
|
|
|
QString local_lbs = QObject::tr("lbs");
|
2014-01-08 14:24:35 +08:00
|
|
|
|
weight_t weight;
|
2014-01-02 20:52:47 -08:00
|
|
|
|
|
2014-01-03 11:22:37 -08:00
|
|
|
|
if (rest.startsWith("kg") || rest.startsWith(local_kg))
|
2014-01-02 20:52:47 -08:00
|
|
|
|
goto kg;
|
2014-01-03 11:22:37 -08:00
|
|
|
|
// using just "lb" instead of "lbs" is intentional - some people might enter the singular
|
|
|
|
|
if (rest.startsWith("lb") || rest.startsWith(local_lbs))
|
2014-01-02 20:52:47 -08:00
|
|
|
|
goto lbs;
|
|
|
|
|
if (prefs.units.weight == prefs.units.LBS)
|
|
|
|
|
goto lbs;
|
|
|
|
|
kg:
|
2014-01-08 14:24:35 +08:00
|
|
|
|
weight.grams = rint(value * 1000);
|
|
|
|
|
return weight;
|
2014-01-02 20:52:47 -08:00
|
|
|
|
lbs:
|
2014-01-08 14:24:35 +08:00
|
|
|
|
weight.grams = lbs_to_grams(value);
|
|
|
|
|
return weight;
|
2014-01-02 20:52:47 -08:00
|
|
|
|
}
|
|
|
|
|
|
2014-04-16 23:56:42 -03:00
|
|
|
|
//TODO: Move to C.
|
2014-01-08 14:55:47 +08:00
|
|
|
|
depth_t string_to_depth(const char *str)
|
|
|
|
|
{
|
|
|
|
|
const char *end;
|
|
|
|
|
double value = strtod_flags(str, &end, 0);
|
|
|
|
|
QString rest = QString(end).trimmed();
|
2014-07-15 20:27:32 -03:00
|
|
|
|
QString local_ft = QObject::tr("ft");
|
|
|
|
|
QString local_m = QObject::tr("m");
|
2014-01-08 14:55:47 +08:00
|
|
|
|
depth_t depth;
|
|
|
|
|
|
|
|
|
|
if (rest.startsWith("m") || rest.startsWith(local_m))
|
|
|
|
|
goto m;
|
|
|
|
|
if (rest.startsWith("ft") || rest.startsWith(local_ft))
|
|
|
|
|
goto ft;
|
|
|
|
|
if (prefs.units.length == prefs.units.FEET)
|
|
|
|
|
goto ft;
|
|
|
|
|
m:
|
|
|
|
|
depth.mm = rint(value * 1000);
|
|
|
|
|
return depth;
|
|
|
|
|
ft:
|
|
|
|
|
depth.mm = feet_to_mm(value);
|
|
|
|
|
return depth;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-16 23:56:42 -03:00
|
|
|
|
//TODO: Move to C.
|
2014-01-09 08:49:21 +08:00
|
|
|
|
pressure_t string_to_pressure(const char *str)
|
|
|
|
|
{
|
|
|
|
|
const char *end;
|
|
|
|
|
double value = strtod_flags(str, &end, 0);
|
|
|
|
|
QString rest = QString(end).trimmed();
|
2014-07-15 20:27:32 -03:00
|
|
|
|
QString local_psi = QObject::tr("psi");
|
|
|
|
|
QString local_bar = QObject::tr("bar");
|
2014-01-09 08:49:21 +08:00
|
|
|
|
pressure_t pressure;
|
|
|
|
|
|
|
|
|
|
if (rest.startsWith("bar") || rest.startsWith(local_bar))
|
|
|
|
|
goto bar;
|
|
|
|
|
if (rest.startsWith("psi") || rest.startsWith(local_psi))
|
|
|
|
|
goto psi;
|
|
|
|
|
if (prefs.units.pressure == prefs.units.PSI)
|
|
|
|
|
goto psi;
|
|
|
|
|
bar:
|
|
|
|
|
pressure.mbar = rint(value * 1000);
|
|
|
|
|
return pressure;
|
|
|
|
|
psi:
|
|
|
|
|
pressure.mbar = psi_to_mbar(value);
|
|
|
|
|
return pressure;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-16 23:56:42 -03:00
|
|
|
|
//TODO: Move to C.
|
2014-01-09 10:34:25 +08:00
|
|
|
|
/* Imperial cylinder volumes need working pressure to be meaningful */
|
|
|
|
|
volume_t string_to_volume(const char *str, pressure_t workp)
|
|
|
|
|
{
|
|
|
|
|
const char *end;
|
|
|
|
|
double value = strtod_flags(str, &end, 0);
|
|
|
|
|
QString rest = QString(end).trimmed();
|
2014-07-15 20:27:32 -03:00
|
|
|
|
QString local_l = QObject::tr("l");
|
|
|
|
|
QString local_cuft = QObject::tr("cuft");
|
2014-01-09 10:34:25 +08:00
|
|
|
|
volume_t volume;
|
|
|
|
|
|
2014-06-08 20:31:11 -07:00
|
|
|
|
if (rest.startsWith("l") || rest.startsWith("ℓ") || rest.startsWith(local_l))
|
2014-01-09 10:34:25 +08:00
|
|
|
|
goto l;
|
|
|
|
|
if (rest.startsWith("cuft") || rest.startsWith(local_cuft))
|
|
|
|
|
goto cuft;
|
|
|
|
|
/*
|
|
|
|
|
* If we don't have explicit units, and there is no working
|
|
|
|
|
* pressure, we're going to assume "liter" even in imperial
|
|
|
|
|
* measurements.
|
|
|
|
|
*/
|
|
|
|
|
if (!workp.mbar)
|
|
|
|
|
goto l;
|
|
|
|
|
if (prefs.units.volume == prefs.units.LITER)
|
|
|
|
|
goto l;
|
|
|
|
|
cuft:
|
|
|
|
|
if (workp.mbar)
|
|
|
|
|
value /= bar_to_atm(workp.mbar / 1000.0);
|
|
|
|
|
value = cuft_to_l(value);
|
|
|
|
|
l:
|
|
|
|
|
volume.mliter = rint(value * 1000);
|
|
|
|
|
return volume;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-16 23:56:42 -03:00
|
|
|
|
//TODO: Move to C.
|
2014-01-09 10:43:28 +08:00
|
|
|
|
fraction_t string_to_fraction(const char *str)
|
|
|
|
|
{
|
|
|
|
|
const char *end;
|
|
|
|
|
double value = strtod_flags(str, &end, 0);
|
|
|
|
|
fraction_t fraction;
|
|
|
|
|
|
|
|
|
|
fraction.permille = rint(value * 10);
|
|
|
|
|
return fraction;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
|
bool WeightModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
2013-05-22 12:20:00 -03:00
|
|
|
|
{
|
2014-01-02 09:12:32 -08:00
|
|
|
|
QString vString = value.toString();
|
2014-07-02 22:38:08 -07:00
|
|
|
|
weightsystem_t *ws = &displayed_dive.weightsystem[index.row()];
|
2014-01-16 11:50:56 +07:00
|
|
|
|
switch (index.column()) {
|
2013-05-23 18:40:16 -07:00
|
|
|
|
case TYPE:
|
|
|
|
|
if (!value.isNull()) {
|
2014-04-16 23:56:42 -03:00
|
|
|
|
//TODO: C-function weigth_system_set_description ?
|
2014-01-02 09:12:32 -08:00
|
|
|
|
if (!ws->description || gettextFromC::instance()->tr(ws->description) != vString) {
|
2013-12-02 12:41:23 -08:00
|
|
|
|
// loop over translations to see if one matches
|
|
|
|
|
int i = -1;
|
2014-02-27 20:09:57 -08:00
|
|
|
|
while (ws_info[++i].name) {
|
2014-01-02 09:12:32 -08:00
|
|
|
|
if (gettextFromC::instance()->tr(ws_info[i].name) == vString) {
|
2014-11-14 13:33:12 -08:00
|
|
|
|
ws->description = copy_string(ws_info[i].name);
|
2013-12-02 12:41:23 -08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (ws_info[i].name == NULL) // didn't find a match
|
2014-01-02 09:12:32 -08:00
|
|
|
|
ws->description = strdup(vString.toUtf8().constData());
|
2013-09-25 14:23:51 -03:00
|
|
|
|
changed = true;
|
2013-05-23 18:40:16 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-05-22 12:20:00 -03:00
|
|
|
|
break;
|
|
|
|
|
case WEIGHT:
|
2014-01-09 10:47:28 +08:00
|
|
|
|
if (CHANGED()) {
|
2014-01-08 14:24:35 +08:00
|
|
|
|
ws->weight = string_to_weight(vString.toUtf8().data());
|
2013-05-23 22:56:12 -07:00
|
|
|
|
// now update the ws_info
|
2013-09-25 14:23:51 -03:00
|
|
|
|
changed = true;
|
2013-05-23 22:56:12 -07:00
|
|
|
|
WSInfoModel *wsim = WSInfoModel::instance();
|
2014-02-27 20:09:57 -08:00
|
|
|
|
QModelIndexList matches = wsim->match(wsim->index(0, 0), Qt::DisplayRole, gettextFromC::instance()->tr(ws->description));
|
2013-05-23 22:56:12 -07:00
|
|
|
|
if (!matches.isEmpty())
|
|
|
|
|
wsim->setData(wsim->index(matches.first().row(), WSInfoModel::GR), ws->weight.grams);
|
2013-05-23 18:40:16 -07:00
|
|
|
|
}
|
2013-05-22 12:20:00 -03:00
|
|
|
|
break;
|
|
|
|
|
}
|
2013-07-16 19:13:58 -03:00
|
|
|
|
dataChanged(index, index);
|
|
|
|
|
return true;
|
2013-05-22 12:20:00 -03:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
|
Qt::ItemFlags WeightModel::flags(const QModelIndex &index) const
|
2013-05-22 11:00:20 -03:00
|
|
|
|
{
|
|
|
|
|
if (index.column() == REMOVE)
|
|
|
|
|
return Qt::ItemIsEnabled;
|
2013-05-22 12:20:00 -03:00
|
|
|
|
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
|
2013-05-22 11:00:20 -03:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
|
int WeightModel::rowCount(const QModelIndex &parent) const
|
2013-04-13 10:17:59 -03:00
|
|
|
|
{
|
2013-05-21 09:59:41 -03:00
|
|
|
|
return rows;
|
2013-04-13 10:17:59 -03:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-22 14:52:38 -03:00
|
|
|
|
void WeightModel::add()
|
2013-04-13 10:17:59 -03:00
|
|
|
|
{
|
2013-05-21 11:29:21 -07:00
|
|
|
|
if (rows >= MAX_WEIGHTSYSTEMS)
|
2013-05-01 14:49:17 -07:00
|
|
|
|
return;
|
2013-05-01 10:11:46 -07:00
|
|
|
|
|
2013-05-21 09:59:41 -03:00
|
|
|
|
int row = rows;
|
2013-05-01 10:11:46 -07:00
|
|
|
|
beginInsertRows(QModelIndex(), row, row);
|
2013-05-21 09:59:41 -03:00
|
|
|
|
rows++;
|
2013-09-25 14:23:51 -03:00
|
|
|
|
changed = true;
|
2013-05-01 10:11:46 -07:00
|
|
|
|
endInsertRows();
|
2013-04-13 10:17:59 -03:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-02 22:38:08 -07:00
|
|
|
|
void WeightModel::updateDive()
|
2013-05-21 09:59:41 -03:00
|
|
|
|
{
|
2014-07-02 22:38:08 -07:00
|
|
|
|
clear();
|
2013-11-27 22:59:17 +01:00
|
|
|
|
rows = 0;
|
2014-02-27 20:09:57 -08:00
|
|
|
|
for (int i = 0; i < MAX_WEIGHTSYSTEMS; i++) {
|
2014-07-02 22:38:08 -07:00
|
|
|
|
if (!weightsystem_none(&displayed_dive.weightsystem[i])) {
|
2014-02-27 20:09:57 -08:00
|
|
|
|
rows = i + 1;
|
2013-05-21 09:59:41 -03:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-27 22:59:17 +01:00
|
|
|
|
if (rows > 0) {
|
2014-02-27 20:09:57 -08:00
|
|
|
|
beginInsertRows(QModelIndex(), 0, rows - 1);
|
2013-10-13 16:20:32 +03:00
|
|
|
|
endInsertRows();
|
|
|
|
|
}
|
2013-04-13 10:17:59 -03:00
|
|
|
|
}
|
2013-04-15 15:04:35 -03:00
|
|
|
|
|
2013-06-17 18:59:50 -03:00
|
|
|
|
//#################################################################################################
|
|
|
|
|
//#
|
|
|
|
|
//# Tree Model - a Basic Tree Model so I don't need to kill myself repeating this for every model.
|
|
|
|
|
//#
|
|
|
|
|
//#################################################################################################
|
2013-04-27 12:27:27 -03:00
|
|
|
|
|
2013-04-21 22:12:36 -03: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.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2013-05-01 23:51:34 -03:00
|
|
|
|
|
2013-06-18 13:29:37 -07:00
|
|
|
|
TreeItem::TreeItem()
|
|
|
|
|
{
|
|
|
|
|
parent = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-17 18:59:50 -03:00
|
|
|
|
TreeItem::~TreeItem()
|
2013-04-21 22:12:36 -03:00
|
|
|
|
{
|
2013-05-14 09:28:30 +02:00
|
|
|
|
qDeleteAll(children);
|
2013-05-01 23:51:34 -03:00
|
|
|
|
}
|
2013-04-25 09:50:01 +02:00
|
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
|
Qt::ItemFlags TreeItem::flags(const QModelIndex &index) const
|
2013-11-18 22:33:01 -02:00
|
|
|
|
{
|
|
|
|
|
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-17 18:59:50 -03:00
|
|
|
|
int TreeItem::row() const
|
2013-05-01 23:51:34 -03:00
|
|
|
|
{
|
|
|
|
|
if (parent)
|
2014-02-27 20:09:57 -08:00
|
|
|
|
return parent->children.indexOf(const_cast<TreeItem *>(this));
|
2013-05-01 23:51:34 -03:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
2013-04-21 22:12:36 -03:00
|
|
|
|
|
2013-06-17 18:59:50 -03:00
|
|
|
|
QVariant TreeItem::data(int column, int role) const
|
2013-05-01 23:51:34 -03:00
|
|
|
|
{
|
2013-06-17 18:59:50 -03:00
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
|
TreeModel::TreeModel(QObject *parent) : QAbstractItemModel(parent)
|
2013-06-17 18:59:50 -03:00
|
|
|
|
{
|
2014-03-03 22:21:33 -08:00
|
|
|
|
columns = 0; // I'm not sure about this one - I can't see where it gets initialized
|
2013-06-17 18:59:50 -03:00
|
|
|
|
rootItem = new TreeItem();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TreeModel::~TreeModel()
|
|
|
|
|
{
|
|
|
|
|
delete rootItem;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
|
QVariant TreeModel::data(const QModelIndex &index, int role) const
|
2013-06-17 18:59:50 -03:00
|
|
|
|
{
|
|
|
|
|
if (!index.isValid())
|
|
|
|
|
return QVariant();
|
|
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
|
TreeItem *item = static_cast<TreeItem *>(index.internalPointer());
|
2013-06-19 10:30:36 -07:00
|
|
|
|
QVariant val = item->data(index.column(), role);
|
2013-06-17 18:59:50 -03:00
|
|
|
|
|
2013-06-19 10:30:36 -07:00
|
|
|
|
if (role == Qt::FontRole && !val.isValid())
|
|
|
|
|
return defaultModelFont();
|
|
|
|
|
else
|
|
|
|
|
return val;
|
2013-05-01 23:51:34 -03:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
|
bool TreeItem::setData(const QModelIndex &index, const QVariant &value, int role)
|
2013-11-18 22:33:01 -02:00
|
|
|
|
{
|
2013-11-21 00:32:13 +01:00
|
|
|
|
return false;
|
2013-11-18 22:33:01 -02:00
|
|
|
|
}
|
|
|
|
|
|
2014-03-05 12:19:45 -08:00
|
|
|
|
QModelIndex TreeModel::index(int row, int column, const QModelIndex &parent) const
|
2013-06-17 18:59:50 -03:00
|
|
|
|
{
|
|
|
|
|
if (!hasIndex(row, column, parent))
|
|
|
|
|
return QModelIndex();
|
|
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
|
TreeItem *parentItem = (!parent.isValid()) ? rootItem : static_cast<TreeItem *>(parent.internalPointer());
|
2013-06-17 18:59:50 -03:00
|
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
|
TreeItem *childItem = parentItem->children[row];
|
2013-06-17 18:59:50 -03:00
|
|
|
|
|
|
|
|
|
return (childItem) ? createIndex(row, column, childItem) : QModelIndex();
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
|
QModelIndex TreeModel::parent(const QModelIndex &index) const
|
2013-06-17 18:59:50 -03:00
|
|
|
|
{
|
|
|
|
|
if (!index.isValid())
|
|
|
|
|
return QModelIndex();
|
|
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
|
TreeItem *childItem = static_cast<TreeItem *>(index.internalPointer());
|
|
|
|
|
TreeItem *parentItem = childItem->parent;
|
2013-06-17 18:59:50 -03:00
|
|
|
|
|
|
|
|
|
if (parentItem == rootItem || !parentItem)
|
|
|
|
|
return QModelIndex();
|
|
|
|
|
|
|
|
|
|
return createIndex(parentItem->row(), 0, parentItem);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
|
int TreeModel::rowCount(const QModelIndex &parent) const
|
2013-06-17 18:59:50 -03:00
|
|
|
|
{
|
2014-02-27 20:09:57 -08:00
|
|
|
|
TreeItem *parentItem;
|
2013-06-17 18:59:50 -03:00
|
|
|
|
|
|
|
|
|
if (!parent.isValid())
|
|
|
|
|
parentItem = rootItem;
|
|
|
|
|
else
|
2014-02-27 20:09:57 -08:00
|
|
|
|
parentItem = static_cast<TreeItem *>(parent.internalPointer());
|
2013-06-17 18:59:50 -03:00
|
|
|
|
|
|
|
|
|
int amount = parentItem->children.count();
|
|
|
|
|
return amount;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
|
int TreeModel::columnCount(const QModelIndex &parent) const
|
2013-06-17 18:59:50 -03:00
|
|
|
|
{
|
|
|
|
|
return columns;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*################################################################
|
|
|
|
|
*
|
|
|
|
|
* 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 12:46:35 -07:00
|
|
|
|
/*####################################################################
|
2013-06-07 11:43:45 -03:00
|
|
|
|
*
|
2013-06-17 12:46:35 -07:00
|
|
|
|
* Dive Computer Model
|
2013-06-07 11:43:45 -03:00
|
|
|
|
*
|
|
|
|
|
*####################################################################
|
|
|
|
|
*/
|
|
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
|
DiveComputerModel::DiveComputerModel(QMultiMap<QString, DiveComputerNode> &dcMap, QObject *parent) : CleanerTableModel()
|
2013-06-07 11:43:45 -03:00
|
|
|
|
{
|
2013-10-11 11:42:33 -03:00
|
|
|
|
setHeaderDataStrings(QStringList() << "" << tr("Model") << tr("Device ID") << tr("Nickname"));
|
2013-06-17 15:58:26 -07:00
|
|
|
|
dcWorkingMap = dcMap;
|
|
|
|
|
numRows = 0;
|
2013-06-07 11:43:45 -03:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
|
QVariant DiveComputerModel::data(const QModelIndex &index, int role) const
|
2013-06-07 11:43:45 -03:00
|
|
|
|
{
|
2013-06-17 15:58:26 -07:00
|
|
|
|
QList<DiveComputerNode> values = dcWorkingMap.values();
|
|
|
|
|
DiveComputerNode node = values.at(index.row());
|
2013-06-07 11:43:45 -03:00
|
|
|
|
|
|
|
|
|
QVariant ret;
|
2014-01-16 11:50:56 +07:00
|
|
|
|
if (role == Qt::DisplayRole || role == Qt::EditRole) {
|
|
|
|
|
switch (index.column()) {
|
2014-02-27 20:09:57 -08:00
|
|
|
|
case ID:
|
|
|
|
|
ret = QString("0x").append(QString::number(node.deviceId, 16));
|
|
|
|
|
break;
|
|
|
|
|
case MODEL:
|
|
|
|
|
ret = node.model;
|
|
|
|
|
break;
|
|
|
|
|
case NICKNAME:
|
|
|
|
|
ret = node.nickName;
|
|
|
|
|
break;
|
2013-06-07 11:43:45 -03:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-06-17 12:46:35 -07:00
|
|
|
|
|
2014-01-16 11:50:56 +07:00
|
|
|
|
if (index.column() == REMOVE) {
|
|
|
|
|
switch (role) {
|
2014-02-27 20:09:57 -08:00
|
|
|
|
case Qt::DecorationRole:
|
2014-10-19 16:15:20 +02:00
|
|
|
|
ret = trashIcon();
|
|
|
|
|
break;
|
|
|
|
|
case Qt::SizeHintRole:
|
|
|
|
|
ret = trashIcon().size();
|
2014-02-27 20:09:57 -08:00
|
|
|
|
break;
|
|
|
|
|
case Qt::ToolTipRole:
|
2014-07-11 09:21:38 +01:00
|
|
|
|
ret = tr("Clicking here will remove this dive computer.");
|
2014-02-27 20:09:57 -08:00
|
|
|
|
break;
|
2013-11-21 23:32:11 -02:00
|
|
|
|
}
|
2013-06-07 11:43:45 -03:00
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
|
int DiveComputerModel::rowCount(const QModelIndex &parent) const
|
2013-06-07 11:43:45 -03:00
|
|
|
|
{
|
|
|
|
|
return numRows;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DiveComputerModel::update()
|
|
|
|
|
{
|
2013-06-17 15:58:26 -07:00
|
|
|
|
QList<DiveComputerNode> values = dcWorkingMap.values();
|
|
|
|
|
int count = values.count();
|
2013-06-07 12:57:35 -03:00
|
|
|
|
|
2014-01-16 11:50:56 +07:00
|
|
|
|
if (numRows) {
|
2014-02-27 20:09:57 -08:00
|
|
|
|
beginRemoveRows(QModelIndex(), 0, numRows - 1);
|
2013-06-07 11:43:45 -03:00
|
|
|
|
numRows = 0;
|
|
|
|
|
endRemoveRows();
|
|
|
|
|
}
|
2013-06-07 12:57:35 -03:00
|
|
|
|
|
2014-01-16 11:50:56 +07:00
|
|
|
|
if (count) {
|
2014-02-27 20:09:57 -08:00
|
|
|
|
beginInsertRows(QModelIndex(), 0, count - 1);
|
2013-06-07 11:43:45 -03:00
|
|
|
|
numRows = count;
|
|
|
|
|
endInsertRows();
|
|
|
|
|
}
|
2013-06-07 12:57:35 -03:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
|
Qt::ItemFlags DiveComputerModel::flags(const QModelIndex &index) const
|
2013-06-07 12:57:35 -03:00
|
|
|
|
{
|
|
|
|
|
Qt::ItemFlags flags = QAbstractItemModel::flags(index);
|
|
|
|
|
if (index.column() == NICKNAME)
|
|
|
|
|
flags |= Qt::ItemIsEditable;
|
2014-02-27 20:09:57 -08:00
|
|
|
|
return flags;
|
2013-06-07 12:57:35 -03:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
|
bool DiveComputerModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
2013-06-07 12:57:35 -03:00
|
|
|
|
{
|
2013-06-17 15:58:26 -07:00
|
|
|
|
QList<DiveComputerNode> values = dcWorkingMap.values();
|
|
|
|
|
DiveComputerNode node = values.at(index.row());
|
|
|
|
|
dcWorkingMap.remove(node.model, node);
|
|
|
|
|
node.nickName = value.toString();
|
|
|
|
|
dcWorkingMap.insert(node.model, node);
|
2013-07-16 19:13:58 -03:00
|
|
|
|
emit dataChanged(index, index);
|
2013-06-07 15:25:29 -03:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
|
void DiveComputerModel::remove(const QModelIndex &index)
|
2013-06-07 15:25:29 -03:00
|
|
|
|
{
|
2013-06-17 15:58:26 -07:00
|
|
|
|
QList<DiveComputerNode> values = dcWorkingMap.values();
|
|
|
|
|
DiveComputerNode node = values.at(index.row());
|
|
|
|
|
dcWorkingMap.remove(node.model, node);
|
2013-06-07 15:25:29 -03:00
|
|
|
|
update();
|
2013-06-07 11:43:45 -03:00
|
|
|
|
}
|
2013-06-17 19:41:05 -03:00
|
|
|
|
|
2013-06-18 09:25:24 -07:00
|
|
|
|
void DiveComputerModel::dropWorkingList()
|
|
|
|
|
{
|
|
|
|
|
// how do I prevent the memory leak ?
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DiveComputerModel::keepWorkingList()
|
|
|
|
|
{
|
|
|
|
|
if (dcList.dcMap != dcWorkingMap)
|
2014-01-15 09:30:42 +01:00
|
|
|
|
mark_divelist_changed(true);
|
2013-06-18 09:25:24 -07:00
|
|
|
|
dcList.dcMap = dcWorkingMap;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-17 19:41:05 -03:00
|
|
|
|
/*#################################################################
|
|
|
|
|
* #
|
|
|
|
|
* # Yearly Statistics Model
|
|
|
|
|
* #
|
|
|
|
|
* ################################################################
|
|
|
|
|
*/
|
|
|
|
|
|
2014-01-16 11:50:56 +07:00
|
|
|
|
class YearStatisticsItem : public TreeItem {
|
2013-06-17 21:05:17 -03:00
|
|
|
|
public:
|
2014-02-27 20:09:57 -08:00
|
|
|
|
enum {
|
|
|
|
|
YEAR,
|
|
|
|
|
DIVES,
|
|
|
|
|
TOTAL_TIME,
|
|
|
|
|
AVERAGE_TIME,
|
|
|
|
|
SHORTEST_TIME,
|
|
|
|
|
LONGEST_TIME,
|
|
|
|
|
AVG_DEPTH,
|
|
|
|
|
MIN_DEPTH,
|
|
|
|
|
MAX_DEPTH,
|
|
|
|
|
AVG_SAC,
|
|
|
|
|
MIN_SAC,
|
|
|
|
|
MAX_SAC,
|
|
|
|
|
AVG_TEMP,
|
|
|
|
|
MIN_TEMP,
|
|
|
|
|
MAX_TEMP,
|
|
|
|
|
COLUMNS
|
|
|
|
|
};
|
2013-06-17 21:05:17 -03:00
|
|
|
|
|
|
|
|
|
QVariant data(int column, int role) const;
|
|
|
|
|
YearStatisticsItem(stats_t interval);
|
2014-02-27 20:09:57 -08:00
|
|
|
|
|
2013-06-17 21:05:17 -03:00
|
|
|
|
private:
|
|
|
|
|
stats_t stats_interval;
|
|
|
|
|
};
|
|
|
|
|
|
2013-06-18 09:26:23 -07:00
|
|
|
|
YearStatisticsItem::YearStatisticsItem(stats_t interval) : stats_interval(interval)
|
2013-06-17 21:05:17 -03:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant YearStatisticsItem::data(int column, int role) const
|
|
|
|
|
{
|
2013-06-18 09:26:23 -07:00
|
|
|
|
double value;
|
2013-06-17 21:05:17 -03:00
|
|
|
|
QVariant ret;
|
|
|
|
|
|
2013-06-19 10:30:36 -07:00
|
|
|
|
if (role == Qt::FontRole) {
|
|
|
|
|
QFont font = defaultModelFont();
|
|
|
|
|
font.setBold(stats_interval.is_year);
|
|
|
|
|
return font;
|
|
|
|
|
} else if (role != Qt::DisplayRole) {
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
2014-01-16 11:50:56 +07:00
|
|
|
|
switch (column) {
|
2013-11-24 03:09:34 +02:00
|
|
|
|
case YEAR:
|
|
|
|
|
if (stats_interval.is_trip) {
|
|
|
|
|
ret = stats_interval.location;
|
|
|
|
|
} else {
|
2014-02-27 20:09:57 -08:00
|
|
|
|
ret = stats_interval.period;
|
2013-11-24 03:09:34 +02:00
|
|
|
|
}
|
|
|
|
|
break;
|
2014-02-27 20:09:57 -08:00
|
|
|
|
case DIVES:
|
|
|
|
|
ret = stats_interval.selection_size;
|
|
|
|
|
break;
|
|
|
|
|
case TOTAL_TIME:
|
|
|
|
|
ret = get_time_string(stats_interval.total_time.seconds, 0);
|
|
|
|
|
break;
|
|
|
|
|
case AVERAGE_TIME:
|
|
|
|
|
ret = get_minutes(stats_interval.total_time.seconds / stats_interval.selection_size);
|
|
|
|
|
break;
|
|
|
|
|
case SHORTEST_TIME:
|
|
|
|
|
ret = get_minutes(stats_interval.shortest_time.seconds);
|
|
|
|
|
break;
|
|
|
|
|
case LONGEST_TIME:
|
|
|
|
|
ret = get_minutes(stats_interval.longest_time.seconds);
|
|
|
|
|
break;
|
|
|
|
|
case AVG_DEPTH:
|
|
|
|
|
ret = get_depth_string(stats_interval.avg_depth);
|
|
|
|
|
break;
|
|
|
|
|
case MIN_DEPTH:
|
|
|
|
|
ret = get_depth_string(stats_interval.min_depth);
|
|
|
|
|
break;
|
|
|
|
|
case MAX_DEPTH:
|
|
|
|
|
ret = get_depth_string(stats_interval.max_depth);
|
|
|
|
|
break;
|
|
|
|
|
case AVG_SAC:
|
|
|
|
|
ret = get_volume_string(stats_interval.avg_sac);
|
|
|
|
|
break;
|
|
|
|
|
case MIN_SAC:
|
|
|
|
|
ret = get_volume_string(stats_interval.min_sac);
|
|
|
|
|
break;
|
|
|
|
|
case MAX_SAC:
|
|
|
|
|
ret = get_volume_string(stats_interval.max_sac);
|
|
|
|
|
break;
|
2013-06-18 09:26:23 -07:00
|
|
|
|
case AVG_TEMP:
|
|
|
|
|
if (stats_interval.combined_temp && stats_interval.combined_count) {
|
2013-06-18 10:48:46 -07:00
|
|
|
|
ret = QString::number(stats_interval.combined_temp / stats_interval.combined_count, 'f', 1);
|
2013-06-18 09:26:23 -07:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case MIN_TEMP:
|
2013-06-18 10:48:46 -07:00
|
|
|
|
value = get_temp_units(stats_interval.min_temp, NULL);
|
|
|
|
|
if (value > -100.0)
|
2014-02-27 20:09:57 -08:00
|
|
|
|
ret = QString::number(value, 'f', 1);
|
2013-06-18 09:26:23 -07:00
|
|
|
|
break;
|
|
|
|
|
case MAX_TEMP:
|
2013-06-18 10:48:46 -07:00
|
|
|
|
value = get_temp_units(stats_interval.max_temp, NULL);
|
|
|
|
|
if (value > -100.0)
|
2014-02-27 20:09:57 -08:00
|
|
|
|
ret = QString::number(value, 'f', 1);
|
2013-06-18 09:26:23 -07:00
|
|
|
|
break;
|
2013-06-17 21:05:17 -03:00
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
|
YearlyStatisticsModel::YearlyStatisticsModel(QObject *parent)
|
2013-06-17 19:41:05 -03:00
|
|
|
|
{
|
2013-06-17 20:02:30 -03:00
|
|
|
|
columns = COLUMNS;
|
2013-06-17 21:05:17 -03:00
|
|
|
|
update_yearly_stats();
|
2013-06-17 19:41:05 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant YearlyStatisticsModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
|
|
|
{
|
|
|
|
|
QVariant val;
|
2013-06-18 09:26:23 -07:00
|
|
|
|
if (role == Qt::FontRole)
|
2014-02-27 20:09:57 -08:00
|
|
|
|
val = defaultModelFont();
|
2013-06-17 21:05:17 -03:00
|
|
|
|
|
2013-06-18 09:26:23 -07:00
|
|
|
|
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
|
2014-01-16 11:50:56 +07:00
|
|
|
|
switch (section) {
|
2014-02-27 20:09:57 -08:00
|
|
|
|
case YEAR:
|
|
|
|
|
val = tr("Year \n > Month / Trip");
|
|
|
|
|
break;
|
|
|
|
|
case DIVES:
|
|
|
|
|
val = tr("#");
|
|
|
|
|
break;
|
|
|
|
|
case TOTAL_TIME:
|
|
|
|
|
val = tr("Duration \n Total");
|
|
|
|
|
break;
|
|
|
|
|
case AVERAGE_TIME:
|
|
|
|
|
val = tr("\nAverage");
|
|
|
|
|
break;
|
|
|
|
|
case SHORTEST_TIME:
|
|
|
|
|
val = tr("\nShortest");
|
|
|
|
|
break;
|
|
|
|
|
case LONGEST_TIME:
|
|
|
|
|
val = tr("\nLongest");
|
|
|
|
|
break;
|
|
|
|
|
case AVG_DEPTH:
|
|
|
|
|
val = QString(tr("Depth (%1)\n Average")).arg(get_depth_unit());
|
|
|
|
|
break;
|
|
|
|
|
case MIN_DEPTH:
|
|
|
|
|
val = tr("\nMinimum");
|
|
|
|
|
break;
|
|
|
|
|
case MAX_DEPTH:
|
|
|
|
|
val = tr("\nMaximum");
|
|
|
|
|
break;
|
|
|
|
|
case AVG_SAC:
|
|
|
|
|
val = QString(tr("SAC (%1)\n Average")).arg(get_volume_unit());
|
|
|
|
|
break;
|
|
|
|
|
case MIN_SAC:
|
|
|
|
|
val = tr("\nMinimum");
|
|
|
|
|
break;
|
|
|
|
|
case MAX_SAC:
|
|
|
|
|
val = tr("\nMaximum");
|
|
|
|
|
break;
|
|
|
|
|
case AVG_TEMP:
|
|
|
|
|
val = QString(tr("Temp. (%1)\n Average").arg(get_temp_unit()));
|
|
|
|
|
break;
|
|
|
|
|
case MIN_TEMP:
|
|
|
|
|
val = tr("\nMinimum");
|
|
|
|
|
break;
|
|
|
|
|
case MAX_TEMP:
|
|
|
|
|
val = tr("\nMaximum");
|
|
|
|
|
break;
|
2013-06-17 20:02:30 -03:00
|
|
|
|
}
|
2013-06-17 19:41:05 -03:00
|
|
|
|
}
|
2013-06-17 20:02:30 -03:00
|
|
|
|
return val;
|
2013-06-17 19:41:05 -03:00
|
|
|
|
}
|
2013-06-17 21:05:17 -03:00
|
|
|
|
|
|
|
|
|
void YearlyStatisticsModel::update_yearly_stats()
|
|
|
|
|
{
|
|
|
|
|
int i, month = 0;
|
|
|
|
|
unsigned int j, combined_months;
|
|
|
|
|
|
2013-06-18 09:26:23 -07:00
|
|
|
|
for (i = 0; stats_yearly != NULL && stats_yearly[i].period; ++i) {
|
2013-06-17 21:05:17 -03:00
|
|
|
|
YearStatisticsItem *item = new YearStatisticsItem(stats_yearly[i]);
|
|
|
|
|
combined_months = 0;
|
|
|
|
|
for (j = 0; combined_months < stats_yearly[i].selection_size; ++j) {
|
|
|
|
|
combined_months += stats_monthly[month].selection_size;
|
|
|
|
|
YearStatisticsItem *iChild = new YearStatisticsItem(stats_monthly[month]);
|
|
|
|
|
item->children.append(iChild);
|
2013-06-18 13:29:37 -07:00
|
|
|
|
iChild->parent = item;
|
2013-06-17 21:05:17 -03:00
|
|
|
|
month++;
|
|
|
|
|
}
|
|
|
|
|
rootItem->children.append(item);
|
2013-06-18 13:29:37 -07:00
|
|
|
|
item->parent = rootItem;
|
2013-06-17 21:05:17 -03:00
|
|
|
|
}
|
2013-11-24 03:09:34 +02:00
|
|
|
|
|
|
|
|
|
|
2014-01-15 09:30:42 +01:00
|
|
|
|
if (stats_by_trip != NULL && stats_by_trip[0].is_trip == true) {
|
2013-11-24 03:09:34 +02:00
|
|
|
|
YearStatisticsItem *item = new YearStatisticsItem(stats_by_trip[0]);
|
|
|
|
|
for (i = 1; stats_by_trip != NULL && stats_by_trip[i].is_trip; ++i) {
|
|
|
|
|
YearStatisticsItem *iChild = new YearStatisticsItem(stats_by_trip[i]);
|
|
|
|
|
item->children.append(iChild);
|
|
|
|
|
iChild->parent = item;
|
|
|
|
|
}
|
|
|
|
|
rootItem->children.append(item);
|
|
|
|
|
item->parent = rootItem;
|
|
|
|
|
}
|
2013-06-17 21:05:17 -03:00
|
|
|
|
}
|
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();
|
|
|
|
|
}
|
2014-09-17 15:45:18 -03:00
|
|
|
|
|
2014-11-06 11:24:38 -08:00
|
|
|
|
ExtraDataModel::ExtraDataModel(QObject *parent) : CleanerTableModel(parent),
|
|
|
|
|
rows(0)
|
|
|
|
|
{
|
|
|
|
|
//enum Column {KEY, VALUE};
|
|
|
|
|
setHeaderDataStrings(QStringList() << tr("Key") << tr("Value"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ExtraDataModel::clear()
|
|
|
|
|
{
|
|
|
|
|
if (rows > 0) {
|
|
|
|
|
beginRemoveRows(QModelIndex(), 0, rows - 1);
|
|
|
|
|
endRemoveRows();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant ExtraDataModel::data(const QModelIndex &index, int role) const
|
|
|
|
|
{
|
|
|
|
|
QVariant ret;
|
|
|
|
|
struct extra_data *ed = get_dive_dc(&displayed_dive, dc_number)->extra_data;
|
|
|
|
|
int i = -1;
|
|
|
|
|
while (ed && ++i < index.row())
|
|
|
|
|
ed = ed->next;
|
|
|
|
|
if (!ed)
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
|
|
switch (role) {
|
|
|
|
|
case Qt::FontRole:
|
|
|
|
|
ret = defaultModelFont();
|
|
|
|
|
break;
|
|
|
|
|
case Qt::TextAlignmentRole:
|
|
|
|
|
ret = int(Qt::AlignLeft | Qt::AlignVCenter);
|
|
|
|
|
break;
|
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
|
switch (index.column()) {
|
|
|
|
|
case KEY:
|
|
|
|
|
ret = QString(ed->key);
|
|
|
|
|
break;
|
|
|
|
|
case VALUE:
|
|
|
|
|
ret = QString(ed->value);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ExtraDataModel::rowCount(const QModelIndex &parent) const
|
|
|
|
|
{
|
|
|
|
|
return rows;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ExtraDataModel::updateDive()
|
|
|
|
|
{
|
|
|
|
|
clear();
|
|
|
|
|
rows = 0;
|
|
|
|
|
struct extra_data *ed = get_dive_dc(&displayed_dive, dc_number)->extra_data;
|
|
|
|
|
while (ed) {
|
|
|
|
|
rows++;
|
|
|
|
|
ed = ed->next;
|
|
|
|
|
}
|
|
|
|
|
if (rows > 0) {
|
|
|
|
|
beginInsertRows(QModelIndex(), 0, rows - 1);
|
|
|
|
|
endInsertRows();
|
|
|
|
|
}
|
|
|
|
|
}
|