1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
13 #include <reffact.hxx>
14 #include <TableFillingAndNavigationTools.hxx>
15 #include <FTestDialog.hxx>
16 #include <scresid.hxx>
17 #include <strings.hrc>
19 ScFTestDialog::ScFTestDialog(
20 SfxBindings
* pSfxBindings
, SfxChildWindow
* pChildWindow
,
21 weld::Window
* pParent
, ScViewData
& rViewData
) :
22 ScStatisticsTwoVariableDialog(
23 pSfxBindings
, pChildWindow
, pParent
, rViewData
,
24 u
"modules/scalc/ui/ttestdialog.ui"_ustr
, u
"TTestDialog"_ustr
)
26 m_xDialog
->set_title(ScResId(STR_FTEST
));
29 ScFTestDialog::~ScFTestDialog()
32 void ScFTestDialog::Close()
34 DoClose( ScFTestDialogWrapper::GetChildWindowId() );
37 TranslateId
ScFTestDialog::GetUndoNameId()
39 return STR_FTEST_UNDO_NAME
;
42 ScRange
ScFTestDialog::ApplyOutput(ScDocShell
* pDocShell
)
44 AddressWalkerWriter
aOutput(mOutputAddress
, pDocShell
, mDocument
,
45 formula::FormulaGrammar::mergeToGrammar(formula::FormulaGrammar::GRAM_ENGLISH
, mAddressDetails
.eConv
));
46 FormulaTemplate
aTemplate(&mDocument
);
48 std::unique_ptr
<DataRangeIterator
> pVariable1Iterator
;
49 if (mGroupedBy
== BY_COLUMN
)
50 pVariable1Iterator
.reset(new DataRangeByColumnIterator(mVariable1Range
));
52 pVariable1Iterator
.reset(new DataRangeByRowIterator(mVariable1Range
));
54 std::unique_ptr
<DataRangeIterator
> pVariable2Iterator
;
55 if (mGroupedBy
== BY_COLUMN
)
56 pVariable2Iterator
.reset(new DataRangeByColumnIterator(mVariable2Range
));
58 pVariable2Iterator
.reset(new DataRangeByRowIterator(mVariable2Range
));
60 aTemplate
.autoReplaceRange(u
"%VARIABLE1_RANGE%"_ustr
, pVariable1Iterator
->get());
61 aTemplate
.autoReplaceRange(u
"%VARIABLE2_RANGE%"_ustr
, pVariable2Iterator
->get());
63 aOutput
.writeBoldString(ScResId(STR_FTEST_UNDO_NAME
));
67 aOutput
.writeString(ScResId(STR_LABEL_ALPHA
));
69 aOutput
.writeValue(0.05);
70 aTemplate
.autoReplaceAddress(u
"%ALPHA%"_ustr
, aOutput
.current());
74 aOutput
.writeBoldString(ScResId(STR_VARIABLE_1_LABEL
));
76 aOutput
.writeBoldString(ScResId(STR_VARIABLE_2_LABEL
));
79 aOutput
.writeString(ScResId(STRID_CALC_MEAN
));
81 aTemplate
.setTemplate("=AVERAGE(%VARIABLE1_RANGE%)");
82 aOutput
.writeFormula(aTemplate
.getTemplate());
84 aTemplate
.setTemplate("=AVERAGE(%VARIABLE2_RANGE%)");
85 aOutput
.writeFormula(aTemplate
.getTemplate());
88 aOutput
.writeString(ScResId(STRID_CALC_VARIANCE
));
90 aTemplate
.setTemplate("=VAR(%VARIABLE1_RANGE%)");
91 aOutput
.writeFormula(aTemplate
.getTemplate());
92 aTemplate
.autoReplaceAddress(u
"%VARIABLE1_VARIANCE%"_ustr
, aOutput
.current());
94 aTemplate
.setTemplate("=VAR(%VARIABLE2_RANGE%)");
95 aOutput
.writeFormula(aTemplate
.getTemplate());
96 aTemplate
.autoReplaceAddress(u
"%VARIABLE2_VARIANCE%"_ustr
, aOutput
.current());
99 aOutput
.writeString(ScResId(STR_OBSERVATIONS_LABEL
));
100 aOutput
.nextColumn();
101 aTemplate
.setTemplate("=COUNT(%VARIABLE1_RANGE%)");
102 aOutput
.writeFormula(aTemplate
.getTemplate());
103 aTemplate
.autoReplaceAddress(u
"%VARIABLE1_OBSERVATIONS%"_ustr
, aOutput
.current());
104 aOutput
.nextColumn();
105 aTemplate
.setTemplate("=COUNT(%VARIABLE2_RANGE%)");
106 aOutput
.writeFormula(aTemplate
.getTemplate());
107 aTemplate
.autoReplaceAddress(u
"%VARIABLE2_OBSERVATIONS%"_ustr
, aOutput
.current());
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(u
"%VARIABLE1_DEGREE_OF_FREEDOM%"_ustr
, aOutput
.current());
115 aOutput
.nextColumn();
116 aTemplate
.setTemplate("=%VARIABLE2_OBSERVATIONS% - 1");
117 aOutput
.writeFormula(aTemplate
.getTemplate());
118 aTemplate
.autoReplaceAddress(u
"%VARIABLE2_DEGREE_OF_FREEDOM%"_ustr
, aOutput
.current());
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(u
"%F_VALUE%"_ustr
, aOutput
.current());
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(u
"%P_RIGHT_TAIL_VALUE%"_ustr
, aOutput
.current());
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());
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(u
"%P_LEFT_TAIL_VALUE%"_ustr
, aOutput
.current());
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());
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());
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());
168 return ScRange(aOutput
.mMinimumAddress
, aOutput
.mMaximumAddress
);
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */