LCOV - code coverage report
Current view: top level - sc/source/ui/StatisticsDialogs - ExponentialSmoothingDialog.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 54 1.9 %
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 "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             : {
      41           0 :     disposeOnce();
      42           0 : }
      43             : 
      44           0 : void ScExponentialSmoothingDialog::dispose()
      45             : {
      46           0 :     mpSmoothingFactor.clear();
      47           0 :     ScStatisticsInputOutputDialog::dispose();
      48           0 : }
      49             : 
      50           0 : bool ScExponentialSmoothingDialog::Close()
      51             : {
      52           0 :     return DoClose( ScExponentialSmoothingDialogWrapper::GetChildWindowId() );
      53             : }
      54             : 
      55           0 : sal_Int16 ScExponentialSmoothingDialog::GetUndoNameId()
      56             : {
      57           0 :     return STR_EXPONENTIAL_SMOOTHING_UNDO_NAME;
      58             : }
      59             : 
      60           0 : ScRange ScExponentialSmoothingDialog::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             :     // Smoothing factor
      67           0 :     double aSmoothingFactor = mpSmoothingFactor->GetValue() / 100.0;
      68             : 
      69             :     // Alpha
      70           0 :     output.writeBoldString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_LABEL_ALPHA));
      71           0 :     output.nextRow();
      72             : 
      73             :     // Alpha Value
      74           0 :     ScAddress aSmoothingFactorAddress = output.current();
      75           0 :     output.writeValue(aSmoothingFactor);
      76           0 :     output.nextRow();
      77             : 
      78             :     // Exponential Smoothing
      79           0 :     output.push();
      80             : 
      81           0 :     boost::scoped_ptr<DataRangeIterator> pIterator;
      82           0 :     if (mGroupedBy == BY_COLUMN)
      83           0 :         pIterator.reset(new DataRangeByColumnIterator(mInputRange));
      84             :     else
      85           0 :         pIterator.reset(new DataRangeByRowIterator(mInputRange));
      86             : 
      87           0 :     for( ; pIterator->hasNext(); pIterator->next() )
      88             :     {
      89           0 :         output.resetRow();
      90             : 
      91           0 :         ScRange aCurrentRange = pIterator->get();
      92             : 
      93             :         // Write column label
      94           0 :         if (mGroupedBy == BY_COLUMN)
      95           0 :             aTemplate.setTemplate(SC_STRLOAD(RID_STATISTICS_DLGS, STR_COLUMN_LABEL_TEMPLATE));
      96             :         else
      97           0 :             aTemplate.setTemplate(SC_STRLOAD(RID_STATISTICS_DLGS, STR_ROW_LABEL_TEMPLATE));
      98           0 :         aTemplate.applyNumber("%NUMBER%", pIterator->index() + 1);
      99           0 :         output.writeBoldString(aTemplate.getTemplate());
     100           0 :         output.nextRow();
     101             : 
     102             :         // Initial value
     103             :         if (false)
     104             :         {
     105             :             aTemplate.setTemplate("=AVERAGE(%RANGE%)");
     106             :             aTemplate.applyRange("%RANGE%", aCurrentRange);
     107             :             output.writeFormula(aTemplate.getTemplate());
     108             :         }
     109             :         else
     110             :         {
     111           0 :             aTemplate.setTemplate("=%VAR%");
     112           0 :             aTemplate.applyAddress("%VAR%", aCurrentRange.aStart);
     113           0 :             output.writeFormula(aTemplate.getTemplate());
     114             :         }
     115             : 
     116           0 :         output.nextRow();
     117             : 
     118           0 :         DataCellIterator aDataCellIterator = pIterator->iterateCells();
     119             : 
     120           0 :         for (; aDataCellIterator.hasNext(); aDataCellIterator.next())
     121             :         {
     122           0 :             aTemplate.setTemplate("=%VALUE% * %PREVIOUS_INPUT% + (1 - %VALUE%) * %PREVIOUS_OUTPUT%");
     123           0 :             aTemplate.applyAddress("%PREVIOUS_INPUT%",  aDataCellIterator.get());
     124           0 :             aTemplate.applyAddress("%PREVIOUS_OUTPUT%", output.current(0, -1));
     125           0 :             aTemplate.applyAddress("%VALUE%",           aSmoothingFactorAddress);
     126             : 
     127           0 :             output.writeFormula(aTemplate.getTemplate());
     128           0 :             output.nextRow();
     129             :         }
     130           0 :         output.nextColumn();
     131           0 :     }
     132             : 
     133           0 :     return ScRange (output.mMinimumAddress, output.mMaximumAddress);
     134         156 : }
     135             : 
     136             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11