sc/source/core/tool/queryparam.cxx | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-)
New commits: commit f52f599518b5b3aef78b7af1d3a62996eec53a1f Author: Eike Rathke <er...@redhat.com> AuthorDate: Sun May 8 00:55:12 2022 +0200 Commit: Adolfo Jayme Barrientos <fit...@ubuntu.com> CommitDate: Mon May 9 11:11:41 2022 +0200 Resolves: tdf#148948 Use QueryBy(Non)Empty for "=" and "<>" criteria Change-Id: I94e29370076fff977b6552d10883878633bee313 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134000 Reviewed-by: Eike Rathke <er...@redhat.com> Tested-by: Jenkins (cherry picked from commit 920a083f3818765528899ab38170db5a2917a06c) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134054 Reviewed-by: Adolfo Jayme Barrientos <fit...@ubuntu.com> diff --git a/sc/source/core/tool/queryparam.cxx b/sc/source/core/tool/queryparam.cxx index 918bb0d5cdab..9890b2125c07 100644 --- a/sc/source/core/tool/queryparam.cxx +++ b/sc/source/core/tool/queryparam.cxx @@ -229,6 +229,8 @@ void ScQueryParamBase::FillInExcelSyntax( ScQueryEntry& rEntry = GetEntry(nIndex); ScQueryEntry::Item& rItem = rEntry.GetQueryItem(); + bool bByEmpty = false; + bool bByNonEmpty = false; if (rCellStr.isEmpty()) rItem.maString = svl::SharedString::getEmptyString(); @@ -242,6 +244,8 @@ void ScQueryParamBase::FillInExcelSyntax( { rItem.maString = rPool.intern(rCellStr.copy(2)); rEntry.eOp = SC_NOT_EQUAL; + if (rCellStr.getLength() == 2) + bByNonEmpty = true; } else if (rCellStr.getLength() > 1 && rCellStr[1] == '=') { @@ -270,7 +274,11 @@ void ScQueryParamBase::FillInExcelSyntax( else { if (rCellStr[0] == '=') + { rItem.maString = rPool.intern(rCellStr.copy(1)); + if (rCellStr.getLength() == 1) + bByEmpty = true; + } else rItem.maString = rPool.intern(rCellStr); rEntry.eOp = SC_EQUAL; @@ -280,19 +288,32 @@ void ScQueryParamBase::FillInExcelSyntax( if (!pFormatter) return; - sal_uInt32 nFormat = 0; - bool bNumber = pFormatter->IsNumberFormat( rItem.maString.getString(), nFormat, rItem.mfVal); - rItem.meType = bNumber ? ScQueryEntry::ByValue : ScQueryEntry::ByString; - /* TODO: pFormatter currently is also used as a flag whether matching * empty cells with an empty string is triggered from the interpreter. * This could be handled independently if all queries should support * it, needs to be evaluated if that actually is desired. */ + // Interpreter queries have only one query, also QueryByEmpty and + // QueryByNonEmpty rely on that. + if (nIndex != 0) + return; + // (empty = empty) is a match, and (empty <> not-empty) also is a // match. (empty = 0) is not a match. rItem.mbMatchEmpty = ((rEntry.eOp == SC_EQUAL && rItem.maString.isEmpty()) || (rEntry.eOp == SC_NOT_EQUAL && !rItem.maString.isEmpty())); + + // SetQueryBy override item members with special values, so do this last. + if (bByEmpty) + rEntry.SetQueryByEmpty(); + else if (bByNonEmpty) + rEntry.SetQueryByNonEmpty(); + else + { + sal_uInt32 nFormat = 0; + bool bNumber = pFormatter->IsNumberFormat( rItem.maString.getString(), nFormat, rItem.mfVal); + rItem.meType = bNumber ? ScQueryEntry::ByValue : ScQueryEntry::ByString; + } } ScQueryParamTable::ScQueryParamTable() :