Bump version to 4.3-4
[LibreOffice.git] / sc / source / ui / StatisticsDialogs / FTestDialog.cxx
blob785d4755021457d1da80daaabc2acdccebe8054a
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>
14 #include <boost/random.hpp>
15 #include <boost/scoped_ptr.hpp>
17 #include "formulacell.hxx"
18 #include "rangelst.hxx"
19 #include "scitems.hxx"
20 #include "docsh.hxx"
21 #include "document.hxx"
22 #include "uiitems.hxx"
23 #include "reffact.hxx"
24 #include "strload.hxx"
25 #include "docfunc.hxx"
26 #include "StatisticsDialogs.hrc"
27 #include "TableFillingAndNavigationTools.hxx"
29 #include "FTestDialog.hxx"
31 namespace
34 static const OUString strWildcardVariable1Range("%VAR1_RANGE%");
35 static const OUString strWildcardVariable2Range("%VAR2_RANGE%");
39 ScFTestDialog::ScFTestDialog(
40 SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow,
41 Window* pParent, ScViewData* pViewData ) :
42 ScStatisticsTwoVariableDialog(
43 pSfxBindings, pChildWindow, pParent, pViewData,
44 "TTestDialog", "modules/scalc/ui/ttestdialog.ui" )
46 SetText(SC_STRLOAD(RID_STATISTICS_DLGS, STR_FTEST));
49 ScFTestDialog::~ScFTestDialog()
52 bool ScFTestDialog::Close()
54 return DoClose( ScFTestDialogWrapper::GetChildWindowId() );
57 sal_Int16 ScFTestDialog::GetUndoNameId()
59 return STR_FTEST_UNDO_NAME;
62 ScRange ScFTestDialog::ApplyOutput(ScDocShell* pDocShell)
64 AddressWalkerWriter aOutput(mOutputAddress, pDocShell, mDocument,
65 formula::FormulaGrammar::mergeToGrammar(formula::FormulaGrammar::GRAM_ENGLISH, mAddressDetails.eConv));
66 FormulaTemplate aTemplate(mDocument);
68 boost::scoped_ptr<DataRangeIterator> pVariable1Iterator;
69 if (mGroupedBy == BY_COLUMN)
70 pVariable1Iterator.reset(new DataRangeByColumnIterator(mVariable1Range));
71 else
72 pVariable1Iterator.reset(new DataRangeByRowIterator(mVariable1Range));
74 boost::scoped_ptr<DataRangeIterator> pVariable2Iterator;
75 if (mGroupedBy == BY_COLUMN)
76 pVariable2Iterator.reset(new DataRangeByColumnIterator(mVariable2Range));
77 else
78 pVariable2Iterator.reset(new DataRangeByRowIterator(mVariable2Range));
80 aTemplate.autoReplaceRange(strWildcardVariable1Range, pVariable1Iterator->get());
81 aTemplate.autoReplaceRange(strWildcardVariable2Range, pVariable2Iterator->get());
83 aOutput.writeBoldString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_FTEST_UNDO_NAME));
84 aOutput.newLine();
86 aOutput.writeString("Alpha");
87 aOutput.nextColumn();
88 aOutput.writeValue(0.05);
89 aTemplate.autoReplaceAddress("%ALPHA%", aOutput.current());
90 aOutput.newLine();
92 aOutput.nextColumn();
93 aOutput.writeBoldString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_VARIABLE_1_LABEL));
94 aOutput.nextColumn();
95 aOutput.writeBoldString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_VARIABLE_2_LABEL));
96 aOutput.newLine();
98 aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STRID_CALC_MEAN));
99 aOutput.nextColumn();
100 aTemplate.setTemplate("=AVERAGE(%VAR1_RANGE%)");
101 aOutput.writeFormula(aTemplate.getTemplate());
102 aOutput.nextColumn();
103 aTemplate.setTemplate("=AVERAGE(%VAR2_RANGE%)");
104 aOutput.writeFormula(aTemplate.getTemplate());
105 aOutput.newLine();
107 aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STRID_CALC_VARIANCE));
108 aOutput.nextColumn();
109 aTemplate.setTemplate("=VAR(%VAR1_RANGE%)");
110 aOutput.writeFormula(aTemplate.getTemplate());
111 aTemplate.autoReplaceAddress("%VAR1_VARIANCE%", aOutput.current());
112 aOutput.nextColumn();
113 aTemplate.setTemplate("=VAR(%VAR2_RANGE%)");
114 aOutput.writeFormula(aTemplate.getTemplate());
115 aTemplate.autoReplaceAddress("%VAR2_VARIANCE%", aOutput.current());
116 aOutput.newLine();
118 aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_FTEST_OBSERVATIONS_LABEL));
119 aOutput.nextColumn();
120 aTemplate.setTemplate("=COUNT(%VAR1_RANGE%)");
121 aOutput.writeFormula(aTemplate.getTemplate());
122 aTemplate.autoReplaceAddress("%VAR1_OBSERVATIONS%", aOutput.current());
123 aOutput.nextColumn();
124 aTemplate.setTemplate("=COUNT(%VAR2_RANGE%)");
125 aOutput.writeFormula(aTemplate.getTemplate());
126 aTemplate.autoReplaceAddress("%VAR2_OBSERVATIONS%", aOutput.current());
127 aOutput.newLine();
129 aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_ANOVA_LABEL_DF));
130 aOutput.nextColumn();
131 aTemplate.setTemplate("=%VAR1_OBSERVATIONS% - 1");
132 aOutput.writeFormula(aTemplate.getTemplate());
133 aTemplate.autoReplaceAddress("%VAR1_DEGREE_OF_FREEDOM%", aOutput.current());
134 aOutput.nextColumn();
135 aTemplate.setTemplate("=%VAR2_OBSERVATIONS% - 1");
136 aOutput.writeFormula(aTemplate.getTemplate());
137 aTemplate.autoReplaceAddress("%VAR2_DEGREE_OF_FREEDOM%", aOutput.current());
138 aOutput.newLine();
140 aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_ANOVA_LABEL_F));
141 aOutput.nextColumn();
142 aTemplate.setTemplate("=%VAR1_VARIANCE% / %VAR2_VARIANCE%");
143 aOutput.writeFormula(aTemplate.getTemplate());
144 aTemplate.autoReplaceAddress("%F_VALUE%", aOutput.current());
145 aOutput.newLine();
147 aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_FTEST_P_RIGHT_TAIL));
148 aOutput.nextColumn();
149 aTemplate.setTemplate("=FDIST(%F_VALUE%; %VAR1_DEGREE_OF_FREEDOM%; %VAR2_DEGREE_OF_FREEDOM%)");
150 aOutput.writeFormula(aTemplate.getTemplate());
151 aTemplate.autoReplaceAddress("%P_RIGHT_TAIL_VALUE%", aOutput.current());
152 aOutput.newLine();
154 aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_FTEST_F_CRITICAL_RIGHT_TAIL));
155 aOutput.nextColumn();
156 aTemplate.setTemplate("=FINV(%ALPHA%; %VAR1_DEGREE_OF_FREEDOM%; %VAR2_DEGREE_OF_FREEDOM%)");
157 aOutput.writeFormula(aTemplate.getTemplate());
158 aOutput.newLine();
160 aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_FTEST_P_LEFT_TAIL));
161 aOutput.nextColumn();
162 aTemplate.setTemplate("=1 - %P_RIGHT_TAIL_VALUE%");
163 aOutput.writeFormula(aTemplate.getTemplate());
164 aTemplate.autoReplaceAddress("%P_LEFT_TAIL_VALUE%", aOutput.current());
165 aOutput.newLine();
167 aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_FTEST_F_CRITICAL_LEFT_TAIL));
168 aOutput.nextColumn();
169 aTemplate.setTemplate("=FINV(1-%ALPHA%; %VAR1_DEGREE_OF_FREEDOM%; %VAR2_DEGREE_OF_FREEDOM%)");
170 aOutput.writeFormula(aTemplate.getTemplate());
171 aOutput.newLine();
173 aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_FTEST_P_TWO_TAIL));
174 aOutput.nextColumn();
175 aTemplate.setTemplate("=2*MIN(%P_RIGHT_TAIL_VALUE%; %P_LEFT_TAIL_VALUE%)");
176 aOutput.writeFormula(aTemplate.getTemplate());
177 aOutput.newLine();
179 aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_FTEST_F_CRITICAL_TWO_TAIL));
180 aOutput.nextColumn();
181 aTemplate.setTemplate("=FINV(1-(%ALPHA%/2); %VAR1_DEGREE_OF_FREEDOM%; %VAR2_DEGREE_OF_FREEDOM%)");
182 aOutput.writeFormula(aTemplate.getTemplate());
183 aOutput.nextColumn();
184 aTemplate.setTemplate("=FINV(%ALPHA%/2; %VAR1_DEGREE_OF_FREEDOM%; %VAR2_DEGREE_OF_FREEDOM%)");
185 aOutput.writeFormula(aTemplate.getTemplate());
187 return ScRange(aOutput.mMinimumAddress, aOutput.mMaximumAddress);
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */