fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / StatisticsDialogs / ExponentialSmoothingDialog.cxx
blob9acf9ed6f1d7bb7db9f498fd1380484f9b7b8d81
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 */
11 #include <sfx2/dispatch.hxx>
12 #include <svl/zforlist.hxx>
13 #include <svl/undo.hxx>
15 #include "formulacell.hxx"
16 #include "rangelst.hxx"
17 #include "scitems.hxx"
18 #include "docsh.hxx"
19 #include "document.hxx"
20 #include "uiitems.hxx"
21 #include "reffact.hxx"
22 #include "strload.hxx"
23 #include "docfunc.hxx"
24 #include "StatisticsDialogs.hrc"
25 #include "TableFillingAndNavigationTools.hxx"
27 #include "ExponentialSmoothingDialog.hxx"
29 ScExponentialSmoothingDialog::ScExponentialSmoothingDialog(
30 SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow,
31 vcl::Window* pParent, ScViewData* pViewData ) :
32 ScStatisticsInputOutputDialog(
33 pSfxBindings, pChildWindow, pParent, pViewData,
34 "ExponentialSmoothingDialog", "modules/scalc/ui/exponentialsmoothingdialog.ui" )
36 get(mpSmoothingFactor, "smoothing-factor-spin");
39 ScExponentialSmoothingDialog::~ScExponentialSmoothingDialog()
41 disposeOnce();
44 void ScExponentialSmoothingDialog::dispose()
46 mpSmoothingFactor.clear();
47 ScStatisticsInputOutputDialog::dispose();
50 bool ScExponentialSmoothingDialog::Close()
52 return DoClose( ScExponentialSmoothingDialogWrapper::GetChildWindowId() );
55 sal_Int16 ScExponentialSmoothingDialog::GetUndoNameId()
57 return STR_EXPONENTIAL_SMOOTHING_UNDO_NAME;
60 ScRange ScExponentialSmoothingDialog::ApplyOutput(ScDocShell* pDocShell)
62 AddressWalkerWriter output(mOutputAddress, pDocShell, mDocument,
63 formula::FormulaGrammar::mergeToGrammar( formula::FormulaGrammar::GRAM_ENGLISH, mAddressDetails.eConv));
64 FormulaTemplate aTemplate(mDocument);
66 // Smoothing factor
67 double aSmoothingFactor = mpSmoothingFactor->GetValue() / 100.0;
69 // Alpha
70 output.writeBoldString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_LABEL_ALPHA));
71 output.nextRow();
73 // Alpha Value
74 ScAddress aSmoothingFactorAddress = output.current();
75 output.writeValue(aSmoothingFactor);
76 output.nextRow();
78 // Exponential Smoothing
79 output.push();
81 boost::scoped_ptr<DataRangeIterator> pIterator;
82 if (mGroupedBy == BY_COLUMN)
83 pIterator.reset(new DataRangeByColumnIterator(mInputRange));
84 else
85 pIterator.reset(new DataRangeByRowIterator(mInputRange));
87 for( ; pIterator->hasNext(); pIterator->next() )
89 output.resetRow();
91 ScRange aCurrentRange = pIterator->get();
93 // Write column label
94 if (mGroupedBy == BY_COLUMN)
95 aTemplate.setTemplate(SC_STRLOAD(RID_STATISTICS_DLGS, STR_COLUMN_LABEL_TEMPLATE));
96 else
97 aTemplate.setTemplate(SC_STRLOAD(RID_STATISTICS_DLGS, STR_ROW_LABEL_TEMPLATE));
98 aTemplate.applyNumber("%NUMBER%", pIterator->index() + 1);
99 output.writeBoldString(aTemplate.getTemplate());
100 output.nextRow();
102 // Initial value
103 if (false)
105 aTemplate.setTemplate("=AVERAGE(%RANGE%)");
106 aTemplate.applyRange("%RANGE%", aCurrentRange);
107 output.writeFormula(aTemplate.getTemplate());
109 else
111 aTemplate.setTemplate("=%VAR%");
112 aTemplate.applyAddress("%VAR%", aCurrentRange.aStart);
113 output.writeFormula(aTemplate.getTemplate());
116 output.nextRow();
118 DataCellIterator aDataCellIterator = pIterator->iterateCells();
120 for (; aDataCellIterator.hasNext(); aDataCellIterator.next())
122 aTemplate.setTemplate("=%VALUE% * %PREVIOUS_INPUT% + (1 - %VALUE%) * %PREVIOUS_OUTPUT%");
123 aTemplate.applyAddress("%PREVIOUS_INPUT%", aDataCellIterator.get());
124 aTemplate.applyAddress("%PREVIOUS_OUTPUT%", output.current(0, -1));
125 aTemplate.applyAddress("%VALUE%", aSmoothingFactorAddress);
127 output.writeFormula(aTemplate.getTemplate());
128 output.nextRow();
130 output.nextColumn();
133 return ScRange (output.mMinimumAddress, output.mMaximumAddress);
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */