summaryrefslogtreecommitdiff
path: root/sc/source/ui/StatisticsDialogs/ExponentialSmoothingDialog.cxx
diff options
context:
space:
mode:
authorTomaž Vajngerl <quikee@gmail.com>2013-11-07 23:06:26 +0100
committerTomaž Vajngerl <quikee@gmail.com>2013-11-11 23:22:32 +0100
commitf4569ff5ee721683c6ba09b75fe0ce14e3203d3a (patch)
treef26ae6f65fc350907077460fa732071c7d715f37 /sc/source/ui/StatisticsDialogs/ExponentialSmoothingDialog.cxx
parent2f823d458de726d8e8f7c3684e3b1f15d0104e27 (diff)
Iterators for data ranges and data cells.
This is needed to make data and iteration independent from the data orientation (either columns or rows). Change-Id: I03d0fca939ba9b051832668d229e4961c097add6
Diffstat (limited to 'sc/source/ui/StatisticsDialogs/ExponentialSmoothingDialog.cxx')
-rw-r--r--sc/source/ui/StatisticsDialogs/ExponentialSmoothingDialog.cxx31
1 files changed, 14 insertions, 17 deletions
diff --git a/sc/source/ui/StatisticsDialogs/ExponentialSmoothingDialog.cxx b/sc/source/ui/StatisticsDialogs/ExponentialSmoothingDialog.cxx
index 9afeb48d99fc..34cfcf477e64 100644
--- a/sc/source/ui/StatisticsDialogs/ExponentialSmoothingDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/ExponentialSmoothingDialog.cxx
@@ -52,14 +52,9 @@ void ScExponentialSmoothingDialog::CalculateInputAndWriteToOutput( )
svl::IUndoManager* pUndoManager = pDocShell->GetUndoManager();
pUndoManager->EnterListAction( aUndo, aUndo );
- ScAddress aStart = mInputRange.aStart;
- ScAddress aEnd = mInputRange.aEnd;
-
AddressWalkerWriter output(mOutputAddress, pDocShell, mDocument);
FormulaTemplate aTemplate(mDocument, mAddressDetails);
- SCROW inTab = aStart.Tab();
-
// Smoothing factor
double aSmoothingFactor = mpSmoothingFactor->GetValue() / 100.0;
@@ -70,37 +65,39 @@ void ScExponentialSmoothingDialog::CalculateInputAndWriteToOutput( )
// Exponential Smoothing
output.push();
- for (SCCOL inCol = aStart.Col(); inCol <= aEnd.Col(); inCol++)
+ boost::scoped_ptr<DataRangeIterator> pIterator;
+ if (mGroupedBy == BY_COLUMN)
+ pIterator.reset(new DataRangeByColumnIterator(mInputRange));
+ else
+ pIterator.reset(new DataRangeByRowIterator(mInputRange));
+
+ for( ; pIterator->hasNext(); pIterator->next() )
{
output.resetRow();
- SCROW inRow = aStart.Row();
+ ScRange aCurrentRange = pIterator->get();
if (false)
{
- ScRange aColumnRange (
- ScAddress(inCol, mInputRange.aStart.Row(), inTab),
- ScAddress(inCol, mInputRange.aEnd.Row(), inTab));
-
aTemplate.setTemplate("=AVERAGE(%RANGE%)");
- aTemplate.applyRange("%RANGE%", aColumnRange);
+ aTemplate.applyRange("%RANGE%", aCurrentRange);
output.writeFormula(aTemplate.getTemplate());
}
else
{
- ScAddress aFirstValueAddress(inCol, mInputRange.aStart.Row(), inTab);
-
aTemplate.setTemplate("=%VAR%");
- aTemplate.applyAddress("%VAR%", aFirstValueAddress);
+ aTemplate.applyAddress("%VAR%", aCurrentRange.aStart);
output.writeFormula(aTemplate.getTemplate());
}
output.nextRow();
- for (inRow = aStart.Row() + 1; inRow <= aEnd.Row(); inRow++)
+ DataCellIterator aDataCellIterator = pIterator->iterateCells();
+
+ for (; aDataCellIterator.hasNext(); aDataCellIterator.next())
{
aTemplate.setTemplate("=%VALUE% * %PREVIOUS_INPUT% + (1 - %VALUE%) * %PREVIOUS_OUTPUT%");
- aTemplate.applyAddress("%PREVIOUS_INPUT%", ScAddress(inCol, inRow - 1, inTab));
+ aTemplate.applyAddress("%PREVIOUS_INPUT%", aDataCellIterator.get());
aTemplate.applyAddress("%PREVIOUS_OUTPUT%", output.current(0, -1));
aTemplate.applyAddress("%VALUE%", aSmoothingFactorAddress);