LibreOffice Module sc (master) 1
ExponentialSmoothingDialog.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 */
10
11#include <memory>
12
13#include <reffact.hxx>
16#include <scresid.hxx>
17#include <strings.hrc>
18
20 SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow,
21 weld::Window* pParent, ScViewData& rViewData )
23 pSfxBindings, pChildWindow, pParent, rViewData,
24 "modules/scalc/ui/exponentialsmoothingdialog.ui",
25 "ExponentialSmoothingDialog")
26 , mxSmoothingFactor(m_xBuilder->weld_spin_button("smoothing-factor-spin"))
27{
28}
29
31{
32}
33
35{
37}
38
40{
41 return STR_EXPONENTIAL_SMOOTHING_UNDO_NAME;
42}
43
45{
48 FormulaTemplate aTemplate(&mDocument);
49
50 // Smoothing factor
51 double aSmoothingFactor = mxSmoothingFactor->get_value() / 100.0;
52
53 // Alpha
54 output.writeBoldString(ScResId(STR_LABEL_ALPHA));
55 output.nextRow();
56
57 // Alpha Value
58 ScAddress aSmoothingFactorAddress = output.current();
59 output.writeValue(aSmoothingFactor);
60 output.nextRow();
61
62 // Exponential Smoothing
63 output.push();
64
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));
70
71 for( ; pIterator->hasNext(); pIterator->next() )
72 {
73 output.resetRow();
74
75 ScRange aCurrentRange = pIterator->get();
76
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();
85
86 // Initial value
87 if ((false))
88 {
89 aTemplate.setTemplate("=AVERAGE(%RANGE%)");
90 aTemplate.applyRange(u"%RANGE%", aCurrentRange);
91 output.writeFormula(aTemplate.getTemplate());
92 }
93 else
94 {
95 aTemplate.setTemplate("=%VAR%");
96 aTemplate.applyAddress(u"%VAR%", aCurrentRange.aStart);
97 output.writeFormula(aTemplate.getTemplate());
98 }
99
100 output.nextRow();
101
102 DataCellIterator aDataCellIterator = pIterator->iterateCells();
103
104 for (; aDataCellIterator.hasNext(); aDataCellIterator.next())
105 {
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);
110
111 output.writeFormula(aTemplate.getTemplate());
112 output.nextRow();
113 }
114 output.nextColumn();
115 }
116
117 return ScRange (output.mMinimumAddress, output.mMaximumAddress);
118}
119
120/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void writeFormula(const OUString &aFormula)
void writeBoldString(const OUString &aString)
ScAddress current(SCCOL aRelativeCol=0, SCROW aRelativeRow=0, SCTAB aRelativeTab=0)
void push(SCCOL aRelativeCol=0, SCROW aRelativeRow=0, SCTAB aRelativeTab=0)
void setTemplate(const OUString &aTemplate)
void applyRange(std::u16string_view aVariable, const ScRange &aRange, bool b3D=true)
void applyAddress(std::u16string_view aVariable, const ScAddress &aAddress, bool b3D=true)
void applyNumber(std::u16string_view aVariable, sal_Int32 aValue)
ScExponentialSmoothingDialog(SfxBindings *pB, SfxChildWindow *pCW, weld::Window *pParent, ScViewData &rViewData)
std::unique_ptr< weld::SpinButton > mxSmoothingFactor
virtual ScRange ApplyOutput(ScDocShell *pDocShell) override
virtual TranslateId GetUndoNameId() override
ScAddress aStart
Definition: address.hxx:497
bool DoClose(sal_uInt16 nId)
Definition: anyrefdg.cxx:714
static Grammar mergeToGrammar(const Grammar eGrammar, const AddressConvention eConv)
float u
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:90
formula::FormulaGrammar::AddressConvention eConv
Definition: address.hxx:225