diff options
-rw-r--r-- | qt-ui/diveplanner.cpp | 36 | ||||
-rw-r--r-- | qt-ui/diveplanner.h | 7 | ||||
-rw-r--r-- | qt-ui/mainwindow.cpp | 1 |
3 files changed, 41 insertions, 3 deletions
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index d2d2e2a8d..9735fec36 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -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) { // 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")); 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.atmHeight, SIGNAL(valueChanged(int)), this, SLOT(heightChanged(int))); + connect(DivePlannerPointsModel::instance(), SIGNAL(startTimeChanged(QDateTime)), this, SLOT(setupStartTime(QDateTime))); // Creating (and canceling) the plan 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())); /* set defaults. */ - ui.startTime->setTime(QTime(1, 0)); ui.ATMPressure->setValue(1013); ui.atmHeight->setValue(0); @@ -294,6 +311,12 @@ DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidg setMinimumHeight(0); } +void DivePlannerWidget::setupStartTime(QDateTime startTime) +{ + ui.startTime->setTime(startTime.time()); + ui.dateEdit->setDate(startTime.date()); +} + void DivePlannerWidget::settingsChanged() { // 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(&backupDive, 0, sizeof(backupDive)); + startTime = QDateTime::currentDateTimeUtc(); } DivePlannerPointsModel *DivePlannerPointsModel::instance() @@ -690,9 +714,17 @@ void DivePlannerPointsModel::setDropStoneMode(bool value) 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) { - 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)); } diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index 378707d96..08a1ba519 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -3,6 +3,7 @@ #include <QGraphicsPathItem> #include <QAbstractTableModel> +#include <QDateTime> #include "dive.h" @@ -37,6 +38,7 @@ public: void setPlanMode(Mode mode); bool isPlanner(); void createSimpleDive(); + void setupStartTime(); void clear(); Mode currentMode() const; bool setRecalc(bool recalc); @@ -69,6 +71,7 @@ slots: void setBottomSac(int sac); void setDecoSac(int sac); void setStartTime(const QTime &t); + void setStartDate(const QDate &date); void setLastStop6m(bool value); void setDropStoneMode(bool value); void setVerbatim(bool value); @@ -88,6 +91,7 @@ signals: void planCreated(); void planCanceled(); void cylinderModelEdited(); + void startTimeChanged(QDateTime); private: explicit DivePlannerPointsModel(QObject *parent = 0); @@ -103,6 +107,7 @@ private: struct dive *stagingDive; QVector<QPair<int, int> > oldGases; bool drop_stone_mode; + QDateTime startTime; }; class DiveHandler : public QObject, public QGraphicsEllipseItem { @@ -129,9 +134,9 @@ class DivePlannerWidget : public QWidget { Q_OBJECT public: explicit DivePlannerWidget(QWidget *parent = 0, Qt::WindowFlags f = 0); - public slots: + void setupStartTime(QDateTime startTime); void settingsChanged(); void atmPressureChanged(const int pressure); void heightChanged(const int height); diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index ed0488986..1e21f4a59 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -480,6 +480,7 @@ void MainWindow::on_actionDivePlanner_triggered() DivePlannerPointsModel::instance()->setupCylinders(); // create a simple starting dive, using the first gas from the just copied cylidners + DivePlannerPointsModel::instance()->setupStartTime(); createFakeDiveForAddAndPlan(); DivePlannerPointsModel::instance()->createSimpleDive(); |