From 4966336e1d6c729e5763aa3ac607c77f8794e5da Mon Sep 17 00:00:00 2001 From: Robert Helling Date: Mon, 18 Nov 2013 14:53:05 +0100 Subject: Shift times of selected dives This patch adds the possibility to shift the times of all selected dives by a fixed amount to correct for time zone problems or mis-set dive computer clocks. Select the dives and right click in the dive list. [Dirk Hohndel: added .ui file to FORMS and fixed some whitespace damage] Signed-off-by: Robert C. Helling Signed-off-by: Dirk Hohndel --- qt-ui/divelistview.cpp | 7 +++ qt-ui/divelistview.h | 1 + qt-ui/shifttimes.ui | 155 ++++++++++++++++++++++++++++++++++++++++++++++++ qt-ui/simplewidgets.cpp | 27 +++++++++ qt-ui/simplewidgets.h | 12 ++++ 5 files changed, 202 insertions(+) create mode 100644 qt-ui/shifttimes.ui (limited to 'qt-ui') diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp index 95f85d604..ca0ea5713 100644 --- a/qt-ui/divelistview.cpp +++ b/qt-ui/divelistview.cpp @@ -614,6 +614,7 @@ void DiveListView::contextMenuEvent(QContextMenuEvent *event) if (amount_selected >= 1) { popup.addAction(tr("save As"), this, SLOT(saveSelectedDivesAs())); popup.addAction(tr("export As UDDF"), this, SLOT(exportSelectedDivesAsUDDF())); + popup.addAction(tr("shift times"), this, SLOT(shiftTimes())); } // "collapse all" really closes all trips, // "collapse" keeps the trip with the selected dive open @@ -664,3 +665,9 @@ void DiveListView::exportSelectedDivesAsUDDF() if (!filename.isNull() && !filename.isEmpty()) export_dives_uddf(filename.toUtf8(), true); } + + +void DiveListView::shiftTimes() +{ + ShiftTimesDialog::instance()->show(); +} diff --git a/qt-ui/divelistview.h b/qt-ui/divelistview.h index 3d486d1bd..b4a0d3b35 100644 --- a/qt-ui/divelistview.h +++ b/qt-ui/divelistview.h @@ -47,6 +47,7 @@ public slots: void mergeDives(); void saveSelectedDivesAs(); void exportSelectedDivesAsUDDF(); + void shiftTimes(); signals: void currentDiveChanged(int divenr); diff --git a/qt-ui/shifttimes.ui b/qt-ui/shifttimes.ui new file mode 100644 index 000000000..39b3250a1 --- /dev/null +++ b/qt-ui/shifttimes.ui @@ -0,0 +1,155 @@ + + + ShiftTimesDialog + + + + 0 + 0 + 229 + 134 + + + + Shift selected times + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Shift times of selected dives by + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 2000 + 1 + 1 + + + + + 0 + 0 + 0 + 2000 + 1 + 1 + + + + + 2000 + 1 + 1 + + + + Qt::LocalTime + + + + + + + + + + backwards + + + + + + + forward + + + true + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + ShiftTimesDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + ShiftTimesDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/qt-ui/simplewidgets.cpp b/qt-ui/simplewidgets.cpp index f1cf8906d..bbe7b1b37 100644 --- a/qt-ui/simplewidgets.cpp +++ b/qt-ui/simplewidgets.cpp @@ -13,6 +13,7 @@ #include #include "../dive.h" +#include "mainwindow.h" class MinMaxAvgWidgetPrivate{ public: @@ -119,6 +120,32 @@ RenumberDialog::RenumberDialog(): QDialog() connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(buttonClicked(QAbstractButton*))); } +ShiftTimesDialog* ShiftTimesDialog::instance() +{ + static ShiftTimesDialog* self = new ShiftTimesDialog(); + return self; +} + +void ShiftTimesDialog::buttonClicked(QAbstractButton* button) +{ + int amount; + + if (ui.buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole){ + amount = ui.timeEdit->time().hour() * 3600 + ui.timeEdit->time().minute() * 60; + if (ui.backwards->isChecked()) + amount *= -1; + + shift_times(amount); + mainWindow()->refreshDisplay(); + } +} + +ShiftTimesDialog::ShiftTimesDialog(): QDialog() +{ + ui.setupUi(this); + connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(buttonClicked(QAbstractButton*))); +} + bool isGnome3Session() { #if defined(QT_OS_WIW) || defined(QT_OS_MAC) diff --git a/qt-ui/simplewidgets.h b/qt-ui/simplewidgets.h index 057a97251..70d61ca59 100644 --- a/qt-ui/simplewidgets.h +++ b/qt-ui/simplewidgets.h @@ -8,6 +8,7 @@ class QAbstractButton; #include #include "ui_renumber.h" +#include "ui_shifttimes.h" class MinMaxAvgWidget : public QWidget{ Q_OBJECT @@ -41,6 +42,17 @@ private: Ui::RenumberDialog ui; }; +class ShiftTimesDialog : public QDialog { + Q_OBJECT +public: + static ShiftTimesDialog *instance(); +private slots: + void buttonClicked(QAbstractButton *button); +private: + explicit ShiftTimesDialog(); + Ui::ShiftTimesDialog ui; +}; + bool isGnome3Session(); #endif -- cgit v1.2.3-70-g09d2