summaryrefslogtreecommitdiff
path: root/sc/source/ui
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.com>2014-11-18 10:13:50 +0100
committerTomaž Vajngerl <tomaz.vajngerl@collabora.com>2014-11-18 10:16:46 +0100
commitc080641d2f45c6b455d6a60836f53d054853fc53 (patch)
tree5c838f7d0041a36d0c5566d5e400894650fd0474 /sc/source/ui
parent5c339be474c93c0bf42c593b48fd683ea4614250 (diff)
fdo#76868 Add chi-square test Statistics Dialog
Change-Id: I35c115a1f1cb733a0d6841596d8baf2e5ade4a1d
Diffstat (limited to 'sc/source/ui')
-rw-r--r--sc/source/ui/StatisticsDialogs/ChiSquareTestDialog.cxx97
-rw-r--r--sc/source/ui/app/scdll.cxx1
-rw-r--r--sc/source/ui/inc/ChiSquareTestDialog.hxx34
-rw-r--r--sc/source/ui/inc/reffact.hxx7
-rw-r--r--sc/source/ui/view/cellsh1.cxx10
-rw-r--r--sc/source/ui/view/tabvwsh.cxx1
-rw-r--r--sc/source/ui/view/tabvwshc.cxx7
7 files changed, 157 insertions, 0 deletions
diff --git a/sc/source/ui/StatisticsDialogs/ChiSquareTestDialog.cxx b/sc/source/ui/StatisticsDialogs/ChiSquareTestDialog.cxx
new file mode 100644
index 000000000000..f4d092ab7989
--- /dev/null
+++ b/sc/source/ui/StatisticsDialogs/ChiSquareTestDialog.cxx
@@ -0,0 +1,97 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#include <sfx2/dispatch.hxx>
+#include <svl/zforlist.hxx>
+#include <svl/undo.hxx>
+#include <boost/random.hpp>
+#include <boost/scoped_ptr.hpp>
+
+#include "formulacell.hxx"
+#include "rangelst.hxx"
+#include "scitems.hxx"
+#include "docsh.hxx"
+#include "document.hxx"
+#include "uiitems.hxx"
+#include "reffact.hxx"
+#include "strload.hxx"
+#include "docfunc.hxx"
+#include "StatisticsDialogs.hrc"
+#include "TableFillingAndNavigationTools.hxx"
+
+#include "ChiSquareTestDialog.hxx"
+
+ScChiSquareTestDialog::ScChiSquareTestDialog(
+ SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow,
+ vcl::Window* pParent, ScViewData* pViewData ) :
+ ScStatisticsInputOutputDialog(
+ pSfxBindings, pChildWindow, pParent, pViewData,
+ "ChiSquareTestDialog", "modules/scalc/ui/chisquaretestdialog.ui" )
+{
+ SetText(SC_STRLOAD(RID_STATISTICS_DLGS, STR_ZTEST));
+}
+
+ScChiSquareTestDialog::~ScChiSquareTestDialog()
+{}
+
+bool ScChiSquareTestDialog::Close()
+{
+ return DoClose(ScChiSquareTestDialogWrapper::GetChildWindowId());
+}
+
+sal_Int16 ScChiSquareTestDialog::GetUndoNameId()
+{
+ return STR_ZTEST_UNDO_NAME;
+}
+
+ScRange ScChiSquareTestDialog::ApplyOutput(ScDocShell* pDocShell)
+{
+ AddressWalkerWriter aOutput(mOutputAddress, pDocShell, mDocument,
+ formula::FormulaGrammar::mergeToGrammar( formula::FormulaGrammar::GRAM_ENGLISH, mAddressDetails.eConv));
+ FormulaTemplate aTemplate(mDocument);
+
+ aTemplate.autoReplaceRange("%RANGE%", mInputRange);
+
+ aOutput.writeBoldString("Independence Test (Chi-Square)");
+ aOutput.newLine();
+
+ // Alpha
+ aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_LABEL_ALPHA));
+ aOutput.nextColumn();
+ aOutput.writeValue(0.05);
+ aTemplate.autoReplaceAddress("%ALPHA%", aOutput.current());
+ aOutput.newLine();
+
+ // DF
+ aOutput.writeString("df");
+ aOutput.nextColumn();
+ aTemplate.setTemplate("=(COLUMNS(%RANGE%) - 1) * (ROWS(%RANGE%) - 1)");
+ aTemplate.autoReplaceAddress("%DEGREES_OF_FREEDOM%", aOutput.current());
+ aOutput.writeFormula(aTemplate.getTemplate());
+ aOutput.newLine();
+
+ // p Value
+ aOutput.writeString("P-Value");
+ aOutput.nextColumn();
+ aTemplate.setTemplate("=CHITEST(%RANGE%; MMULT(MMULT(%RANGE%;TRANSPOSE(IF(COLUMN(%RANGE%))));MMULT(TRANSPOSE(IF(ROW(%RANGE%)));%RANGE%)) / SUM(%RANGE%))");
+ aOutput.writeFormula(aTemplate.getTemplate());
+ aOutput.newLine();
+
+ // Critical value
+ aOutput.writeString("Critical Value");
+ aOutput.nextColumn();
+ aTemplate.setTemplate("=CHIINV(%ALPHA%; %DEGREES_OF_FREEDOM%)");
+ aOutput.writeFormula(aTemplate.getTemplate());
+ aOutput.newLine();
+
+ return ScRange(aOutput.mMinimumAddress, aOutput.mMaximumAddress);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/app/scdll.cxx b/sc/source/ui/app/scdll.cxx
index d62004964da2..2bccd1d965fe 100644
--- a/sc/source/ui/app/scdll.cxx
+++ b/sc/source/ui/app/scdll.cxx
@@ -260,6 +260,7 @@ void ScDLL::Init()
ScTTestDialogWrapper ::RegisterChildWindow(false, pMod);
ScFTestDialogWrapper ::RegisterChildWindow(false, pMod);
ScZTestDialogWrapper ::RegisterChildWindow(false, pMod);
+ ScChiSquareTestDialogWrapper ::RegisterChildWindow(false, pMod);
// First docking Window for Calc
ScFunctionChildWindow ::RegisterChildWindow(false, pMod);
diff --git a/sc/source/ui/inc/ChiSquareTestDialog.hxx b/sc/source/ui/inc/ChiSquareTestDialog.hxx
new file mode 100644
index 000000000000..199cbfa361e5
--- /dev/null
+++ b/sc/source/ui/inc/ChiSquareTestDialog.hxx
@@ -0,0 +1,34 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#ifndef INCLUDED_SC_SOURCE_UI_INC_CHISQUARETESTDIALOG_HXX
+#define INCLUDED_SC_SOURCE_UI_INC_CHISQUARETESTDIALOG_HXX
+
+#include "StatisticsInputOutputDialog.hxx"
+
+class ScChiSquareTestDialog : public ScStatisticsInputOutputDialog
+{
+public:
+ ScChiSquareTestDialog(
+ SfxBindings* pB, SfxChildWindow* pCW,
+ vcl::Window* pParent, ScViewData* pViewData );
+
+ virtual ~ScChiSquareTestDialog();
+
+ virtual bool Close() SAL_OVERRIDE;
+
+protected:
+ virtual sal_Int16 GetUndoNameId() SAL_OVERRIDE;
+ virtual ScRange ApplyOutput(ScDocShell* pDocShell) SAL_OVERRIDE;
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/inc/reffact.hxx b/sc/source/ui/inc/reffact.hxx
index 4fd3b270d631..1187db297a40 100644
--- a/sc/source/ui/inc/reffact.hxx
+++ b/sc/source/ui/inc/reffact.hxx
@@ -128,6 +128,13 @@ private:
ScZTestDialogWrapper() SAL_DELETED_FUNCTION;
};
+class ScChiSquareTestDialogWrapper :
+ public ChildWindowWrapper<SID_CHI_SQUARE_TEST_DIALOG>
+{
+private:
+ ScChiSquareTestDialogWrapper() SAL_DELETED_FUNCTION;
+};
+
class ScAcceptChgDlgWrapper: public SfxChildWindow
{
public:
diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx
index 624b77dc8e14..331a76556ebe 100644
--- a/sc/source/ui/view/cellsh1.cxx
+++ b/sc/source/ui/view/cellsh1.cxx
@@ -1002,6 +1002,16 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
}
break;
+ case SID_CHI_SQUARE_TEST_DIALOG:
+ {
+ sal_uInt16 nId = ScChiSquareTestDialogWrapper::GetChildWindowId();
+ SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
+ SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
+
+ pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
+
+ }
+ break;
case SID_SEARCH_RESULTS_DIALOG:
{
diff --git a/sc/source/ui/view/tabvwsh.cxx b/sc/source/ui/view/tabvwsh.cxx
index d07feb7bb453..027adfc8ce1d 100644
--- a/sc/source/ui/view/tabvwsh.cxx
+++ b/sc/source/ui/view/tabvwsh.cxx
@@ -96,6 +96,7 @@ void ScTabViewShell::InitInterface_Impl()
GetStaticInterface()->RegisterChildWindow(ScTTestDialogWrapper::GetChildWindowId());
GetStaticInterface()->RegisterChildWindow(ScFTestDialogWrapper::GetChildWindowId());
GetStaticInterface()->RegisterChildWindow(ScZTestDialogWrapper::GetChildWindowId());
+ GetStaticInterface()->RegisterChildWindow(ScChiSquareTestDialogWrapper::GetChildWindowId());
}
SFX_IMPL_NAMED_VIEWFACTORY( ScTabViewShell, "Default" )
diff --git a/sc/source/ui/view/tabvwshc.cxx b/sc/source/ui/view/tabvwshc.cxx
index 6621d55bc3bb..bc5cff707733 100644
--- a/sc/source/ui/view/tabvwshc.cxx
+++ b/sc/source/ui/view/tabvwshc.cxx
@@ -69,6 +69,7 @@
#include "TTestDialog.hxx"
#include "FTestDialog.hxx"
#include "ZTestDialog.hxx"
+#include "ChiSquareTestDialog.hxx"
#include "PivotLayoutDialog.hxx"
@@ -388,6 +389,12 @@ SfxModelessDialog* ScTabViewShell::CreateRefDialog(
}
break;
+ case SID_CHI_SQUARE_TEST_DIALOG:
+ {
+ pResult = new ScChiSquareTestDialog( pB, pCW, pParent, &GetViewData() );
+ }
+ break;
+
case SID_OPENDLG_OPTSOLVER:
{
ScViewData& rViewData = GetViewData();