Kaydet (Commit) 343a2305 authored tarafından Laurent Balland-Poirier's avatar Laurent Balland-Poirier Kaydeden (comit) Caolán McNamara

tdf#88960 Scientific format: add/remove digits with buttons

Use buttons "Add Decimal Place" or "Delete Decimal Place" to change the
number of significant digits with scientific format (also works for
"General" format)
Improve format management for "red for negative"
to be compatible with tdf#88999

Change-Id: Id681afc4fc73674c9823172c6cd71925e63b867f
Reviewed-on: https://gerrit.libreoffice.org/14264Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst 07cf8750
...@@ -2504,15 +2504,15 @@ void ScViewFunc::ChangeNumFmtDecimals( bool bIncrement ) ...@@ -2504,15 +2504,15 @@ void ScViewFunc::ChangeNumFmtDecimals( bool bIncrement )
short nOldType = pOldEntry->GetType(); short nOldType = pOldEntry->GetType();
if ( 0 == ( nOldType & ( if ( 0 == ( nOldType & (
NUMBERFORMAT_NUMBER | NUMBERFORMAT_CURRENCY | NUMBERFORMAT_PERCENT ) ) ) NUMBERFORMAT_NUMBER | NUMBERFORMAT_CURRENCY | NUMBERFORMAT_PERCENT | NUMBERFORMAT_SCIENTIFIC ) ) )
{ {
// date, time, fraction, logical, text can not be changed // date, time, fraction, logical, text can not be changed
//! in case of scientific the Numberformatter also can't
bError = true; bError = true;
} }
//! SvNumberformat has a Member bStandard, but doesn't disclose it //! SvNumberformat has a Member bStandard, but doesn't disclose it
bool bWasStandard = ( nOldFormat == pFormatter->GetStandardIndex( eLanguage ) ); bool bWasStandard = ( nOldFormat == pFormatter->GetStandardIndex( eLanguage ) );
OUString sExponentialStandardFormat = "";
if (bWasStandard) if (bWasStandard)
{ {
// with "Standard" the decimal places depend on cell content // with "Standard" the decimal places depend on cell content
...@@ -2526,16 +2526,22 @@ void ScViewFunc::ChangeNumFmtDecimals( bool bIncrement ) ...@@ -2526,16 +2526,22 @@ void ScViewFunc::ChangeNumFmtDecimals( bool bIncrement )
nPrecision = 0; nPrecision = 0;
// 'E' for exponential is fixed in Numberformatter // 'E' for exponential is fixed in Numberformatter
if ( aOut.indexOf((sal_Unicode)'E') >= 0 ) sal_Int32 nIndexE = aOut.indexOf((sal_Unicode)'E');
bError = true; // exponential not changed if ( nIndexE >= 0 )
else
{ {
OUString aDecSep( pFormatter->GetFormatDecimalSep( nOldFormat ) ); sExponentialStandardFormat = aOut.copy( nIndexE ).replace( '-', '+' );
sal_Int32 nPos = aOut.indexOf( aDecSep ); for ( sal_Int32 i=1 ; i<sExponentialStandardFormat.getLength() ; i++ )
if ( nPos >= 0 ) {
nPrecision = aOut.getLength() - nPos - aDecSep.getLength(); if ( sExponentialStandardFormat[i] >= '1' && sExponentialStandardFormat[i] <= '9' )
// else keep 0 sExponentialStandardFormat = sExponentialStandardFormat.replaceAt( i, 1, OUString( "0" ) );
}
aOut = aOut.copy( 0, nIndexE ); // remove exponential part
} }
OUString aDecSep( pFormatter->GetFormatDecimalSep( nOldFormat ) );
sal_Int32 nPos = aOut.indexOf( aDecSep );
if ( nPos >= 0 )
nPrecision = aOut.getLength() - nPos - aDecSep.getLength();
// else keep 0
} }
if (!bError) if (!bError)
...@@ -2560,7 +2566,8 @@ void ScViewFunc::ChangeNumFmtDecimals( bool bIncrement ) ...@@ -2560,7 +2566,8 @@ void ScViewFunc::ChangeNumFmtDecimals( bool bIncrement )
{ {
OUString aNewPicture = pFormatter->GenerateFormat(nOldFormat, eLanguage, OUString aNewPicture = pFormatter->GenerateFormat(nOldFormat, eLanguage,
bThousand, bNegRed, bThousand, bNegRed,
nPrecision, nLeading); nPrecision, nLeading)
+ sExponentialStandardFormat;
nNewFormat = pFormatter->GetEntryKey( aNewPicture, eLanguage ); nNewFormat = pFormatter->GetEntryKey( aNewPicture, eLanguage );
if ( nNewFormat == NUMBERFORMAT_ENTRY_NOT_FOUND ) if ( nNewFormat == NUMBERFORMAT_ENTRY_NOT_FOUND )
......
...@@ -2652,6 +2652,19 @@ OUString SvNumberFormatter::GenerateFormat(sal_uInt32 nIndex, ...@@ -2652,6 +2652,19 @@ OUString SvNumberFormatter::GenerateFormat(sal_uInt32 nIndex,
{ {
sString.append('%'); sString.append('%');
} }
else if (eType == NUMBERFORMAT_SCIENTIFIC)
{
OUStringBuffer sOldFormatString = pFormat->GetFormatstring();
sal_Int32 nIndexE = sOldFormatString.indexOf('E');
if (nIndexE > -1)
{
sal_Int32 nIndexSep = sOldFormatString.indexOf(';');
if (nIndexSep > -1)
sString.append( sOldFormatString.copy(nIndexE, nIndexSep - nIndexE) );
else
sString.append( sOldFormatString.copy(nIndexE) );
}
}
else if (eType == NUMBERFORMAT_CURRENCY) else if (eType == NUMBERFORMAT_CURRENCY)
{ {
OUStringBuffer sNegStr(sString); OUStringBuffer sNegStr(sString);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment