From 5d7f294407c29f39e017d0ac6a05d769caef56b2 Mon Sep 17 00:00:00 2001 From: Michael Keller Date: Tue, 23 May 2023 18:45:32 +1200 Subject: [PATCH] Desktop: Rework Setting of Custom Date / Time Formats. Rework the setting of custom date / time format preferences: - fix bug causing case changes if custom format case insensitively matches a drop down entry; - fix invalid format examples in tooltip; - update URL for the format documentation; - add support for quoted literals to the format validity warning. From discussion in https://github.com/subsurface/subsurface/issues/3849#issuecomment-1481239270. Signed-off-by: Michael Keller --- .../preferences/preferences_language.cpp | 19 +++++++++++-------- .../preferences/preferences_language.ui | 4 ++-- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/desktop-widgets/preferences/preferences_language.cpp b/desktop-widgets/preferences/preferences_language.cpp index 161c94721..7a8433622 100644 --- a/desktop-widgets/preferences/preferences_language.cpp +++ b/desktop-widgets/preferences/preferences_language.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include "qt-models/models.h" @@ -28,12 +29,14 @@ PreferencesLanguage::PreferencesLanguage() : AbstractPreferencesWidget(tr("Langu dateFormatShortMap.insert("yyyy-MM-dd", "yy-M-d"); foreach (QString format, dateFormatShortMap.keys()) ui->dateFormatEntry->addItem(format); + ui->dateFormatEntry->completer()->setCaseSensitivity(Qt::CaseSensitive); connect(ui->dateFormatEntry, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(dateFormatChanged(const QString&))); ui->timeFormatEntry->addItem("hh:mm"); ui->timeFormatEntry->addItem("h:mm AP"); ui->timeFormatEntry->addItem("hh:mm AP"); + ui->timeFormatEntry->completer()->setCaseSensitivity(Qt::CaseSensitive); } PreferencesLanguage::~PreferencesLanguage() @@ -94,15 +97,15 @@ void PreferencesLanguage::syncSettings() // Therefore, refresh the UI fields to give the user a visual feedback of the new formats. refreshSettings(); - QString qDateTimeWeb = tr("These will be used as is. This might not be what you intended.\nSee http://doc.qt.io/qt-5/qdatetime.html#toString"); - QRegularExpression tfillegalchars("[^hHmszaApPt\\s:;\\.,]"); - if (tfillegalchars.match(ui->timeFormatEntry->currentText()).hasMatch()) + QString qDateTimeWeb = tr("These will be used as is. This might not be what you intended. To avoid this warning wrap the literal parts in quotes (').\nSee https://doc.qt.io/archives/qt-4.8/qdatetime.html#fromString"); + QRegularExpression timeStandardFormat("^([hHmszaApP\\s:\\.]|'[^']*')*$"); + if (!timeStandardFormat.match(ui->timeFormatEntry->currentText()).hasMatch()) QMessageBox::warning(this, tr("Literal characters"), - tr("Non-special character(s) in time format.\n") + qDateTimeWeb); + tr("Non-standard character(s) in time format.\n") + qDateTimeWeb); - QRegularExpression dfillegalchars("[^dMy/\\s:;\\.,\\-]"); - if (dfillegalchars.match(ui->dateFormatEntry->currentText()).hasMatch() || - dfillegalchars.match(ui->shortDateFormatEntry->text()).hasMatch()) + QRegularExpression dateStandardFormat("^([dMy\\s/\\.,\\-]|'[^']*')*$"); + if (!dateStandardFormat.match(ui->dateFormatEntry->currentText()).hasMatch() || + !dateStandardFormat.match(ui->shortDateFormatEntry->text()).hasMatch()) QMessageBox::warning(this, tr("Literal characters"), - tr("Non-special character(s) in date format.\n") + qDateTimeWeb); + tr("Non-standard character(s) in date format.\n") + qDateTimeWeb); } diff --git a/desktop-widgets/preferences/preferences_language.ui b/desktop-widgets/preferences/preferences_language.ui index b51dd083f..9c836dfb6 100644 --- a/desktop-widgets/preferences/preferences_language.ui +++ b/desktop-widgets/preferences/preferences_language.ui @@ -110,7 +110,7 @@ - <html><head/><body><p>Preferred date format. Commonly used fields are</p><p>d (day of month)</p><p>ddd (abbr. day name)</p><p>M (month number)</p><p>MMM (abbr. month name)</p><p>yy/yyyy (2/4 digit year)</p></body></html> + <html><head/><body><p>Preferred date format. Commonly used fields are</p><p>d (day of month)</p><p>ddd (abbreviated day name)</p><p>M (month number)</p><p>MMM (abbreviated month name)</p><p>yy/yyyy (2/4 digit year)</p><p>See https://doc.qt.io/archives/qt-4.8/qdatetime.html#fromString for full list.</p></body></html> true @@ -148,7 +148,7 @@ - <html><head/><body><p>Preferred time format</p><p>Commonly used format specifiers are</p><p>h (hours in 12h format)</p><p>H (hours in 24h format)</p><p>mm (2 digit minutes)</p><p>ss (2 digit seconds)</p><p>t/tt (a/p or am/pm)</p></body></html> + <html><head/><body><p>Preferred time format</p><p>Commonly used format specifiers are</p><p>h (hours)</p><p>hh (2 digit hours)</p><p>mm (2 digit minutes)</p><p>ss (2 digit seconds)</p><p>AP or ap (AM/PM or am/pm)</p><p>See https://doc.qt.io/archives/qt-4.8/qdatetime.html#fromString for full list.</p></body></html> true