Bump version to 4.3-4
[LibreOffice.git] / sc / source / ui / StatisticsDialogs / ExponentialSmoothingDialog.cxx
blob091f1a05833bc3f8ed7b66028828f5e698afc57b
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 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()
42 bool ScExponentialSmoothingDialog::Close()
44 return DoClose( ScExponentialSmoothingDialogWrapper::GetChildWindowId() );
47 sal_Int16 ScExponentialSmoothingDialog::GetUndoNameId()
49 return STR_EXPONENTIAL_SMOOTHING_UNDO_NAME;
52 ScRange ScExponentialSmoothingDialog::ApplyOutput(ScDocShell* pDocShell)
54 AddressWalkerWriter output(mOutputAddress, pDocShell, mDocument,
55 formula::FormulaGrammar::mergeToGrammar( formula::FormulaGrammar::GRAM_ENGLISH, mAddressDetails.eConv));
56 FormulaTemplate aTemplate(mDocument);
58 // Smoothing factor
59 double aSmoothingFactor = mpSmoothingFactor->GetValue() / 100.0;
61 // Alpha
62 output.writeBoldString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_LABEL_ALPHA));
63 output.nextRow();
65 // Alpha Value
66 ScAddress aSmoothingFactorAddress = output.current();
67 output.writeValue(aSmoothingFactor);
68 output.nextRow();
70 // Exponential Smoothing
71 output.push();
73 boost::scoped_ptr<DataRangeIterator> pIterator;
74 if (mGroupedBy == BY_COLUMN)
75 pIterator.reset(new DataRangeByColumnIterator(mInputRange));
76 else
77 pIterator.reset(new DataRangeByRowIterator(mInputRange));
79 for( ; pIterator->hasNext(); pIterator->next() )
81 output.resetRow();
83 ScRange aCurrentRange = pIterator->get();
85 // Write column label
86 if (mGroupedBy == BY_COLUMN)
87 aTemplate.setTemplate(SC_STRLOAD(RID_STATISTICS_DLGS, STR_COLUMN_LABEL_TEMPLATE));
88 else
89 aTemplate.setTemplate(SC_STRLOAD(RID_STATISTICS_DLGS, STR_ROW_LABEL_TEMPLATE));
90 aTemplate.applyNumber("%NUMBER%", pIterator->index() + 1);
91 output.writeBoldString(aTemplate.getTemplate());
92 output.nextRow();
94 // Initial value
95 if (false)
97 aTemplate.setTemplate("=AVERAGE(%RANGE%)");
98 aTemplate.applyRange("%RANGE%", aCurrentRange);
99 output.writeFormula(aTemplate.getTemplate());
101 else
103 aTemplate.setTemplate("=%VAR%");
104 aTemplate.applyAddress("%VAR%", aCurrentRange.aStart);
105 output.writeFormula(aTemplate.getTemplate());
108 output.nextRow();
110 DataCellIterator aDataCellIterator = pIterator->iterateCells();
112 for (; aDataCellIterator.hasNext(); aDataCellIterator.next())
114 aTemplate.setTemplate("=%VALUE% * %PREVIOUS_INPUT% + (1 - %VALUE%) * %PREVIOUS_OUTPUT%");
115 aTemplate.applyAddress("%PREVIOUS_INPUT%", aDataCellIterator.get());
116 aTemplate.applyAddress("%PREVIOUS_OUTPUT%", output.current(0, -1));
117 aTemplate.applyAddress("%VALUE%", aSmoothingFactorAddress);
119 output.writeFormula(aTemplate.getTemplate());
120 output.nextRow();
122 output.nextColumn();
125 return ScRange (output.mMinimumAddress, output.mMaximumAddress);
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */