LCOV - code coverage report
Current view: top level - sc/source/ui/StatisticsDialogs - MovingAverageDialog.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 45 2.2 %
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             : 
      15             : #include "formulacell.hxx"
      16             : #include "rangelst.hxx"
      17             : #include "scitems.hxx"
      18             : #include "docsh.hxx"
      19             : #include "document.hxx"
      20             : #include "uiitems.hxx"
      21             : #include "reffact.hxx"
      22             : #include "strload.hxx"
      23             : #include "docfunc.hxx"
      24             : #include "StatisticsDialogs.hrc"
      25             : #include "TableFillingAndNavigationTools.hxx"
      26             : 
      27             : #include "MovingAverageDialog.hxx"
      28             : 
      29           0 : ScMovingAverageDialog::ScMovingAverageDialog(
      30             :                     SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow,
      31             :                     vcl::Window* pParent, ScViewData* pViewData ) :
      32             :     ScStatisticsInputOutputDialog(
      33             :             pSfxBindings, pChildWindow, pParent, pViewData,
      34           0 :             "MovingAverageDialog", "modules/scalc/ui/movingaveragedialog.ui" )
      35             : {
      36           0 :     get(mpIntervalSpin, "interval-spin");
      37           0 : }
      38             : 
      39           0 : ScMovingAverageDialog::~ScMovingAverageDialog()
      40           0 : {}
      41             : 
      42           0 : bool ScMovingAverageDialog::Close()
      43             : {
      44           0 :     return DoClose( ScMovingAverageDialogWrapper::GetChildWindowId() );
      45             : }
      46             : 
      47           0 : sal_Int16 ScMovingAverageDialog::GetUndoNameId()
      48             : {
      49           0 :     return STR_MOVING_AVERAGE_UNDO_NAME;
      50             : }
      51             : 
      52           0 : ScRange ScMovingAverageDialog::ApplyOutput(ScDocShell* pDocShell)
      53             : {
      54             :     AddressWalkerWriter output(mOutputAddress, pDocShell, mDocument,
      55           0 :             formula::FormulaGrammar::mergeToGrammar( formula::FormulaGrammar::GRAM_ENGLISH, mAddressDetails.eConv));
      56           0 :     FormulaTemplate aTemplate(mDocument);
      57             : 
      58           0 :     boost::scoped_ptr<DataRangeIterator> pIterator;
      59           0 :     if (mGroupedBy == BY_COLUMN)
      60           0 :         pIterator.reset(new DataRangeByColumnIterator(mInputRange));
      61             :     else
      62           0 :         pIterator.reset(new DataRangeByRowIterator(mInputRange));
      63             : 
      64           0 :     sal_Int32 aIntervalSize = mpIntervalSpin->GetValue();
      65           0 :     const bool aCentral = true; //to-do add support to change this to the dialog
      66             : 
      67           0 :     for( ; pIterator->hasNext(); pIterator->next() )
      68             :     {
      69           0 :         output.resetRow();
      70             : 
      71             :         // Write label
      72           0 :         if (mGroupedBy == BY_COLUMN)
      73           0 :             aTemplate.setTemplate(SC_STRLOAD(RID_STATISTICS_DLGS, STR_COLUMN_LABEL_TEMPLATE));
      74             :         else
      75           0 :             aTemplate.setTemplate(SC_STRLOAD(RID_STATISTICS_DLGS, STR_ROW_LABEL_TEMPLATE));
      76             : 
      77           0 :         aTemplate.applyNumber("%NUMBER%", pIterator->index() + 1);
      78           0 :         output.writeBoldString(aTemplate.getTemplate());
      79           0 :         output.nextRow();
      80             : 
      81           0 :         DataCellIterator aDataCellIterator = pIterator->iterateCells();
      82             : 
      83           0 :         for (; aDataCellIterator.hasNext(); aDataCellIterator.next())
      84             :         {
      85           0 :             ScAddress aIntervalStart;
      86           0 :             ScAddress aIntervalEnd;
      87             : 
      88             :             if (aCentral)
      89             :             {
      90           0 :                 sal_Int32 aHalf = aIntervalSize / 2;
      91           0 :                 sal_Int32 aHalfRemainder = aIntervalSize % 2;
      92           0 :                 aIntervalStart = aDataCellIterator.getRelative(-aHalf);
      93           0 :                 aIntervalEnd = aDataCellIterator.getRelative(aHalf - 1 + aHalfRemainder);
      94             :             }
      95             :             else
      96             :             {
      97             :                 aIntervalStart = aDataCellIterator.getRelative(-aIntervalSize);
      98             :                 aIntervalEnd = aDataCellIterator.getRelative(0);
      99             :             }
     100             : 
     101           0 :             if(aIntervalStart.IsValid() && aIntervalEnd.IsValid())
     102             :             {
     103           0 :                 aTemplate.setTemplate("=AVERAGE(%RANGE%)");
     104           0 :                 aTemplate.applyRange("%RANGE%", ScRange(aIntervalStart, aIntervalEnd));
     105           0 :                 output.writeFormula(aTemplate.getTemplate());
     106             :             }
     107             :             else
     108             :             {
     109           0 :                 output.writeFormula("=#N/A");
     110             :             }
     111           0 :             output.nextRow();
     112             :         }
     113           0 :         output.nextColumn();
     114           0 :     }
     115           0 :     return ScRange(output.mMinimumAddress, output.mMaximumAddress);
     116         228 : }
     117             : 
     118             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10