sc/source/core/data/table3.cxx |  121 +++++++++++++++++++++--------------------
 1 file changed, 64 insertions(+), 57 deletions(-)

New commits:
commit f606ddd86ba402661e4989718e8b8b8e6e2c2f65
Author:     Luboš Luňák <l.lu...@collabora.com>
AuthorDate: Tue Nov 23 11:47:10 2021 +0100
Commit:     Luboš Luňák <l.lu...@collabora.com>
CommitDate: Tue Nov 23 20:54:27 2021 +0100

    move code to a separate function
    
    To be extended in following commits.
    
    Change-Id: I09eaf0f5cfdbbe0aff254231dbb983fd7f72cc5c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125732
    Tested-by: Jenkins
    Reviewed-by: Luboš Luňák <l.lu...@collabora.com>

diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index 9455b3d2f856..d0311e1d191e 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -2956,6 +2956,68 @@ public:
     }
 };
 
+std::pair<bool,bool> validQueryProcessEntry(SCROW nRow, SCCOL nCol, SCTAB 
nTab, const ScQueryParam& rParam,
+    ScRefCellValue& aCell, const ScInterpreterContext* pContext, 
QueryEvaluator& aEval,
+    const ScQueryEntry& rEntry )
+{
+    std::pair<bool,bool> aRes(false, false);
+    const ScQueryEntry::QueryItemsType& rItems = rEntry.GetQueryItems();
+    if (rItems.size() == 1 && rItems.front().meType == ScQueryEntry::ByEmpty)
+    {
+        if (rEntry.IsQueryByEmpty())
+            aRes.first = aCell.isEmpty();
+        else
+        {
+            assert(rEntry.IsQueryByNonEmpty());
+            aRes.first = !aCell.isEmpty();
+        }
+        return aRes;
+    }
+    // Generic handling.
+    for (const auto& rItem : rItems)
+    {
+        if (rItem.meType == ScQueryEntry::ByTextColor)
+        {
+            std::pair<bool, bool> aThisRes
+                = aEval.compareByTextColor(nCol, nRow, nTab, rItem);
+            aRes.first |= aThisRes.first;
+            aRes.second |= aThisRes.second;
+        }
+        else if (rItem.meType == ScQueryEntry::ByBackgroundColor)
+        {
+            std::pair<bool,bool> aThisRes =
+                aEval.compareByBackgroundColor(nCol, nRow, nTab, rItem);
+            aRes.first |= aThisRes.first;
+            aRes.second |= aThisRes.second;
+        }
+        else if (QueryEvaluator::isQueryByValue(rItem, aCell))
+        {
+            std::pair<bool,bool> aThisRes =
+                aEval.compareByValue(aCell, nCol, nRow, rEntry, rItem, 
pContext);
+            aRes.first |= aThisRes.first;
+            aRes.second |= aThisRes.second;
+        }
+        else if (QueryEvaluator::isQueryByString(rEntry, rItem, aCell))
+        {
+            std::pair<bool,bool> aThisRes =
+                aEval.compareByString(aCell, nRow, rEntry, rItem, pContext);
+            aRes.first |= aThisRes.first;
+            aRes.second |= aThisRes.second;
+        }
+        else if (rParam.mbRangeLookup)
+        {
+            std::pair<bool,bool> aThisRes =
+                QueryEvaluator::compareByRangeLookup(aCell, rEntry, rItem);
+            aRes.first |= aThisRes.first;
+            aRes.second |= aThisRes.second;
+        }
+
+        if (aRes.first && aRes.second)
+            break;
+    }
+    return aRes;
+}
+
 }
 
 bool ScTable::ValidQuery(
@@ -2996,63 +3058,8 @@ bool ScTable::ValidQuery(
         else
             aCell = GetCellValue(nCol, nRow);
 
-        std::pair<bool,bool> aRes(false, false);
-
-        const ScQueryEntry::QueryItemsType& rItems = rEntry.GetQueryItems();
-        if (rItems.size() == 1 && rItems.front().meType == 
ScQueryEntry::ByEmpty)
-        {
-            if (rEntry.IsQueryByEmpty())
-                aRes.first = aCell.isEmpty();
-            else
-            {
-                assert(rEntry.IsQueryByNonEmpty());
-                aRes.first = !aCell.isEmpty();
-            }
-        }
-        else
-        {
-            for (const auto& rItem : rItems)
-            {
-                if (rItem.meType == ScQueryEntry::ByTextColor)
-                {
-                    std::pair<bool, bool> aThisRes
-                        = aEval.compareByTextColor(nCol, nRow, nTab, rItem);
-                    aRes.first |= aThisRes.first;
-                    aRes.second |= aThisRes.second;
-                }
-                else if (rItem.meType == ScQueryEntry::ByBackgroundColor)
-                {
-                    std::pair<bool,bool> aThisRes =
-                        aEval.compareByBackgroundColor(nCol, nRow, nTab, 
rItem);
-                    aRes.first |= aThisRes.first;
-                    aRes.second |= aThisRes.second;
-                }
-                else if (QueryEvaluator::isQueryByValue(rItem, aCell))
-                {
-                    std::pair<bool,bool> aThisRes =
-                        aEval.compareByValue(aCell, nCol, nRow, rEntry, rItem, 
pContext);
-                    aRes.first |= aThisRes.first;
-                    aRes.second |= aThisRes.second;
-                }
-                else if (QueryEvaluator::isQueryByString(rEntry, rItem, aCell))
-                {
-                    std::pair<bool,bool> aThisRes =
-                        aEval.compareByString(aCell, nRow, rEntry, rItem, 
pContext);
-                    aRes.first |= aThisRes.first;
-                    aRes.second |= aThisRes.second;
-                }
-                else if (rParam.mbRangeLookup)
-                {
-                    std::pair<bool,bool> aThisRes =
-                        QueryEvaluator::compareByRangeLookup(aCell, rEntry, 
rItem);
-                    aRes.first |= aThisRes.first;
-                    aRes.second |= aThisRes.second;
-                }
-
-                if (aRes.first && aRes.second)
-                    break;
-            }
-        }
+        std::pair<bool,bool> aRes = validQueryProcessEntry(nRow, nCol, nTab, 
rParam, aCell, pContext,
+            aEval, rEntry);
 
         if (nPos == -1)
         {

Reply via email to