Kaydet (Commit) 775d93cd authored tarafından Eike Rathke's avatar Eike Rathke

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: 's avatarEike Rathke <erack@redhat.com>
üst e3e15d8c
......@@ -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;
......
......@@ -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:
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment