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 <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"
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 "ChiSquareTestDialog.hxx"
31 ScChiSquareTestDialog::ScChiSquareTestDialog(
32 SfxBindings
* pSfxBindings
, SfxChildWindow
* pChildWindow
,
33 vcl::Window
* pParent
, ScViewData
* pViewData
) :
34 ScStatisticsInputOutputDialog(
35 pSfxBindings
, pChildWindow
, pParent
, pViewData
,
36 "ChiSquareTestDialog", "modules/scalc/ui/chisquaretestdialog.ui" )
38 SetText(SC_STRLOAD(RID_STATISTICS_DLGS
, STR_CHI_SQUARE_TEST
));
41 ScChiSquareTestDialog::~ScChiSquareTestDialog()
44 bool ScChiSquareTestDialog::Close()
46 return DoClose(ScChiSquareTestDialogWrapper::GetChildWindowId());
49 sal_Int16
ScChiSquareTestDialog::GetUndoNameId()
51 return STR_CHI_SQUARE_TEST
;
54 ScRange
ScChiSquareTestDialog::ApplyOutput(ScDocShell
* pDocShell
)
56 AddressWalkerWriter
aOutput(mOutputAddress
, pDocShell
, mDocument
,
57 formula::FormulaGrammar::mergeToGrammar( formula::FormulaGrammar::GRAM_ENGLISH
, mAddressDetails
.eConv
));
58 FormulaTemplate
aTemplate(mDocument
);
60 aTemplate
.autoReplaceRange("%RANGE%", mInputRange
);
62 aOutput
.writeBoldString(SC_STRLOAD(RID_STATISTICS_DLGS
, STR_CHI_SQUARE_TEST
));
66 aOutput
.writeString(SC_STRLOAD(RID_STATISTICS_DLGS
, STR_LABEL_ALPHA
));
68 aOutput
.writeValue(0.05);
69 aTemplate
.autoReplaceAddress("%ALPHA%", aOutput
.current());
73 aOutput
.writeString(SC_STRLOAD(RID_STATISTICS_DLGS
, STR_DEGREES_OF_FREEDOM_LABEL
));
75 aTemplate
.setTemplate("=(COLUMNS(%RANGE%) - 1) * (ROWS(%RANGE%) - 1)");
76 aTemplate
.autoReplaceAddress("%DEGREES_OF_FREEDOM%", aOutput
.current());
77 aOutput
.writeFormula(aTemplate
.getTemplate());
81 aOutput
.writeString(SC_STRLOAD(RID_STATISTICS_DLGS
, STR_P_VALUE_LABEL
));
83 aTemplate
.setTemplate("=CHITEST(%RANGE%; MMULT(MMULT(%RANGE%;TRANSPOSE(IF(COLUMN(%RANGE%))));MMULT(TRANSPOSE(IF(ROW(%RANGE%)));%RANGE%)) / SUM(%RANGE%))");
84 aTemplate
.autoReplaceAddress("%P_VALUE%", aOutput
.current());
85 aOutput
.writeFormula(aTemplate
.getTemplate());
89 aOutput
.writeString(SC_STRLOAD(RID_STATISTICS_DLGS
, STR_TEST_STATISTIC_LABEL
));
91 aTemplate
.setTemplate("=CHIINV(%P_VALUE%; %DEGREES_OF_FREEDOM%)");
92 aOutput
.writeFormula(aTemplate
.getTemplate());
96 aOutput
.writeString(SC_STRLOAD(RID_STATISTICS_DLGS
, STR_CRITICAL_VALUE_LABEL
));
98 aTemplate
.setTemplate("=CHIINV(%ALPHA%; %DEGREES_OF_FREEDOM%)");
99 aOutput
.writeFormula(aTemplate
.getTemplate());
102 return ScRange(aOutput
.mMinimumAddress
, aOutput
.mMaximumAddress
);
105 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */