diff options
author | Caolán McNamara <caolanm@redhat.com> | 2021-01-21 20:52:41 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2021-01-22 12:00:51 +0100 |
commit | 90f2a582a2d5e435012ec38e50022f41b04ae882 (patch) | |
tree | bcebdbefa10f6f1a84b7fa70150094083c373d4f /dbaccess | |
parent | ba05c093143ba993af143e25acdeda76d9d1f888 (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/+/109772
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'dbaccess')
-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 2909c13be20d..8bbcb305e106 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 f321276827b0..8288ae3155e9 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; } }; |