From f4569ff5ee721683c6ba09b75fe0ce14e3203d3a Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Thu, 7 Nov 2013 23:06:26 +0100 Subject: 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 --- .../ExponentialSmoothingDialog.cxx | 31 ++++++++++------------ 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'sc/source/ui/StatisticsDialogs/ExponentialSmoothingDialog.cxx') 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 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); -- cgit