LCOV - code coverage report
Current view: top level - sc/source/ui/StatisticsDialogs - ExponentialSmoothingDialog.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 49 2.0 %
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 "ExponentialSmoothingDialog.hxx"
      28             : 
      29           0 : ScExponentialSmoothingDialog::ScExponentialSmoothingDialog(
      30             :                     SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow,
      31             :                     vcl::Window* pParent, ScViewData* pViewData ) :
      32             :     ScStatisticsInputOutputDialog(
      33             :             pSfxBindings, pChildWindow, pParent, pViewData,
      34           0 :             "ExponentialSmoothingDialog", "modules/scalc/ui/exponentialsmoothingdialog.ui" )
      35             : {
      36           0 :     get(mpSmoothingFactor, "smoothing-factor-spin");
      37           0 : }
      38             : 
      39           0 : ScExponentialSmoothingDialog::~ScExponentialSmoothingDialog()
      40           0 : {}
      41             : 
      42           0 : bool ScExponentialSmoothingDialog::Close()
      43             : {
      44           0 :     return DoClose( ScExponentialSmoothingDialogWrapper::GetChildWindowId() );
      45             : }
      46             : 
      47           0 : sal_Int16 ScExponentialSmoothingDialog::GetUndoNameId()
      48             : {
      49           0 :     return STR_EXPONENTIAL_SMOOTHING_UNDO_NAME;
      50             : }
      51             : 
      52           0 : ScRange ScExponentialSmoothingDialog::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             :     // Smoothing factor
      59           0 :     double aSmoothingFactor = mpSmoothingFactor->GetValue() / 100.0;
      60             : 
      61             :     // Alpha
      62           0 :     output.writeBoldString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_LABEL_ALPHA));
      63           0 :     output.nextRow();
      64             : 
      65             :     // Alpha Value
      66           0 :     ScAddress aSmoothingFactorAddress = output.current();
      67           0 :     output.writeValue(aSmoothingFactor);
      68           0 :     output.nextRow();
      69             : 
      70             :     // Exponential Smoothing
      71           0 :     output.push();
      72             : 
      73           0 :     boost::scoped_ptr<DataRangeIterator> pIterator;
      74           0 :     if (mGroupedBy == BY_COLUMN)
      75           0 :         pIterator.reset(new DataRangeByColumnIterator(mInputRange));
      76             :     else
      77           0 :         pIterator.reset(new DataRangeByRowIterator(mInputRange));
      78             : 
      79           0 :     for( ; pIterator->hasNext(); pIterator->next() )
      80             :     {
      81           0 :         output.resetRow();
      82             : 
      83           0 :         ScRange aCurrentRange = pIterator->get();
      84             : 
      85             :         // Write column label
      86           0 :         if (mGroupedBy == BY_COLUMN)
      87           0 :             aTemplate.setTemplate(SC_STRLOAD(RID_STATISTICS_DLGS, STR_COLUMN_LABEL_TEMPLATE));
      88             :         else
      89           0 :             aTemplate.setTemplate(SC_STRLOAD(RID_STATISTICS_DLGS, STR_ROW_LABEL_TEMPLATE));
      90           0 :         aTemplate.applyNumber("%NUMBER%", pIterator->index() + 1);
      91           0 :         output.writeBoldString(aTemplate.getTemplate());
      92           0 :         output.nextRow();
      93             : 
      94             :         // Initial value
      95             :         if (false)
      96             :         {
      97             :             aTemplate.setTemplate("=AVERAGE(%RANGE%)");
      98             :             aTemplate.applyRange("%RANGE%", aCurrentRange);
      99             :             output.writeFormula(aTemplate.getTemplate());
     100             :         }
     101             :         else
     102             :         {
     103           0 :             aTemplate.setTemplate("=%VAR%");
     104           0 :             aTemplate.applyAddress("%VAR%", aCurrentRange.aStart);
     105           0 :             output.writeFormula(aTemplate.getTemplate());
     106             :         }
     107             : 
     108           0 :         output.nextRow();
     109             : 
     110           0 :         DataCellIterator aDataCellIterator = pIterator->iterateCells();
     111             : 
     112           0 :         for (; aDataCellIterator.hasNext(); aDataCellIterator.next())
     113             :         {
     114           0 :             aTemplate.setTemplate("=%VALUE% * %PREVIOUS_INPUT% + (1 - %VALUE%) * %PREVIOUS_OUTPUT%");
     115           0 :             aTemplate.applyAddress("%PREVIOUS_INPUT%",  aDataCellIterator.get());
     116           0 :             aTemplate.applyAddress("%PREVIOUS_OUTPUT%", output.current(0, -1));
     117           0 :             aTemplate.applyAddress("%VALUE%",           aSmoothingFactorAddress);
     118             : 
     119           0 :             output.writeFormula(aTemplate.getTemplate());
     120           0 :             output.nextRow();
     121             :         }
     122           0 :         output.nextColumn();
     123           0 :     }
     124             : 
     125           0 :     return ScRange (output.mMinimumAddress, output.mMaximumAddress);
     126         228 : }
     127             : 
     128             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10