tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / StatisticsDialogs / ZTestDialog.cxx
blob627c1cf65006ce6ead2181d1433a07fa628dcca4
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 <ZTestDialog.hxx>
16 #include <scresid.hxx>
17 #include <strings.hrc>
19 ScZTestDialog::ScZTestDialog(
20 SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow,
21 weld::Window* pParent, ScViewData& rViewData ) :
22 ScStatisticsTwoVariableDialog(
23 pSfxBindings, pChildWindow, pParent, rViewData,
24 u"modules/scalc/ui/ztestdialog.ui"_ustr, u"ZTestDialog"_ustr)
26 m_xDialog->set_title(ScResId(STR_ZTEST));
29 ScZTestDialog::~ScZTestDialog()
32 void ScZTestDialog::Close()
34 DoClose( ScZTestDialogWrapper::GetChildWindowId() );
37 TranslateId ScZTestDialog::GetUndoNameId()
39 return STR_ZTEST_UNDO_NAME;
42 ScRange ScZTestDialog::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));
51 else
52 pVariable1Iterator.reset(new DataRangeByRowIterator(mVariable1Range));
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));
60 aTemplate.autoReplaceRange(u"%VARIABLE1_RANGE%"_ustr, pVariable1Iterator->get());
61 aTemplate.autoReplaceRange(u"%VARIABLE2_RANGE%"_ustr, pVariable2Iterator->get());
63 aOutput.writeBoldString(ScResId(STR_ZTEST));
64 aOutput.newLine();
66 // Alpha
67 aOutput.writeString(ScResId(STR_LABEL_ALPHA));
68 aOutput.nextColumn();
69 aOutput.writeValue(0.05);
70 aTemplate.autoReplaceAddress(u"%ALPHA%"_ustr, aOutput.current());
71 aOutput.newLine();
73 // Hypothesized mean difference
74 aOutput.writeString(ScResId(STR_HYPOTHESIZED_MEAN_DIFFERENCE_LABEL));
75 aOutput.nextColumn();
76 aOutput.writeValue(0);
77 aTemplate.autoReplaceAddress(u"%HYPOTHESIZED_MEAN_DIFFERENCE%"_ustr, aOutput.current());
78 aOutput.newLine();
80 // Variable Label
81 aOutput.nextColumn();
82 aOutput.writeBoldString(ScResId(STR_VARIABLE_1_LABEL));
83 aOutput.nextColumn();
84 aOutput.writeBoldString(ScResId(STR_VARIABLE_2_LABEL));
85 aOutput.newLine();
87 // Known Variance
88 aOutput.writeString(ScResId(STR_ZTEST_KNOWN_VARIANCE));
89 aOutput.nextColumn();
90 aOutput.writeValue(0);
91 aTemplate.autoReplaceAddress(u"%KNOWN_VARIANCE_VARIABLE1%"_ustr, aOutput.current());
92 aOutput.nextColumn();
93 aOutput.writeValue(0);
94 aTemplate.autoReplaceAddress(u"%KNOWN_VARIANCE_VARIABLE2%"_ustr, aOutput.current());
95 aOutput.newLine();
97 // Mean
98 aOutput.writeString(ScResId(STRID_CALC_MEAN));
99 aOutput.nextColumn();
100 aTemplate.setTemplate("=AVERAGE(%VARIABLE1_RANGE%)");
101 aTemplate.autoReplaceAddress(u"%MEAN_VARIABLE1%"_ustr, aOutput.current());
102 aOutput.writeFormula(aTemplate.getTemplate());
103 aOutput.nextColumn();
104 aTemplate.setTemplate("=AVERAGE(%VARIABLE2_RANGE%)");
105 aTemplate.autoReplaceAddress(u"%MEAN_VARIABLE2%"_ustr, aOutput.current());
106 aOutput.writeFormula(aTemplate.getTemplate());
107 aOutput.newLine();
109 // Observations
110 aOutput.writeString(ScResId(STR_OBSERVATIONS_LABEL));
111 aOutput.nextColumn();
112 aTemplate.setTemplate("=COUNT(%VARIABLE1_RANGE%)");
113 aOutput.writeFormula(aTemplate.getTemplate());
114 aTemplate.autoReplaceAddress(u"%OBSERVATION_VARIABLE1%"_ustr, aOutput.current());
115 aOutput.nextColumn();
116 aTemplate.setTemplate("=COUNT(%VARIABLE2_RANGE%)");
117 aOutput.writeFormula(aTemplate.getTemplate());
118 aTemplate.autoReplaceAddress(u"%OBSERVATION_VARIABLE2%"_ustr, aOutput.current());
119 aOutput.newLine();
121 // Observed mean difference
122 aOutput.writeString(ScResId(STR_OBSERVED_MEAN_DIFFERENCE_LABEL));
123 aOutput.nextColumn();
124 aTemplate.setTemplate("=%MEAN_VARIABLE1% - %MEAN_VARIABLE2%");
125 aOutput.writeMatrixFormula(aTemplate.getTemplate());
126 aTemplate.autoReplaceAddress(u"%OBSERVED_MEAN_DIFFERENCE%"_ustr, aOutput.current());
127 aOutput.newLine();
129 // z
130 aOutput.writeString(ScResId(STR_ZTEST_Z_VALUE));
131 aOutput.nextColumn();
132 aTemplate.setTemplate("=(%OBSERVED_MEAN_DIFFERENCE% - %HYPOTHESIZED_MEAN_DIFFERENCE%) / SQRT( %KNOWN_VARIANCE_VARIABLE1% / %OBSERVATION_VARIABLE1% + %KNOWN_VARIANCE_VARIABLE2% / %OBSERVATION_VARIABLE2% )");
133 aOutput.writeFormula(aTemplate.getTemplate());
134 aTemplate.autoReplaceAddress(u"%Z_STAT%"_ustr, aOutput.current());
135 aOutput.newLine();
137 // P one-tail
138 aOutput.writeString(ScResId(STR_ZTEST_P_ONE_TAIL));
139 aOutput.nextColumn();
140 aTemplate.setTemplate("=1 - NORMSDIST(ABS(%Z_STAT%))");
141 aOutput.writeFormula(aTemplate.getTemplate());
142 aOutput.newLine();
144 // z critical one-tail
145 aOutput.writeString(ScResId(STR_ZTEST_Z_CRITICAL_ONE_TAIL));
146 aOutput.nextColumn();
147 aTemplate.setTemplate("=-NORMSINV(%ALPHA%)");
148 aOutput.writeFormula(aTemplate.getTemplate());
149 aOutput.newLine();
151 // P two-tail
152 aOutput.writeString(ScResId(STR_ZTEST_P_TWO_TAIL));
153 aOutput.nextColumn();
154 aTemplate.setTemplate("=2 * NORMSDIST(-ABS(%Z_STAT%))");
155 aOutput.writeFormula(aTemplate.getTemplate());
156 aOutput.newLine();
158 // z critical two-tail
159 aOutput.writeString(ScResId(STR_ZTEST_Z_CRITICAL_TWO_TAIL));
160 aOutput.nextColumn();
161 aTemplate.setTemplate("=-NORMSINV(%ALPHA%/2)");
162 aOutput.writeFormula(aTemplate.getTemplate());
164 return ScRange(aOutput.mMinimumAddress, aOutput.mMaximumAddress);
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */