mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-07 19:43:24 +00:00
Planner: implement sane way to set the start time of the planned dive
This uses the same widgets we use on the maintab. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
4b18da1f22
commit
06a8002a2d
3 changed files with 41 additions and 3 deletions
|
@ -82,6 +82,22 @@ void DivePlannerPointsModel::createSimpleDive()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DivePlannerPointsModel::setupStartTime()
|
||||||
|
{
|
||||||
|
// if the latest dive is in the future, then start an hour after it ends
|
||||||
|
// otherwise start an hour from now
|
||||||
|
startTime = QDateTime::currentDateTimeUtc().addSecs(3600 + gettimezoneoffset());
|
||||||
|
if (dive_table.nr) {
|
||||||
|
struct dive *d = get_dive(dive_table.nr - 1);
|
||||||
|
time_t ends = d->when + d->duration.seconds;
|
||||||
|
time_t diff = ends - startTime.toTime_t();
|
||||||
|
if (diff > 0) {
|
||||||
|
startTime = startTime.addSecs(diff + 3600);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
emit startTimeChanged(startTime);
|
||||||
|
}
|
||||||
|
|
||||||
void DivePlannerPointsModel::loadFromDive(dive *d)
|
void DivePlannerPointsModel::loadFromDive(dive *d)
|
||||||
{
|
{
|
||||||
// We need to make a copy, because as soon as the model is modified, it will
|
// We need to make a copy, because as soon as the model is modified, it will
|
||||||
|
@ -276,8 +292,10 @@ DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidg
|
||||||
|
|
||||||
ui.tableWidget->setBtnToolTip(tr("add dive data point"));
|
ui.tableWidget->setBtnToolTip(tr("add dive data point"));
|
||||||
connect(ui.startTime, SIGNAL(timeChanged(QTime)), plannerModel, SLOT(setStartTime(QTime)));
|
connect(ui.startTime, SIGNAL(timeChanged(QTime)), plannerModel, SLOT(setStartTime(QTime)));
|
||||||
|
connect(ui.dateEdit, SIGNAL(dateChanged(QDate)), plannerModel, SLOT(setStartDate(QDate)));
|
||||||
connect(ui.ATMPressure, SIGNAL(valueChanged(int)), this, SLOT(atmPressureChanged(int)));
|
connect(ui.ATMPressure, SIGNAL(valueChanged(int)), this, SLOT(atmPressureChanged(int)));
|
||||||
connect(ui.atmHeight, SIGNAL(valueChanged(int)), this, SLOT(heightChanged(int)));
|
connect(ui.atmHeight, SIGNAL(valueChanged(int)), this, SLOT(heightChanged(int)));
|
||||||
|
connect(DivePlannerPointsModel::instance(), SIGNAL(startTimeChanged(QDateTime)), this, SLOT(setupStartTime(QDateTime)));
|
||||||
|
|
||||||
// Creating (and canceling) the plan
|
// Creating (and canceling) the plan
|
||||||
connect(ui.buttonBox, SIGNAL(accepted()), plannerModel, SLOT(createPlan()));
|
connect(ui.buttonBox, SIGNAL(accepted()), plannerModel, SLOT(createPlan()));
|
||||||
|
@ -286,7 +304,6 @@ DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidg
|
||||||
connect(closeKey, SIGNAL(activated()), plannerModel, SLOT(cancelPlan()));
|
connect(closeKey, SIGNAL(activated()), plannerModel, SLOT(cancelPlan()));
|
||||||
|
|
||||||
/* set defaults. */
|
/* set defaults. */
|
||||||
ui.startTime->setTime(QTime(1, 0));
|
|
||||||
ui.ATMPressure->setValue(1013);
|
ui.ATMPressure->setValue(1013);
|
||||||
ui.atmHeight->setValue(0);
|
ui.atmHeight->setValue(0);
|
||||||
|
|
||||||
|
@ -294,6 +311,12 @@ DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidg
|
||||||
setMinimumHeight(0);
|
setMinimumHeight(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DivePlannerWidget::setupStartTime(QDateTime startTime)
|
||||||
|
{
|
||||||
|
ui.startTime->setTime(startTime.time());
|
||||||
|
ui.dateEdit->setDate(startTime.date());
|
||||||
|
}
|
||||||
|
|
||||||
void DivePlannerWidget::settingsChanged()
|
void DivePlannerWidget::settingsChanged()
|
||||||
{
|
{
|
||||||
// right now there's nothing special we do when settings change
|
// right now there's nothing special we do when settings change
|
||||||
|
@ -595,6 +618,7 @@ DivePlannerPointsModel::DivePlannerPointsModel(QObject *parent) : QAbstractTable
|
||||||
{
|
{
|
||||||
memset(&diveplan, 0, sizeof(diveplan));
|
memset(&diveplan, 0, sizeof(diveplan));
|
||||||
memset(&backupDive, 0, sizeof(backupDive));
|
memset(&backupDive, 0, sizeof(backupDive));
|
||||||
|
startTime = QDateTime::currentDateTimeUtc();
|
||||||
}
|
}
|
||||||
|
|
||||||
DivePlannerPointsModel *DivePlannerPointsModel::instance()
|
DivePlannerPointsModel *DivePlannerPointsModel::instance()
|
||||||
|
@ -690,9 +714,17 @@ void DivePlannerPointsModel::setDropStoneMode(bool value)
|
||||||
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
|
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DivePlannerPointsModel::setStartDate(const QDate &date)
|
||||||
|
{
|
||||||
|
startTime.setDate(date);
|
||||||
|
diveplan.when = startTime.toTime_t();
|
||||||
|
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
|
||||||
|
}
|
||||||
|
|
||||||
void DivePlannerPointsModel::setStartTime(const QTime &t)
|
void DivePlannerPointsModel::setStartTime(const QTime &t)
|
||||||
{
|
{
|
||||||
diveplan.when = (t.msec() + QDateTime::currentMSecsSinceEpoch()) / 1000 - gettimezoneoffset();
|
startTime.setTime(t);
|
||||||
|
diveplan.when = startTime.toTime_t();
|
||||||
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
|
emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <QGraphicsPathItem>
|
#include <QGraphicsPathItem>
|
||||||
#include <QAbstractTableModel>
|
#include <QAbstractTableModel>
|
||||||
|
#include <QDateTime>
|
||||||
|
|
||||||
#include "dive.h"
|
#include "dive.h"
|
||||||
|
|
||||||
|
@ -37,6 +38,7 @@ public:
|
||||||
void setPlanMode(Mode mode);
|
void setPlanMode(Mode mode);
|
||||||
bool isPlanner();
|
bool isPlanner();
|
||||||
void createSimpleDive();
|
void createSimpleDive();
|
||||||
|
void setupStartTime();
|
||||||
void clear();
|
void clear();
|
||||||
Mode currentMode() const;
|
Mode currentMode() const;
|
||||||
bool setRecalc(bool recalc);
|
bool setRecalc(bool recalc);
|
||||||
|
@ -69,6 +71,7 @@ slots:
|
||||||
void setBottomSac(int sac);
|
void setBottomSac(int sac);
|
||||||
void setDecoSac(int sac);
|
void setDecoSac(int sac);
|
||||||
void setStartTime(const QTime &t);
|
void setStartTime(const QTime &t);
|
||||||
|
void setStartDate(const QDate &date);
|
||||||
void setLastStop6m(bool value);
|
void setLastStop6m(bool value);
|
||||||
void setDropStoneMode(bool value);
|
void setDropStoneMode(bool value);
|
||||||
void setVerbatim(bool value);
|
void setVerbatim(bool value);
|
||||||
|
@ -88,6 +91,7 @@ signals:
|
||||||
void planCreated();
|
void planCreated();
|
||||||
void planCanceled();
|
void planCanceled();
|
||||||
void cylinderModelEdited();
|
void cylinderModelEdited();
|
||||||
|
void startTimeChanged(QDateTime);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit DivePlannerPointsModel(QObject *parent = 0);
|
explicit DivePlannerPointsModel(QObject *parent = 0);
|
||||||
|
@ -103,6 +107,7 @@ private:
|
||||||
struct dive *stagingDive;
|
struct dive *stagingDive;
|
||||||
QVector<QPair<int, int> > oldGases;
|
QVector<QPair<int, int> > oldGases;
|
||||||
bool drop_stone_mode;
|
bool drop_stone_mode;
|
||||||
|
QDateTime startTime;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DiveHandler : public QObject, public QGraphicsEllipseItem {
|
class DiveHandler : public QObject, public QGraphicsEllipseItem {
|
||||||
|
@ -129,9 +134,9 @@ class DivePlannerWidget : public QWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit DivePlannerWidget(QWidget *parent = 0, Qt::WindowFlags f = 0);
|
explicit DivePlannerWidget(QWidget *parent = 0, Qt::WindowFlags f = 0);
|
||||||
|
|
||||||
public
|
public
|
||||||
slots:
|
slots:
|
||||||
|
void setupStartTime(QDateTime startTime);
|
||||||
void settingsChanged();
|
void settingsChanged();
|
||||||
void atmPressureChanged(const int pressure);
|
void atmPressureChanged(const int pressure);
|
||||||
void heightChanged(const int height);
|
void heightChanged(const int height);
|
||||||
|
|
|
@ -480,6 +480,7 @@ void MainWindow::on_actionDivePlanner_triggered()
|
||||||
DivePlannerPointsModel::instance()->setupCylinders();
|
DivePlannerPointsModel::instance()->setupCylinders();
|
||||||
|
|
||||||
// create a simple starting dive, using the first gas from the just copied cylidners
|
// create a simple starting dive, using the first gas from the just copied cylidners
|
||||||
|
DivePlannerPointsModel::instance()->setupStartTime();
|
||||||
createFakeDiveForAddAndPlan();
|
createFakeDiveForAddAndPlan();
|
||||||
DivePlannerPointsModel::instance()->createSimpleDive();
|
DivePlannerPointsModel::instance()->createSimpleDive();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue