LibreOffice Module sc (master)  1
FTestDialog.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>
15 #include <FTestDialog.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/ttestdialog.ui", "TTestDialog" )
25 {
26  m_xDialog->set_title(ScResId(STR_FTEST));
27 }
28 
30 {}
31 
33 {
35 }
36 
38 {
39  return STR_FTEST_UNDO_NAME;
40 }
41 
43 {
44  AddressWalkerWriter aOutput(mOutputAddress, pDocShell, mDocument,
46  FormulaTemplate aTemplate(&mDocument);
47 
48  std::unique_ptr<DataRangeIterator> pVariable1Iterator;
49  if (mGroupedBy == BY_COLUMN)
50  pVariable1Iterator.reset(new DataRangeByColumnIterator(mVariable1Range));
51  else
52  pVariable1Iterator.reset(new DataRangeByRowIterator(mVariable1Range));
53 
54  std::unique_ptr<DataRangeIterator> pVariable2Iterator;
55  if (mGroupedBy == BY_COLUMN)
56  pVariable2Iterator.reset(new DataRangeByColumnIterator(mVariable2Range));
57  else
58  pVariable2Iterator.reset(new DataRangeByRowIterator(mVariable2Range));
59 
60  aTemplate.autoReplaceRange("%VARIABLE1_RANGE%", pVariable1Iterator->get());
61  aTemplate.autoReplaceRange("%VARIABLE2_RANGE%", pVariable2Iterator->get());
62 
63  aOutput.writeBoldString(ScResId(STR_FTEST_UNDO_NAME));
64  aOutput.newLine();
65 
66  // Alpha
67  aOutput.writeString(ScResId(STR_LABEL_ALPHA));
68  aOutput.nextColumn();
69  aOutput.writeValue(0.05);
70  aTemplate.autoReplaceAddress("%ALPHA%", aOutput.current());
71  aOutput.newLine();
72 
73  aOutput.nextColumn();
74  aOutput.writeBoldString(ScResId(STR_VARIABLE_1_LABEL));
75  aOutput.nextColumn();
76  aOutput.writeBoldString(ScResId(STR_VARIABLE_2_LABEL));
77  aOutput.newLine();
78 
79  aOutput.writeString(ScResId(STRID_CALC_MEAN));
80  aOutput.nextColumn();
81  aTemplate.setTemplate("=AVERAGE(%VARIABLE1_RANGE%)");
82  aOutput.writeFormula(aTemplate.getTemplate());
83  aOutput.nextColumn();
84  aTemplate.setTemplate("=AVERAGE(%VARIABLE2_RANGE%)");
85  aOutput.writeFormula(aTemplate.getTemplate());
86  aOutput.newLine();
87 
88  aOutput.writeString(ScResId(STRID_CALC_VARIANCE));
89  aOutput.nextColumn();
90  aTemplate.setTemplate("=VAR(%VARIABLE1_RANGE%)");
91  aOutput.writeFormula(aTemplate.getTemplate());
92  aTemplate.autoReplaceAddress("%VARIABLE1_VARIANCE%", aOutput.current());
93  aOutput.nextColumn();
94  aTemplate.setTemplate("=VAR(%VARIABLE2_RANGE%)");
95  aOutput.writeFormula(aTemplate.getTemplate());
96  aTemplate.autoReplaceAddress("%VARIABLE2_VARIANCE%", aOutput.current());
97  aOutput.newLine();
98 
99  aOutput.writeString(ScResId(STR_OBSERVATIONS_LABEL));
100  aOutput.nextColumn();
101  aTemplate.setTemplate("=COUNT(%VARIABLE1_RANGE%)");
102  aOutput.writeFormula(aTemplate.getTemplate());
103  aTemplate.autoReplaceAddress("%VARIABLE1_OBSERVATIONS%", aOutput.current());
104  aOutput.nextColumn();
105  aTemplate.setTemplate("=COUNT(%VARIABLE2_RANGE%)");
106  aOutput.writeFormula(aTemplate.getTemplate());
107  aTemplate.autoReplaceAddress("%VARIABLE2_OBSERVATIONS%", aOutput.current());
108  aOutput.newLine();
109 
110  aOutput.writeString(ScResId(STR_ANOVA_LABEL_DF));
111  aOutput.nextColumn();
112  aTemplate.setTemplate("=%VARIABLE1_OBSERVATIONS% - 1");
113  aOutput.writeFormula(aTemplate.getTemplate());
114  aTemplate.autoReplaceAddress("%VARIABLE1_DEGREE_OF_FREEDOM%", aOutput.current());
115  aOutput.nextColumn();
116  aTemplate.setTemplate("=%VARIABLE2_OBSERVATIONS% - 1");
117  aOutput.writeFormula(aTemplate.getTemplate());
118  aTemplate.autoReplaceAddress("%VARIABLE2_DEGREE_OF_FREEDOM%", aOutput.current());
119  aOutput.newLine();
120 
121  aOutput.writeString(ScResId(STR_ANOVA_LABEL_F));
122  aOutput.nextColumn();
123  aTemplate.setTemplate("=%VARIABLE1_VARIANCE% / %VARIABLE2_VARIANCE%");
124  aOutput.writeFormula(aTemplate.getTemplate());
125  aTemplate.autoReplaceAddress("%F_VALUE%", aOutput.current());
126  aOutput.newLine();
127 
128  aOutput.writeString(ScResId(STR_FTEST_P_RIGHT_TAIL));
129  aOutput.nextColumn();
130  aTemplate.setTemplate("=FDIST(%F_VALUE%; %VARIABLE1_DEGREE_OF_FREEDOM%; %VARIABLE2_DEGREE_OF_FREEDOM%)");
131  aOutput.writeFormula(aTemplate.getTemplate());
132  aTemplate.autoReplaceAddress("%P_RIGHT_TAIL_VALUE%", aOutput.current());
133  aOutput.newLine();
134 
135  aOutput.writeString(ScResId(STR_FTEST_F_CRITICAL_RIGHT_TAIL));
136  aOutput.nextColumn();
137  aTemplate.setTemplate("=FINV(%ALPHA%; %VARIABLE1_DEGREE_OF_FREEDOM%; %VARIABLE2_DEGREE_OF_FREEDOM%)");
138  aOutput.writeFormula(aTemplate.getTemplate());
139  aOutput.newLine();
140 
141  aOutput.writeString(ScResId(STR_FTEST_P_LEFT_TAIL));
142  aOutput.nextColumn();
143  aTemplate.setTemplate("=1 - %P_RIGHT_TAIL_VALUE%");
144  aOutput.writeFormula(aTemplate.getTemplate());
145  aTemplate.autoReplaceAddress("%P_LEFT_TAIL_VALUE%", aOutput.current());
146  aOutput.newLine();
147 
148  aOutput.writeString(ScResId(STR_FTEST_F_CRITICAL_LEFT_TAIL));
149  aOutput.nextColumn();
150  aTemplate.setTemplate("=FINV(1-%ALPHA%; %VARIABLE1_DEGREE_OF_FREEDOM%; %VARIABLE2_DEGREE_OF_FREEDOM%)");
151  aOutput.writeFormula(aTemplate.getTemplate());
152  aOutput.newLine();
153 
154  aOutput.writeString(ScResId(STR_FTEST_P_TWO_TAIL));
155  aOutput.nextColumn();
156  aTemplate.setTemplate("=2*MIN(%P_RIGHT_TAIL_VALUE%; %P_LEFT_TAIL_VALUE%)");
157  aOutput.writeFormula(aTemplate.getTemplate());
158  aOutput.newLine();
159 
160  aOutput.writeString(ScResId(STR_FTEST_F_CRITICAL_TWO_TAIL));
161  aOutput.nextColumn();
162  aTemplate.setTemplate("=FINV(1-(%ALPHA%/2); %VARIABLE1_DEGREE_OF_FREEDOM%; %VARIABLE2_DEGREE_OF_FREEDOM%)");
163  aOutput.writeFormula(aTemplate.getTemplate());
164  aOutput.nextColumn();
165  aTemplate.setTemplate("=FINV(%ALPHA%/2; %VARIABLE1_DEGREE_OF_FREEDOM%; %VARIABLE2_DEGREE_OF_FREEDOM%)");
166  aOutput.writeFormula(aTemplate.getTemplate());
167 
168  return ScRange(aOutput.mMinimumAddress, aOutput.mMaximumAddress);
169 }
170 
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScFTestDialog(SfxBindings *pB, SfxChildWindow *pCW, weld::Window *pParent, ScViewData &rViewData)
Definition: FTestDialog.cxx:19
void writeFormula(const OUString &aFormula)
void writeString(const OUString &aString)
virtual ScRange ApplyOutput(ScDocShell *pDocShell) override
Definition: FTestDialog.cxx:42
formula::FormulaGrammar::AddressConvention eConv
Definition: address.hxx:213
void writeBoldString(const OUString &aString)
static Grammar mergeToGrammar(const Grammar eGrammar, const AddressConvention eConv)
ScAddress current(SCCOL aRelativeCol=0, SCROW aRelativeRow=0, SCTAB aRelativeTab=0)
virtual const char * GetUndoNameId() override
Definition: FTestDialog.cxx:37
OUString ScResId(const char *pId)
Definition: scdll.cxx:89
void autoReplaceRange(const OUString &aVariable, const ScRange &rRange)
void autoReplaceAddress(const OUString &aVariable, ScAddress const &aAddress)
Reference< XExecutableDialog > m_xDialog
virtual ~ScFTestDialog() override
Definition: FTestDialog.cxx:29
virtual void Close() override
Definition: FTestDialog.cxx:32
void setTemplate(const OUString &aTemplate)
bool DoClose(sal_uInt16 nId)
Definition: anyrefdg.cxx:694