diff options
author | Matteo Casalin <matteo.casalin@yahoo.com> | 2019-02-10 16:11:30 +0100 |
---|---|---|
committer | Matteo Casalin <matteo.casalin@yahoo.com> | 2019-02-13 07:58:43 +0100 |
commit | 6d7308acb7b1ae606b49d6bba3a4c5cbfd0521ed (patch) | |
tree | bf1a9e2c67230c2cf0336f88a13d7d7ab156fcd7 /sdext/source/minimizer | |
parent | bcee672425d37bc0007b666cc4a8152aa1a76bb5 (diff) |
OptimizerDialog: simplify string operations when selecting...
... image resolution: introduce local method to:
* use indexed getToken
* avoid getting all tokens in advance
* reduce calls to non-trivial getString method
Change-Id: Ib47c2e9bb5788132328fbda1b1dce05e495ad3ed
Reviewed-on: https://gerrit.libreoffice.org/67638
Tested-by: Jenkins
Reviewed-by: Matteo Casalin <matteo.casalin@yahoo.com>
Diffstat (limited to 'sdext/source/minimizer')
-rw-r--r-- | sdext/source/minimizer/optimizerdialogcontrols.cxx | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/sdext/source/minimizer/optimizerdialogcontrols.cxx b/sdext/source/minimizer/optimizerdialogcontrols.cxx index e5326e5096b0..1dfd165aa4f0 100644 --- a/sdext/source/minimizer/optimizerdialogcontrols.cxx +++ b/sdext/source/minimizer/optimizerdialogcontrols.cxx @@ -467,6 +467,19 @@ void OptimizerDialog::InitPage1() UpdateControlStatesPage1(); } +namespace +{ + +bool lcl_getResolutionText(OUString& rResolutionText, const OUString& rImageResolution, sal_Int32 nTargetRes) +{ + sal_Int32 nIdx{ 0 }; + if (rImageResolution.getToken(0, ';', nIdx).toInt32()!=nTargetRes) + return false; + rResolutionText = rImageResolution.getToken(0, ';', nIdx); + return true; +} + +} void OptimizerDialog::UpdateControlStatesPage2() { @@ -477,23 +490,12 @@ void OptimizerDialog::UpdateControlStatesPage2() sal_Int32 nImageResolution( GetConfigProperty( TK_ImageResolution, sal_Int32(0) ) ); - sal_Int32 nI0, nI1, nI2, nI3; - nI0 = nI1 = nI2 = nI3 = 0; OUString aResolutionText; - Sequence< OUString > aResolutionItemList( 4 ); - aResolutionItemList[ 0 ] = getString( STR_IMAGE_RESOLUTION_0 ).getToken( 1, ';', nI0 ); - aResolutionItemList[ 1 ] = getString( STR_IMAGE_RESOLUTION_1 ).getToken( 1, ';', nI1 ); - aResolutionItemList[ 2 ] = getString( STR_IMAGE_RESOLUTION_2 ).getToken( 1, ';', nI2 ); - aResolutionItemList[ 3 ] = getString( STR_IMAGE_RESOLUTION_3 ).getToken( 1, ';', nI3 ); - nI0 = nI1 = nI2 = nI3 = 0; - if ( getString( STR_IMAGE_RESOLUTION_0 ).getToken( 0, ';', nI0 ).toInt32() == nImageResolution ) - aResolutionText = aResolutionItemList[ 0 ]; - else if ( getString( STR_IMAGE_RESOLUTION_1 ).getToken( 0, ';', nI1 ).toInt32() == nImageResolution ) - aResolutionText = aResolutionItemList[ 1 ]; - else if ( getString( STR_IMAGE_RESOLUTION_2 ).getToken( 0, ';', nI2 ).toInt32() == nImageResolution ) - aResolutionText = aResolutionItemList[ 2 ]; - else if ( getString( STR_IMAGE_RESOLUTION_3 ).getToken( 0, ';', nI3 ).toInt32() == nImageResolution ) - aResolutionText = aResolutionItemList[ 3 ]; + for (int nIR{ STR_IMAGE_RESOLUTION_0 }; nIR<=STR_IMAGE_RESOLUTION_3; ++nIR) + { + if (lcl_getResolutionText(aResolutionText, getString(static_cast<PPPOptimizerTokenEnum>(nIR)), nImageResolution)) + break; + } if ( aResolutionText.isEmpty() ) aResolutionText = OUString::number( nImageResolution ); |