summaryrefslogtreecommitdiffstats
path: root/desktop-widgets/preferences
diff options
context:
space:
mode:
authorGravatar Lubomir I. Ivanov <neolit123@gmail.com>2017-11-10 16:52:12 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-11-10 09:21:47 -0800
commit2c06cb027f20eee42769fb3a56e41c87b1a4d252 (patch)
treef10ca05b6a01ebfb020c53ae740efc1e01a0a7af /desktop-widgets/preferences
parentf1437cfec7978929a09ff7b1f5ad3a013dd0c713 (diff)
downloadsubsurface-2c06cb027f20eee42769fb3a56e41c87b1a4d252.tar.gz
preferences: support a pre-defined list of date formats
Add a combo-box in place of the single line text field and support some pre-defined date formats, such as: MM/dd/yyyy Each long format has a corresponding short variant stored in the QMap dateFormatShortMap and it's updated automatically once the user selects a combo box item for the long format. The regex for dates is slighly modified: [^dMy/\\s:;\\.,\\-] The user is still allowed to enter custom long / short date foramats. Fixes #276 Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Diffstat (limited to 'desktop-widgets/preferences')
-rw-r--r--desktop-widgets/preferences/preferences_language.cpp21
-rw-r--r--desktop-widgets/preferences/preferences_language.h4
-rw-r--r--desktop-widgets/preferences/prefs_language.ui47
3 files changed, 46 insertions, 26 deletions
diff --git a/desktop-widgets/preferences/preferences_language.cpp b/desktop-widgets/preferences/preferences_language.cpp
index ff0429721..4d200d82f 100644
--- a/desktop-widgets/preferences/preferences_language.cpp
+++ b/desktop-widgets/preferences/preferences_language.cpp
@@ -22,6 +22,14 @@ PreferencesLanguage::PreferencesLanguage() : AbstractPreferencesWidget(tr("Langu
filterModel->sort(0);
connect(ui->languageFilter, &QLineEdit::textChanged,
filterModel, &QSortFilterProxyModel::setFilterFixedString);
+
+ dateFormatShortMap.insert("MM/dd/yyyy", "M/d/yy");
+ dateFormatShortMap.insert("dd.MM.yyyy", "d.M.yy");
+ dateFormatShortMap.insert("yyyy-MM-dd", "yy-M-d");
+ foreach (QString format, dateFormatShortMap.keys())
+ ui->dateFormatEntry->addItem(format);
+ connect(ui->dateFormatEntry, SIGNAL(currentIndexChanged(const QString&)),
+ this, SLOT(dateFormatChanged(const QString&)));
}
PreferencesLanguage::~PreferencesLanguage()
@@ -29,13 +37,18 @@ PreferencesLanguage::~PreferencesLanguage()
delete ui;
}
+void PreferencesLanguage::dateFormatChanged(const QString &text)
+{
+ ui->shortDateFormatEntry->setText(dateFormatShortMap.value(text));
+}
+
void PreferencesLanguage::refreshSettings()
{
ui->languageSystemDefault->setChecked(prefs.locale.use_system_language);
ui->timeFormatSystemDefault->setChecked(!prefs.time_format_override);
ui->dateFormatSystemDefault->setChecked(!prefs.date_format_override);
ui->timeFormatEntry->setText(prefs.time_format);
- ui->dateFormatEntry->setText(prefs.date_format);
+ ui->dateFormatEntry->setCurrentText(prefs.date_format);
ui->shortDateFormatEntry->setText(prefs.date_format_short);
QAbstractItemModel *m = ui->languageDropdown->model();
QModelIndexList languages = m->match(m->index(0, 0), Qt::UserRole, QString(prefs.locale.lang_locale).replace("-", "_"));
@@ -72,7 +85,7 @@ void PreferencesLanguage::syncSettings()
lang->setTimeFormatOverride(!ui->timeFormatSystemDefault->isChecked());
lang->setDateFormatOverride(!ui->dateFormatSystemDefault->isChecked());
lang->setTimeFormat(ui->timeFormatEntry->text());
- lang->setDateFormat(ui->dateFormatEntry->text());
+ lang->setDateFormat(ui->dateFormatEntry->currentText());
lang->setDateFormatShort(ui->shortDateFormatEntry->text());
uiLanguage(NULL);
@@ -81,8 +94,8 @@ void PreferencesLanguage::syncSettings()
QMessageBox::warning(this, tr("Literal characters"),
tr("Non-special character(s) in time format.\nThese will be used as is. This might not be what you intended.\nSee http://doc.qt.io/qt-5/qdatetime.html#toString"));
- QRegExp dfillegalchars("[^dMy/\\s:;\\.,]");
- if (dfillegalchars.indexIn(ui->dateFormatEntry->text()) >= 0 ||
+ QRegExp dfillegalchars("[^dMy/\\s:;\\.,\\-]");
+ if (dfillegalchars.indexIn(ui->dateFormatEntry->currentText()) >= 0 ||
dfillegalchars.indexIn(ui->shortDateFormatEntry->text()) >= 0)
QMessageBox::warning(this, tr("Literal characters"),
tr("Non-special character(s) in time format.\nThese will be used as is. This might not be what you intended.\nSee http://doc.qt.io/qt-5/qdatetime.html#toString"));
diff --git a/desktop-widgets/preferences/preferences_language.h b/desktop-widgets/preferences/preferences_language.h
index aaff67eed..4ff268b87 100644
--- a/desktop-widgets/preferences/preferences_language.h
+++ b/desktop-widgets/preferences/preferences_language.h
@@ -2,6 +2,7 @@
#ifndef PREFERENCES_LANGUAGE_H
#define PREFERENCES_LANGUAGE_H
+#include <QMap>
#include "abstractpreferenceswidget.h"
namespace Ui {
@@ -17,6 +18,9 @@ public:
virtual void syncSettings();
private:
Ui::PreferencesLanguage *ui;
+ QMap<QString, QString> dateFormatShortMap;
+public slots:
+ void dateFormatChanged(const QString&);
};
#endif
diff --git a/desktop-widgets/preferences/prefs_language.ui b/desktop-widgets/preferences/prefs_language.ui
index af3a0ad87..470e8b6d1 100644
--- a/desktop-widgets/preferences/prefs_language.ui
+++ b/desktop-widgets/preferences/prefs_language.ui
@@ -74,13 +74,6 @@
<string>Date format</string>
</property>
<layout class="QGridLayout" name="gridLayout">
- <item row="0" column="1">
- <widget class="QLineEdit" name="dateFormatEntry">
- <property name="toolTip">
- <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Preferred date format. Commonly used fields are&lt;/p&gt;&lt;p&gt;d (day of month)&lt;/p&gt;&lt;p&gt;ddd (abbr. day name)&lt;/p&gt;&lt;p&gt;M (month number)&lt;/p&gt;&lt;p&gt;MMM (abbr. month name)&lt;/p&gt;&lt;p&gt;yy/yyyy (2/4 digit year)&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
- </property>
- </widget>
- </item>
<item row="0" column="0">
<widget class="QCheckBox" name="dateFormatSystemDefault">
<property name="text">
@@ -114,6 +107,16 @@
</property>
</spacer>
</item>
+ <item row="0" column="1">
+ <widget class="QComboBox" name="dateFormatEntry">
+ <property name="toolTip">
+ <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Preferred date format. Commonly used fields are&lt;/p&gt;&lt;p&gt;d (day of month)&lt;/p&gt;&lt;p&gt;ddd (abbr. day name)&lt;/p&gt;&lt;p&gt;M (month number)&lt;/p&gt;&lt;p&gt;MMM (abbr. month name)&lt;/p&gt;&lt;p&gt;yy/yyyy (2/4 digit year)&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+ </property>
+ <property name="editable">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
</item>
@@ -209,50 +212,50 @@
</hints>
</connection>
<connection>
- <sender>dateFormatSystemDefault</sender>
+ <sender>timeFormatSystemDefault</sender>
<signal>toggled(bool)</signal>
- <receiver>dateFormatEntry</receiver>
+ <receiver>timeFormatEntry</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>79</x>
- <y>132</y>
+ <y>210</y>
</hint>
<hint type="destinationlabel">
<x>264</x>
- <y>132</y>
+ <y>210</y>
</hint>
</hints>
</connection>
<connection>
- <sender>timeFormatSystemDefault</sender>
+ <sender>dateFormatSystemDefault</sender>
<signal>toggled(bool)</signal>
- <receiver>timeFormatEntry</receiver>
+ <receiver>shortDateFormatEntry</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
- <x>79</x>
- <y>210</y>
+ <x>99</x>
+ <y>132</y>
</hint>
<hint type="destinationlabel">
- <x>264</x>
- <y>210</y>
+ <x>293</x>
+ <y>169</y>
</hint>
</hints>
</connection>
<connection>
<sender>dateFormatSystemDefault</sender>
<signal>toggled(bool)</signal>
- <receiver>shortDateFormatEntry</receiver>
+ <receiver>dateFormatEntry</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
- <x>99</x>
- <y>132</y>
+ <x>89</x>
+ <y>103</y>
</hint>
<hint type="destinationlabel">
- <x>293</x>
- <y>169</y>
+ <x>273</x>
+ <y>103</y>
</hint>
</hints>
</connection>