2013-04-14 03:44:02 +00:00
|
|
|
|
/*
|
|
|
|
|
* models.cpp
|
|
|
|
|
*
|
|
|
|
|
* classes for the equipment models of Subsurface
|
|
|
|
|
*
|
|
|
|
|
*/
|
2013-04-13 13:17:59 +00:00
|
|
|
|
#include "models.h"
|
2013-11-13 12:45:54 +00:00
|
|
|
|
#include "diveplanner.h"
|
|
|
|
|
#include "mainwindow.h"
|
2014-11-04 01:32:12 +00:00
|
|
|
|
#include "helpers.h"
|
|
|
|
|
#include "dive.h"
|
|
|
|
|
#include "device.h"
|
|
|
|
|
#include "statistics.h"
|
|
|
|
|
#include "qthelper.h"
|
|
|
|
|
#include "gettextfromc.h"
|
|
|
|
|
#include "display.h"
|
2013-06-07 18:25:29 +00:00
|
|
|
|
|
2013-05-02 02:51:34 +00:00
|
|
|
|
#include <QCoreApplication>
|
|
|
|
|
#include <QDebug>
|
2013-12-06 16:29:38 +00:00
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QSettings>
|
2013-05-02 21:19:15 +00:00
|
|
|
|
#include <QColor>
|
|
|
|
|
#include <QBrush>
|
2013-05-19 13:46:49 +00:00
|
|
|
|
#include <QFont>
|
2013-05-22 14:00:20 +00:00
|
|
|
|
#include <QIcon>
|
2013-11-13 12:45:54 +00:00
|
|
|
|
#include <QMessageBox>
|
2014-02-11 17:50:44 +00:00
|
|
|
|
#include <QStringListModel>
|
2013-04-24 15:57:30 +00:00
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
CleanerTableModel::CleanerTableModel(QObject *parent) : QAbstractTableModel(parent)
|
2013-04-13 13:17:59 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
int CleanerTableModel::columnCount(const QModelIndex &parent) const
|
2013-10-11 13:50:40 +00:00
|
|
|
|
{
|
|
|
|
|
return headers.count();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant CleanerTableModel::headerData(int section, Qt::Orientation orientation, int role) const
|
2013-04-13 13:17:59 +00:00
|
|
|
|
{
|
|
|
|
|
QVariant ret;
|
2013-05-26 03:04:31 +00:00
|
|
|
|
|
2013-05-02 05:00:08 +00:00
|
|
|
|
if (orientation == Qt::Vertical)
|
2013-04-13 13:17:59 +00:00
|
|
|
|
return ret;
|
|
|
|
|
|
2013-05-26 03:04:31 +00:00
|
|
|
|
switch (role) {
|
|
|
|
|
case Qt::FontRole:
|
2013-06-16 14:13:32 +00:00
|
|
|
|
ret = defaultModelFont();
|
|
|
|
|
break;
|
2013-05-26 03:04:31 +00:00
|
|
|
|
case Qt::DisplayRole:
|
2013-10-11 14:04:27 +00:00
|
|
|
|
ret = headers.at(section);
|
2013-04-13 13:17:59 +00:00
|
|
|
|
}
|
2013-10-11 14:04:27 +00:00
|
|
|
|
return ret;
|
2013-04-13 13:17:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
void CleanerTableModel::setHeaderDataStrings(const QStringList &newHeaders)
|
2013-10-11 13:50:40 +00:00
|
|
|
|
{
|
|
|
|
|
headers = newHeaders;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-19 14:15:20 +00:00
|
|
|
|
static QPixmap *trashIconPixmap;
|
|
|
|
|
|
|
|
|
|
// initialize the trash icon if necessary
|
2014-10-31 21:28:39 +00:00
|
|
|
|
static void initTrashIcon()
|
|
|
|
|
{
|
2014-10-19 14:15:20 +00:00
|
|
|
|
if (!trashIconPixmap)
|
|
|
|
|
trashIconPixmap = new QPixmap(QIcon(":trash").pixmap(defaultIconMetrics().sz_small));
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-31 21:28:39 +00:00
|
|
|
|
const QPixmap &trashIcon()
|
|
|
|
|
{
|
2014-10-19 14:15:20 +00:00
|
|
|
|
return *trashIconPixmap;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-13 20:51:23 +00:00
|
|
|
|
CylindersModel::CylindersModel(QObject *parent) : changed(false),
|
2014-11-08 13:11:06 +00:00
|
|
|
|
rows(0)
|
2013-04-13 13:17:59 +00:00
|
|
|
|
{
|
2014-01-16 04:50:56 +00:00
|
|
|
|
// enum {REMOVE, TYPE, SIZE, WORKINGPRESS, START, END, O2, HE, DEPTH};
|
2014-11-25 15:47:23 +00:00
|
|
|
|
setHeaderDataStrings(QStringList() << "" << tr("Type") << tr("Size") << tr("Work press.") << tr("Start press.") << tr("End press.") << tr("O₂%") << tr("He%")
|
2014-11-17 14:03:37 +00:00
|
|
|
|
<< tr("Switch at") << tr("Use"));
|
2014-10-19 14:15:20 +00:00
|
|
|
|
|
|
|
|
|
initTrashIcon();
|
2013-04-13 13:17:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-09 22:06:26 +00:00
|
|
|
|
CylindersModel *CylindersModel::instance()
|
|
|
|
|
{
|
2014-10-19 14:15:20 +00:00
|
|
|
|
|
2013-11-30 17:18:04 +00:00
|
|
|
|
static QScopedPointer<CylindersModel> self(new CylindersModel());
|
|
|
|
|
return self.data();
|
2013-11-09 22:06:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-20 04:22:09 +00:00
|
|
|
|
static QVariant percent_string(fraction_t fraction)
|
|
|
|
|
{
|
|
|
|
|
int permille = fraction.permille;
|
|
|
|
|
|
|
|
|
|
if (!permille)
|
|
|
|
|
return QVariant();
|
|
|
|
|
return QString("%1%").arg(permille / 10.0, 0, 'f', 1);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
QVariant CylindersModel::data(const QModelIndex &index, int role) const
|
2013-04-13 13:17:59 +00:00
|
|
|
|
{
|
|
|
|
|
QVariant ret;
|
2013-05-26 03:04:31 +00:00
|
|
|
|
|
2013-05-02 05:00:08 +00:00
|
|
|
|
if (!index.isValid() || index.row() >= MAX_CYLINDERS)
|
2013-04-13 13:17:59 +00:00
|
|
|
|
return ret;
|
2013-05-02 05:00:08 +00:00
|
|
|
|
|
2014-07-03 05:38:08 +00:00
|
|
|
|
cylinder_t *cyl = &displayed_dive.cylinder[index.row()];
|
2013-05-26 03:04:31 +00:00
|
|
|
|
switch (role) {
|
2014-08-06 04:21:31 +00:00
|
|
|
|
case Qt::BackgroundRole: {
|
|
|
|
|
switch (index.column()) {
|
|
|
|
|
// mark the cylinder start / end pressure in red if the values
|
|
|
|
|
// seem implausible
|
|
|
|
|
case START:
|
|
|
|
|
case END:
|
|
|
|
|
if ((cyl->start.mbar && !cyl->end.mbar) ||
|
|
|
|
|
(cyl->end.mbar && cyl->start.mbar <= cyl->end.mbar))
|
|
|
|
|
ret = REDORANGE1_HIGH_TRANS;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-06-20 04:42:48 +00:00
|
|
|
|
case Qt::FontRole: {
|
|
|
|
|
QFont font = defaultModelFont();
|
|
|
|
|
switch (index.column()) {
|
2014-02-28 04:09:57 +00:00
|
|
|
|
case START:
|
|
|
|
|
font.setItalic(!cyl->start.mbar);
|
|
|
|
|
break;
|
|
|
|
|
case END:
|
|
|
|
|
font.setItalic(!cyl->end.mbar);
|
|
|
|
|
break;
|
2013-06-20 04:42:48 +00:00
|
|
|
|
}
|
|
|
|
|
ret = font;
|
2013-05-26 03:04:31 +00:00
|
|
|
|
break;
|
2013-06-20 04:42:48 +00:00
|
|
|
|
}
|
2013-05-26 03:04:31 +00:00
|
|
|
|
case Qt::TextAlignmentRole:
|
2013-11-22 01:24:58 +00:00
|
|
|
|
ret = Qt::AlignCenter;
|
2014-02-28 04:09:57 +00:00
|
|
|
|
break;
|
2013-05-26 03:04:31 +00:00
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
|
case Qt::EditRole:
|
2014-01-16 04:50:56 +00:00
|
|
|
|
switch (index.column()) {
|
2013-04-13 13:17:59 +00:00
|
|
|
|
case TYPE:
|
2013-05-21 19:03:05 +00:00
|
|
|
|
ret = QString(cyl->type.description);
|
2013-04-13 13:17:59 +00:00
|
|
|
|
break;
|
|
|
|
|
case SIZE:
|
2014-01-03 05:36:01 +00:00
|
|
|
|
if (cyl->type.size.mliter)
|
2014-01-15 08:30:42 +00:00
|
|
|
|
ret = get_volume_string(cyl->type.size, true, cyl->type.workingpressure.mbar);
|
2013-04-13 13:17:59 +00:00
|
|
|
|
break;
|
2013-05-22 20:29:17 +00:00
|
|
|
|
case WORKINGPRESS:
|
2013-05-21 19:03:05 +00:00
|
|
|
|
if (cyl->type.workingpressure.mbar)
|
2014-01-15 08:30:42 +00:00
|
|
|
|
ret = get_pressure_string(cyl->type.workingpressure, true);
|
2013-04-13 13:17:59 +00:00
|
|
|
|
break;
|
|
|
|
|
case START:
|
2013-05-21 19:03:05 +00:00
|
|
|
|
if (cyl->start.mbar)
|
2014-01-15 08:30:42 +00:00
|
|
|
|
ret = get_pressure_string(cyl->start, true);
|
2013-06-20 04:42:48 +00:00
|
|
|
|
else if (cyl->sample_start.mbar)
|
2014-01-15 08:30:42 +00:00
|
|
|
|
ret = get_pressure_string(cyl->sample_start, true);
|
2013-04-13 13:17:59 +00:00
|
|
|
|
break;
|
|
|
|
|
case END:
|
2013-05-21 19:03:05 +00:00
|
|
|
|
if (cyl->end.mbar)
|
2014-01-15 08:30:42 +00:00
|
|
|
|
ret = get_pressure_string(cyl->end, true);
|
2013-06-20 04:42:48 +00:00
|
|
|
|
else if (cyl->sample_end.mbar)
|
2014-01-15 08:30:42 +00:00
|
|
|
|
ret = get_pressure_string(cyl->sample_end, true);
|
2013-04-13 13:17:59 +00:00
|
|
|
|
break;
|
|
|
|
|
case O2:
|
2013-06-20 04:22:09 +00:00
|
|
|
|
ret = percent_string(cyl->gasmix.o2);
|
2013-04-13 13:17:59 +00:00
|
|
|
|
break;
|
|
|
|
|
case HE:
|
2013-06-20 04:22:09 +00:00
|
|
|
|
ret = percent_string(cyl->gasmix.he);
|
2013-04-13 13:17:59 +00:00
|
|
|
|
break;
|
2014-03-22 14:13:58 +00:00
|
|
|
|
case DEPTH:
|
|
|
|
|
ret = get_depth_string(cyl->depth, true);
|
|
|
|
|
break;
|
2014-11-17 14:03:37 +00:00
|
|
|
|
case USE:
|
2014-11-17 14:15:19 +00:00
|
|
|
|
ret = gettextFromC::instance()->trGettext(cylinderuse_text[cyl->cylinder_use]);
|
2014-11-17 14:03:37 +00:00
|
|
|
|
break;
|
2013-04-13 13:17:59 +00:00
|
|
|
|
}
|
2013-05-26 03:04:31 +00:00
|
|
|
|
break;
|
|
|
|
|
case Qt::DecorationRole:
|
2013-05-23 04:25:05 +00:00
|
|
|
|
if (index.column() == REMOVE)
|
2014-10-19 14:15:20 +00:00
|
|
|
|
ret = trashIcon();
|
|
|
|
|
break;
|
|
|
|
|
case Qt::SizeHintRole:
|
|
|
|
|
if (index.column() == REMOVE)
|
|
|
|
|
ret = trashIcon().size();
|
2013-05-26 03:04:31 +00:00
|
|
|
|
break;
|
2013-11-22 01:32:11 +00:00
|
|
|
|
|
|
|
|
|
case Qt::ToolTipRole:
|
|
|
|
|
if (index.column() == REMOVE)
|
|
|
|
|
ret = tr("Clicking here will remove this cylinder.");
|
|
|
|
|
break;
|
2013-05-22 14:00:20 +00:00
|
|
|
|
}
|
2013-07-18 13:24:02 +00:00
|
|
|
|
|
2013-04-13 13:17:59 +00:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
cylinder_t *CylindersModel::cylinderAt(const QModelIndex &index)
|
2013-07-18 13:24:02 +00:00
|
|
|
|
{
|
2014-07-03 05:38:08 +00:00
|
|
|
|
return &displayed_dive.cylinder[index.row()];
|
2013-07-18 13:24:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-23 20:31:46 +00: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-28 04:09:57 +00:00
|
|
|
|
void CylindersModel::passInData(const QModelIndex &index, const QVariant &value)
|
2013-05-23 20:31:46 +00:00
|
|
|
|
{
|
2013-11-12 07:33:01 +00:00
|
|
|
|
cylinder_t *cyl = cylinderAt(index);
|
2014-01-16 04:50:56 +00:00
|
|
|
|
switch (index.column()) {
|
2013-05-23 20:31:46 +00:00
|
|
|
|
case SIZE:
|
|
|
|
|
if (cyl->type.size.mliter != value.toInt()) {
|
|
|
|
|
cyl->type.size.mliter = value.toInt();
|
2013-07-16 22:13:58 +00:00
|
|
|
|
dataChanged(index, index);
|
2013-05-23 20:31:46 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case WORKINGPRESS:
|
|
|
|
|
if (cyl->type.workingpressure.mbar != value.toInt()) {
|
|
|
|
|
cyl->type.workingpressure.mbar = value.toInt();
|
2013-07-16 22:13:58 +00:00
|
|
|
|
dataChanged(index, index);
|
2013-05-23 20:31:46 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-09 02:47:28 +00:00
|
|
|
|
/* Has the string value changed */
|
|
|
|
|
#define CHANGED() \
|
2014-03-05 20:19:45 +00:00
|
|
|
|
(vString = value.toString()) != data(index, role).toString()
|
2013-05-22 20:29:17 +00:00
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
bool CylindersModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
2013-05-22 15:20:00 +00:00
|
|
|
|
{
|
2014-01-02 17:12:32 +00:00
|
|
|
|
QString vString;
|
2013-11-13 12:45:54 +00:00
|
|
|
|
bool addDiveMode = DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING;
|
|
|
|
|
if (addDiveMode)
|
|
|
|
|
DivePlannerPointsModel::instance()->rememberTanks();
|
|
|
|
|
|
2013-11-12 07:33:01 +00:00
|
|
|
|
cylinder_t *cyl = cylinderAt(index);
|
2014-01-16 04:50:56 +00:00
|
|
|
|
switch (index.column()) {
|
2013-05-22 20:29:17 +00:00
|
|
|
|
case TYPE:
|
|
|
|
|
if (!value.isNull()) {
|
Fix usage of temporary QByteArrays
This commit fixes three different things:
- a memory leak in WeightModel::setData()
- getSetting() calling strdup() on a QByteArray
- a possible usage of memory after deallocation
Here's an explanation of the last issue (taken from the mailing list, slightly
adapted):
toByteArray(), as well as others "toSomething()" methods, returns
a new object which the compiler allocates on the stack. The compiler
will consider it a temporary data, and destroy it on the next line. So,
when one does
char *text= value.toByteArray().data(); // line 1
if (strcmp(description, text)) { // line 2
the compiler creates a QByteArray on line 1, calls ::data() on it, which
returns a valid char *, and assigns its value to "text". So far, so
good. But before jumping to line 2, the compiler destroys the temporary
QByteArray, and this will in turn invoke the QByteArray destructor,
which will destroy the internal data. The result is that on line 2,
"text" will point to some memory which has already been freed.
One solution is to store a copy of the temporary QByteArray into a local
variable: the compiler will still destroy the temporary QByteArray it created,
but (thanks to the reference-counted data sharing built in QByteArray) now the
destructor will see that the data is referenced by another instance of
QByteArray (the local variable "ba") and will not free the internal data.
In this way, the internal data will be available until the local variable is
destroyed, which will happen at the end of the {} block where it is defined.
Please note that when one uses the data in the same line, one doesn't need to
worry about this issue. In fact,
text = strdup(value.toString().toUtf8().data());
works just fine.
Signed-off-by: Alberto Mardegan <mardy@users.sourceforge.net>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-24 11:39:37 +00:00
|
|
|
|
QByteArray ba = value.toByteArray();
|
|
|
|
|
const char *text = ba.constData();
|
2013-05-22 23:22:21 +00:00
|
|
|
|
if (!cyl->type.description || strcmp(cyl->type.description, text)) {
|
2013-05-22 20:29:17 +00:00
|
|
|
|
cyl->type.description = strdup(text);
|
2013-09-25 17:23:51 +00:00
|
|
|
|
changed = true;
|
2013-05-22 20:29:17 +00:00
|
|
|
|
}
|
2013-05-22 15:20:00 +00:00
|
|
|
|
}
|
2013-05-22 20:29:17 +00:00
|
|
|
|
break;
|
|
|
|
|
case SIZE:
|
2014-01-09 02:47:28 +00:00
|
|
|
|
if (CHANGED()) {
|
2014-01-09 02:34:25 +00:00
|
|
|
|
TankInfoModel *tanks = TankInfoModel::instance();
|
2014-02-28 04:09:57 +00:00
|
|
|
|
QModelIndexList matches = tanks->match(tanks->index(0, 0), Qt::DisplayRole, cyl->type.description);
|
2014-01-09 02:34:25 +00:00
|
|
|
|
|
|
|
|
|
cyl->type.size = string_to_volume(vString.toUtf8().data(), cyl->type.workingpressure);
|
2014-01-15 08:30:42 +00:00
|
|
|
|
mark_divelist_changed(true);
|
2014-01-09 02:34:25 +00:00
|
|
|
|
if (!matches.isEmpty())
|
|
|
|
|
tanks->setData(tanks->index(matches.first().row(), TankInfoModel::ML), cyl->type.size.mliter);
|
|
|
|
|
changed = true;
|
2013-05-22 20:29:17 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case WORKINGPRESS:
|
2014-01-09 02:47:28 +00:00
|
|
|
|
if (CHANGED()) {
|
2014-01-09 00:49:21 +00:00
|
|
|
|
TankInfoModel *tanks = TankInfoModel::instance();
|
2014-02-28 04:09:57 +00:00
|
|
|
|
QModelIndexList matches = tanks->match(tanks->index(0, 0), Qt::DisplayRole, cyl->type.description);
|
2014-01-09 00:49:21 +00:00
|
|
|
|
cyl->type.workingpressure = string_to_pressure(vString.toUtf8().data());
|
|
|
|
|
if (!matches.isEmpty())
|
|
|
|
|
tanks->setData(tanks->index(matches.first().row(), TankInfoModel::BAR), cyl->type.workingpressure.mbar / 1000.0);
|
|
|
|
|
changed = true;
|
2013-05-22 20:29:17 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case START:
|
2014-08-06 04:21:31 +00:00
|
|
|
|
if (CHANGED()) {
|
2014-01-09 00:49:21 +00:00
|
|
|
|
cyl->start = string_to_pressure(vString.toUtf8().data());
|
|
|
|
|
changed = true;
|
2013-05-22 20:29:17 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case END:
|
2014-08-06 04:21:31 +00:00
|
|
|
|
if (CHANGED()) {
|
|
|
|
|
//&& (!cyl->start.mbar || string_to_pressure(vString.toUtf8().data()).mbar <= cyl->start.mbar)) {
|
2014-01-09 00:49:21 +00:00
|
|
|
|
cyl->end = string_to_pressure(vString.toUtf8().data());
|
|
|
|
|
changed = true;
|
2013-05-22 20:29:17 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case O2:
|
2014-01-09 02:47:28 +00:00
|
|
|
|
if (CHANGED()) {
|
2014-01-09 02:43:28 +00:00
|
|
|
|
cyl->gasmix.o2 = string_to_fraction(vString.toUtf8().data());
|
2014-06-22 14:41:44 +00:00
|
|
|
|
pressure_t modpO2;
|
2015-01-16 12:02:26 +00:00
|
|
|
|
if (displayed_dive.dc.divemode == PSCR)
|
|
|
|
|
modpO2.mbar = prefs.decopo2 + (1000 - get_o2(&cyl->gasmix)) * SURFACE_PRESSURE *
|
|
|
|
|
prefs.o2consumption / prefs.decosac / prefs.pscr_ratio;
|
|
|
|
|
else
|
|
|
|
|
modpO2.mbar = prefs.decopo2;
|
2014-09-17 22:39:49 +00:00
|
|
|
|
cyl->depth = gas_mod(&cyl->gasmix, modpO2, M_OR_FT(3, 10));
|
2014-01-09 02:43:28 +00:00
|
|
|
|
changed = true;
|
2013-05-22 20:29:17 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case HE:
|
2014-01-09 02:47:28 +00:00
|
|
|
|
if (CHANGED()) {
|
2014-01-09 02:43:28 +00:00
|
|
|
|
cyl->gasmix.he = string_to_fraction(vString.toUtf8().data());
|
|
|
|
|
changed = true;
|
2013-05-22 20:29:17 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
2014-03-22 14:13:58 +00:00
|
|
|
|
case DEPTH:
|
|
|
|
|
if (CHANGED()) {
|
|
|
|
|
cyl->depth = string_to_depth(vString.toUtf8().data());
|
|
|
|
|
changed = true;
|
|
|
|
|
}
|
2014-11-17 14:03:37 +00:00
|
|
|
|
break;
|
|
|
|
|
case USE:
|
|
|
|
|
if (CHANGED()) {
|
|
|
|
|
cyl->cylinder_use = (enum cylinderuse)vString.toInt();
|
|
|
|
|
changed = true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2013-05-22 15:20:00 +00:00
|
|
|
|
}
|
2013-11-13 12:45:54 +00:00
|
|
|
|
if (addDiveMode)
|
|
|
|
|
DivePlannerPointsModel::instance()->tanksUpdated();
|
2014-05-30 00:45:06 +00:00
|
|
|
|
dataChanged(index, index);
|
2013-07-16 22:13:58 +00:00
|
|
|
|
return true;
|
2013-05-22 15:20:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
int CylindersModel::rowCount(const QModelIndex &parent) const
|
2013-04-13 13:17:59 +00:00
|
|
|
|
{
|
2014-02-28 04:09:57 +00:00
|
|
|
|
return rows;
|
2013-04-13 13:17:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-22 17:52:38 +00:00
|
|
|
|
void CylindersModel::add()
|
2013-04-13 13:17:59 +00:00
|
|
|
|
{
|
2013-05-21 12:33:55 +00:00
|
|
|
|
if (rows >= MAX_CYLINDERS) {
|
2013-05-01 21:49:17 +00:00
|
|
|
|
return;
|
2013-04-13 13:17:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-21 12:33:55 +00:00
|
|
|
|
int row = rows;
|
2014-07-03 05:38:08 +00:00
|
|
|
|
fill_default_cylinder(&displayed_dive.cylinder[row]);
|
|
|
|
|
displayed_dive.cylinder[row].manually_added = true;
|
2013-04-13 13:17:59 +00:00
|
|
|
|
beginInsertRows(QModelIndex(), row, row);
|
2013-05-21 12:33:55 +00:00
|
|
|
|
rows++;
|
2013-09-25 17:23:51 +00:00
|
|
|
|
changed = true;
|
2013-04-13 13:17:59 +00:00
|
|
|
|
endInsertRows();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CylindersModel::clear()
|
|
|
|
|
{
|
2013-05-21 12:33:55 +00:00
|
|
|
|
if (rows > 0) {
|
2014-02-28 04:09:57 +00:00
|
|
|
|
beginRemoveRows(QModelIndex(), 0, rows - 1);
|
2013-04-13 13:17:59 +00:00
|
|
|
|
endRemoveRows();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-03 05:38:08 +00:00
|
|
|
|
void CylindersModel::updateDive()
|
2013-05-21 12:33:55 +00:00
|
|
|
|
{
|
2014-07-03 05:38:08 +00:00
|
|
|
|
clear();
|
2013-11-27 21:59:16 +00:00
|
|
|
|
rows = 0;
|
2014-02-28 04:09:57 +00:00
|
|
|
|
for (int i = 0; i < MAX_CYLINDERS; i++) {
|
2014-07-03 05:38:08 +00:00
|
|
|
|
if (!cylinder_none(&displayed_dive.cylinder[i]) &&
|
|
|
|
|
(prefs.display_unused_tanks ||
|
2014-07-17 15:19:19 +00:00
|
|
|
|
is_cylinder_used(&displayed_dive, i) ||
|
2014-07-03 05:38:08 +00:00
|
|
|
|
displayed_dive.cylinder[i].manually_added))
|
2014-02-28 04:09:57 +00:00
|
|
|
|
rows = i + 1;
|
2013-05-21 12:33:55 +00:00
|
|
|
|
}
|
2013-11-27 21:59:16 +00:00
|
|
|
|
if (rows > 0) {
|
2014-02-28 04:09:57 +00:00
|
|
|
|
beginInsertRows(QModelIndex(), 0, rows - 1);
|
2013-10-13 13:20:32 +00:00
|
|
|
|
endInsertRows();
|
|
|
|
|
}
|
2013-05-21 12:33:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-08 21:36:45 +00:00
|
|
|
|
void CylindersModel::copyFromDive(dive *d)
|
|
|
|
|
{
|
|
|
|
|
if (!d)
|
|
|
|
|
return;
|
|
|
|
|
rows = 0;
|
|
|
|
|
for (int i = 0; i < MAX_CYLINDERS; i++) {
|
2015-02-15 11:28:46 +00:00
|
|
|
|
if (!cylinder_none(&d->cylinder[i]) &&
|
|
|
|
|
(is_cylinder_used(d, i) || prefs.display_unused_tanks)) {
|
2014-05-08 21:36:45 +00:00
|
|
|
|
rows = i + 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (rows > 0) {
|
|
|
|
|
beginInsertRows(QModelIndex(), 0, rows - 1);
|
|
|
|
|
endInsertRows();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
Qt::ItemFlags CylindersModel::flags(const QModelIndex &index) const
|
2013-05-22 14:00:20 +00:00
|
|
|
|
{
|
|
|
|
|
if (index.column() == REMOVE)
|
|
|
|
|
return Qt::ItemIsEnabled;
|
2013-05-22 15:20:00 +00:00
|
|
|
|
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
|
2013-05-22 14:00:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
void CylindersModel::remove(const QModelIndex &index)
|
2013-05-22 14:00:20 +00:00
|
|
|
|
{
|
2013-05-23 04:25:05 +00:00
|
|
|
|
if (index.column() != REMOVE) {
|
2013-05-22 14:00:20 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2014-07-16 03:36:49 +00:00
|
|
|
|
int same_gas = -1;
|
2014-07-03 05:38:08 +00:00
|
|
|
|
cylinder_t *cyl = &displayed_dive.cylinder[index.row()];
|
2014-07-16 03:36:49 +00:00
|
|
|
|
struct gasmix *mygas = &cyl->gasmix;
|
|
|
|
|
for (int i = 0; i < MAX_CYLINDERS; i++) {
|
|
|
|
|
if (i == index.row() || cylinder_none(&displayed_dive.cylinder[i]))
|
|
|
|
|
continue;
|
|
|
|
|
struct gasmix *gas2 = &displayed_dive.cylinder[i].gasmix;
|
|
|
|
|
if (gasmix_distance(mygas, gas2) == 0)
|
|
|
|
|
same_gas = i;
|
|
|
|
|
}
|
|
|
|
|
if (same_gas == -1 &&
|
|
|
|
|
((DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING &&
|
|
|
|
|
DivePlannerPointsModel::instance()->tankInUse(cyl->gasmix)) ||
|
|
|
|
|
(DivePlannerPointsModel::instance()->currentMode() == DivePlannerPointsModel::NOTHING &&
|
2014-07-17 15:19:19 +00:00
|
|
|
|
(cyl->manually_added || is_cylinder_used(&displayed_dive, index.row()))))) {
|
2014-02-12 14:22:54 +00:00
|
|
|
|
QMessageBox::warning(MainWindow::instance(), TITLE_OR_TEXT(
|
2014-09-17 22:39:49 +00:00
|
|
|
|
tr("Cylinder cannot be removed"),
|
|
|
|
|
tr("This gas is in use. Only cylinders that are not used in the dive can be removed.")),
|
2014-02-28 04:09:57 +00:00
|
|
|
|
QMessageBox::Ok);
|
2013-11-13 12:45:54 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2013-05-22 14:40:57 +00:00
|
|
|
|
beginRemoveRows(QModelIndex(), index.row(), index.row()); // yah, know, ugly.
|
2013-05-22 17:02:28 +00:00
|
|
|
|
rows--;
|
2014-07-16 03:36:49 +00:00
|
|
|
|
if (index.row() == 0) {
|
|
|
|
|
// first gas - we need to make sure that the same gas ends up
|
|
|
|
|
// as first gas
|
|
|
|
|
memmove(cyl, &displayed_dive.cylinder[same_gas], sizeof(*cyl));
|
|
|
|
|
remove_cylinder(&displayed_dive, same_gas);
|
|
|
|
|
} else {
|
|
|
|
|
remove_cylinder(&displayed_dive, index.row());
|
|
|
|
|
}
|
2013-09-25 17:23:51 +00:00
|
|
|
|
changed = true;
|
2013-05-22 14:40:57 +00:00
|
|
|
|
endRemoveRows();
|
2013-05-22 14:00:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-11-04 23:05:35 +00:00
|
|
|
|
WeightModel::WeightModel(QObject *parent) : CleanerTableModel(parent),
|
2014-11-08 13:11:06 +00:00
|
|
|
|
changed(false),
|
|
|
|
|
rows(0)
|
2013-05-24 01:40:16 +00:00
|
|
|
|
{
|
2013-10-11 14:04:27 +00:00
|
|
|
|
//enum Column {REMOVE, TYPE, WEIGHT};
|
|
|
|
|
setHeaderDataStrings(QStringList() << tr("") << tr("Type") << tr("Weight"));
|
2014-10-19 14:15:20 +00:00
|
|
|
|
|
|
|
|
|
initTrashIcon();
|
2013-05-24 01:40:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
weightsystem_t *WeightModel::weightSystemAt(const QModelIndex &index)
|
2013-07-18 14:53:47 +00:00
|
|
|
|
{
|
2014-07-03 05:38:08 +00:00
|
|
|
|
return &displayed_dive.weightsystem[index.row()];
|
2013-07-18 14:53:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
void WeightModel::remove(const QModelIndex &index)
|
2013-05-22 14:00:20 +00:00
|
|
|
|
{
|
2013-05-23 04:25:05 +00:00
|
|
|
|
if (index.column() != REMOVE) {
|
2013-05-22 14:00:20 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2013-05-22 14:40:57 +00:00
|
|
|
|
beginRemoveRows(QModelIndex(), index.row(), index.row()); // yah, know, ugly.
|
2013-05-22 17:02:28 +00:00
|
|
|
|
rows--;
|
2014-07-03 05:38:08 +00:00
|
|
|
|
remove_weightsystem(&displayed_dive, index.row());
|
2013-09-25 17:23:51 +00:00
|
|
|
|
changed = true;
|
2013-05-22 14:40:57 +00:00
|
|
|
|
endRemoveRows();
|
2013-05-22 14:00:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-13 13:17:59 +00:00
|
|
|
|
void WeightModel::clear()
|
|
|
|
|
{
|
2013-05-21 12:59:41 +00:00
|
|
|
|
if (rows > 0) {
|
2014-02-28 04:09:57 +00:00
|
|
|
|
beginRemoveRows(QModelIndex(), 0, rows - 1);
|
2013-05-01 16:04:14 +00:00
|
|
|
|
endRemoveRows();
|
|
|
|
|
}
|
2013-04-13 13:17:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
QVariant WeightModel::data(const QModelIndex &index, int role) const
|
2013-04-13 13:17:59 +00:00
|
|
|
|
{
|
2013-05-01 17:11:46 +00:00
|
|
|
|
QVariant ret;
|
2013-05-02 05:00:08 +00:00
|
|
|
|
if (!index.isValid() || index.row() >= MAX_WEIGHTSYSTEMS)
|
2013-05-01 17:11:46 +00:00
|
|
|
|
return ret;
|
2013-05-02 05:00:08 +00:00
|
|
|
|
|
2014-07-03 05:38:08 +00:00
|
|
|
|
weightsystem_t *ws = &displayed_dive.weightsystem[index.row()];
|
2013-05-01 17:11:46 +00:00
|
|
|
|
|
2013-05-26 03:04:31 +00:00
|
|
|
|
switch (role) {
|
|
|
|
|
case Qt::FontRole:
|
2013-06-16 14:13:32 +00:00
|
|
|
|
ret = defaultModelFont();
|
2013-05-26 03:04:31 +00:00
|
|
|
|
break;
|
|
|
|
|
case Qt::TextAlignmentRole:
|
2013-11-22 01:36:39 +00:00
|
|
|
|
ret = Qt::AlignCenter;
|
2014-02-28 04:09:57 +00:00
|
|
|
|
break;
|
2013-05-26 03:04:31 +00:00
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
|
case Qt::EditRole:
|
2014-01-16 04:50:56 +00:00
|
|
|
|
switch (index.column()) {
|
2013-05-01 17:11:46 +00:00
|
|
|
|
case TYPE:
|
2013-12-02 18:10:55 +00:00
|
|
|
|
ret = gettextFromC::instance()->tr(ws->description);
|
2013-05-01 17:11:46 +00:00
|
|
|
|
break;
|
|
|
|
|
case WEIGHT:
|
2014-01-15 08:30:42 +00:00
|
|
|
|
ret = get_weight_string(ws->weight, true);
|
2013-05-01 17:11:46 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2013-05-26 03:04:31 +00:00
|
|
|
|
break;
|
|
|
|
|
case Qt::DecorationRole:
|
2013-05-23 04:25:05 +00:00
|
|
|
|
if (index.column() == REMOVE)
|
2014-10-19 14:15:20 +00:00
|
|
|
|
ret = trashIcon();
|
|
|
|
|
break;
|
|
|
|
|
case Qt::SizeHintRole:
|
|
|
|
|
if (index.column() == REMOVE)
|
|
|
|
|
ret = trashIcon().size();
|
2013-05-26 03:04:31 +00:00
|
|
|
|
break;
|
2013-11-22 01:32:11 +00:00
|
|
|
|
case Qt::ToolTipRole:
|
|
|
|
|
if (index.column() == REMOVE)
|
2014-07-11 08:21:38 +00:00
|
|
|
|
ret = tr("Clicking here will remove this weight system.");
|
2013-11-22 01:32:11 +00:00
|
|
|
|
break;
|
2013-05-22 14:00:20 +00:00
|
|
|
|
}
|
2013-05-01 17:11:46 +00:00
|
|
|
|
return ret;
|
2013-04-13 13:17:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-24 01:40:16 +00: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-28 04:09:57 +00:00
|
|
|
|
void WeightModel::passInData(const QModelIndex &index, const QVariant &value)
|
2013-05-24 01:40:16 +00:00
|
|
|
|
{
|
2014-07-03 05:38:08 +00:00
|
|
|
|
weightsystem_t *ws = &displayed_dive.weightsystem[index.row()];
|
2013-05-24 01:40:16 +00:00
|
|
|
|
if (index.column() == WEIGHT) {
|
|
|
|
|
if (ws->weight.grams != value.toInt()) {
|
|
|
|
|
ws->weight.grams = value.toInt();
|
2013-07-16 22:13:58 +00:00
|
|
|
|
dataChanged(index, index);
|
2013-05-24 01:40:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-04-17 02:56:42 +00:00
|
|
|
|
//TODO: Move to C
|
2014-01-08 06:51:22 +00:00
|
|
|
|
weight_t string_to_weight(const char *str)
|
2014-01-03 04:52:47 +00:00
|
|
|
|
{
|
2014-01-08 06:51:22 +00:00
|
|
|
|
const char *end;
|
2014-01-03 04:52:47 +00:00
|
|
|
|
double value = strtod_flags(str, &end, 0);
|
2014-01-03 19:22:37 +00:00
|
|
|
|
QString rest = QString(end).trimmed();
|
2014-07-15 23:27:32 +00:00
|
|
|
|
QString local_kg = QObject::tr("kg");
|
|
|
|
|
QString local_lbs = QObject::tr("lbs");
|
2014-01-08 06:24:35 +00:00
|
|
|
|
weight_t weight;
|
2014-01-03 04:52:47 +00:00
|
|
|
|
|
2014-01-03 19:22:37 +00:00
|
|
|
|
if (rest.startsWith("kg") || rest.startsWith(local_kg))
|
2014-01-03 04:52:47 +00:00
|
|
|
|
goto kg;
|
2014-01-03 19:22:37 +00: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-03 04:52:47 +00:00
|
|
|
|
goto lbs;
|
|
|
|
|
if (prefs.units.weight == prefs.units.LBS)
|
|
|
|
|
goto lbs;
|
|
|
|
|
kg:
|
2014-01-08 06:24:35 +00:00
|
|
|
|
weight.grams = rint(value * 1000);
|
|
|
|
|
return weight;
|
2014-01-03 04:52:47 +00:00
|
|
|
|
lbs:
|
2014-01-08 06:24:35 +00:00
|
|
|
|
weight.grams = lbs_to_grams(value);
|
|
|
|
|
return weight;
|
2014-01-03 04:52:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-04-17 02:56:42 +00:00
|
|
|
|
//TODO: Move to C.
|
2014-01-08 06:55:47 +00: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 23:27:32 +00:00
|
|
|
|
QString local_ft = QObject::tr("ft");
|
|
|
|
|
QString local_m = QObject::tr("m");
|
2014-01-08 06:55:47 +00: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-17 02:56:42 +00:00
|
|
|
|
//TODO: Move to C.
|
2014-01-09 00:49:21 +00: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 23:27:32 +00:00
|
|
|
|
QString local_psi = QObject::tr("psi");
|
|
|
|
|
QString local_bar = QObject::tr("bar");
|
2014-01-09 00:49:21 +00: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-17 02:56:42 +00:00
|
|
|
|
//TODO: Move to C.
|
2014-01-09 02:34:25 +00: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 23:27:32 +00:00
|
|
|
|
QString local_l = QObject::tr("l");
|
|
|
|
|
QString local_cuft = QObject::tr("cuft");
|
2014-01-09 02:34:25 +00:00
|
|
|
|
volume_t volume;
|
|
|
|
|
|
2014-06-09 03:31:11 +00:00
|
|
|
|
if (rest.startsWith("l") || rest.startsWith("ℓ") || rest.startsWith(local_l))
|
2014-01-09 02:34:25 +00: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-17 02:56:42 +00:00
|
|
|
|
//TODO: Move to C.
|
2014-01-09 02:43:28 +00: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-28 04:09:57 +00:00
|
|
|
|
bool WeightModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
2013-05-22 15:20:00 +00:00
|
|
|
|
{
|
2014-01-02 17:12:32 +00:00
|
|
|
|
QString vString = value.toString();
|
2014-07-03 05:38:08 +00:00
|
|
|
|
weightsystem_t *ws = &displayed_dive.weightsystem[index.row()];
|
2014-01-16 04:50:56 +00:00
|
|
|
|
switch (index.column()) {
|
2013-05-24 01:40:16 +00:00
|
|
|
|
case TYPE:
|
|
|
|
|
if (!value.isNull()) {
|
2014-04-17 02:56:42 +00:00
|
|
|
|
//TODO: C-function weigth_system_set_description ?
|
2014-01-02 17:12:32 +00:00
|
|
|
|
if (!ws->description || gettextFromC::instance()->tr(ws->description) != vString) {
|
2013-12-02 20:41:23 +00:00
|
|
|
|
// loop over translations to see if one matches
|
|
|
|
|
int i = -1;
|
2014-02-28 04:09:57 +00:00
|
|
|
|
while (ws_info[++i].name) {
|
2014-01-02 17:12:32 +00:00
|
|
|
|
if (gettextFromC::instance()->tr(ws_info[i].name) == vString) {
|
2014-11-14 21:33:12 +00:00
|
|
|
|
ws->description = copy_string(ws_info[i].name);
|
2013-12-02 20:41:23 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (ws_info[i].name == NULL) // didn't find a match
|
2014-01-02 17:12:32 +00:00
|
|
|
|
ws->description = strdup(vString.toUtf8().constData());
|
2013-09-25 17:23:51 +00:00
|
|
|
|
changed = true;
|
2013-05-24 01:40:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-05-22 15:20:00 +00:00
|
|
|
|
break;
|
|
|
|
|
case WEIGHT:
|
2014-01-09 02:47:28 +00:00
|
|
|
|
if (CHANGED()) {
|
2014-01-08 06:24:35 +00:00
|
|
|
|
ws->weight = string_to_weight(vString.toUtf8().data());
|
2013-05-24 05:56:12 +00:00
|
|
|
|
// now update the ws_info
|
2013-09-25 17:23:51 +00:00
|
|
|
|
changed = true;
|
2013-05-24 05:56:12 +00:00
|
|
|
|
WSInfoModel *wsim = WSInfoModel::instance();
|
2014-02-28 04:09:57 +00:00
|
|
|
|
QModelIndexList matches = wsim->match(wsim->index(0, 0), Qt::DisplayRole, gettextFromC::instance()->tr(ws->description));
|
2013-05-24 05:56:12 +00:00
|
|
|
|
if (!matches.isEmpty())
|
|
|
|
|
wsim->setData(wsim->index(matches.first().row(), WSInfoModel::GR), ws->weight.grams);
|
2013-05-24 01:40:16 +00:00
|
|
|
|
}
|
2013-05-22 15:20:00 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2013-07-16 22:13:58 +00:00
|
|
|
|
dataChanged(index, index);
|
|
|
|
|
return true;
|
2013-05-22 15:20:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
Qt::ItemFlags WeightModel::flags(const QModelIndex &index) const
|
2013-05-22 14:00:20 +00:00
|
|
|
|
{
|
|
|
|
|
if (index.column() == REMOVE)
|
|
|
|
|
return Qt::ItemIsEnabled;
|
2013-05-22 15:20:00 +00:00
|
|
|
|
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
|
2013-05-22 14:00:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
int WeightModel::rowCount(const QModelIndex &parent) const
|
2013-04-13 13:17:59 +00:00
|
|
|
|
{
|
2013-05-21 12:59:41 +00:00
|
|
|
|
return rows;
|
2013-04-13 13:17:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-22 17:52:38 +00:00
|
|
|
|
void WeightModel::add()
|
2013-04-13 13:17:59 +00:00
|
|
|
|
{
|
2013-05-21 18:29:21 +00:00
|
|
|
|
if (rows >= MAX_WEIGHTSYSTEMS)
|
2013-05-01 21:49:17 +00:00
|
|
|
|
return;
|
2013-05-01 17:11:46 +00:00
|
|
|
|
|
2013-05-21 12:59:41 +00:00
|
|
|
|
int row = rows;
|
2013-05-01 17:11:46 +00:00
|
|
|
|
beginInsertRows(QModelIndex(), row, row);
|
2013-05-21 12:59:41 +00:00
|
|
|
|
rows++;
|
2013-09-25 17:23:51 +00:00
|
|
|
|
changed = true;
|
2013-05-01 17:11:46 +00:00
|
|
|
|
endInsertRows();
|
2013-04-13 13:17:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-03 05:38:08 +00:00
|
|
|
|
void WeightModel::updateDive()
|
2013-05-21 12:59:41 +00:00
|
|
|
|
{
|
2014-07-03 05:38:08 +00:00
|
|
|
|
clear();
|
2013-11-27 21:59:17 +00:00
|
|
|
|
rows = 0;
|
2014-02-28 04:09:57 +00:00
|
|
|
|
for (int i = 0; i < MAX_WEIGHTSYSTEMS; i++) {
|
2014-07-03 05:38:08 +00:00
|
|
|
|
if (!weightsystem_none(&displayed_dive.weightsystem[i])) {
|
2014-02-28 04:09:57 +00:00
|
|
|
|
rows = i + 1;
|
2013-05-21 12:59:41 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-27 21:59:17 +00:00
|
|
|
|
if (rows > 0) {
|
2014-02-28 04:09:57 +00:00
|
|
|
|
beginInsertRows(QModelIndex(), 0, rows - 1);
|
2013-10-13 13:20:32 +00:00
|
|
|
|
endInsertRows();
|
|
|
|
|
}
|
2013-04-13 13:17:59 +00:00
|
|
|
|
}
|
2013-04-15 18:04:35 +00:00
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
WSInfoModel *WSInfoModel::instance()
|
2013-05-24 01:40:16 +00:00
|
|
|
|
{
|
2013-11-30 17:18:04 +00:00
|
|
|
|
static QScopedPointer<WSInfoModel> self(new WSInfoModel());
|
|
|
|
|
return self.data();
|
2013-05-24 01:40:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
bool WSInfoModel::insertRows(int row, int count, const QModelIndex &parent)
|
2013-05-24 01:40:16 +00:00
|
|
|
|
{
|
|
|
|
|
beginInsertRows(parent, rowCount(), rowCount());
|
|
|
|
|
rows += count;
|
|
|
|
|
endInsertRows();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
bool WSInfoModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
2013-05-24 01:40:16 +00:00
|
|
|
|
{
|
2013-09-10 18:44:49 +00:00
|
|
|
|
struct ws_info_t *info = &ws_info[index.row()];
|
2014-01-16 04:50:56 +00:00
|
|
|
|
switch (index.column()) {
|
2013-05-24 05:56:12 +00:00
|
|
|
|
case DESCRIPTION:
|
|
|
|
|
info->name = strdup(value.toByteArray().data());
|
|
|
|
|
break;
|
|
|
|
|
case GR:
|
|
|
|
|
info->grams = value.toInt();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-07-16 22:13:58 +00:00
|
|
|
|
emit dataChanged(index, index);
|
2014-01-15 08:30:42 +00:00
|
|
|
|
return true;
|
2013-05-24 01:40:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WSInfoModel::clear()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
QVariant WSInfoModel::data(const QModelIndex &index, int role) const
|
2013-05-24 01:40:16 +00:00
|
|
|
|
{
|
|
|
|
|
QVariant ret;
|
|
|
|
|
if (!index.isValid()) {
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
2013-09-10 18:44:49 +00:00
|
|
|
|
struct ws_info_t *info = &ws_info[index.row()];
|
2013-05-24 01:40:16 +00:00
|
|
|
|
|
|
|
|
|
int gr = info->grams;
|
2014-01-16 04:50:56 +00:00
|
|
|
|
switch (role) {
|
2014-02-28 04:09:57 +00:00
|
|
|
|
case Qt::FontRole:
|
|
|
|
|
ret = defaultModelFont();
|
|
|
|
|
break;
|
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
|
case Qt::EditRole:
|
|
|
|
|
switch (index.column()) {
|
|
|
|
|
case GR:
|
|
|
|
|
ret = gr;
|
2013-06-16 14:13:32 +00:00
|
|
|
|
break;
|
2014-02-28 04:09:57 +00:00
|
|
|
|
case DESCRIPTION:
|
|
|
|
|
ret = gettextFromC::instance()->tr(info->name);
|
2013-06-16 14:13:32 +00:00
|
|
|
|
break;
|
2014-02-28 04:09:57 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
2013-05-24 01:40:16 +00:00
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
int WSInfoModel::rowCount(const QModelIndex &parent) const
|
2013-05-24 01:40:16 +00:00
|
|
|
|
{
|
2014-02-28 04:09:57 +00:00
|
|
|
|
return rows + 1;
|
2013-05-24 01:40:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
const QString &WSInfoModel::biggerString() const
|
2013-06-16 16:28:59 +00:00
|
|
|
|
{
|
|
|
|
|
return biggerEntry;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-11 14:13:16 +00:00
|
|
|
|
WSInfoModel::WSInfoModel() : rows(-1)
|
2013-05-24 01:40:16 +00:00
|
|
|
|
{
|
2014-02-28 04:09:57 +00:00
|
|
|
|
setHeaderDataStrings(QStringList() << tr("Description") << tr("kg"));
|
2013-09-10 18:44:49 +00:00
|
|
|
|
struct ws_info_t *info = ws_info;
|
2014-01-16 04:50:56 +00:00
|
|
|
|
for (info = ws_info; info->name; info++, rows++) {
|
2013-12-02 18:10:55 +00:00
|
|
|
|
QString wsInfoName = gettextFromC::instance()->tr(info->name);
|
2014-02-28 04:09:57 +00:00
|
|
|
|
if (wsInfoName.count() > biggerEntry.count())
|
2013-06-16 16:28:59 +00:00
|
|
|
|
biggerEntry = wsInfoName;
|
|
|
|
|
}
|
2013-05-24 01:40:16 +00:00
|
|
|
|
|
|
|
|
|
if (rows > -1) {
|
|
|
|
|
beginInsertRows(QModelIndex(), 0, rows);
|
|
|
|
|
endInsertRows();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-10 18:42:26 +00:00
|
|
|
|
void WSInfoModel::updateInfo()
|
|
|
|
|
{
|
2013-09-10 18:44:49 +00:00
|
|
|
|
struct ws_info_t *info = ws_info;
|
2013-09-10 18:42:26 +00:00
|
|
|
|
beginRemoveRows(QModelIndex(), 0, this->rows);
|
|
|
|
|
endRemoveRows();
|
2013-09-10 21:55:30 +00:00
|
|
|
|
rows = -1;
|
2014-01-16 04:50:56 +00:00
|
|
|
|
for (info = ws_info; info->name; info++, rows++) {
|
2013-12-02 18:10:55 +00:00
|
|
|
|
QString wsInfoName = gettextFromC::instance()->tr(info->name);
|
2014-02-28 04:09:57 +00:00
|
|
|
|
if (wsInfoName.count() > biggerEntry.count())
|
2013-09-10 18:42:26 +00:00
|
|
|
|
biggerEntry = wsInfoName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (rows > -1) {
|
|
|
|
|
beginInsertRows(QModelIndex(), 0, rows);
|
|
|
|
|
endInsertRows();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-24 01:40:16 +00:00
|
|
|
|
void WSInfoModel::update()
|
|
|
|
|
{
|
|
|
|
|
if (rows > -1) {
|
|
|
|
|
beginRemoveRows(QModelIndex(), 0, rows);
|
|
|
|
|
endRemoveRows();
|
2013-05-24 05:56:12 +00:00
|
|
|
|
rows = -1;
|
2013-05-24 01:40:16 +00:00
|
|
|
|
}
|
2013-09-10 18:44:49 +00:00
|
|
|
|
struct ws_info_t *info = ws_info;
|
2014-02-28 04:09:57 +00:00
|
|
|
|
for (info = ws_info; info->name; info++, rows++)
|
|
|
|
|
;
|
2013-05-24 01:40:16 +00:00
|
|
|
|
|
|
|
|
|
if (rows > -1) {
|
|
|
|
|
beginInsertRows(QModelIndex(), 0, rows);
|
|
|
|
|
endInsertRows();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
TankInfoModel *TankInfoModel::instance()
|
2013-04-15 18:04:35 +00:00
|
|
|
|
{
|
2013-11-30 17:18:04 +00:00
|
|
|
|
static QScopedPointer<TankInfoModel> self(new TankInfoModel());
|
|
|
|
|
return self.data();
|
2013-05-23 18:33:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
const QString &TankInfoModel::biggerString() const
|
2013-06-16 16:28:59 +00:00
|
|
|
|
{
|
|
|
|
|
return biggerEntry;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
bool TankInfoModel::insertRows(int row, int count, const QModelIndex &parent)
|
2013-05-23 18:33:20 +00:00
|
|
|
|
{
|
|
|
|
|
beginInsertRows(parent, rowCount(), rowCount());
|
|
|
|
|
rows += count;
|
|
|
|
|
endInsertRows();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
bool TankInfoModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
2013-05-23 18:33:20 +00:00
|
|
|
|
{
|
2013-09-10 18:44:49 +00:00
|
|
|
|
struct tank_info_t *info = &tank_info[index.row()];
|
2014-01-16 04:50:56 +00:00
|
|
|
|
switch (index.column()) {
|
2013-05-24 05:56:12 +00:00
|
|
|
|
case DESCRIPTION:
|
|
|
|
|
info->name = strdup(value.toByteArray().data());
|
|
|
|
|
break;
|
|
|
|
|
case ML:
|
|
|
|
|
info->ml = value.toInt();
|
|
|
|
|
break;
|
|
|
|
|
case BAR:
|
|
|
|
|
info->bar = value.toInt();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-07-16 22:13:58 +00:00
|
|
|
|
emit dataChanged(index, index);
|
2014-01-15 08:30:42 +00:00
|
|
|
|
return true;
|
2013-04-15 18:04:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TankInfoModel::clear()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
QVariant TankInfoModel::data(const QModelIndex &index, int role) const
|
2013-04-15 18:04:35 +00:00
|
|
|
|
{
|
|
|
|
|
QVariant ret;
|
|
|
|
|
if (!index.isValid()) {
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
2014-01-16 04:50:56 +00:00
|
|
|
|
if (role == Qt::FontRole) {
|
2013-06-16 15:33:27 +00:00
|
|
|
|
return defaultModelFont();
|
|
|
|
|
}
|
2013-06-19 21:36:48 +00:00
|
|
|
|
if (role == Qt::DisplayRole || role == Qt::EditRole) {
|
2013-09-10 18:44:49 +00:00
|
|
|
|
struct tank_info_t *info = &tank_info[index.row()];
|
2013-06-19 21:36:48 +00:00
|
|
|
|
int ml = info->ml;
|
|
|
|
|
double bar = (info->psi) ? psi_to_bar(info->psi) : info->bar;
|
2013-06-16 15:33:27 +00:00
|
|
|
|
|
2013-06-19 21:36:48 +00:00
|
|
|
|
if (info->cuft && info->psi)
|
|
|
|
|
ml = cuft_to_l(info->cuft) * 1000 / bar_to_atm(bar);
|
2013-04-15 18:04:35 +00:00
|
|
|
|
|
2014-01-16 04:50:56 +00:00
|
|
|
|
switch (index.column()) {
|
2014-02-28 04:09:57 +00:00
|
|
|
|
case BAR:
|
|
|
|
|
ret = bar * 1000;
|
|
|
|
|
break;
|
|
|
|
|
case ML:
|
|
|
|
|
ret = ml;
|
|
|
|
|
break;
|
|
|
|
|
case DESCRIPTION:
|
|
|
|
|
ret = QString(info->name);
|
|
|
|
|
break;
|
2013-04-15 18:04:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
int TankInfoModel::rowCount(const QModelIndex &parent) const
|
2013-04-15 18:04:35 +00:00
|
|
|
|
{
|
2014-02-28 04:09:57 +00:00
|
|
|
|
return rows + 1;
|
2013-04-15 18:04:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
TankInfoModel::TankInfoModel() : rows(-1)
|
2013-04-15 18:04:35 +00:00
|
|
|
|
{
|
2014-02-28 04:09:57 +00:00
|
|
|
|
setHeaderDataStrings(QStringList() << tr("Description") << tr("ml") << tr("bar"));
|
2013-09-10 18:44:49 +00:00
|
|
|
|
struct tank_info_t *info = tank_info;
|
2014-01-16 04:50:56 +00:00
|
|
|
|
for (info = tank_info; info->name; info++, rows++) {
|
2013-12-02 15:36:40 +00:00
|
|
|
|
QString infoName = gettextFromC::instance()->tr(info->name);
|
2013-10-11 13:21:04 +00:00
|
|
|
|
if (infoName.count() > biggerEntry.count())
|
2013-06-16 16:28:59 +00:00
|
|
|
|
biggerEntry = infoName;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-15 18:04:35 +00:00
|
|
|
|
if (rows > -1) {
|
|
|
|
|
beginInsertRows(QModelIndex(), 0, rows);
|
|
|
|
|
endInsertRows();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TankInfoModel::update()
|
|
|
|
|
{
|
2013-05-23 04:25:05 +00:00
|
|
|
|
if (rows > -1) {
|
2013-04-15 18:04:35 +00:00
|
|
|
|
beginRemoveRows(QModelIndex(), 0, rows);
|
|
|
|
|
endRemoveRows();
|
2013-05-24 05:56:12 +00:00
|
|
|
|
rows = -1;
|
2013-04-15 18:04:35 +00:00
|
|
|
|
}
|
2013-09-10 18:44:49 +00:00
|
|
|
|
struct tank_info_t *info = tank_info;
|
2014-02-28 04:09:57 +00:00
|
|
|
|
for (info = tank_info; info->name; info++, rows++)
|
|
|
|
|
;
|
2013-04-15 18:04:35 +00:00
|
|
|
|
|
|
|
|
|
if (rows > -1) {
|
|
|
|
|
beginInsertRows(QModelIndex(), 0, rows);
|
|
|
|
|
endInsertRows();
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-04-22 01:12:36 +00:00
|
|
|
|
|
2013-06-17 21:59:50 +00:00
|
|
|
|
//#################################################################################################
|
|
|
|
|
//#
|
|
|
|
|
//# Tree Model - a Basic Tree Model so I don't need to kill myself repeating this for every model.
|
|
|
|
|
//#
|
|
|
|
|
//#################################################################################################
|
2013-04-27 15:27:27 +00:00
|
|
|
|
|
2013-04-22 01:12:36 +00:00
|
|
|
|
/*! A DiveItem for use with a DiveTripModel
|
|
|
|
|
*
|
|
|
|
|
* A simple class which wraps basic stats for a dive (e.g. duration, depth) and
|
|
|
|
|
* tidies up after it's children. This is done manually as we don't inherit from
|
|
|
|
|
* QObject.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2013-05-02 02:51:34 +00:00
|
|
|
|
|
2013-06-18 20:29:37 +00:00
|
|
|
|
TreeItem::TreeItem()
|
|
|
|
|
{
|
|
|
|
|
parent = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-17 21:59:50 +00:00
|
|
|
|
TreeItem::~TreeItem()
|
2013-04-22 01:12:36 +00:00
|
|
|
|
{
|
2013-05-14 07:28:30 +00:00
|
|
|
|
qDeleteAll(children);
|
2013-05-02 02:51:34 +00:00
|
|
|
|
}
|
2013-04-25 07:50:01 +00:00
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
Qt::ItemFlags TreeItem::flags(const QModelIndex &index) const
|
2013-11-19 00:33:01 +00:00
|
|
|
|
{
|
|
|
|
|
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-17 21:59:50 +00:00
|
|
|
|
int TreeItem::row() const
|
2013-05-02 02:51:34 +00:00
|
|
|
|
{
|
|
|
|
|
if (parent)
|
2014-02-28 04:09:57 +00:00
|
|
|
|
return parent->children.indexOf(const_cast<TreeItem *>(this));
|
2013-05-02 02:51:34 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
2013-04-22 01:12:36 +00:00
|
|
|
|
|
2013-06-17 21:59:50 +00:00
|
|
|
|
QVariant TreeItem::data(int column, int role) const
|
2013-05-02 02:51:34 +00:00
|
|
|
|
{
|
2013-06-17 21:59:50 +00:00
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
TreeModel::TreeModel(QObject *parent) : QAbstractItemModel(parent)
|
2013-06-17 21:59:50 +00:00
|
|
|
|
{
|
2014-03-04 06:21:33 +00:00
|
|
|
|
columns = 0; // I'm not sure about this one - I can't see where it gets initialized
|
2013-06-17 21:59:50 +00:00
|
|
|
|
rootItem = new TreeItem();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TreeModel::~TreeModel()
|
|
|
|
|
{
|
|
|
|
|
delete rootItem;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
QVariant TreeModel::data(const QModelIndex &index, int role) const
|
2013-06-17 21:59:50 +00:00
|
|
|
|
{
|
|
|
|
|
if (!index.isValid())
|
|
|
|
|
return QVariant();
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
TreeItem *item = static_cast<TreeItem *>(index.internalPointer());
|
2013-06-19 17:30:36 +00:00
|
|
|
|
QVariant val = item->data(index.column(), role);
|
2013-06-17 21:59:50 +00:00
|
|
|
|
|
2013-06-19 17:30:36 +00:00
|
|
|
|
if (role == Qt::FontRole && !val.isValid())
|
|
|
|
|
return defaultModelFont();
|
|
|
|
|
else
|
|
|
|
|
return val;
|
2013-05-02 02:51:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
bool TreeItem::setData(const QModelIndex &index, const QVariant &value, int role)
|
2013-11-19 00:33:01 +00:00
|
|
|
|
{
|
2013-11-20 23:32:13 +00:00
|
|
|
|
return false;
|
2013-11-19 00:33:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-03-05 20:19:45 +00:00
|
|
|
|
QModelIndex TreeModel::index(int row, int column, const QModelIndex &parent) const
|
2013-06-17 21:59:50 +00:00
|
|
|
|
{
|
|
|
|
|
if (!hasIndex(row, column, parent))
|
|
|
|
|
return QModelIndex();
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
TreeItem *parentItem = (!parent.isValid()) ? rootItem : static_cast<TreeItem *>(parent.internalPointer());
|
2013-06-17 21:59:50 +00:00
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
TreeItem *childItem = parentItem->children[row];
|
2013-06-17 21:59:50 +00:00
|
|
|
|
|
|
|
|
|
return (childItem) ? createIndex(row, column, childItem) : QModelIndex();
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
QModelIndex TreeModel::parent(const QModelIndex &index) const
|
2013-06-17 21:59:50 +00:00
|
|
|
|
{
|
|
|
|
|
if (!index.isValid())
|
|
|
|
|
return QModelIndex();
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
TreeItem *childItem = static_cast<TreeItem *>(index.internalPointer());
|
|
|
|
|
TreeItem *parentItem = childItem->parent;
|
2013-06-17 21:59:50 +00:00
|
|
|
|
|
|
|
|
|
if (parentItem == rootItem || !parentItem)
|
|
|
|
|
return QModelIndex();
|
|
|
|
|
|
|
|
|
|
return createIndex(parentItem->row(), 0, parentItem);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
int TreeModel::rowCount(const QModelIndex &parent) const
|
2013-06-17 21:59:50 +00:00
|
|
|
|
{
|
2014-02-28 04:09:57 +00:00
|
|
|
|
TreeItem *parentItem;
|
2013-06-17 21:59:50 +00:00
|
|
|
|
|
|
|
|
|
if (!parent.isValid())
|
|
|
|
|
parentItem = rootItem;
|
|
|
|
|
else
|
2014-02-28 04:09:57 +00:00
|
|
|
|
parentItem = static_cast<TreeItem *>(parent.internalPointer());
|
2013-06-17 21:59:50 +00:00
|
|
|
|
|
|
|
|
|
int amount = parentItem->children.count();
|
|
|
|
|
return amount;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
int TreeModel::columnCount(const QModelIndex &parent) const
|
2013-06-17 21:59:50 +00:00
|
|
|
|
{
|
|
|
|
|
return columns;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*################################################################
|
|
|
|
|
*
|
|
|
|
|
* Implementation of the Dive List.
|
|
|
|
|
*
|
|
|
|
|
* ############################################################### */
|
|
|
|
|
struct TripItem : public TreeItem {
|
2013-05-02 02:51:34 +00:00
|
|
|
|
virtual QVariant data(int column, int role) const;
|
2014-02-28 04:09:57 +00:00
|
|
|
|
dive_trip_t *trip;
|
2013-05-02 02:51:34 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
QVariant TripItem::data(int column, int role) const
|
|
|
|
|
{
|
|
|
|
|
QVariant ret;
|
2013-04-25 14:04:41 +00:00
|
|
|
|
|
2013-06-27 05:16:40 +00:00
|
|
|
|
if (role == DiveTripModel::TRIP_ROLE)
|
2014-02-28 04:09:57 +00:00
|
|
|
|
return QVariant::fromValue<void *>(trip);
|
2013-06-27 05:16:40 +00:00
|
|
|
|
|
2013-06-17 21:59:50 +00:00
|
|
|
|
if (role == DiveTripModel::SORT_ROLE)
|
2013-05-29 05:54:39 +00:00
|
|
|
|
return (qulonglong)trip->when;
|
|
|
|
|
|
2013-05-02 16:33:51 +00:00
|
|
|
|
if (role == Qt::DisplayRole) {
|
|
|
|
|
switch (column) {
|
2014-02-28 04:09:57 +00: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 22:16:33 +00: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 22:16:33 +00:00
|
|
|
|
else
|
2014-11-16 18:46:07 +00:00
|
|
|
|
ret = get_trip_date_string(trip->when, trip->nrdives) + shownText;
|
2013-05-02 16:33:51 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2013-05-02 02:51:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-29 05:54:39 +00:00
|
|
|
|
static int nitrox_sort_value(struct dive *dive)
|
|
|
|
|
{
|
2015-01-25 17:06:27 +00:00
|
|
|
|
int o2, he, o2max;
|
|
|
|
|
get_dive_gas(dive, &o2, &he, &o2max);
|
2014-02-28 04:09:57 +00:00
|
|
|
|
return he * 1000 + o2;
|
2013-05-29 05:54:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-30 17:19:39 +00:00
|
|
|
|
static QVariant dive_table_alignment(int column)
|
2014-09-11 20:59:52 +00: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 17:19:39 +00:00
|
|
|
|
retVal = int(Qt::AlignRight | Qt::AlignVCenter);
|
2014-09-11 20:59:52 +00: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-02 02:51:34 +00:00
|
|
|
|
QVariant DiveItem::data(int column, int role) const
|
2013-04-22 01:12:36 +00:00
|
|
|
|
{
|
2013-05-02 02:51:34 +00:00
|
|
|
|
QVariant retVal;
|
2014-05-18 21:38:37 +00:00
|
|
|
|
struct dive *dive = get_dive_by_uniq_id(diveId);
|
2015-01-09 22:55:21 +00:00
|
|
|
|
if (!dive)
|
|
|
|
|
return QVariant();
|
2013-05-02 02:51:34 +00:00
|
|
|
|
|
2013-05-02 21:05:53 +00:00
|
|
|
|
switch (role) {
|
|
|
|
|
case Qt::TextAlignmentRole:
|
2014-10-30 17:19:39 +00:00
|
|
|
|
retVal = dive_table_alignment(column);
|
2013-05-02 21:05:53 +00:00
|
|
|
|
break;
|
2014-02-28 04:09:57 +00:00
|
|
|
|
case DiveTripModel::SORT_ROLE:
|
2014-01-07 04:22:22 +00:00
|
|
|
|
Q_ASSERT(dive != NULL);
|
2013-05-29 05:54:39 +00:00
|
|
|
|
switch (column) {
|
2014-02-28 04:09:57 +00: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 13:07:56 +00:00
|
|
|
|
case GAS:
|
2014-02-28 04:09:57 +00: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:
|
|
|
|
|
retVal = QString(dive->location);
|
|
|
|
|
break;
|
2013-05-29 05:54:39 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
2013-05-02 21:05:53 +00:00
|
|
|
|
case Qt::DisplayRole:
|
2014-01-07 04:22:22 +00:00
|
|
|
|
Q_ASSERT(dive != NULL);
|
2013-05-02 02:51:34 +00:00
|
|
|
|
switch (column) {
|
2014-02-28 04:09:57 +00: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:
|
|
|
|
|
retVal = QString(dive->location);
|
|
|
|
|
break;
|
2014-12-18 07:47:43 +00:00
|
|
|
|
case GAS:
|
|
|
|
|
const char *gas_string = get_dive_gas_string(dive);
|
|
|
|
|
retVal = QString(gas_string);
|
|
|
|
|
free((void*)gas_string);
|
|
|
|
|
break;
|
2013-05-02 02:51:34 +00:00
|
|
|
|
}
|
2013-05-02 21:05:53 +00:00
|
|
|
|
break;
|
2014-10-30 14:40:22 +00: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-02 02:51:34 +00:00
|
|
|
|
}
|
2013-05-02 23:32:57 +00:00
|
|
|
|
|
2014-01-07 04:22:22 +00:00
|
|
|
|
if (role == DiveTripModel::STAR_ROLE) {
|
|
|
|
|
Q_ASSERT(dive != NULL);
|
2013-05-02 23:32:57 +00:00
|
|
|
|
retVal = dive->rating;
|
2014-01-07 04:22:22 +00:00
|
|
|
|
}
|
|
|
|
|
if (role == DiveTripModel::DIVE_ROLE) {
|
2014-02-28 04:09:57 +00:00
|
|
|
|
retVal = QVariant::fromValue<void *>(dive);
|
2014-01-07 04:22:22 +00:00
|
|
|
|
}
|
2014-01-16 04:50:56 +00:00
|
|
|
|
if (role == DiveTripModel::DIVE_IDX) {
|
2014-01-07 04:22:22 +00:00
|
|
|
|
Q_ASSERT(dive != NULL);
|
2013-11-16 20:41:47 +00:00
|
|
|
|
retVal = get_divenr(dive);
|
|
|
|
|
}
|
2013-05-02 02:51:34 +00:00
|
|
|
|
return retVal;
|
2013-04-22 01:12:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
Qt::ItemFlags DiveItem::flags(const QModelIndex &index) const
|
2013-11-19 00:33:01 +00:00
|
|
|
|
{
|
2014-01-16 04:50:56 +00:00
|
|
|
|
if (index.column() == NR) {
|
2013-11-19 00:33:01 +00:00
|
|
|
|
return TreeItem::flags(index) | Qt::ItemIsEditable;
|
|
|
|
|
}
|
|
|
|
|
return TreeItem::flags(index);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
bool DiveItem::setData(const QModelIndex &index, const QVariant &value, int role)
|
2013-11-19 00:33:01 +00:00
|
|
|
|
{
|
|
|
|
|
if (role != Qt::EditRole)
|
|
|
|
|
return false;
|
|
|
|
|
if (index.column() != NR)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
int v = value.toInt();
|
2013-11-19 00:34:22 +00:00
|
|
|
|
if (v == 0)
|
|
|
|
|
return false;
|
|
|
|
|
|
2013-11-19 00:33:01 +00:00
|
|
|
|
int i;
|
|
|
|
|
struct dive *d;
|
2014-05-22 18:40:22 +00:00
|
|
|
|
for_each_dive (i, d) {
|
2013-11-19 00:33:01 +00:00
|
|
|
|
if (d->number == v)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-05-18 21:38:37 +00:00
|
|
|
|
d = get_dive_by_uniq_id(diveId);
|
2014-01-07 03:57:20 +00:00
|
|
|
|
d->number = value.toInt();
|
2014-01-15 08:30:42 +00:00
|
|
|
|
mark_divelist_changed(true);
|
2013-11-19 00:33:01 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-11 09:41:50 +00:00
|
|
|
|
QString DiveItem::displayDate() const
|
|
|
|
|
{
|
2014-05-18 21:38:37 +00:00
|
|
|
|
struct dive *dive = get_dive_by_uniq_id(diveId);
|
2013-10-16 22:00:17 +00:00
|
|
|
|
return get_dive_date_string(dive->when);
|
2013-07-11 09:41:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-24 15:57:30 +00:00
|
|
|
|
QString DiveItem::displayDepth() const
|
|
|
|
|
{
|
2014-05-18 21:38:37 +00:00
|
|
|
|
struct dive *dive = get_dive_by_uniq_id(diveId);
|
2014-07-12 04:59:21 +00: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 15:57:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString DiveItem::displayDuration() const
|
|
|
|
|
{
|
2014-10-30 16:49:05 +00:00
|
|
|
|
int hrs, mins;
|
2014-05-18 21:38:37 +00:00
|
|
|
|
struct dive *dive = get_dive_by_uniq_id(diveId);
|
2014-10-31 21:28:39 +00:00
|
|
|
|
mins = (dive->duration.seconds + 59) / 60;
|
2013-04-24 23:03:14 +00:00
|
|
|
|
hrs = mins / 60;
|
|
|
|
|
mins -= hrs * 60;
|
2013-04-24 15:57:30 +00:00
|
|
|
|
|
|
|
|
|
QString displayTime;
|
2013-04-24 23:03:14 +00:00
|
|
|
|
if (hrs)
|
2014-10-30 16:49:05 +00:00
|
|
|
|
displayTime = QString("%1:%2").arg(hrs).arg(mins, 2, 10, QChar('0'));
|
2013-04-24 15:57:30 +00:00
|
|
|
|
else
|
2014-10-30 16:49:05 +00:00
|
|
|
|
displayTime = QString("%1").arg(mins);
|
2013-04-24 15:57:30 +00:00
|
|
|
|
return displayTime;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-25 06:21:57 +00:00
|
|
|
|
QString DiveItem::displayTemperature() const
|
|
|
|
|
{
|
|
|
|
|
QString str;
|
2014-05-18 21:38:37 +00:00
|
|
|
|
struct dive *dive = get_dive_by_uniq_id(diveId);
|
2013-05-14 07:45:01 +00:00
|
|
|
|
if (!dive->watertemp.mkelvin)
|
|
|
|
|
return str;
|
2013-05-02 05:00:08 +00:00
|
|
|
|
if (get_units()->temperature == units::CELSIUS)
|
2013-04-25 14:04:41 +00:00
|
|
|
|
str = QString::number(mkelvin_to_C(dive->watertemp.mkelvin), 'f', 1);
|
2013-05-02 05:00:08 +00:00
|
|
|
|
else
|
2013-04-25 14:04:41 +00:00
|
|
|
|
str = QString::number(mkelvin_to_F(dive->watertemp.mkelvin), 'f', 1);
|
2013-04-25 06:21:57 +00:00
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString DiveItem::displaySac() const
|
|
|
|
|
{
|
|
|
|
|
QString str;
|
2014-05-18 21:38:37 +00:00
|
|
|
|
struct dive *dive = get_dive_by_uniq_id(diveId);
|
2014-08-06 14:38:18 +00:00
|
|
|
|
if (dive->sac) {
|
|
|
|
|
const char *unit;
|
|
|
|
|
int decimal;
|
|
|
|
|
double value = get_volume_units(dive->sac, &decimal, &unit);
|
2014-08-22 21:41:24 +00:00
|
|
|
|
return QString::number(value, 'f', decimal);
|
2014-08-06 14:38:18 +00:00
|
|
|
|
}
|
|
|
|
|
return QString("");
|
2013-04-25 06:21:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString DiveItem::displayWeight() const
|
|
|
|
|
{
|
2013-10-04 18:39:33 +00:00
|
|
|
|
QString str = weight_string(weight());
|
2013-04-25 06:21:57 +00:00
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-02 02:51:34 +00:00
|
|
|
|
int DiveItem::weight() const
|
2013-04-22 01:12:36 +00:00
|
|
|
|
{
|
2014-05-18 21:38:37 +00:00
|
|
|
|
struct dive *dive = get_dive_by_uniq_id(diveId);
|
2013-05-02 02:51:34 +00:00
|
|
|
|
weight_t tw = { total_weight(dive) };
|
|
|
|
|
return tw.grams;
|
2013-04-22 01:12:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
DiveTripModel::DiveTripModel(QObject *parent) : TreeModel(parent)
|
2013-05-02 02:51:34 +00:00
|
|
|
|
{
|
2013-06-17 21:59:50 +00:00
|
|
|
|
columns = COLUMNS;
|
2013-04-22 01:12:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
Qt::ItemFlags DiveTripModel::flags(const QModelIndex &index) const
|
2013-04-22 01:12:36 +00:00
|
|
|
|
{
|
2013-05-02 02:51:34 +00:00
|
|
|
|
if (!index.isValid())
|
2013-04-22 01:12:36 +00:00
|
|
|
|
return 0;
|
2013-05-02 02:51:34 +00:00
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
TripItem *item = static_cast<TripItem *>(index.internalPointer());
|
2013-11-19 00:33:01 +00:00
|
|
|
|
return item->flags(index);
|
2013-04-22 01:12:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-17 21:59:50 +00:00
|
|
|
|
QVariant DiveTripModel::headerData(int section, Qt::Orientation orientation, int role) const
|
2013-04-22 01:12:36 +00:00
|
|
|
|
{
|
2013-06-17 21:59:50 +00:00
|
|
|
|
QVariant ret;
|
|
|
|
|
if (orientation == Qt::Vertical)
|
|
|
|
|
return ret;
|
2013-04-22 01:12:36 +00:00
|
|
|
|
|
2014-01-16 04:50:56 +00:00
|
|
|
|
switch (role) {
|
2014-09-11 20:59:52 +00:00
|
|
|
|
case Qt::TextAlignmentRole:
|
2014-10-30 17:19:39 +00:00
|
|
|
|
ret = dive_table_alignment(section);
|
2014-09-11 20:59:52 +00:00
|
|
|
|
break;
|
2014-02-28 04:09:57 +00:00
|
|
|
|
case Qt::FontRole:
|
|
|
|
|
ret = defaultModelFont();
|
|
|
|
|
break;
|
|
|
|
|
case Qt::DisplayRole:
|
2014-10-30 14:40:22 +00: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-28 04:09:57 +00:00
|
|
|
|
switch (section) {
|
|
|
|
|
case NR:
|
|
|
|
|
ret = tr("#");
|
|
|
|
|
break;
|
|
|
|
|
case DATE:
|
2014-07-11 17:39:04 +00:00
|
|
|
|
ret = tr("Date");
|
2014-02-28 04:09:57 +00:00
|
|
|
|
break;
|
|
|
|
|
case RATING:
|
2014-08-22 21:41:24 +00:00
|
|
|
|
ret = tr("Rating");
|
2014-02-28 04:09:57 +00:00
|
|
|
|
break;
|
|
|
|
|
case DEPTH:
|
2014-08-22 21:41:24 +00:00
|
|
|
|
ret = tr("Depth(%1)").arg((get_units()->length == units::METERS) ? tr("m") : tr("ft"));
|
2014-02-28 04:09:57 +00:00
|
|
|
|
break;
|
|
|
|
|
case DURATION:
|
2014-08-22 21:41:24 +00:00
|
|
|
|
ret = tr("Duration");
|
2014-02-28 04:09:57 +00:00
|
|
|
|
break;
|
|
|
|
|
case TEMPERATURE:
|
2014-08-22 21:41:24 +00:00
|
|
|
|
ret = tr("Temp(%1%2)").arg(UTF8_DEGREE).arg((get_units()->temperature == units::CELSIUS) ? "C" : "F");
|
2014-02-28 04:09:57 +00:00
|
|
|
|
break;
|
|
|
|
|
case TOTALWEIGHT:
|
2014-08-22 21:41:24 +00:00
|
|
|
|
ret = tr("Weight(%1)").arg((get_units()->weight == units::KG) ? tr("kg") : tr("lbs"));
|
2014-02-28 04:09:57 +00:00
|
|
|
|
break;
|
|
|
|
|
case SUIT:
|
2014-07-11 17:39:04 +00:00
|
|
|
|
ret = tr("Suit");
|
2014-02-28 04:09:57 +00:00
|
|
|
|
break;
|
|
|
|
|
case CYLINDER:
|
2014-07-11 17:39:04 +00:00
|
|
|
|
ret = tr("Cyl");
|
2014-02-28 04:09:57 +00:00
|
|
|
|
break;
|
2014-07-20 13:07:56 +00:00
|
|
|
|
case GAS:
|
2014-07-20 13:07:55 +00:00
|
|
|
|
ret = tr("Gas");
|
2014-02-28 04:09:57 +00:00
|
|
|
|
break;
|
|
|
|
|
case SAC:
|
2014-08-22 21:41:24 +00:00
|
|
|
|
const char *unit;
|
|
|
|
|
get_volume_units(0, NULL, &unit);
|
|
|
|
|
ret = tr("SAC(%1)").arg(QString(unit).append(tr("/min")));
|
2014-02-28 04:09:57 +00:00
|
|
|
|
break;
|
|
|
|
|
case OTU:
|
|
|
|
|
ret = tr("OTU");
|
|
|
|
|
break;
|
|
|
|
|
case MAXCNS:
|
2014-07-11 17:39:04 +00:00
|
|
|
|
ret = tr("Max CNS");
|
2014-02-28 04:09:57 +00:00
|
|
|
|
break;
|
|
|
|
|
case LOCATION:
|
2014-07-11 17:39:04 +00:00
|
|
|
|
ret = tr("Location");
|
2014-02-28 04:09:57 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2013-06-16 14:13:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-17 21:59:50 +00:00
|
|
|
|
return ret;
|
2013-05-02 02:51:34 +00:00
|
|
|
|
}
|
2013-04-22 01:12:36 +00:00
|
|
|
|
|
2013-05-02 02:51:34 +00:00
|
|
|
|
void DiveTripModel::setupModelData()
|
2013-04-22 01:12:36 +00:00
|
|
|
|
{
|
2013-05-02 02:51:34 +00:00
|
|
|
|
int i = dive_table.nr;
|
|
|
|
|
|
2014-01-16 04:50:56 +00:00
|
|
|
|
if (rowCount()) {
|
2014-02-28 04:09:57 +00:00
|
|
|
|
beginRemoveRows(QModelIndex(), 0, rowCount() - 1);
|
2013-05-28 19:56:58 +00:00
|
|
|
|
endRemoveRows();
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-15 23:45:04 +00:00
|
|
|
|
if (autogroup)
|
|
|
|
|
autogroup_dives();
|
|
|
|
|
dive_table.preexisting = dive_table.nr;
|
2013-05-02 02:51:34 +00:00
|
|
|
|
while (--i >= 0) {
|
2014-02-28 04:09:57 +00:00
|
|
|
|
struct dive *dive = get_dive(i);
|
2013-05-07 03:36:37 +00:00
|
|
|
|
update_cylinder_related_info(dive);
|
2014-02-28 04:09:57 +00:00
|
|
|
|
dive_trip_t *trip = dive->divetrip;
|
2013-05-02 02:51:34 +00:00
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
DiveItem *diveItem = new DiveItem();
|
2014-01-07 03:57:20 +00:00
|
|
|
|
diveItem->diveId = dive->id;
|
2013-05-02 02:51:34 +00:00
|
|
|
|
|
2013-05-28 19:56:58 +00:00
|
|
|
|
if (!trip || currentLayout == LIST) {
|
2013-05-02 02:51:34 +00:00
|
|
|
|
diveItem->parent = rootItem;
|
2013-05-14 07:28:30 +00:00
|
|
|
|
rootItem->children.push_back(diveItem);
|
2013-05-02 02:51:34 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2013-05-28 19:56:58 +00:00
|
|
|
|
if (currentLayout == LIST)
|
|
|
|
|
continue;
|
|
|
|
|
|
2013-05-02 02:51:34 +00:00
|
|
|
|
if (!trips.keys().contains(trip)) {
|
2014-02-28 04:09:57 +00:00
|
|
|
|
TripItem *tripItem = new TripItem();
|
2013-05-02 02:51:34 +00:00
|
|
|
|
tripItem->trip = trip;
|
|
|
|
|
tripItem->parent = rootItem;
|
2013-05-14 07:28:30 +00:00
|
|
|
|
tripItem->children.push_back(diveItem);
|
2013-05-02 02:51:34 +00:00
|
|
|
|
trips[trip] = tripItem;
|
2013-05-14 07:28:30 +00:00
|
|
|
|
rootItem->children.push_back(tripItem);
|
2013-05-02 02:51:34 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2014-02-28 04:09:57 +00:00
|
|
|
|
TripItem *tripItem = trips[trip];
|
2013-05-14 07:28:30 +00:00
|
|
|
|
tripItem->children.push_back(diveItem);
|
2013-04-22 01:12:36 +00:00
|
|
|
|
}
|
2013-05-28 19:56:58 +00:00
|
|
|
|
|
2014-01-16 04:50:56 +00:00
|
|
|
|
if (rowCount()) {
|
2013-05-29 20:43:14 +00:00
|
|
|
|
beginInsertRows(QModelIndex(), 0, rowCount() - 1);
|
2013-05-28 19:56:58 +00:00
|
|
|
|
endInsertRows();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DiveTripModel::Layout DiveTripModel::layout() const
|
|
|
|
|
{
|
|
|
|
|
return currentLayout;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DiveTripModel::setLayout(DiveTripModel::Layout layout)
|
|
|
|
|
{
|
|
|
|
|
currentLayout = layout;
|
|
|
|
|
setupModelData();
|
2013-04-22 01:12:36 +00:00
|
|
|
|
}
|
2013-06-07 14:43:45 +00:00
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
bool DiveTripModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
2013-11-19 00:33:01 +00:00
|
|
|
|
{
|
2014-02-28 04:09:57 +00:00
|
|
|
|
TreeItem *item = static_cast<TreeItem *>(index.internalPointer());
|
|
|
|
|
DiveItem *diveItem = dynamic_cast<DiveItem *>(item);
|
2014-01-16 04:50:56 +00:00
|
|
|
|
if (!diveItem)
|
2013-11-19 00:33:01 +00:00
|
|
|
|
return false;
|
2014-02-28 04:09:57 +00:00
|
|
|
|
return diveItem->setData(index, value, role);
|
|
|
|
|
}
|
2013-11-19 00:33:01 +00:00
|
|
|
|
|
|
|
|
|
|
2013-06-17 19:46:35 +00:00
|
|
|
|
/*####################################################################
|
2013-06-07 14:43:45 +00:00
|
|
|
|
*
|
2013-06-17 19:46:35 +00:00
|
|
|
|
* Dive Computer Model
|
2013-06-07 14:43:45 +00:00
|
|
|
|
*
|
|
|
|
|
*####################################################################
|
|
|
|
|
*/
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
DiveComputerModel::DiveComputerModel(QMultiMap<QString, DiveComputerNode> &dcMap, QObject *parent) : CleanerTableModel()
|
2013-06-07 14:43:45 +00:00
|
|
|
|
{
|
2013-10-11 14:42:33 +00:00
|
|
|
|
setHeaderDataStrings(QStringList() << "" << tr("Model") << tr("Device ID") << tr("Nickname"));
|
2013-06-17 22:58:26 +00:00
|
|
|
|
dcWorkingMap = dcMap;
|
|
|
|
|
numRows = 0;
|
2014-10-19 14:15:20 +00:00
|
|
|
|
|
|
|
|
|
initTrashIcon();
|
2013-06-07 14:43:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
QVariant DiveComputerModel::data(const QModelIndex &index, int role) const
|
2013-06-07 14:43:45 +00:00
|
|
|
|
{
|
2013-06-17 22:58:26 +00:00
|
|
|
|
QList<DiveComputerNode> values = dcWorkingMap.values();
|
|
|
|
|
DiveComputerNode node = values.at(index.row());
|
2013-06-07 14:43:45 +00:00
|
|
|
|
|
|
|
|
|
QVariant ret;
|
2014-01-16 04:50:56 +00:00
|
|
|
|
if (role == Qt::DisplayRole || role == Qt::EditRole) {
|
|
|
|
|
switch (index.column()) {
|
2014-02-28 04:09:57 +00: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 14:43:45 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-06-17 19:46:35 +00:00
|
|
|
|
|
2014-01-16 04:50:56 +00:00
|
|
|
|
if (index.column() == REMOVE) {
|
|
|
|
|
switch (role) {
|
2014-02-28 04:09:57 +00:00
|
|
|
|
case Qt::DecorationRole:
|
2014-10-19 14:15:20 +00:00
|
|
|
|
ret = trashIcon();
|
|
|
|
|
break;
|
|
|
|
|
case Qt::SizeHintRole:
|
|
|
|
|
ret = trashIcon().size();
|
2014-02-28 04:09:57 +00:00
|
|
|
|
break;
|
|
|
|
|
case Qt::ToolTipRole:
|
2014-07-11 08:21:38 +00:00
|
|
|
|
ret = tr("Clicking here will remove this dive computer.");
|
2014-02-28 04:09:57 +00:00
|
|
|
|
break;
|
2013-11-22 01:32:11 +00:00
|
|
|
|
}
|
2013-06-07 14:43:45 +00:00
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
int DiveComputerModel::rowCount(const QModelIndex &parent) const
|
2013-06-07 14:43:45 +00:00
|
|
|
|
{
|
|
|
|
|
return numRows;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DiveComputerModel::update()
|
|
|
|
|
{
|
2013-06-17 22:58:26 +00:00
|
|
|
|
QList<DiveComputerNode> values = dcWorkingMap.values();
|
|
|
|
|
int count = values.count();
|
2013-06-07 15:57:35 +00:00
|
|
|
|
|
2014-01-16 04:50:56 +00:00
|
|
|
|
if (numRows) {
|
2014-02-28 04:09:57 +00:00
|
|
|
|
beginRemoveRows(QModelIndex(), 0, numRows - 1);
|
2013-06-07 14:43:45 +00:00
|
|
|
|
numRows = 0;
|
|
|
|
|
endRemoveRows();
|
|
|
|
|
}
|
2013-06-07 15:57:35 +00:00
|
|
|
|
|
2014-01-16 04:50:56 +00:00
|
|
|
|
if (count) {
|
2014-02-28 04:09:57 +00:00
|
|
|
|
beginInsertRows(QModelIndex(), 0, count - 1);
|
2013-06-07 14:43:45 +00:00
|
|
|
|
numRows = count;
|
|
|
|
|
endInsertRows();
|
|
|
|
|
}
|
2013-06-07 15:57:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
Qt::ItemFlags DiveComputerModel::flags(const QModelIndex &index) const
|
2013-06-07 15:57:35 +00:00
|
|
|
|
{
|
|
|
|
|
Qt::ItemFlags flags = QAbstractItemModel::flags(index);
|
|
|
|
|
if (index.column() == NICKNAME)
|
|
|
|
|
flags |= Qt::ItemIsEditable;
|
2014-02-28 04:09:57 +00:00
|
|
|
|
return flags;
|
2013-06-07 15:57:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
bool DiveComputerModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
2013-06-07 15:57:35 +00:00
|
|
|
|
{
|
2013-06-17 22:58:26 +00: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 22:13:58 +00:00
|
|
|
|
emit dataChanged(index, index);
|
2013-06-07 18:25:29 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
void DiveComputerModel::remove(const QModelIndex &index)
|
2013-06-07 18:25:29 +00:00
|
|
|
|
{
|
2013-06-17 22:58:26 +00:00
|
|
|
|
QList<DiveComputerNode> values = dcWorkingMap.values();
|
|
|
|
|
DiveComputerNode node = values.at(index.row());
|
|
|
|
|
dcWorkingMap.remove(node.model, node);
|
2013-06-07 18:25:29 +00:00
|
|
|
|
update();
|
2013-06-07 14:43:45 +00:00
|
|
|
|
}
|
2013-06-17 22:41:05 +00:00
|
|
|
|
|
2013-06-18 16:25:24 +00:00
|
|
|
|
void DiveComputerModel::dropWorkingList()
|
|
|
|
|
{
|
|
|
|
|
// how do I prevent the memory leak ?
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DiveComputerModel::keepWorkingList()
|
|
|
|
|
{
|
|
|
|
|
if (dcList.dcMap != dcWorkingMap)
|
2014-01-15 08:30:42 +00:00
|
|
|
|
mark_divelist_changed(true);
|
2013-06-18 16:25:24 +00:00
|
|
|
|
dcList.dcMap = dcWorkingMap;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-17 22:41:05 +00:00
|
|
|
|
/*#################################################################
|
|
|
|
|
* #
|
|
|
|
|
* # Yearly Statistics Model
|
|
|
|
|
* #
|
|
|
|
|
* ################################################################
|
|
|
|
|
*/
|
|
|
|
|
|
2014-01-16 04:50:56 +00:00
|
|
|
|
class YearStatisticsItem : public TreeItem {
|
2013-06-18 00:05:17 +00:00
|
|
|
|
public:
|
2014-02-28 04:09:57 +00: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-18 00:05:17 +00:00
|
|
|
|
|
|
|
|
|
QVariant data(int column, int role) const;
|
|
|
|
|
YearStatisticsItem(stats_t interval);
|
2014-02-28 04:09:57 +00:00
|
|
|
|
|
2013-06-18 00:05:17 +00:00
|
|
|
|
private:
|
|
|
|
|
stats_t stats_interval;
|
|
|
|
|
};
|
|
|
|
|
|
2013-06-18 16:26:23 +00:00
|
|
|
|
YearStatisticsItem::YearStatisticsItem(stats_t interval) : stats_interval(interval)
|
2013-06-18 00:05:17 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant YearStatisticsItem::data(int column, int role) const
|
|
|
|
|
{
|
2013-06-18 16:26:23 +00:00
|
|
|
|
double value;
|
2013-06-18 00:05:17 +00:00
|
|
|
|
QVariant ret;
|
|
|
|
|
|
2013-06-19 17:30:36 +00: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 04:50:56 +00:00
|
|
|
|
switch (column) {
|
2013-11-24 01:09:34 +00:00
|
|
|
|
case YEAR:
|
|
|
|
|
if (stats_interval.is_trip) {
|
|
|
|
|
ret = stats_interval.location;
|
|
|
|
|
} else {
|
2014-02-28 04:09:57 +00:00
|
|
|
|
ret = stats_interval.period;
|
2013-11-24 01:09:34 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
2014-02-28 04:09:57 +00: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 16:26:23 +00:00
|
|
|
|
case AVG_TEMP:
|
|
|
|
|
if (stats_interval.combined_temp && stats_interval.combined_count) {
|
2013-06-18 17:48:46 +00:00
|
|
|
|
ret = QString::number(stats_interval.combined_temp / stats_interval.combined_count, 'f', 1);
|
2013-06-18 16:26:23 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case MIN_TEMP:
|
2013-06-18 17:48:46 +00:00
|
|
|
|
value = get_temp_units(stats_interval.min_temp, NULL);
|
|
|
|
|
if (value > -100.0)
|
2014-02-28 04:09:57 +00:00
|
|
|
|
ret = QString::number(value, 'f', 1);
|
2013-06-18 16:26:23 +00:00
|
|
|
|
break;
|
|
|
|
|
case MAX_TEMP:
|
2013-06-18 17:48:46 +00:00
|
|
|
|
value = get_temp_units(stats_interval.max_temp, NULL);
|
|
|
|
|
if (value > -100.0)
|
2014-02-28 04:09:57 +00:00
|
|
|
|
ret = QString::number(value, 'f', 1);
|
2013-06-18 16:26:23 +00:00
|
|
|
|
break;
|
2013-06-18 00:05:17 +00:00
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
YearlyStatisticsModel::YearlyStatisticsModel(QObject *parent)
|
2013-06-17 22:41:05 +00:00
|
|
|
|
{
|
2013-06-17 23:02:30 +00:00
|
|
|
|
columns = COLUMNS;
|
2013-06-18 00:05:17 +00:00
|
|
|
|
update_yearly_stats();
|
2013-06-17 22:41:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant YearlyStatisticsModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
|
|
|
{
|
|
|
|
|
QVariant val;
|
2013-06-18 16:26:23 +00:00
|
|
|
|
if (role == Qt::FontRole)
|
2014-02-28 04:09:57 +00:00
|
|
|
|
val = defaultModelFont();
|
2013-06-18 00:05:17 +00:00
|
|
|
|
|
2013-06-18 16:26:23 +00:00
|
|
|
|
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
|
2014-01-16 04:50:56 +00:00
|
|
|
|
switch (section) {
|
2014-02-28 04:09:57 +00: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 23:02:30 +00:00
|
|
|
|
}
|
2013-06-17 22:41:05 +00:00
|
|
|
|
}
|
2013-06-17 23:02:30 +00:00
|
|
|
|
return val;
|
2013-06-17 22:41:05 +00:00
|
|
|
|
}
|
2013-06-18 00:05:17 +00:00
|
|
|
|
|
|
|
|
|
void YearlyStatisticsModel::update_yearly_stats()
|
|
|
|
|
{
|
|
|
|
|
int i, month = 0;
|
|
|
|
|
unsigned int j, combined_months;
|
|
|
|
|
|
2013-06-18 16:26:23 +00:00
|
|
|
|
for (i = 0; stats_yearly != NULL && stats_yearly[i].period; ++i) {
|
2013-06-18 00:05:17 +00: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 20:29:37 +00:00
|
|
|
|
iChild->parent = item;
|
2013-06-18 00:05:17 +00:00
|
|
|
|
month++;
|
|
|
|
|
}
|
|
|
|
|
rootItem->children.append(item);
|
2013-06-18 20:29:37 +00:00
|
|
|
|
item->parent = rootItem;
|
2013-06-18 00:05:17 +00:00
|
|
|
|
}
|
2013-11-24 01:09:34 +00:00
|
|
|
|
|
|
|
|
|
|
2014-01-15 08:30:42 +00:00
|
|
|
|
if (stats_by_trip != NULL && stats_by_trip[0].is_trip == true) {
|
2013-11-24 01:09:34 +00: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-18 00:05:17 +00:00
|
|
|
|
}
|
2013-07-25 09:52:20 +00: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 08:30:44 +00:00
|
|
|
|
beginResetModel();
|
|
|
|
|
endResetModel();
|
2013-07-25 09:52:20 +00: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-28 04:09:57 +00: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 09:52:20 +00:00
|
|
|
|
}
|
2014-07-12 04:51:44 +00: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 09:52:20 +00: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-28 04:09:57 +00: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 16:24:29 +00: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 09:52:20 +00: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 14:50:40 +00:00
|
|
|
|
|
|
|
|
|
/*#################################################################
|
|
|
|
|
* #
|
|
|
|
|
* # Profile Print Model
|
|
|
|
|
* #
|
|
|
|
|
* ################################################################
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
ProfilePrintModel::ProfilePrintModel(QObject *parent)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProfilePrintModel::setDive(struct dive *divePtr)
|
|
|
|
|
{
|
2014-01-07 03:57:20 +00:00
|
|
|
|
diveId = divePtr->id;
|
2013-10-03 14:50:40 +00:00
|
|
|
|
// reset();
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-12 04:30:40 +00:00
|
|
|
|
void ProfilePrintModel::setFontsize(double size)
|
|
|
|
|
{
|
|
|
|
|
fontSize = size;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-03 14:50:40 +00:00
|
|
|
|
int ProfilePrintModel::rowCount(const QModelIndex &parent) const
|
|
|
|
|
{
|
2013-11-30 12:38:54 +00:00
|
|
|
|
return 12;
|
2013-10-03 14:50:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ProfilePrintModel::columnCount(const QModelIndex &parent) const
|
|
|
|
|
{
|
2013-11-30 12:38:54 +00:00
|
|
|
|
return 5;
|
2013-10-03 14:50:40 +00: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-18 21:38:37 +00:00
|
|
|
|
struct dive *dive = get_dive_by_uniq_id(diveId);
|
2013-10-03 14:50:40 +00:00
|
|
|
|
struct DiveItem di;
|
2014-01-07 03:57:20 +00:00
|
|
|
|
di.diveId = diveId;
|
2013-10-11 13:21:04 +00:00
|
|
|
|
|
|
|
|
|
const QString unknown = tr("unknown");
|
2013-10-03 14:50:40 +00:00
|
|
|
|
|
|
|
|
|
// dive# + date, depth, location, duration
|
|
|
|
|
if (row == 0) {
|
|
|
|
|
if (col == 0)
|
2013-10-11 13:21:04 +00:00
|
|
|
|
return tr("Dive #%1 - %2").arg(dive->number).arg(di.displayDate());
|
2014-07-12 04:40:22 +00:00
|
|
|
|
if (col == 3) {
|
2013-10-11 13:21:04 +00:00
|
|
|
|
QString unit = (get_units()->length == units::METERS) ? "m" : "ft";
|
|
|
|
|
return tr("Max depth: %1 %2").arg(di.displayDepth()).arg(unit);
|
2013-10-03 14:50:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (row == 1) {
|
|
|
|
|
if (col == 0)
|
2013-11-30 13:46:13 +00:00
|
|
|
|
return QString(dive->location);
|
2014-07-12 04:40:22 +00:00
|
|
|
|
if (col == 3)
|
2013-10-03 14:50:40 +00:00
|
|
|
|
return QString(tr("Duration: %1 min")).arg(di.displayDuration());
|
|
|
|
|
}
|
2013-11-30 14:00:51 +00:00
|
|
|
|
// headings
|
2013-10-03 14:50:40 +00:00
|
|
|
|
if (row == 2) {
|
|
|
|
|
if (col == 0)
|
2014-07-11 08:21:38 +00:00
|
|
|
|
return tr("Gas used:");
|
2013-10-03 14:50:40 +00:00
|
|
|
|
if (col == 2)
|
2014-07-12 04:39:44 +00:00
|
|
|
|
return tr("Tags:");
|
2013-11-30 14:00:51 +00:00
|
|
|
|
if (col == 3)
|
2014-07-12 04:39:44 +00:00
|
|
|
|
return tr("SAC:");
|
2013-11-30 14:00:51 +00:00
|
|
|
|
if (col == 4)
|
|
|
|
|
return tr("Weights:");
|
2013-10-03 14:50:40 +00:00
|
|
|
|
}
|
2013-11-30 14:09:54 +00:00
|
|
|
|
// notes
|
|
|
|
|
if (col == 0) {
|
|
|
|
|
if (row == 6)
|
|
|
|
|
return tr("Notes:");
|
|
|
|
|
if (row == 7)
|
|
|
|
|
return QString(dive->notes);
|
|
|
|
|
}
|
2013-11-30 14:23:19 +00:00
|
|
|
|
// more headings
|
|
|
|
|
if (row == 4) {
|
|
|
|
|
if (col == 0)
|
|
|
|
|
return tr("Divemaster:");
|
2013-10-03 14:50:40 +00:00
|
|
|
|
if (col == 1)
|
2013-11-30 14:23:19 +00:00
|
|
|
|
return tr("Buddy:");
|
2013-10-03 14:50:40 +00:00
|
|
|
|
if (col == 2)
|
2013-11-30 14:23:19 +00:00
|
|
|
|
return tr("Suit:");
|
|
|
|
|
if (col == 3)
|
|
|
|
|
return tr("Viz:");
|
|
|
|
|
if (col == 4)
|
|
|
|
|
return tr("Rating:");
|
2013-10-03 14:50:40 +00:00
|
|
|
|
}
|
2013-11-30 14:51:28 +00:00
|
|
|
|
// values for gas, sac, etc...
|
|
|
|
|
if (row == 3) {
|
|
|
|
|
if (col == 0) {
|
|
|
|
|
int added = 0;
|
2014-07-12 04:39:44 +00:00
|
|
|
|
QString gas, gases;
|
2013-11-30 14:51:28 +00:00
|
|
|
|
for (int i = 0; i < MAX_CYLINDERS; i++) {
|
2014-08-06 14:08:31 +00:00
|
|
|
|
if (!is_cylinder_used(dive, i))
|
|
|
|
|
continue;
|
2014-07-12 04:39:44 +00:00
|
|
|
|
gas = dive->cylinder[i].type.description;
|
|
|
|
|
gas += QString(!gas.isEmpty() ? " " : "") + gasname(&dive->cylinder[i].gasmix);
|
2013-11-30 14:51:28 +00:00
|
|
|
|
// if has a description and if such gas is not already present
|
2014-07-12 04:39:44 +00:00
|
|
|
|
if (!gas.isEmpty() && gases.indexOf(gas) == -1) {
|
2013-11-30 14:51:28 +00:00
|
|
|
|
if (added > 0)
|
|
|
|
|
gases += QString(" / ");
|
2014-07-12 04:39:44 +00:00
|
|
|
|
gases += gas;
|
2013-11-30 14:51:28 +00:00
|
|
|
|
added++;
|
|
|
|
|
}
|
2013-10-03 14:50:40 +00:00
|
|
|
|
}
|
2013-11-30 14:51:28 +00:00
|
|
|
|
return gases;
|
2013-10-03 14:50:40 +00:00
|
|
|
|
}
|
2014-07-12 04:39:44 +00:00
|
|
|
|
if (col == 2) {
|
|
|
|
|
char buffer[256];
|
|
|
|
|
taglist_get_tagstring(dive->tag_list, buffer, 256);
|
|
|
|
|
return QString(buffer);
|
|
|
|
|
}
|
2013-11-30 17:10:47 +00:00
|
|
|
|
if (col == 3)
|
2014-07-12 04:39:44 +00:00
|
|
|
|
return di.displaySac();
|
2013-11-30 14:51:28 +00:00
|
|
|
|
if (col == 4) {
|
|
|
|
|
weight_t tw = { total_weight(dive) };
|
|
|
|
|
return get_weight_string(tw, true);
|
2013-10-03 14:50:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-30 15:09:10 +00: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 14:50:40 +00:00
|
|
|
|
}
|
2013-10-11 13:21:04 +00:00
|
|
|
|
return QString();
|
2013-10-03 14:50:40 +00:00
|
|
|
|
}
|
|
|
|
|
case Qt::FontRole: {
|
|
|
|
|
QFont font;
|
2014-07-12 04:30:40 +00:00
|
|
|
|
font.setPointSizeF(fontSize);
|
2013-10-03 14:50:40 +00:00
|
|
|
|
if (row == 0 && col == 0) {
|
|
|
|
|
font.setBold(true);
|
|
|
|
|
}
|
|
|
|
|
return QVariant::fromValue(font);
|
|
|
|
|
}
|
|
|
|
|
case Qt::TextAlignmentRole: {
|
2013-11-30 13:41:18 +00: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 14:50:40 +00:00
|
|
|
|
align = Qt::AlignRight | Qt::AlignVCenter;
|
|
|
|
|
return QVariant::fromValue(align);
|
|
|
|
|
}
|
|
|
|
|
} // switch (role)
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
2013-11-14 19:39:35 +00:00
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
Qt::ItemFlags GasSelectionModel::flags(const QModelIndex &index) const
|
2013-11-14 19:39:35 +00:00
|
|
|
|
{
|
2013-11-20 02:17:50 +00:00
|
|
|
|
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
2013-11-14 19:39:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
GasSelectionModel *GasSelectionModel::instance()
|
2013-11-14 19:39:35 +00:00
|
|
|
|
{
|
2013-11-30 17:18:04 +00:00
|
|
|
|
static QScopedPointer<GasSelectionModel> self(new GasSelectionModel());
|
|
|
|
|
return self.data();
|
2013-11-14 19:39:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GasSelectionModel::repopulate()
|
|
|
|
|
{
|
2013-11-20 02:17:50 +00:00
|
|
|
|
setStringList(DivePlannerPointsModel::instance()->getGasList());
|
2013-11-14 19:39:35 +00:00
|
|
|
|
}
|
2013-11-14 19:43:28 +00:00
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
QVariant GasSelectionModel::data(const QModelIndex &index, int role) const
|
2013-11-14 19:43:28 +00:00
|
|
|
|
{
|
2014-01-16 04:50:56 +00:00
|
|
|
|
if (role == Qt::FontRole) {
|
2013-11-14 19:43:28 +00:00
|
|
|
|
return defaultModelFont();
|
|
|
|
|
}
|
|
|
|
|
return QStringListModel::data(index, role);
|
|
|
|
|
}
|
2013-12-06 16:29:38 +00:00
|
|
|
|
|
|
|
|
|
// Language Model, The Model to populate the list of possible Languages.
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
LanguageModel *LanguageModel::instance()
|
2013-12-06 16:29:38 +00:00
|
|
|
|
{
|
|
|
|
|
static LanguageModel *self = new LanguageModel();
|
|
|
|
|
QLocale l;
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
LanguageModel::LanguageModel(QObject *parent) : QAbstractListModel(parent)
|
2013-12-06 16:29:38 +00:00
|
|
|
|
{
|
|
|
|
|
QSettings s;
|
2013-12-06 20:30:05 +00:00
|
|
|
|
QDir d(getSubsurfaceDataPath("translations"));
|
2014-07-15 17:43:20 +00:00
|
|
|
|
Q_FOREACH (const QString &s, d.entryList()) {
|
2014-02-28 04:09:57 +00:00
|
|
|
|
if (s.startsWith("subsurface_") && s.endsWith(".qm")) {
|
|
|
|
|
languages.push_back((s == "subsurface_source.qm") ? "English" : s);
|
2013-12-06 16:29:38 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
QVariant LanguageModel::data(const QModelIndex &index, int role) const
|
2013-12-06 16:29:38 +00:00
|
|
|
|
{
|
|
|
|
|
QLocale loc;
|
2013-12-06 19:48:38 +00:00
|
|
|
|
QString currentString = languages.at(index.row());
|
2014-01-16 04:50:56 +00:00
|
|
|
|
if (!index.isValid())
|
2013-12-06 16:29:38 +00:00
|
|
|
|
return QVariant();
|
2014-01-16 04:50:56 +00:00
|
|
|
|
switch (role) {
|
2014-02-12 14:18:15 +00:00
|
|
|
|
case Qt::DisplayRole: {
|
2014-02-28 04:09:57 +00:00
|
|
|
|
QLocale l(currentString.remove("subsurface_"));
|
2014-02-12 14:18:15 +00:00
|
|
|
|
return currentString == "English" ? currentString : QString("%1 (%2)").arg(l.languageToString(l.language())).arg(l.countryToString(l.country()));
|
|
|
|
|
}
|
|
|
|
|
case Qt::UserRole:
|
|
|
|
|
return currentString == "English" ? "en_US" : currentString.remove("subsurface_");
|
2013-12-06 16:29:38 +00:00
|
|
|
|
}
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
int LanguageModel::rowCount(const QModelIndex &parent) const
|
2013-12-06 16:29:38 +00:00
|
|
|
|
{
|
|
|
|
|
return languages.count();
|
|
|
|
|
}
|
2014-09-17 18:45:18 +00:00
|
|
|
|
|
2014-11-06 19:24:38 +00: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();
|
|
|
|
|
}
|
|
|
|
|
}
|