Commit dc16327e authored by Stefan Gerlach's avatar Stefan Gerlach

[locale] Add automatic option for number locale

parent 6bd96bf5
......@@ -67,7 +67,11 @@ constexpr std::add_const_t<T>& qAsConst(T& t) noexcept {
#define ENUM_COUNT(class, enum) \
(class::staticMetaObject.enumerator(class::staticMetaObject.indexOfEnumerator(#enum)).keyCount())
#define SET_NUMBER_LOCALE QLocale numberLocale(static_cast<QLocale::Language>(KSharedConfig::openConfig()->group("Settings_General").readEntry( QLatin1String("DecimalSeparatorLocale"), static_cast<int>(QLocale().language()) )) );
// define number locale from setting (using system locale when QLocale::AnyLanguage)
#define SET_NUMBER_LOCALE \
QLocale::Language numberLocaleLanguage = static_cast<QLocale::Language>(KSharedConfig::openConfig()->group("Settings_General").readEntry( QLatin1String("DecimalSeparatorLocale"), static_cast<int>(QLocale().language()) )); \
QLocale numberLocale(numberLocaleLanguage == QLocale::AnyLanguage ? QLocale().language() : numberLocaleLanguage);
//////////////////////// LineEdit Access ///////////////////////////////
#define SET_INT_FROM_LE(var, le) { \
bool ok; \
......
......@@ -69,26 +69,29 @@ SettingsGeneralPage::DecimalSeparator SettingsGeneralPage::decimalSeparator(QLoc
QLocale::Language SettingsGeneralPage::decimalSeparatorLocale() const {
int currentIndex = ui.cbDecimalSeparator->currentIndex();
if (currentIndex == static_cast<int>(decimalSeparator()))
if (currentIndex == static_cast<int>(decimalSeparator())) // system decimal separator selected
return QLocale().language();
QChar groupSeparator{QLocale().groupSeparator()};
if (currentIndex == static_cast<int>(DecimalSeparator::Dot)) {
switch (currentIndex) {
case static_cast<int>(DecimalSeparator::Dot):
if (groupSeparator == QLocale(QLocale::Language::Zarma).groupSeparator()) // \u00a0
return QLocale::Language::Zarma; // . \u00a0
else if (groupSeparator == QLocale(QLocale::Language::SwissGerman).groupSeparator()) // \u2019
return QLocale::Language::SwissGerman; // . \u2019
else
return QLocale::Language::C; // . ,
} else if (currentIndex == static_cast<int>(DecimalSeparator::Comma)) {
case static_cast<int>(DecimalSeparator::Comma):
if (groupSeparator == QLocale(QLocale::Language::French).groupSeparator()) // \u00a0
return QLocale::Language::French; // , \u00a0
else if (groupSeparator == QLocale(QLocale::Language::Walser).groupSeparator()) // \u2019
return QLocale::Language::Walser; // , \u2019
else
return QLocale::Language::German; // , .
} else {
case static_cast<int>(DecimalSeparator::Arabic):
return QLocale::Language::Arabic; // \u066b \u066c
default: // automatic
return QLocale().language();
}
}
......@@ -100,7 +103,10 @@ void SettingsGeneralPage::applySettings() {
group.writeEntry(QLatin1String("TabPosition"), ui.cbTabPosition->currentIndex());
group.writeEntry(QLatin1String("MdiWindowVisibility"), ui.cbMdiVisibility->currentIndex());
group.writeEntry(QLatin1String("Units"), ui.cbUnits->currentIndex());
group.writeEntry(QLatin1String("DecimalSeparatorLocale"), static_cast<int>(decimalSeparatorLocale()));
if (ui.cbDecimalSeparator->currentIndex() == static_cast<int>(DecimalSeparator::Automatic))
group.writeEntry(QLatin1String("DecimalSeparatorLocale"), static_cast<int>(QLocale::Language::AnyLanguage));
else
group.writeEntry(QLatin1String("DecimalSeparatorLocale"), static_cast<int>(decimalSeparatorLocale()));
group.writeEntry(QLatin1String("AutoSave"), ui.chkAutoSave->isChecked());
group.writeEntry(QLatin1String("AutoSaveInterval"), ui.sbAutoSaveInterval->value());
group.writeEntry(QLatin1String("ShowMemoryInfo"), ui.chkMemoryInfo->isChecked());
......@@ -114,7 +120,7 @@ void SettingsGeneralPage::restoreDefaults() {
ui.cbTabPosition->setCurrentIndex(0);
ui.cbMdiVisibility->setCurrentIndex(0);
ui.cbUnits->setCurrentIndex(0);
ui.cbDecimalSeparator->setCurrentIndex(static_cast<int>(decimalSeparator()));
ui.cbDecimalSeparator->setCurrentIndex(static_cast<int>(DecimalSeparator::Automatic));
ui.chkAutoSave->setChecked(false);
ui.sbAutoSaveInterval->setValue(0);
ui.sbAutoSaveInterval->setValue(5);
......@@ -131,7 +137,10 @@ void SettingsGeneralPage::loadSettings() {
ui.cbMdiVisibility->setCurrentIndex(group.readEntry(QLatin1String("MdiWindowVisibility"), 0));
ui.cbUnits->setCurrentIndex(group.readEntry(QLatin1String("Units"), 0));
QLocale locale(static_cast<QLocale::Language>(group.readEntry( QLatin1String("DecimalSeparatorLocale"), static_cast<int>(QLocale().language()) )) );
ui.cbDecimalSeparator->setCurrentIndex( static_cast<int>(decimalSeparator(locale)) );
if (locale.language() == QLocale().language()) // no or default setting
ui.cbDecimalSeparator->setCurrentIndex( static_cast<int>(DecimalSeparator::Automatic) );
else
ui.cbDecimalSeparator->setCurrentIndex( static_cast<int>(decimalSeparator(locale)) );
ui.chkAutoSave->setChecked(group.readEntry<bool>(QLatin1String("AutoSave"), false));
ui.sbAutoSaveInterval->setValue(group.readEntry(QLatin1String("AutoSaveInterval"), 0));
ui.chkMemoryInfo->setChecked(group.readEntry<bool>(QLatin1String("ShowMemoryInfo"), true));
......@@ -171,6 +180,7 @@ void SettingsGeneralPage::retranslateUi() {
ui.cbDecimalSeparator->addItem(i18n("Dot (.)"));
ui.cbDecimalSeparator->addItem(i18n("Comma (,)"));
ui.cbDecimalSeparator->addItem(i18n("Arabic"));
ui.cbDecimalSeparator->addItem(i18n("Automatic"));
}
void SettingsGeneralPage::changed() {
......
......@@ -37,7 +37,7 @@ class SettingsGeneralPage : public SettingsPage {
Q_OBJECT
public:
enum class DecimalSeparator{Dot, Comma, Arabic};
enum class DecimalSeparator{Dot, Comma, Arabic, Automatic};
explicit SettingsGeneralPage(QWidget*);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment