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

Generated by: LCOV version 1.10