]> git.lyx.org Git - lyx.git/commitdiff
Localize the default decimal separator
authorJuergen Spitzmueller <spitz@lyx.org>
Mon, 22 Jul 2019 06:05:28 +0000 (08:05 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Mon, 22 Jul 2019 06:05:28 +0000 (08:05 +0200)
Do not blindly use (English) "." as default, but the locale default of
the current context language.

Fixes: #7204
src/Language.cpp
src/Language.h
src/LyXRC.cpp
src/LyXRC.h
src/frontends/qt/GuiPrefs.cpp
src/frontends/qt/GuiPrefs.h
src/frontends/qt/GuiTabular.cpp
src/frontends/qt/GuiTabular.h
src/frontends/qt/ui/PrefLanguageUi.ui
src/insets/InsetTabular.cpp

index ccac6975690152452f6a674bbb97e2cc16179cd3..799abca1bad32e6c4d9a9274f2721e783520f8a1 100644 (file)
 #include "support/filetools.h"
 #include "support/lassert.h"
 #include "support/lstrings.h"
+#include "support/qstring_helpers.h"
 #include "support/Messages.h"
 
+#include <QLocale>
+#include <QString>
+
 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 {
index 9201b00d96a578fbedbdc1eae53894fc068b51c7..0445503d9af348cf99ce0e11ad89c84f1419d9b4 100644 (file)
@@ -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_; }
        ///
index 55efe9c7cade62811393853aea2e7ee3e29220bd..a8d086d9e8ae4fac679c58da2c655bfca020366e 100644 (file)
@@ -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:
index c15cb1aa48cc8c7d123364d7066550b1c90e909c..10df6361aefabe8d4bf5d262e6801ea2a2e70cea 100644 (file)
@@ -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;
        ///
index 185b7180838c0df920372f0060aee1be969fe39e..fec146aed5c56b1d7c64b317330a09e37bc07623 100644 (file)
@@ -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);
 
index edf3aad72a083fedb11214134547e68a29b63bf5..8bd264eaff64cf6690a7888216ca14d44423d058 100644 (file)
@@ -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_;
index a09d9df62128efcffe74365dac91e44549024e7e..435f44098967165d5432e5032e3687c9dd70989b 100644 (file)
 #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)) {
index 5890c520660312caad762636456643ba27a242f7..a546ec09c7056581eab862cd83d3f0596dbd6118 100644 (file)
@@ -76,6 +76,8 @@ private:
        GuiSetBorder::BorderState orig_rightborder_;
        ///
        int lastrow_;
+       ///
+       docstring decimal_sep_;
 };
 
 } // namespace frontend
index 3f3fb84bca1b8d1ad830320c06f6898598a58024..0255531076cd41edfc61171a9a198acdb64efeb1 100644 (file)
      <layout class="QGridLayout" name="gridLayout_3">
       <item row="0" column="0">
        <widget class="QLabel" name="decimalPointL">
+        <property name="toolTip">
+         <string>Here you can specify the decimal separator that is used in the tabular dialog by default. &quot;Language default&quot; selects the appropriate separator for the current language.</string>
+        </property>
         <property name="text">
          <string>Default decimal &amp;separator:</string>
         </property>
         <property name="buddy">
-         <cstring>defaultDecimalPointLE</cstring>
+         <cstring>defaultDecimalSepED</cstring>
         </property>
        </widget>
       </item>
-      <item row="1" column="0">
-       <widget class="QLabel" name="defaultLengthUnitLA">
-        <property name="text">
-         <string>Default length &amp;unit:</string>
+      <item row="1" column="6">
+       <spacer name="horizontalSpacer_2">
+        <property name="orientation">
+         <enum>Qt::Horizontal</enum>
         </property>
-        <property name="buddy">
-         <cstring>defaultLengthUnitCO</cstring>
+        <property name="sizeHint" stdset="0">
+         <size>
+          <width>40</width>
+          <height>20</height>
+         </size>
         </property>
-       </widget>
+       </spacer>
       </item>
-      <item row="0" column="1">
-       <widget class="QLineEdit" name="defaultDecimalPointLE">
+      <item row="0" column="3">
+       <widget class="QLineEdit" name="defaultDecimalSepED">
         <property name="maximumSize">
          <size>
-          <width>20</width>
+          <width>40</width>
           <height>16777215</height>
          </size>
         </property>
+        <property name="toolTip">
+         <string>Insert a custom decimal separator here</string>
+        </property>
         <property name="inputMask">
          <string/>
         </property>
         </property>
        </widget>
       </item>
-      <item row="1" column="1">
-       <widget class="QComboBox" name="defaultLengthUnitCO"/>
+      <item row="1" column="0">
+       <widget class="QLabel" name="defaultLengthUnitLA">
+        <property name="toolTip">
+         <string>Select the default length unit for LyX dialogs</string>
+        </property>
+        <property name="text">
+         <string>Default length &amp;unit:</string>
+        </property>
+        <property name="buddy">
+         <cstring>defaultLengthUnitCO</cstring>
+        </property>
+       </widget>
       </item>
-      <item row="1" column="2">
-       <spacer name="horizontalSpacer_2">
-        <property name="orientation">
-         <enum>Qt::Horizontal</enum>
+      <item row="0" column="1">
+       <widget class="QComboBox" name="defaultDecimalSepCO">
+        <property name="toolTip">
+         <string>Here you can specify the decimal separator that is used in the tabular dialog by default. &quot;Language default&quot; selects the appropriate separator for the current language.</string>
         </property>
-        <property name="sizeHint" stdset="0">
-         <size>
-          <width>40</width>
-          <height>20</height>
-         </size>
+        <item>
+         <property name="text">
+          <string>Language Default</string>
+         </property>
+        </item>
+        <item>
+         <property name="text">
+          <string>Custom</string>
+         </property>
+        </item>
+       </widget>
+      </item>
+      <item row="1" column="1">
+       <widget class="QComboBox" name="defaultLengthUnitCO">
+        <property name="toolTip">
+         <string>Select the default length unit for LyX dialogs</string>
         </property>
-       </spacer>
+       </widget>
       </item>
      </layout>
     </widget>
   <tabstop>languagePackageED</tabstop>
   <tabstop>startCommandED</tabstop>
   <tabstop>endCommandED</tabstop>
-  <tabstop>defaultDecimalPointLE</tabstop>
-  <tabstop>defaultLengthUnitCO</tabstop>
+  <tabstop>defaultDecimalSepED</tabstop>
   <tabstop>globalCB</tabstop>
   <tabstop>explicitDocLangBeginCB</tabstop>
   <tabstop>markForeignCB</tabstop>
index 334f09adff38efa4a67d2001d0420191f4116180..19a0498f4ed1f8ab2c77e5c3825b527d0f55f8c8 100644 (file)
@@ -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);