From 06a8002a2de0dc731f0ecd5ec87cf210ec2b9c2c Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sat, 28 Jun 2014 08:07:28 -0700 Subject: 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 --- qt-ui/diveplanner.cpp | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'qt-ui/diveplanner.cpp') 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)); } -- cgit v1.2.3-70-g09d2