From b852df91bc2c88779a7e675574121819cfc3a44d Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Mon, 22 Jul 2019 08:05:28 +0200 Subject: [PATCH] Localize the default decimal separator Do not blindly use (English) "." as default, but the locale default of the current context language. Fixes: #7204 --- src/Language.cpp | 14 +++++ src/Language.h | 2 + src/LyXRC.cpp | 14 ++--- src/LyXRC.h | 4 +- src/frontends/qt/GuiPrefs.cpp | 28 ++++++++-- src/frontends/qt/GuiPrefs.h | 1 + src/frontends/qt/GuiTabular.cpp | 20 ++++--- src/frontends/qt/GuiTabular.h | 2 + src/frontends/qt/ui/PrefLanguageUi.ui | 79 ++++++++++++++++++--------- src/insets/InsetTabular.cpp | 6 +- 10 files changed, 121 insertions(+), 49 deletions(-) diff --git a/src/Language.cpp b/src/Language.cpp index ccac697569..799abca1ba 100644 --- a/src/Language.cpp +++ b/src/Language.cpp @@ -25,8 +25,12 @@ #include "support/filetools.h" #include "support/lassert.h" #include "support/lstrings.h" +#include "support/qstring_helpers.h" #include "support/Messages.h" +#include +#include + using namespace std; using namespace lyx::support; @@ -111,6 +115,16 @@ string Language::dateFormat(size_t i) const } +docstring Language::decimalSeparator() const +{ + if (lyxrc.default_decimal_sep == "locale") { + QLocale loc = QLocale(toqstr(code())); + return qstring_to_ucs4(QString(loc.decimalPoint())); + } + return from_utf8(lyxrc.default_decimal_sep); +} + + bool Language::readLanguage(Lexer & lex) { enum LanguageTags { diff --git a/src/Language.h b/src/Language.h index 9201b00d96..0445503d9a 100644 --- a/src/Language.h +++ b/src/Language.h @@ -91,6 +91,8 @@ public: std::string fontenc(BufferParams const &) const; /// Return the localized date formats (long, medium, short format) std::string dateFormat(size_t i) const; + /// Return the localized decimal separator + docstring decimalSeparator() const; /// This language corresponds to a translation of the GUI bool hasGuiSupport() const { return has_gui_support_; } /// diff --git a/src/LyXRC.cpp b/src/LyXRC.cpp index 55efe9c7ca..a8d086d9e8 100644 --- a/src/LyXRC.cpp +++ b/src/LyXRC.cpp @@ -95,7 +95,7 @@ LexerKeyword lyxrcTags[] = { { "\\cursor_follows_scrollbar", LyXRC::RC_CURSOR_FOLLOWS_SCROLLBAR }, { "\\cursor_width", LyXRC::RC_CURSOR_WIDTH }, { "\\def_file", LyXRC::RC_DEFFILE }, - { "\\default_decimal_point", LyXRC::RC_DEFAULT_DECIMAL_POINT }, + { "\\default_decimal_point", LyXRC::RC_DEFAULT_DECIMAL_SEP }, { "\\default_length_unit", LyXRC::RC_DEFAULT_LENGTH_UNIT }, { "\\default_otf_view_format", LyXRC::RC_DEFAULT_OTF_VIEW_FORMAT }, { "\\default_platex_view_format", LyXRC::RC_DEFAULT_PLATEX_VIEW_FORMAT }, @@ -752,8 +752,8 @@ LyXRC::ReturnValues LyXRC::read(Lexer & lexrc, bool check_format) if (lexrc.next()) backupdir_path = os::internal_path(lexrc.getString()); break; - case RC_DEFAULT_DECIMAL_POINT: - lexrc >> default_decimal_point; + case RC_DEFAULT_DECIMAL_SEP: + lexrc >> default_decimal_sep; break; case RC_DEFAULT_LENGTH_UNIT: if (lexrc.next()) @@ -2267,10 +2267,10 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c << "#\n\n"; // fall through - case RC_DEFAULT_DECIMAL_POINT: + case RC_DEFAULT_DECIMAL_SEP: if (ignore_system_lyxrc || - default_decimal_point != system_lyxrc.default_decimal_point) { - os << "\\default_decimal_point " << default_decimal_point << '\n'; + default_decimal_sep != system_lyxrc.default_decimal_sep) { + os << "\\default_decimal_point \"" << default_decimal_sep << "\"" << '\n'; } if (tag != RC_LAST) break; @@ -2892,7 +2892,7 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new) case LyXRC::RC_FORWARD_SEARCH_DVI: case LyXRC::RC_FORWARD_SEARCH_PDF: case LyXRC::RC_EXPORT_OVERWRITE: - case LyXRC::RC_DEFAULT_DECIMAL_POINT: + case LyXRC::RC_DEFAULT_DECIMAL_SEP: case LyXRC::RC_DEFAULT_LENGTH_UNIT: case LyXRC::RC_SCROLL_WHEEL_ZOOM: case LyXRC::RC_CURSOR_WIDTH: diff --git a/src/LyXRC.h b/src/LyXRC.h index c15cb1aa48..10df6361ae 100644 --- a/src/LyXRC.h +++ b/src/LyXRC.h @@ -68,7 +68,7 @@ public: RC_COPIER, RC_CURSOR_FOLLOWS_SCROLLBAR, RC_CURSOR_WIDTH, - RC_DEFAULT_DECIMAL_POINT, + RC_DEFAULT_DECIMAL_SEP, RC_DEFAULT_LENGTH_UNIT, RC_DEFAULT_OTF_VIEW_FORMAT, RC_DEFAULT_PLATEX_VIEW_FORMAT, @@ -525,7 +525,7 @@ public: /// int export_overwrite = NO_FILES; /// Default decimal point when aligning table columns on decimal - std::string default_decimal_point = "."; + std::string default_decimal_sep = "locale"; /// Length::UNIT default_length_unit = Length::CM; /// diff --git a/src/frontends/qt/GuiPrefs.cpp b/src/frontends/qt/GuiPrefs.cpp index 185b718083..fec146aed5 100644 --- a/src/frontends/qt/GuiPrefs.cpp +++ b/src/frontends/qt/GuiPrefs.cpp @@ -2412,7 +2412,9 @@ PrefLanguage::PrefLanguage(GuiPreferences * form) this, SIGNAL(changed())); connect(uiLanguageCO, SIGNAL(activated(int)), this, SIGNAL(changed())); - connect(defaultDecimalPointLE, SIGNAL(textChanged(QString)), + connect(defaultDecimalSepED, SIGNAL(textChanged(QString)), + this, SIGNAL(changed())); + connect(defaultDecimalSepCO, SIGNAL(activated(int)), this, SIGNAL(changed())); connect(defaultLengthUnitCO, SIGNAL(activated(int)), this, SIGNAL(changed())); @@ -2421,8 +2423,8 @@ PrefLanguage::PrefLanguage(GuiPreferences * form) startCommandED->setValidator(new NoNewLineValidator(startCommandED)); endCommandED->setValidator(new NoNewLineValidator(endCommandED)); - defaultDecimalPointLE->setInputMask("X; "); - defaultDecimalPointLE->setMaxLength(1); + defaultDecimalSepED->setInputMask("X; "); + defaultDecimalSepED->setMaxLength(1); defaultLengthUnitCO->addItem(lyx::qt_(unit_name_gui[Length::CM]), Length::CM); defaultLengthUnitCO->addItem(lyx::qt_(unit_name_gui[Length::IN]), Length::IN); @@ -2473,6 +2475,12 @@ void PrefLanguage::on_languagePackageCO_currentIndexChanged(int i) } +void PrefLanguage::on_defaultDecimalSepCO_currentIndexChanged(int i) +{ + defaultDecimalSepED->setEnabled(i == 1); +} + + void PrefLanguage::applyRC(LyXRC & rc) const { rc.visual_cursor = visualCursorRB->isChecked(); @@ -2495,7 +2503,10 @@ void PrefLanguage::applyRC(LyXRC & rc) const rc.language_command_end = fromqstr(endCommandED->text()); rc.gui_language = fromqstr( uiLanguageCO->itemData(uiLanguageCO->currentIndex()).toString()); - rc.default_decimal_point = fromqstr(defaultDecimalPointLE->text()); + if (defaultDecimalSepCO->currentIndex() == 0) + rc.default_decimal_sep = "locale"; + else + rc.default_decimal_sep = fromqstr(defaultDecimalSepED->text()); rc.default_length_unit = (Length::UNIT) defaultLengthUnitCO->itemData(defaultLengthUnitCO->currentIndex()).toInt(); } @@ -2519,10 +2530,17 @@ void PrefLanguage::updateRC(LyXRC const & rc) save_langpack_ = toqstr(rc.language_custom_package); languagePackageED->setEnabled(false); } + defaultDecimalSepED->setEnabled(defaultDecimalSepCO->currentIndex() == 1); globalCB->setChecked(rc.language_global_options); startCommandED->setText(toqstr(rc.language_command_begin)); endCommandED->setText(toqstr(rc.language_command_end)); - defaultDecimalPointLE->setText(toqstr(rc.default_decimal_point)); + if (rc.default_decimal_sep == "locale") { + defaultDecimalSepCO->setCurrentIndex(0); + defaultDecimalSepED->clear(); + } else { + defaultDecimalSepCO->setCurrentIndex(1); + defaultDecimalSepED->setText(toqstr(rc.default_decimal_sep)); + } int pos = defaultLengthUnitCO->findData(int(rc.default_length_unit)); defaultLengthUnitCO->setCurrentIndex(pos); diff --git a/src/frontends/qt/GuiPrefs.h b/src/frontends/qt/GuiPrefs.h index edf3aad72a..8bd264eaff 100644 --- a/src/frontends/qt/GuiPrefs.h +++ b/src/frontends/qt/GuiPrefs.h @@ -408,6 +408,7 @@ public: private Q_SLOTS: void on_uiLanguageCO_currentIndexChanged(int); void on_languagePackageCO_currentIndexChanged(int); + void on_defaultDecimalSepCO_currentIndexChanged(int); private: /// QString save_langpack_; diff --git a/src/frontends/qt/GuiTabular.cpp b/src/frontends/qt/GuiTabular.cpp index a09d9df621..435f440989 100644 --- a/src/frontends/qt/GuiTabular.cpp +++ b/src/frontends/qt/GuiTabular.cpp @@ -22,10 +22,12 @@ #include "qt_helpers.h" #include "Validator.h" +#include "Buffer.h" #include "BufferView.h" #include "Cursor.h" #include "FuncRequest.h" #include "FuncStatus.h" +#include "Language.h" #include "LyX.h" #include "LyXRC.h" @@ -550,10 +552,10 @@ docstring GuiTabular::dialogToParams() const setHAlign(param_str); // SET_DECIMAL_POINT must come after setHAlign() (ALIGN_DECIMAL) - string decimal_point = fromqstr(decimalPointED->text()); - if (decimal_point.empty()) - decimal_point = lyxrc.default_decimal_point; - setParam(param_str, Tabular::SET_DECIMAL_POINT, decimal_point); + string decimal_sep = fromqstr(decimalPointED->text()); + if (decimal_sep.empty()) + decimal_sep = to_utf8(decimal_sep_); + setParam(param_str, Tabular::SET_DECIMAL_POINT, decimal_sep); setVAlign(param_str); setTableAlignment(param_str); @@ -1053,10 +1055,12 @@ void GuiTabular::paramsToDialog(Inset const * inset) hAlignCO->setCurrentIndex(hAlignCO->findData(toqstr(align))); // - QString decimal_point = toqstr(tabular.column_info[col].decimal_point); - if (decimal_point.isEmpty()) - decimal_point = toqstr(from_utf8(lyxrc.default_decimal_point)); - decimalPointED->setText(decimal_point); + decimal_sep_ = tabular.column_info[col].decimal_point; + if (decimal_sep_.empty()) { + Language const * lang = itab->buffer().paragraphs().front().getParLanguage(itab->buffer().params()); + decimal_sep_ = lang->decimalSeparator(); + } + decimalPointED->setText(toqstr(decimal_sep_)); int valign = 0; switch (tabular.getVAlignment(cell)) { diff --git a/src/frontends/qt/GuiTabular.h b/src/frontends/qt/GuiTabular.h index 5890c52066..a546ec09c7 100644 --- a/src/frontends/qt/GuiTabular.h +++ b/src/frontends/qt/GuiTabular.h @@ -76,6 +76,8 @@ private: GuiSetBorder::BorderState orig_rightborder_; /// int lastrow_; + /// + docstring decimal_sep_; }; } // namespace frontend diff --git a/src/frontends/qt/ui/PrefLanguageUi.ui b/src/frontends/qt/ui/PrefLanguageUi.ui index 3f3fb84bca..0255531076 100644 --- a/src/frontends/qt/ui/PrefLanguageUi.ui +++ b/src/frontends/qt/ui/PrefLanguageUi.ui @@ -282,32 +282,41 @@ + + Here you can specify the decimal separator that is used in the tabular dialog by default. "Language default" selects the appropriate separator for the current language. + Default decimal &separator: - defaultDecimalPointLE + defaultDecimalSepED - - - - Default length &unit: + + + + Qt::Horizontal - - defaultLengthUnitCO + + + 40 + 20 + - + - - + + - 20 + 40 16777215 + + Insert a custom decimal separator here + @@ -316,21 +325,42 @@ - - + + + + Select the default length unit for LyX dialogs + + + Default length &unit: + + + defaultLengthUnitCO + + - - - - Qt::Horizontal + + + + Here you can specify the decimal separator that is used in the tabular dialog by default. "Language default" selects the appropriate separator for the current language. - - - 40 - 20 - + + + Language Default + + + + + Custom + + + + + + + + Select the default length unit for LyX dialogs - + @@ -359,8 +389,7 @@ languagePackageED startCommandED endCommandED - defaultDecimalPointLE - defaultLengthUnitCO + defaultDecimalSepED globalCB explicitDocLangBeginCB markForeignCB diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index 334f09adff..19a0498f4e 100644 --- a/src/insets/InsetTabular.cpp +++ b/src/insets/InsetTabular.cpp @@ -1210,8 +1210,10 @@ void Tabular::setAlignment(idx_type cell, LyXAlignment align, } column_info[col].alignment = align; docstring & dpoint = column_info[col].decimal_point; - if (align == LYX_ALIGN_DECIMAL && dpoint.empty()) - dpoint = from_utf8(lyxrc.default_decimal_point); + if (align == LYX_ALIGN_DECIMAL && dpoint.empty()) { + Language const * tlang = buffer().paragraphs().front().getParLanguage(buffer().params()); + dpoint = tlang->decimalSeparator(); + } } else { cellInfo(cell).alignment = align; cellInset(cell)->setContentAlignment(align); -- 2.39.5