[Libreoffice-commits] core.git: Branch 'distro/nisz/libreoffice-7-0' - sc/inc sc/source
Eike Rathke (via logerrit)
logerrit at kemper.freedesktop.org
Thu Feb 18 15:36:59 UTC 2021
sc/inc/validat.hxx | 10 ++++
sc/source/core/data/validat.cxx | 81 ++++++++++++++++++++++++++--------------
2 files changed, 64 insertions(+), 27 deletions(-)
New commits:
commit ada5033f8edc29b0e97962765947ea40bc6dfaa0
Author: Eike Rathke <erack at redhat.com>
AuthorDate: Fri Sep 25 23:26:19 2020 +0200
Commit: Gabor Kelemen <kelemen.gabor2 at nisz.hu>
CommitDate: Thu Feb 18 16:36:22 2021 +0100
Consolidate, factor out common duplicated code, tdf#128797 follow-up
Change-Id: I939c9f88a6cf09e1caa87131562ad67e389c2710
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103470
Reviewed-by: Eike Rathke <erack at redhat.com>
Tested-by: Jenkins
(cherry picked from commit ebe4bbb25a9bcb4263b079a50d932384c7c7fb3e)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111145
Tested-by: Gabor Kelemen <kelemen.gabor2 at nisz.hu>
Reviewed-by: Gabor Kelemen <kelemen.gabor2 at nisz.hu>
diff --git a/sc/inc/validat.hxx b/sc/inc/validat.hxx
index d4e92bd9ce4e..19c4bb31c354 100644
--- a/sc/inc/validat.hxx
+++ b/sc/inc/validat.hxx
@@ -34,6 +34,7 @@ struct RefUpdateContext;
class ScPatternAttr;
class ScTokenArray;
class ScTypedStrData;
+struct ScValidationDataIsNumeric;
enum ScValidationMode
{
@@ -183,6 +184,15 @@ private:
/** Tests, if contents of pCell occur in cell range referenced by own formula, or in a string list. */
bool IsListValid( ScRefCellValue& rCell, const ScAddress& rPos ) const;
+
+ /** Tests, if string or numeric data has valid text length.
+ @param pDataNumeric
+ nullptr if string data to be tested, else for numeric data a
+ properly initialized ScValidationDataIsNumeric struct, see
+ implementation.
+ */
+ bool IsDataValidTextLen( const OUString& rTest, const ScAddress& rPos,
+ ScValidationDataIsNumeric* pDataNumeric ) const;
};
// list of conditions:
diff --git a/sc/source/core/data/validat.cxx b/sc/source/core/data/validat.cxx
index 221796a9567e..2600d9cc668e 100644
--- a/sc/source/core/data/validat.cxx
+++ b/sc/source/core/data/validat.cxx
@@ -471,6 +471,53 @@ bool ScValidationData::IsDataValidCustom(
return bRet;
}
+/** To test numeric data text length in IsDataValidTextLen().
+
+ If mpFormatter is not set, it is obtained from the document and the format
+ key is determined from the cell position's attribute pattern.
+ */
+struct ScValidationDataIsNumeric
+{
+ SvNumberFormatter* mpFormatter;
+ double mfVal;
+ sal_uInt32 mnFormat;
+
+ ScValidationDataIsNumeric( double fVal, SvNumberFormatter* pFormatter = nullptr, sal_uInt32 nFormat = 0 )
+ : mpFormatter(pFormatter), mfVal(fVal), mnFormat(nFormat)
+ {
+ }
+
+ void init( const ScDocument& rDoc, const ScAddress& rPos )
+ {
+ const ScPatternAttr* pPattern = rDoc.GetPattern( rPos.Col(), rPos.Row(), rPos.Tab());
+ mpFormatter = rDoc.GetFormatTable();
+ mnFormat = pPattern->GetNumberFormat( mpFormatter);
+ }
+};
+
+bool ScValidationData::IsDataValidTextLen( const OUString& rTest, const ScAddress& rPos,
+ ScValidationDataIsNumeric* pDataNumeric ) const
+{
+ sal_Int32 nLen;
+ if (!pDataNumeric)
+ nLen = rTest.getLength();
+ else
+ {
+ if (!pDataNumeric->mpFormatter)
+ pDataNumeric->init( *GetDocument(), rPos);
+
+ // For numeric values use the resulting input line string to
+ // determine length, otherwise an once accepted value maybe could
+ // not be edited again, for example abbreviated dates or leading
+ // zeros or trailing zeros after decimal separator change length.
+ OUString aStr;
+ pDataNumeric->mpFormatter->GetInputLineString( pDataNumeric->mfVal, pDataNumeric->mnFormat, aStr);
+ nLen = aStr.getLength();
+ }
+ ScRefCellValue aTmpCell( static_cast<double>(nLen));
+ return IsCellValid( aTmpCell, rPos);
+}
+
bool ScValidationData::IsDataValid(
const OUString& rTest, const ScPatternAttr& rPattern, const ScAddress& rPos ) const
{
@@ -493,21 +540,13 @@ bool ScValidationData::IsDataValid(
bool bRet;
if (SC_VALID_TEXTLEN == eDataMode)
{
- double nLenVal;
if (!bIsVal)
- nLenVal = static_cast<double>(rTest.getLength());
+ bRet = IsDataValidTextLen( rTest, rPos, nullptr);
else
{
- // For numeric values use the resulting input line string to
- // determine length, otherwise an once accepted value maybe could
- // not be edited again, for example abbreviated dates or leading
- // zeros or trailing zeros after decimal separator change length.
- OUString aStr;
- pFormatter->GetInputLineString( nVal, nFormat, aStr);
- nLenVal = static_cast<double>( aStr.getLength() );
+ ScValidationDataIsNumeric aDataNumeric( nVal, pFormatter, nFormat);
+ bRet = IsDataValidTextLen( rTest, rPos, &aDataNumeric);
}
- ScRefCellValue aTmpCell(nLenVal);
- bRet = IsCellValid(aTmpCell, rPos);
}
else
{
@@ -584,25 +623,13 @@ bool ScValidationData::IsDataValid( ScRefCellValue& rCell, const ScAddress& rPos
break;
case SC_VALID_TEXTLEN:
- {
- double nLenVal;
- bOk = !bIsVal; // only Text
- if ( bOk )
- {
- nLenVal = static_cast<double>(aString.getLength());
- }
+ if (!bIsVal)
+ bOk = IsDataValidTextLen( aString, rPos, nullptr);
else
{
- const ScPatternAttr* pPattern
- = mpDoc->GetPattern(rPos.Col(), rPos.Row(), rPos.Tab());
- SvNumberFormatter* pFormatter = GetDocument()->GetFormatTable();
- sal_uInt32 nFormat = pPattern->GetNumberFormat(pFormatter);
- pFormatter->GetInputLineString(nVal, nFormat, aString);
- nLenVal = static_cast<double>(aString.getLength());
+ ScValidationDataIsNumeric aDataNumeric( nVal);
+ bOk = IsDataValidTextLen( aString, rPos, &aDataNumeric);
}
- ScRefCellValue aTmpCell(nLenVal);
- bOk = IsCellValid(aTmpCell, rPos);
- }
break;
default:
More information about the Libreoffice-commits
mailing list