Commit 2bb5ea08 authored by Stefan Gerlach's avatar Stefan Gerlach

[locale] Improve number locale settings and usage

parent b65f506a
......@@ -69,8 +69,8 @@ constexpr std::add_const_t<T>& qAsConst(T& t) noexcept {
// 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);
QLocale::Language numberLocaleLanguage = static_cast<QLocale::Language>(KSharedConfig::openConfig()->group("Settings_General").readEntry( QLatin1String("DecimalSeparatorLocale"), static_cast<int>(QLocale::Language::AnyLanguage) )); \
QLocale numberLocale(numberLocaleLanguage == QLocale::AnyLanguage ? QLocale() : numberLocaleLanguage);
//////////////////////// LineEdit Access ///////////////////////////////
#define SET_INT_FROM_LE(var, le) { \
......
......@@ -61,6 +61,13 @@ const QString getSystemInfo() {
#else
const QString buildType(i18n("Debug build"));
#endif
QLocale locale;
const QString numberSystemInfo{ '('
+ i18n("Decimal point ") + '\'' + QString(locale.decimalPoint())
+ QLatin1String("\', ")
+ i18n("Group separator ") + '\'' + QString(locale.groupSeparator())
+ QLatin1String("\')")};
SET_NUMBER_LOCALE
const QString numberLocaleInfo{ ' '
+ i18n("Decimal point ") + '\'' + QString(numberLocale.decimalPoint())
......@@ -69,20 +76,19 @@ const QString getSystemInfo() {
+ QLatin1String("\', ")
+ i18n("Exponential ") + '\'' + QString(numberLocale.exponential())
+ QLatin1String("\', ")
+ i18n("Zero digit: ") + '\'' + QString(numberLocale.zeroDigit())
+ i18n("Zero digit ") + '\'' + QString(numberLocale.zeroDigit())
+ QLatin1String("\', ")
+ i18n("Percent: ") + '\'' + QString(numberLocale.percent())
+ i18n("Percent ") + '\'' + QString(numberLocale.percent())
+ QLatin1String("\', ")
+ i18n("Positive/Negative sign: ") + '\'' + QString(numberLocale.positiveSign()) + '\''
+ '/' + '\'' + QString(numberLocale.negativeSign()) };
+ i18n("Positive/Negative sign ") + '\'' + QString(numberLocale.positiveSign()) + '\''
+ '/' + '\'' + QString(numberLocale.negativeSign()) + '\'' };
QLocale locale;
return buildType + '\n'
+ QString("%1, %2").arg(__DATE__).arg(__TIME__) + '\n'
+ i18n("System: ") + QSysInfo::prettyProductName() + '\n'
+ i18n("Locale: ") + QLocale::languageToString(locale.language()) + ','
+ QLocale::countryToString(locale.country()) + '\n'
+ i18n("Number settings:") + numberLocaleInfo + '\n'
+ QLocale::countryToString(locale.country()) + ' ' + numberSystemInfo + '\n'
+ i18n("Number settings:") + numberLocaleInfo + QLatin1String(" (") + i18n("Updated on restart") + ')' + '\n'
+ i18n("Architecture: ") + QSysInfo::buildAbi() + '\n'
+ i18n("Kernel: ") + QSysInfo::kernelType() + ' ' + QSysInfo::kernelVersion() + '\n'
+ i18n("C++ Compiler: ") + QString(CXX_COMPILER) + '\n'
......
......@@ -57,10 +57,10 @@ SettingsGeneralPage::SettingsGeneralPage(QWidget* parent) : SettingsPage(parent)
autoSaveChanged(ui.chkAutoSave->checkState());
}
/* returns decimal separator (as SettingsGeneralPage::DecimalSeparator) of given locale (default: system setting) */
SettingsGeneralPage::DecimalSeparator SettingsGeneralPage::decimalSeparator(QLocale locale) {
DEBUG("SettingsGeneralPage::decimalSeparator()")
DEBUG(" LOCALE: " << STDSTRING(locale.name()))
DEBUG(" LOCALE LANG: " << locale.language())
DEBUG(" LOCALE: " << STDSTRING(locale.name()) << ',' << locale.language())
QChar decimalPoint{locale.decimalPoint()};
DEBUG(" SEPARATING CHAR: " << STDSTRING(QString(decimalPoint)) )
if (decimalPoint == QChar('.'))
......@@ -72,13 +72,12 @@ SettingsGeneralPage::DecimalSeparator SettingsGeneralPage::decimalSeparator(QLoc
}
QLocale::Language SettingsGeneralPage::decimalSeparatorLocale() const {
DEBUG("SettingsGeneralPage::decimalSeparatorLocale()")
int currentIndex = ui.cbDecimalSeparator->currentIndex();
DEBUG(" SYSTEM LOCALE: " << STDSTRING(QLocale().name()))
DEBUG(" SYSTEM LOCALE LANG: " << QLocale().language())
DEBUG(" CURRENT SEPARATING CHAR: " << STDSTRING(QString(QLocale().decimalPoint())) )
DEBUG(" GERMAN SEPARATING CHAR: " << STDSTRING(QString(QLocale(QLocale::Language::German).decimalPoint())) )
DEBUG(" SYSTEM LOCALE: " << STDSTRING(QLocale().name()) << ':' << QLocale().language())
DEBUG(" SYSTEM SEPARATING CHAR: " << STDSTRING(QString(QLocale().decimalPoint())) )
if (currentIndex == static_cast<int>(decimalSeparator())) // system decimal separator selected
return QLocale().language();
return QLocale::Language::AnyLanguage;
QChar groupSeparator{QLocale().groupSeparator()};
switch (currentIndex) {
......@@ -99,7 +98,7 @@ QLocale::Language SettingsGeneralPage::decimalSeparatorLocale() const {
case static_cast<int>(DecimalSeparator::Arabic):
return QLocale::Language::Arabic; // \u066b \u066c
default: // automatic
return QLocale().language();
return QLocale::Language::AnyLanguage;
}
}
......@@ -111,7 +110,7 @@ void SettingsGeneralPage::applySettings() {
group.writeEntry(QLatin1String("TabPosition"), ui.cbTabPosition->currentIndex());
group.writeEntry(QLatin1String("MdiWindowVisibility"), ui.cbMdiVisibility->currentIndex());
group.writeEntry(QLatin1String("Units"), ui.cbUnits->currentIndex());
if (ui.cbDecimalSeparator->currentIndex() == static_cast<int>(DecimalSeparator::Automatic))
if (ui.cbDecimalSeparator->currentIndex() == static_cast<int>(DecimalSeparator::Automatic)) // needed to overwrite previous setting
group.writeEntry(QLatin1String("DecimalSeparatorLocale"), static_cast<int>(QLocale::Language::AnyLanguage));
else
group.writeEntry(QLatin1String("DecimalSeparatorLocale"), static_cast<int>(decimalSeparatorLocale()));
......@@ -144,8 +143,8 @@ void SettingsGeneralPage::loadSettings() {
ui.cbTabPosition->setCurrentIndex(group.readEntry(QLatin1String("TabPosition"), 0));
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()) )) );
if (locale.language() == QLocale().language()) // no or default setting
QLocale locale(static_cast<QLocale::Language>(group.readEntry( QLatin1String("DecimalSeparatorLocale"), static_cast<int>(QLocale::Language::AnyLanguage) )) );
if (locale.language() == QLocale().language() && locale.decimalPoint() == QLocale().decimalPoint()) // no or default setting
ui.cbDecimalSeparator->setCurrentIndex( static_cast<int>(DecimalSeparator::Automatic) );
else
ui.cbDecimalSeparator->setCurrentIndex( static_cast<int>(decimalSeparator(locale)) );
......
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