split StringToMetric and TextToValue into fieldvalue.hxx
Change-Id: I5d1102f7a50a7a246df9f6de8b7a6df6557eb54d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88682 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com>
This commit is contained in:
@@ -219,9 +219,6 @@ public:
|
||||
virtual OUString CreateFieldText( sal_Int64 nValue ) const override;
|
||||
sal_Int64 GetCorrectedValue( FieldUnit eOutUnit ) const;
|
||||
|
||||
static FieldUnit StringToMetric(const OUString &rMetricString);
|
||||
static bool TextToValue(const OUString& rStr, double& rValue, sal_Int64 nBaseValue, sal_uInt16 nDecDigits, const LocaleDataWrapper& rLocaleDataWrapper, FieldUnit eUnit);
|
||||
|
||||
protected:
|
||||
FieldUnit meUnit;
|
||||
|
||||
|
@@ -21,11 +21,19 @@
|
||||
#define INCLUDED_VCL_FIELDVALUES_HXX
|
||||
|
||||
#include <vcl/dllapi.h>
|
||||
#include <rtl/ustring.hxx>
|
||||
#include <tools/fldunit.hxx>
|
||||
#include <tools/mapunit.hxx>
|
||||
|
||||
class LocaleDataWrapper;
|
||||
|
||||
namespace vcl
|
||||
{
|
||||
VCL_DLLPUBLIC FieldUnit StringToMetric(const OUString& rMetricString);
|
||||
VCL_DLLPUBLIC bool TextToValue(const OUString& rStr, double& rValue, sal_Int64 nBaseValue,
|
||||
sal_uInt16 nDecDigits, const LocaleDataWrapper& rLocaleDataWrapper,
|
||||
FieldUnit eUnit);
|
||||
|
||||
VCL_DLLPUBLIC sal_Int64 ConvertValue(sal_Int64 nValue, sal_Int64 mnBaseValue, sal_uInt16 nDecDigits,
|
||||
FieldUnit eInUnit, FieldUnit eOutUnit);
|
||||
VCL_DLLPUBLIC sal_Int64 ConvertValue(sal_Int64 nValue, sal_uInt16 nDecDigits, MapUnit eInUnit,
|
||||
|
@@ -17,7 +17,7 @@
|
||||
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
||||
*/
|
||||
|
||||
#include <vcl/field.hxx>
|
||||
#include <vcl/fieldvalues.hxx>
|
||||
#include <svl/intitem.hxx>
|
||||
#include <vcl/toolbox.hxx>
|
||||
|
||||
@@ -116,7 +116,7 @@ IMPL_LINK(SdPagesField, spin_button_input, int*, result, bool)
|
||||
{
|
||||
const LocaleDataWrapper& rLocaleData = Application::GetSettings().GetLocaleDataWrapper();
|
||||
double fResult(0.0);
|
||||
bool bRet = MetricFormatter::TextToValue(m_xWidget->get_text(), fResult, 0, m_xWidget->get_digits(), rLocaleData, FieldUnit::NONE);
|
||||
bool bRet = vcl::TextToValue(m_xWidget->get_text(), fResult, 0, m_xWidget->get_digits(), rLocaleData, FieldUnit::NONE);
|
||||
if (bRet)
|
||||
{
|
||||
if (fResult > SAL_MAX_INT32)
|
||||
|
@@ -1180,7 +1180,7 @@ int FontSizeBox::get_value() const
|
||||
const SvtSysLocale aSysLocale;
|
||||
const LocaleDataWrapper& rLocaleData = aSysLocale.GetLocaleData();
|
||||
double fResult(0.0);
|
||||
(void)MetricFormatter::TextToValue(aStr, fResult, 0, GetDecimalDigits(), rLocaleData, GetUnit());
|
||||
(void)vcl::TextToValue(aStr, fResult, 0, GetDecimalDigits(), rLocaleData, GetUnit());
|
||||
if (!aStr.isEmpty())
|
||||
{
|
||||
if (fResult < nMin)
|
||||
|
@@ -23,7 +23,7 @@
|
||||
#include <vcl/builder.hxx>
|
||||
#include <vcl/commandevent.hxx>
|
||||
#include <vcl/event.hxx>
|
||||
#include <vcl/field.hxx>
|
||||
#include <vcl/fieldvalues.hxx>
|
||||
#include <vcl/image.hxx>
|
||||
#include <vcl/settings.hxx>
|
||||
#include <vcl/virdev.hxx>
|
||||
@@ -3253,7 +3253,7 @@ void SvxRuler::Notify(SfxBroadcaster&, const SfxHint& rHint)
|
||||
IMPL_LINK( SvxRuler, MenuSelect, Menu *, pMenu, bool )
|
||||
{
|
||||
/* Handler of the context menus for switching the unit of measurement */
|
||||
SetUnit(MetricFormatter::StringToMetric(OUString::fromUtf8(pMenu->GetCurItemIdent())));
|
||||
SetUnit(vcl::StringToMetric(OUString::fromUtf8(pMenu->GetCurItemIdent())));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -3332,7 +3332,7 @@ void SvxRuler::Command( const CommandEvent& rCommandEvent )
|
||||
{
|
||||
sal_uInt16 nId = aMenu->GetItemId(i - 1);
|
||||
OString sIdent = aMenu->GetItemIdent(nId);
|
||||
FieldUnit eMenuUnit = MetricFormatter::StringToMetric(OUString::fromUtf8(sIdent));
|
||||
FieldUnit eMenuUnit = vcl::StringToMetric(OUString::fromUtf8(sIdent));
|
||||
aMenu->CheckItem(nId, eMenuUnit == eUnit);
|
||||
if( bReduceMetric )
|
||||
{
|
||||
|
@@ -1052,23 +1052,26 @@ static OUString ImplMetricToString( FieldUnit rUnit )
|
||||
return OUString();
|
||||
}
|
||||
|
||||
FieldUnit MetricFormatter::StringToMetric(const OUString &rMetricString)
|
||||
namespace vcl
|
||||
{
|
||||
// return FieldUnit
|
||||
OUString aStr = rMetricString.toAsciiLowerCase().replaceAll(" ", "");
|
||||
for (auto const& elem : ImplGetCleanedFieldUnits())
|
||||
FieldUnit StringToMetric(const OUString &rMetricString)
|
||||
{
|
||||
if ( elem.first == aStr )
|
||||
return elem.second;
|
||||
}
|
||||
// return FieldUnit
|
||||
OUString aStr = rMetricString.toAsciiLowerCase().replaceAll(" ", "");
|
||||
for (auto const& elem : ImplGetCleanedFieldUnits())
|
||||
{
|
||||
if ( elem.first == aStr )
|
||||
return elem.second;
|
||||
}
|
||||
|
||||
return FieldUnit::NONE;
|
||||
return FieldUnit::NONE;
|
||||
}
|
||||
}
|
||||
|
||||
static FieldUnit ImplMetricGetUnit(const OUString& rStr)
|
||||
{
|
||||
OUString aStr = ImplMetricGetUnitText(rStr);
|
||||
return MetricFormatter::StringToMetric(aStr);
|
||||
return vcl::StringToMetric(aStr);
|
||||
}
|
||||
|
||||
#define K *1000L
|
||||
@@ -1357,27 +1360,30 @@ namespace vcl
|
||||
}
|
||||
}
|
||||
|
||||
bool MetricFormatter::TextToValue(const OUString& rStr, double& rValue, sal_Int64 nBaseValue,
|
||||
sal_uInt16 nDecDigits, const LocaleDataWrapper& rLocaleDataWrapper, FieldUnit eUnit)
|
||||
namespace vcl
|
||||
{
|
||||
// Get value
|
||||
sal_Int64 nValue;
|
||||
if ( !ImplNumericGetValue( rStr, nValue, nDecDigits, rLocaleDataWrapper ) )
|
||||
return false;
|
||||
bool TextToValue(const OUString& rStr, double& rValue, sal_Int64 nBaseValue,
|
||||
sal_uInt16 nDecDigits, const LocaleDataWrapper& rLocaleDataWrapper, FieldUnit eUnit)
|
||||
{
|
||||
// Get value
|
||||
sal_Int64 nValue;
|
||||
if ( !ImplNumericGetValue( rStr, nValue, nDecDigits, rLocaleDataWrapper ) )
|
||||
return false;
|
||||
|
||||
// Determine unit
|
||||
FieldUnit eEntryUnit = ImplMetricGetUnit( rStr );
|
||||
// Determine unit
|
||||
FieldUnit eEntryUnit = ImplMetricGetUnit( rStr );
|
||||
|
||||
// Recalculate unit
|
||||
// caution: conversion to double loses precision
|
||||
rValue = vcl::ConvertDoubleValue(static_cast<double>(nValue), nBaseValue, nDecDigits, eEntryUnit, eUnit);
|
||||
// Recalculate unit
|
||||
// caution: conversion to double loses precision
|
||||
rValue = vcl::ConvertDoubleValue(static_cast<double>(nValue), nBaseValue, nDecDigits, eEntryUnit, eUnit);
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void MetricFormatter::ImplMetricReformat( const OUString& rStr, double& rValue, OUString& rOutStr )
|
||||
{
|
||||
if ( !TextToValue( rStr, rValue, 0, GetDecimalDigits(), ImplGetLocaleDataWrapper(), meUnit ) )
|
||||
if (!vcl::TextToValue(rStr, rValue, 0, GetDecimalDigits(), ImplGetLocaleDataWrapper(), meUnit))
|
||||
return;
|
||||
|
||||
double nTempVal = rValue;
|
||||
@@ -1476,7 +1482,7 @@ sal_Int64 MetricFormatter::GetValueFromStringUnit(const OUString& rStr, FieldUni
|
||||
{
|
||||
double nTempValue;
|
||||
// caution: precision loss in double cast
|
||||
if (!TextToValue(rStr, nTempValue, 0, GetDecimalDigits(), ImplGetLocaleDataWrapper(), meUnit))
|
||||
if (!vcl::TextToValue(rStr, nTempValue, 0, GetDecimalDigits(), ImplGetLocaleDataWrapper(), meUnit))
|
||||
nTempValue = static_cast<double>(mnLastValue);
|
||||
|
||||
// caution: precision loss in double cast
|
||||
|
@@ -311,7 +311,7 @@ namespace weld
|
||||
{
|
||||
const LocaleDataWrapper& rLocaleData = Application::GetSettings().GetLocaleDataWrapper();
|
||||
double fResult(0.0);
|
||||
bool bRet = MetricFormatter::TextToValue(get_text(), fResult, 0, m_xSpinButton->get_digits(), rLocaleData, m_eSrcUnit);
|
||||
bool bRet = vcl::TextToValue(get_text(), fResult, 0, m_xSpinButton->get_digits(), rLocaleData, m_eSrcUnit);
|
||||
if (bRet)
|
||||
{
|
||||
if (fResult > SAL_MAX_INT32)
|
||||
|
Reference in New Issue
Block a user