LCOV - code coverage report
Current view: top level - sc/source/ui/StatisticsDialogs - DescriptiveStatisticsDialog.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 3 47 6.4 %
Date: 2014-11-03 Functions: 2 8 25.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  */
      10             : 
      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>
      16             : 
      17             : #include "formulacell.hxx"
      18             : #include "rangelst.hxx"
      19             : #include "scitems.hxx"
      20             : #include "docsh.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"
      28             : 
      29             : #include "DescriptiveStatisticsDialog.hxx"
      30             : 
      31             : namespace
      32             : {
      33             : 
      34             : struct StatisticCalculation {
      35             :     sal_Int16   aCalculationNameId;
      36             :     const char* aFormula;
      37             : };
      38             : 
      39             : static const StatisticCalculation lclCalcDefinitions[] =
      40             : {
      41             :     { STRID_CALC_MEAN,           "=AVERAGE(%RANGE%)" },
      42             :     { STRID_CALC_STD_ERROR,      "=SQRT(VAR(%RANGE%)/COUNT(%RANGE%))"},
      43             :     { STRID_CALC_MODE,           "=MODE(%RANGE%)"},
      44             :     { STRID_CALC_MEDIAN,         "=MEDIAN(%RANGE%)"},
      45             :     { STRID_CALC_VARIANCE,       "=VAR(%RANGE%)"},
      46             :     { STRID_CALC_STD_DEVIATION,  "=STDEV(%RANGE%)"},
      47             :     { STRID_CALC_KURTOSIS,       "=KURT(%RANGE%)"},
      48             :     { STRID_CALC_SKEWNESS,       "=SKEW(%RANGE%)"},
      49             :     { STRID_CALC_RANGE,          "=MAX(%RANGE%)-MIN(%RANGE%)"},
      50             :     { STRID_CALC_MIN,            "=MIN(%RANGE%)"},
      51             :     { STRID_CALC_MAX,            "=MAX(%RANGE%)"},
      52             :     { STRID_CALC_SUM,            "=SUM(%RANGE%)"},
      53             :     { STRID_CALC_COUNT,          "=COUNT(%RANGE%)" },
      54             :     { 0,                         NULL }
      55             : };
      56             : 
      57          76 : static const OUString strWildcardRange("%RANGE%");
      58          76 : static const OUString strWildcardNumber("%NUMBER%");
      59             : 
      60             : }
      61             : 
      62           0 : ScDescriptiveStatisticsDialog::ScDescriptiveStatisticsDialog(
      63             :                     SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow,
      64             :                     vcl::Window* pParent, ScViewData* pViewData ) :
      65             :     ScStatisticsInputOutputDialog(
      66             :             pSfxBindings, pChildWindow, pParent, pViewData,
      67           0 :             "DescriptiveStatisticsDialog", "modules/scalc/ui/descriptivestatisticsdialog.ui" )
      68           0 : {}
      69             : 
      70           0 : ScDescriptiveStatisticsDialog::~ScDescriptiveStatisticsDialog()
      71           0 : {}
      72             : 
      73           0 : bool ScDescriptiveStatisticsDialog::Close()
      74             : {
      75           0 :     return DoClose( ScDescriptiveStatisticsDialogWrapper::GetChildWindowId() );
      76             : }
      77             : 
      78           0 : sal_Int16 ScDescriptiveStatisticsDialog::GetUndoNameId()
      79             : {
      80           0 :     return STR_DESCRIPTIVE_STATISTICS_UNDO_NAME;
      81             : }
      82             : 
      83           0 : ScRange ScDescriptiveStatisticsDialog::ApplyOutput(ScDocShell* pDocShell)
      84             : {
      85             :     AddressWalkerWriter aOutput(mOutputAddress, pDocShell, mDocument,
      86           0 :             formula::FormulaGrammar::mergeToGrammar( formula::FormulaGrammar::GRAM_ENGLISH, mAddressDetails.eConv));
      87           0 :     FormulaTemplate aTemplate(mDocument);
      88             : 
      89           0 :     boost::scoped_ptr<DataRangeIterator> pIterator;
      90           0 :     if (mGroupedBy == BY_COLUMN)
      91           0 :         pIterator.reset(new DataRangeByColumnIterator(mInputRange));
      92             :     else
      93           0 :         pIterator.reset(new DataRangeByRowIterator(mInputRange));
      94             : 
      95           0 :     aOutput.nextColumn();
      96             : 
      97             :     // Use explicit sheet name in case the input and output are on different sheets.
      98           0 :     bool b3DAddress = mInputRange.aStart.Tab() != mOutputAddress.Tab();
      99             : 
     100             :     // Write column/row labels
     101           0 :     for( ; pIterator->hasNext(); pIterator->next() )
     102             :     {
     103           0 :         if (mGroupedBy == BY_COLUMN)
     104           0 :             aTemplate.setTemplate(SC_STRLOAD(RID_STATISTICS_DLGS, STR_COLUMN_LABEL_TEMPLATE));
     105             :         else
     106           0 :             aTemplate.setTemplate(SC_STRLOAD(RID_STATISTICS_DLGS, STR_ROW_LABEL_TEMPLATE));
     107             : 
     108           0 :         aTemplate.applyNumber(strWildcardNumber, pIterator->index() + 1);
     109           0 :         aOutput.writeBoldString(aTemplate.getTemplate());
     110           0 :         aOutput.nextColumn();
     111             :     }
     112           0 :     aOutput.nextRow();
     113           0 :     aOutput.resetColumn();
     114           0 :     aOutput.push();
     115             : 
     116             :     // Write calculation labels
     117           0 :     for(sal_Int32 i = 0; lclCalcDefinitions[i].aFormula != NULL; i++)
     118             :     {
     119           0 :         OUString aLabel(SC_STRLOAD(RID_STATISTICS_DLGS, lclCalcDefinitions[i].aCalculationNameId));
     120           0 :         aOutput.writeString(aLabel);
     121           0 :         aOutput.nextRow();
     122           0 :     }
     123           0 :     aOutput.nextColumn();
     124             : 
     125           0 :     pIterator->reset();
     126             : 
     127           0 :     for( ; pIterator->hasNext(); pIterator->next() )
     128             :     {
     129           0 :         aOutput.resetRow();
     130             : 
     131           0 :         for(sal_Int32 i = 0; lclCalcDefinitions[i].aFormula != NULL; i++)
     132             :         {
     133           0 :             aTemplate.setTemplate(lclCalcDefinitions[i].aFormula);
     134           0 :             aTemplate.applyRange(strWildcardRange, pIterator->get(), b3DAddress);
     135           0 :             aOutput.writeFormula(aTemplate.getTemplate());
     136           0 :             aOutput.nextRow();
     137             :         }
     138           0 :         aOutput.nextColumn();
     139             :     }
     140             : 
     141           0 :     return ScRange(aOutput.mMinimumAddress, aOutput.mMaximumAddress);
     142         228 : }
     143             : 
     144             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10