Files
libreoffice/sc/source/ui/StatisticsDialogs/DescriptiveStatisticsDialog.cxx

142 lines
4.5 KiB
C++
Raw Normal View History

/* -*- 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 "random.hxx"
#include "docfunc.hxx"
#include "StatisticsDialogs.hrc"
#include "TableFillingAndNavigationTools.hxx"
#include "DescriptiveStatisticsDialog.hxx"
namespace
{
struct StatisticCalculation {
sal_Int16 aCalculationNameId;
const char* aFormula;
};
static const StatisticCalculation lclCalcDefinitions[] =
{
{ STRID_CALC_MEAN, "=AVERAGE(%RANGE%)" },
{ STRID_CALC_STD_ERROR, "=SQRT(VAR(%RANGE%)/COUNT(%RANGE%))"},
{ STRID_CALC_MODE, "=MODE(%RANGE%)"},
{ STRID_CALC_MEDIAN, "=MEDIAN(%RANGE%)"},
{ STRID_CALC_VARIANCE, "=VAR(%RANGE%)"},
{ STRID_CALC_STD_DEVIATION, "=STDEV(%RANGE%)"},
{ STRID_CALC_KURTOSIS, "=KURT(%RANGE%)"},
{ STRID_CALC_SKEWNESS, "=SKEW(%RANGE%)"},
{ STRID_CALC_RANGE, "=MAX(%RANGE%)-MIN(%RANGE%)"},
{ STRID_CALC_MIN, "=MIN(%RANGE%)"},
{ STRID_CALC_MAX, "=MAX(%RANGE%)"},
{ STRID_CALC_SUM, "=SUM(%RANGE%)"},
{ STRID_CALC_COUNT, "=COUNT(%RANGE%)" },
{ 0, NULL }
};
static const OUString strWildcardRange("%RANGE%");
static const OUString strWildcardNumber("%NUMBER%");
static const OUString strColumnLabelTemplate("Column %NUMBER%");
static const OUString strRowLabelTemplate("Row %NUMBER%");
}
ScDescriptiveStatisticsDialog::ScDescriptiveStatisticsDialog(
SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow,
Window* pParent, ScViewData* pViewData ) :
ScStatisticsInputOutputDialog(
pSfxBindings, pChildWindow, pParent, pViewData,
"DescriptiveStatisticsDialog", "modules/scalc/ui/descriptivestatisticsdialog.ui" )
{}
ScDescriptiveStatisticsDialog::~ScDescriptiveStatisticsDialog()
{}
sal_Bool ScDescriptiveStatisticsDialog::Close()
{
return DoClose( ScDescriptiveStatisticsDialogWrapper::GetChildWindowId() );
}
sal_Int16 ScDescriptiveStatisticsDialog::GetUndoNameId()
{
return STR_DESCRIPTIVE_STATISTICS_UNDO_NAME;
}
ScRange ScDescriptiveStatisticsDialog::ApplyOutput(ScDocShell* pDocShell)
{
AddressWalkerWriter aOutput(mOutputAddress, pDocShell, mDocument);
FormulaTemplate aTemplate(mDocument, mAddressDetails);
boost::scoped_ptr<DataRangeIterator> pIterator;
if (mGroupedBy == BY_COLUMN)
pIterator.reset(new DataRangeByColumnIterator(mInputRange));
else
pIterator.reset(new DataRangeByRowIterator(mInputRange));
aOutput.nextColumn();
// Write column/row labels
for( ; pIterator->hasNext(); pIterator->next() )
{
if (mGroupedBy == BY_COLUMN)
aTemplate.setTemplate(strColumnLabelTemplate);
else
aTemplate.setTemplate(strRowLabelTemplate);
aTemplate.applyNumber(strWildcardNumber, pIterator->index() + 1);
aOutput.writeBoldString(aTemplate.getTemplate());
aOutput.nextColumn();
}
aOutput.nextRow();
aOutput.resetColumn();
aOutput.push();
// Write calculation labels
for(sal_Int32 i = 0; lclCalcDefinitions[i].aFormula != NULL; i++)
{
OUString aLabel(SC_STRLOAD(RID_STATISTICS_DLGS, lclCalcDefinitions[i].aCalculationNameId));
aOutput.writeString(aLabel);
aOutput.nextRow();
}
aOutput.nextColumn();
pIterator->reset();
for( ; pIterator->hasNext(); pIterator->next() )
{
aOutput.resetRow();
for(sal_Int32 i = 0; lclCalcDefinitions[i].aFormula != NULL; i++)
{
aTemplate.setTemplate(lclCalcDefinitions[i].aFormula);
aTemplate.applyRange(strWildcardRange, pIterator->get());
aOutput.writeFormula(aTemplate.getTemplate());
aOutput.nextRow();
}
aOutput.nextColumn();
}
return ScRange(aOutput.mMinimumAddress, aOutput.mMaximumAddress);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */