From 00ff63f186f65df809610d70ca9b132197b6e72d Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Fri, 22 May 2020 09:49:48 +0200 Subject: [PATCH] desktop: update date and time fields if user changes format This was more painful than expected, because we get the "preferences" changed signal too early when the user switches to system format. The correct format is set by the preferences-widget, not the preferences subsystem. Signed-off-by: Berthold Stoeger --- CHANGELOG.md | 1 + desktop-widgets/tab-widgets/maintab.cpp | 15 +++++++++++++-- desktop-widgets/tab-widgets/maintab.h | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f82572bad..99cf0dcdb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +desktop: update date and time fields on maintab if user changes preferences mobile: small improvements to usability with dark theme Core: improve service selection for BLE, adding white list and black list Filter: fix searching for tags [#2842] diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp index 9c08ddcbd..d11581516 100644 --- a/desktop-widgets/tab-widgets/maintab.cpp +++ b/desktop-widgets/tab-widgets/maintab.cpp @@ -8,6 +8,7 @@ #include "desktop-widgets/tab-widgets/maintab.h" #include "desktop-widgets/mainwindow.h" #include "desktop-widgets/mapwidget.h" +#include "desktop-widgets/preferences/preferencesdialog.h" #include "core/qthelper.h" #include "core/trip.h" #include "qt-models/diveplannermodel.h" @@ -71,8 +72,7 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), extraWidgets << new TabDiveSite(this); ui.tabWidget->addTab(extraWidgets.last(), tr("Dive sites")); - ui.dateEdit->setDisplayFormat(prefs.date_format); - ui.timeEdit->setDisplayFormat(prefs.time_format); + updateDateTimeFields(); closeMessage(); @@ -86,6 +86,11 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), connect(ui.location, &DiveLocationLineEdit::currentChanged, MapWidget::instance(), &MapWidget::centerOnIndex); connect(ui.location, &DiveLocationLineEdit::editingFinished, this, &MainTab::on_location_diveSiteSelected); + // One might think that we could listen to the precise property-changed signals of the preferences system. + // Alas, this is not the case. When the user switches to system-format, the preferences sends the according + // signal. However, the correct date and time format is set by the preferences dialog later. This should be fixed. + connect(PreferencesDialog::instance(), &PreferencesDialog::settingsChanged, this, &MainTab::updateDateTimeFields); + QAction *action = new QAction(tr("Apply changes"), this); connect(action, SIGNAL(triggered(bool)), this, SLOT(acceptChanges())); ui.diveNotesMessage->addAction(action); @@ -178,6 +183,12 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), ui.diveTripLocation->hide(); } +void MainTab::updateDateTimeFields() +{ + ui.dateEdit->setDisplayFormat(prefs.date_format); + ui.timeEdit->setDisplayFormat(prefs.time_format); +} + void MainTab::hideMessage() { ui.diveNotesMessage->animatedHide(); diff --git a/desktop-widgets/tab-widgets/maintab.h b/desktop-widgets/tab-widgets/maintab.h index c083554b1..e0bf908d1 100644 --- a/desktop-widgets/tab-widgets/maintab.h +++ b/desktop-widgets/tab-widgets/maintab.h @@ -66,6 +66,7 @@ slots: void displayMessage(QString str); void enableEdition(); void escDetected(void); + void updateDateTimeFields(); private: Ui::MainTab ui; bool editMode;