diff options
author | Caolán McNamara <caolanm@redhat.com> | 2021-01-21 20:52:41 +0000 |
---|---|---|
committer | Christian Lohmaier <lohmaier+LibreOffice@googlemail.com> | 2021-01-27 15:43:37 +0100 |
commit | e6004bddfc8d7d41f4e17691eaeefd770c608a13 (patch) | |
tree | f52d74d60c7271783c01d09688015e2ba3c54e63 | |
parent | 44d2f2e2cb3ad893bdf1e9b11689297e2f7e29b4 (diff) |
tdf#138409 numerical ControlFormat strings shouldn't be localized
i.e. input fr/de 12,34 should be stored as 12.34
Change-Id: I20c97d2d604998a40e3a15963aa3d8716101e3c4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109750
Tested-by: Jenkins
Reviewed-by: Lionel Mamane <lionel@mamane.lu>
(cherry picked from commit c10b7b3c2e9743b284b0acb21a7dd219918d51ac)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109798
Reviewed-by: Adolfo Jayme Barrientos <fitojb@ubuntu.com>
Reviewed-by: Christian Lohmaier <lohmaier+LibreOffice@googlemail.com>
Tested-by: Christian Lohmaier <lohmaier+LibreOffice@googlemail.com>
-rw-r--r-- | dbaccess/source/ui/control/FieldDescControl.cxx | 47 | ||||
-rw-r--r-- | dbaccess/source/ui/inc/FieldDescControl.hxx | 5 |
2 files changed, 50 insertions, 2 deletions
diff --git a/dbaccess/source/ui/control/FieldDescControl.cxx b/dbaccess/source/ui/control/FieldDescControl.cxx index bbd39519ce45..5b925a93f56a 100644 --- a/dbaccess/source/ui/control/FieldDescControl.cxx +++ b/dbaccess/source/ui/control/FieldDescControl.cxx @@ -1107,7 +1107,9 @@ void OFieldDescControl::SaveData( OFieldDescription* pFieldDescr ) OUString sDefault; if (m_xDefault) { - sDefault = m_xDefault->get_text(); + // tdf#138409 take the control default in the UI Locale format, e.g. 12,34 and return a string + // suitable as the database default, e.g. 12.34 + sDefault = CanonicalizeToControlDefault(pFieldDescr, m_xDefault->get_text()); } else if (m_xBoolDefault) { @@ -1338,4 +1340,47 @@ OUString OFieldDescControl::getControlDefault( const OFieldDescription* _pFieldD return sDefault; } +// tdf#138409 intended to be effectively the reverse of getControlDefault to +// turn a user's possibly 12,34 format into 12.34 format for numerical types +OUString OFieldDescControl::CanonicalizeToControlDefault(const OFieldDescription* pFieldDescr, const OUString& rDefault) const +{ + if (rDefault.isEmpty()) + return rDefault; + + bool bIsNumericalType = false; + switch (pFieldDescr->GetType()) + { + case DataType::TINYINT: + case DataType::SMALLINT: + case DataType::INTEGER: + case DataType::BIGINT: + case DataType::FLOAT: + case DataType::REAL: + case DataType::DOUBLE: + case DataType::NUMERIC: + case DataType::DECIMAL: + bIsNumericalType = true; + break; + } + + if (!bIsNumericalType) + return rDefault; + + try + { + sal_uInt32 nFormatKey; + bool bTextFormat = isTextFormat(pFieldDescr, nFormatKey); + if (bTextFormat) + return rDefault; + double nValue = GetFormatter()->convertStringToNumber(nFormatKey, rDefault); + return OUString::number(nValue); + } + catch(const Exception&) + { + } + + return rDefault; +} + + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/ui/inc/FieldDescControl.hxx b/dbaccess/source/ui/inc/FieldDescControl.hxx index c467d4ca5402..8c8e0c819cd0 100644 --- a/dbaccess/source/ui/inc/FieldDescControl.hxx +++ b/dbaccess/source/ui/inc/FieldDescControl.hxx @@ -188,7 +188,10 @@ namespace dbaui virtual css::uno::Reference< css::sdbc::XDatabaseMetaData> getMetaData() = 0; virtual css::uno::Reference< css::sdbc::XConnection> getConnection() = 0; - OUString getControlDefault( const OFieldDescription* _pFieldDescr, bool _bCheck = true) const; + OUString getControlDefault( const OFieldDescription* pFieldDescr, bool _bCheck = true) const; + // tdf#138409 take the control default in the UI Locale format, e.g. 12,34 and return a string + // suitable as the database default, e.g. 12.34 + OUString CanonicalizeToControlDefault(const OFieldDescription* pFieldDescr, const OUString& rUserText) const; void setEditWidth(sal_Int32 _nWidth) { m_nEditWidth = _nWidth; } }; |