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/.
11 #include <reffact.hxx>
12 #include <TableFillingAndNavigationTools.hxx>
13 #include <ChiSquareTestDialog.hxx>
14 #include <scresid.hxx>
15 #include <strings.hrc>
17 ScChiSquareTestDialog::ScChiSquareTestDialog(
18 SfxBindings
* pSfxBindings
, SfxChildWindow
* pChildWindow
,
19 weld::Window
* pParent
, ScViewData
& rViewData
) :
20 ScStatisticsInputOutputDialog(
21 pSfxBindings
, pChildWindow
, pParent
, rViewData
,
22 u
"modules/scalc/ui/chisquaretestdialog.ui"_ustr
, u
"ChiSquareTestDialog"_ustr
)
24 m_xDialog
->set_title(ScResId(STR_CHI_SQUARE_TEST
));
27 ScChiSquareTestDialog::~ScChiSquareTestDialog()
30 void ScChiSquareTestDialog::Close()
32 DoClose(ScChiSquareTestDialogWrapper::GetChildWindowId());
35 TranslateId
ScChiSquareTestDialog::GetUndoNameId()
37 return STR_CHI_SQUARE_TEST
;
40 ScRange
ScChiSquareTestDialog::ApplyOutput(ScDocShell
* pDocShell
)
42 AddressWalkerWriter
aOutput(mOutputAddress
, pDocShell
, mDocument
,
43 formula::FormulaGrammar::mergeToGrammar( formula::FormulaGrammar::GRAM_ENGLISH
, mAddressDetails
.eConv
));
44 FormulaTemplate
aTemplate(&mDocument
);
46 aTemplate
.autoReplaceRange(u
"%RANGE%"_ustr
, mInputRange
);
48 aOutput
.writeBoldString(ScResId(STR_CHI_SQUARE_TEST
));
52 aOutput
.writeString(ScResId(STR_LABEL_ALPHA
));
54 aOutput
.writeValue(0.05);
55 aTemplate
.autoReplaceAddress(u
"%ALPHA%"_ustr
, aOutput
.current());
59 aOutput
.writeString(ScResId(STR_DEGREES_OF_FREEDOM_LABEL
));
61 aTemplate
.setTemplate("=(COLUMNS(%RANGE%) - 1) * (ROWS(%RANGE%) - 1)");
62 aTemplate
.autoReplaceAddress(u
"%DEGREES_OF_FREEDOM%"_ustr
, aOutput
.current());
63 aOutput
.writeFormula(aTemplate
.getTemplate());
67 aOutput
.writeString(ScResId(STR_P_VALUE_LABEL
));
69 aTemplate
.setTemplate("=CHITEST(%RANGE%; MMULT(MMULT(%RANGE%;TRANSPOSE(IF(COLUMN(%RANGE%))));MMULT(TRANSPOSE(IF(ROW(%RANGE%)));%RANGE%)) / SUM(%RANGE%))");
70 aTemplate
.autoReplaceAddress(u
"%P_VALUE%"_ustr
, aOutput
.current());
71 aOutput
.writeFormula(aTemplate
.getTemplate());
75 aOutput
.writeString(ScResId(STR_TEST_STATISTIC_LABEL
));
77 aTemplate
.setTemplate("=CHIINV(%P_VALUE%; %DEGREES_OF_FREEDOM%)");
78 aOutput
.writeFormula(aTemplate
.getTemplate());
82 aOutput
.writeString(ScResId(STR_CRITICAL_VALUE_LABEL
));
84 aTemplate
.setTemplate("=CHIINV(%ALPHA%; %DEGREES_OF_FREEDOM%)");
85 aOutput
.writeFormula(aTemplate
.getTemplate());
88 return ScRange(aOutput
.mMinimumAddress
, aOutput
.mMaximumAddress
);
91 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */