LCOV - code coverage report
Current view: top level - sc/source/ui/StatisticsDialogs - MovingAverageDialog.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 50 2.0 %
Date: 2015-06-13 12:38:46 Functions: 2 9 22.2 %
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             : {
      41           0 :     disposeOnce();
      42           0 : }
      43             : 
      44           0 : void ScMovingAverageDialog::dispose()
      45             : {
      46           0 :     mpIntervalSpin.clear();
      47           0 :     ScStatisticsInputOutputDialog::dispose();
      48           0 : }
      49             : 
      50           0 : bool ScMovingAverageDialog::Close()
      51             : {
      52           0 :     return DoClose( ScMovingAverageDialogWrapper::GetChildWindowId() );
      53             : }
      54             : 
      55           0 : sal_Int16 ScMovingAverageDialog::GetUndoNameId()
      56             : {
      57           0 :     return STR_MOVING_AVERAGE_UNDO_NAME;
      58             : }
      59             : 
      60           0 : ScRange ScMovingAverageDialog::ApplyOutput(ScDocShell* pDocShell)
      61             : {
      62             :     AddressWalkerWriter output(mOutputAddress, pDocShell, mDocument,
      63           0 :             formula::FormulaGrammar::mergeToGrammar( formula::FormulaGrammar::GRAM_ENGLISH, mAddressDetails.eConv));
      64           0 :     FormulaTemplate aTemplate(mDocument);
      65             : 
      66           0 :     boost::scoped_ptr<DataRangeIterator> pIterator;
      67           0 :     if (mGroupedBy == BY_COLUMN)
      68           0 :         pIterator.reset(new DataRangeByColumnIterator(mInputRange));
      69             :     else
      70           0 :         pIterator.reset(new DataRangeByRowIterator(mInputRange));
      71             : 
      72           0 :     sal_Int32 aIntervalSize = mpIntervalSpin->GetValue();
      73           0 :     const bool aCentral = true; //to-do add support to change this to the dialog
      74             : 
      75           0 :     for( ; pIterator->hasNext(); pIterator->next() )
      76             :     {
      77           0 :         output.resetRow();
      78             : 
      79             :         // Write label
      80           0 :         if (mGroupedBy == BY_COLUMN)
      81           0 :             aTemplate.setTemplate(SC_STRLOAD(RID_STATISTICS_DLGS, STR_COLUMN_LABEL_TEMPLATE));
      82             :         else
      83           0 :             aTemplate.setTemplate(SC_STRLOAD(RID_STATISTICS_DLGS, STR_ROW_LABEL_TEMPLATE));
      84             : 
      85           0 :         aTemplate.applyNumber("%NUMBER%", pIterator->index() + 1);
      86           0 :         output.writeBoldString(aTemplate.getTemplate());
      87           0 :         output.nextRow();
      88             : 
      89           0 :         DataCellIterator aDataCellIterator = pIterator->iterateCells();
      90             : 
      91           0 :         for (; aDataCellIterator.hasNext(); aDataCellIterator.next())
      92             :         {
      93           0 :             ScAddress aIntervalStart;
      94           0 :             ScAddress aIntervalEnd;
      95             : 
      96             :             if (aCentral)
      97             :             {
      98           0 :                 sal_Int32 aHalf = aIntervalSize / 2;
      99           0 :                 sal_Int32 aHalfRemainder = aIntervalSize % 2;
     100           0 :                 aIntervalStart = aDataCellIterator.getRelative(-aHalf);
     101           0 :                 aIntervalEnd = aDataCellIterator.getRelative(aHalf - 1 + aHalfRemainder);
     102             :             }
     103             :             else
     104             :             {
     105             :                 aIntervalStart = aDataCellIterator.getRelative(-aIntervalSize);
     106             :                 aIntervalEnd = aDataCellIterator.getRelative(0);
     107             :             }
     108             : 
     109           0 :             if(aIntervalStart.IsValid() && aIntervalEnd.IsValid())
     110             :             {
     111           0 :                 aTemplate.setTemplate("=AVERAGE(%RANGE%)");
     112           0 :                 aTemplate.applyRange("%RANGE%", ScRange(aIntervalStart, aIntervalEnd));
     113           0 :                 output.writeFormula(aTemplate.getTemplate());
     114             :             }
     115             :             else
     116             :             {
     117           0 :                 output.writeFormula("=#N/A");
     118             :             }
     119           0 :             output.nextRow();
     120             :         }
     121           0 :         output.nextColumn();
     122           0 :     }
     123           0 :     return ScRange(output.mMinimumAddress, output.mMaximumAddress);
     124         156 : }
     125             : 
     126             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11