diff options
author | Robert Helling <helling@lmu.de> | 2013-11-18 14:53:05 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-11-18 10:03:45 -0800 |
commit | 4966336e1d6c729e5763aa3ac607c77f8794e5da (patch) | |
tree | 0c7183ea8570f38c366e8145557937af8d416821 | |
parent | e289881db9727b5bcfec12c3c390cdd6743f7472 (diff) | |
download | subsurface-4966336e1d6c729e5763aa3ac607c77f8794e5da.tar.gz |
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 <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | dive.c | 12 | ||||
-rw-r--r-- | dive.h | 2 | ||||
-rw-r--r-- | qt-ui/divelistview.cpp | 7 | ||||
-rw-r--r-- | qt-ui/divelistview.h | 1 | ||||
-rw-r--r-- | qt-ui/shifttimes.ui | 155 | ||||
-rw-r--r-- | qt-ui/simplewidgets.cpp | 27 | ||||
-rw-r--r-- | qt-ui/simplewidgets.h | 12 | ||||
-rw-r--r-- | subsurface.pro | 1 |
8 files changed, 217 insertions, 0 deletions
@@ -2072,3 +2072,15 @@ struct dive *find_dive_n_near(timestamp_t when, int n, timestamp_t offset) } return NULL; } + +void shift_times(const timestamp_t amount) +{ + int i; + struct dive *dive; + + for_each_dive (i, dive) { + if (!dive->selected) + continue; + dive->when += amount; + } +} @@ -633,6 +633,8 @@ extern void save_dives_logic(const char *filename, bool select_only); extern void save_dive(FILE *f, struct dive *dive); extern void export_dives_uddf(const char *filename, const bool selected); +extern void shift_times(const timestamp_t amount); + extern xsltStylesheetPtr get_stylesheet(const char *name); extern char *xslt_path; 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>ShiftTimesDialog</class> + <widget class="QDialog" name="ShiftTimesDialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>229</width> + <height>134</height> + </rect> + </property> + <property name="windowTitle"> + <string>Shift selected times</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <property name="spacing"> + <number>0</number> + </property> + <property name="leftMargin"> + <number>0</number> + </property> + <property name="topMargin"> + <number>0</number> + </property> + <property name="rightMargin"> + <number>0</number> + </property> + <property name="bottomMargin"> + <number>0</number> + </property> + <item> + <widget class="QGroupBox" name="groupBox"> + <property name="title"> + <string>Shift times of selected dives by</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <property name="leftMargin"> + <number>0</number> + </property> + <property name="topMargin"> + <number>0</number> + </property> + <property name="rightMargin"> + <number>0</number> + </property> + <property name="bottomMargin"> + <number>0</number> + </property> + <item> + <widget class="QTimeEdit" name="timeEdit"> + <property name="date"> + <date> + <year>2000</year> + <month>1</month> + <day>1</day> + </date> + </property> + <property name="minimumDateTime"> + <datetime> + <hour>0</hour> + <minute>0</minute> + <second>0</second> + <year>2000</year> + <month>1</month> + <day>1</day> + </datetime> + </property> + <property name="maximumDate"> + <date> + <year>2000</year> + <month>1</month> + <day>1</day> + </date> + </property> + <property name="timeSpec"> + <enum>Qt::LocalTime</enum> + </property> + <property name="time"> + <time> + <hour>0</hour> + <minute>0</minute> + <second>0</second> + </time> + </property> + </widget> + </item> + <item> + <widget class="QRadioButton" name="backwards"> + <property name="text"> + <string>backwards</string> + </property> + </widget> + </item> + <item> + <widget class="QRadioButton" name="forward"> + <property name="text"> + <string>forward</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>ShiftTimesDialog</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel"> + <x>248</x> + <y>254</y> + </hint> + <hint type="destinationlabel"> + <x>157</x> + <y>274</y> + </hint> + </hints> + </connection> + <connection> + <sender>buttonBox</sender> + <signal>rejected()</signal> + <receiver>ShiftTimesDialog</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>316</x> + <y>260</y> + </hint> + <hint type="destinationlabel"> + <x>286</x> + <y>274</y> + </hint> + </hints> + </connection> + </connections> +</ui> 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 <QDebug> #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 <QDialog> #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 diff --git a/subsurface.pro b/subsurface.pro index 23fc43af1..8754f1da7 100644 --- a/subsurface.pro +++ b/subsurface.pro @@ -123,6 +123,7 @@ FORMS = \ qt-ui/preferences.ui \ qt-ui/printoptions.ui \ qt-ui/renumber.ui \ + qt-ui/shifttimes.ui \ qt-ui/webservices.ui \ qt-ui/tableview.ui \ qt-ui/csvimportdialog.ui |