tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / StatisticsDialogs / ExponentialSmoothingDialog.cxx
blobd7fe7c8721677dc4bee1530d3fabcab7c693281f
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 <memory>
13 #include <reffact.hxx>
14 #include <TableFillingAndNavigationTools.hxx>
15 #include <ExponentialSmoothingDialog.hxx>
16 #include <scresid.hxx>
17 #include <strings.hrc>
19 ScExponentialSmoothingDialog::ScExponentialSmoothingDialog(
20 SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow,
21 weld::Window* pParent, ScViewData& rViewData )
22 : ScStatisticsInputOutputDialog(
23 pSfxBindings, pChildWindow, pParent, rViewData,
24 u"modules/scalc/ui/exponentialsmoothingdialog.ui"_ustr,
25 u"ExponentialSmoothingDialog"_ustr)
26 , mxSmoothingFactor(m_xBuilder->weld_spin_button(u"smoothing-factor-spin"_ustr))
30 ScExponentialSmoothingDialog::~ScExponentialSmoothingDialog()
34 void ScExponentialSmoothingDialog::Close()
36 DoClose( ScExponentialSmoothingDialogWrapper::GetChildWindowId() );
39 TranslateId ScExponentialSmoothingDialog::GetUndoNameId()
41 return STR_EXPONENTIAL_SMOOTHING_UNDO_NAME;
44 ScRange ScExponentialSmoothingDialog::ApplyOutput(ScDocShell* pDocShell)
46 AddressWalkerWriter output(mOutputAddress, pDocShell, mDocument,
47 formula::FormulaGrammar::mergeToGrammar( formula::FormulaGrammar::GRAM_ENGLISH, mAddressDetails.eConv));
48 FormulaTemplate aTemplate(&mDocument);
50 // Smoothing factor
51 double aSmoothingFactor = mxSmoothingFactor->get_value() / 100.0;
53 // Alpha
54 output.writeBoldString(ScResId(STR_LABEL_ALPHA));
55 output.nextRow();
57 // Alpha Value
58 ScAddress aSmoothingFactorAddress = output.current();
59 output.writeValue(aSmoothingFactor);
60 output.nextRow();
62 // Exponential Smoothing
63 output.push();
65 std::unique_ptr<DataRangeIterator> pIterator;
66 if (mGroupedBy == BY_COLUMN)
67 pIterator.reset(new DataRangeByColumnIterator(mInputRange));
68 else
69 pIterator.reset(new DataRangeByRowIterator(mInputRange));
71 for( ; pIterator->hasNext(); pIterator->next() )
73 output.resetRow();
75 ScRange aCurrentRange = pIterator->get();
77 // Write column label
78 if (mGroupedBy == BY_COLUMN)
79 aTemplate.setTemplate(ScResId(STR_COLUMN_LABEL_TEMPLATE));
80 else
81 aTemplate.setTemplate(ScResId(STR_ROW_LABEL_TEMPLATE));
82 aTemplate.applyNumber(u"%NUMBER%", pIterator->index() + 1);
83 output.writeBoldString(aTemplate.getTemplate());
84 output.nextRow();
86 // Initial value
87 if ((false))
89 aTemplate.setTemplate("=AVERAGE(%RANGE%)");
90 aTemplate.applyRange(u"%RANGE%", aCurrentRange);
91 output.writeFormula(aTemplate.getTemplate());
93 else
95 aTemplate.setTemplate("=%VAR%");
96 aTemplate.applyAddress(u"%VAR%", aCurrentRange.aStart);
97 output.writeFormula(aTemplate.getTemplate());
100 output.nextRow();
102 DataCellIterator aDataCellIterator = pIterator->iterateCells();
104 for (; aDataCellIterator.hasNext(); aDataCellIterator.next())
106 aTemplate.setTemplate("=%VALUE% * %PREVIOUS_INPUT% + (1 - %VALUE%) * %PREVIOUS_OUTPUT%");
107 aTemplate.applyAddress(u"%PREVIOUS_INPUT%", aDataCellIterator.get());
108 aTemplate.applyAddress(u"%PREVIOUS_OUTPUT%", output.current(0, -1));
109 aTemplate.applyAddress(u"%VALUE%", aSmoothingFactorAddress);
111 output.writeFormula(aTemplate.getTemplate());
112 output.nextRow();
114 output.nextColumn();
117 return ScRange (output.mMinimumAddress, output.mMaximumAddress);
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */