[Libreoffice-commits] core.git: sc/inc sc/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Thu Dec 13 20:26:53 UTC 2018


 sc/inc/subtotal.hxx              |    2 +
 sc/source/core/data/column2.cxx  |   60 +++--------------------------------
 sc/source/core/data/documen4.cxx |   66 ---------------------------------------
 3 files changed, 9 insertions(+), 119 deletions(-)

New commits:
commit 775d93cdbf936563f0387e1fca91abc25471838b
Author:     Eike Rathke <erack at redhat.com>
AuthorDate: Thu Dec 13 17:13:37 2018 +0100
Commit:     Eike Rathke <erack at redhat.com>
CommitDate: Thu Dec 13 21:26:26 2018 +0100

    Use ScFunctionData::update() and getResult() instead of direct member access
    
    So we can start to bundle everything in one place.
    
    Change-Id: I5df76bfae0e1bd5e8923b0012c1337e3a7f14db8
    Reviewed-on: https://gerrit.libreoffice.org/65122
    Tested-by: Jenkins
    Reviewed-by: Eike Rathke <erack at redhat.com>

diff --git a/sc/inc/subtotal.hxx b/sc/inc/subtotal.hxx
index 441e2e18c0d3..2c1db3ca2264 100644
--- a/sc/inc/subtotal.hxx
+++ b/sc/inc/subtotal.hxx
@@ -52,9 +52,11 @@ private:
 
 struct ScFunctionData                   // to calculate single functions
 {
+private:
     WelfordRunner   maWelford;
     double          nVal;
     sal_uInt64      nCount;
+public:
     ScSubTotalFunc const  eFunc;
     bool            bError;
 
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index 5f77628699f6..3aabfec3f611 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -3383,60 +3383,12 @@ class UpdateSubTotalHandler
 
         switch (mrData.eFunc)
         {
-            case SUBTOTAL_FUNC_SUM:
-            case SUBTOTAL_FUNC_AVE:
-            {
-                if (!bVal)
-                    return;
-
-                ++mrData.nCount;
-                if (!SubTotal::SafePlus(mrData.nVal, fVal))
-                    mrData.bError = true;
-            }
-            break;
-            case SUBTOTAL_FUNC_CNT:             // only the value
-            {
-                if (!bVal)
-                    return;
-
-                ++mrData.nCount;
-            }
-            break;
-            case SUBTOTAL_FUNC_CNT2:            // everything
-                ++mrData.nCount;
-            break;
-            case SUBTOTAL_FUNC_MAX:
-            {
-                if (!bVal)
-                    return;
-
-                if (++mrData.nCount == 1 || fVal > mrData.nVal)
-                    mrData.nVal = fVal;
-            }
-            break;
-            case SUBTOTAL_FUNC_MIN:
-            {
-                if (!bVal)
-                    return;
-
-                if (++mrData.nCount == 1 || fVal < mrData.nVal)
-                    mrData.nVal = fVal;
-            }
+            case SUBTOTAL_FUNC_CNT2:    // everything
+                mrData.update( fVal);
             break;
-            case SUBTOTAL_FUNC_VAR:
-            case SUBTOTAL_FUNC_VARP:
-            case SUBTOTAL_FUNC_STD:
-            case SUBTOTAL_FUNC_STDP:
-            {
-                if (!bVal)
-                    return;
-
-                mrData.maWelford.update( fVal);
-            }
-            break;
-            default:
-                // unhandled unknown
-                mrData.bError = true;
+            default:                    // only numeric values
+                if (bVal)
+                    mrData.update( fVal);
         }
     }
 
@@ -3520,7 +3472,7 @@ void ScColumn::UpdateSelectionFunction(
         {
             // Simply count selected rows regardless of cell contents.
             for (; it != itEnd; ++it)
-                rData.nCount += it->mnRow2 - it->mnRow1 + 1;
+                rData.update( it->mnRow2 - it->mnRow1 + 1);
         }
         break;
         case SUBTOTAL_FUNC_CNT2:
diff --git a/sc/source/core/data/documen4.cxx b/sc/source/core/data/documen4.cxx
index 94b361cde765..c8065b021455 100644
--- a/sc/source/core/data/documen4.cxx
+++ b/sc/source/core/data/documen4.cxx
@@ -616,71 +616,7 @@ bool ScDocument::GetSelectionFunction( ScSubTotalFunc eFunc,
 
             //TODO: pass rMark to UpdateSelection Function !!!!!
 
-    if (!aData.bError)
-        switch (eFunc)
-        {
-            case SUBTOTAL_FUNC_SUM:
-                rResult = aData.nVal;
-                break;
-            case SUBTOTAL_FUNC_SELECTION_COUNT:
-                rResult = aData.nCount;
-                break;
-            case SUBTOTAL_FUNC_CNT:
-            case SUBTOTAL_FUNC_CNT2:
-                rResult = aData.nCount;
-                break;
-            case SUBTOTAL_FUNC_AVE:
-                if (aData.nCount)
-                    rResult = aData.nVal / static_cast<double>(aData.nCount);
-                else
-                    aData.bError = true;
-                break;
-            case SUBTOTAL_FUNC_MAX:
-            case SUBTOTAL_FUNC_MIN:
-                if (aData.nCount)
-                    rResult = aData.nVal;
-                else
-                    aData.bError = true;
-                break;
-            case SUBTOTAL_FUNC_VAR:
-            case SUBTOTAL_FUNC_STD:
-                if (aData.maWelford.getCount() < 2)
-                    aData.bError = true;
-                else
-                {
-                    rResult = aData.maWelford.getVarianceSample();
-                    if (eFunc == SUBTOTAL_FUNC_STD)
-                    {
-                        if (rResult < 0.0)
-                            aData.bError = true;
-                        else
-                            rResult = sqrt( rResult);
-                    }
-                }
-                break;
-            case SUBTOTAL_FUNC_VARP:
-            case SUBTOTAL_FUNC_STDP:
-                if (aData.maWelford.getCount() < 1)
-                    aData.bError = true;
-                else if (aData.maWelford.getCount() == 1)
-                    rResult = 0.0;
-                else
-                {
-                    rResult = aData.maWelford.getVariancePopulation();
-                    if (eFunc == SUBTOTAL_FUNC_STDP)
-                    {
-                        if (rResult < 0.0)
-                            aData.bError = true;
-                        else
-                            rResult = sqrt( rResult);
-                    }
-                }
-                break;
-            default:
-                // unhandled unknown
-                aData.bError = true;
-        }
-
+    rResult = aData.getResult();
     if (aData.bError)
         rResult = 0.0;
 


More information about the Libreoffice-commits mailing list