LCOV - code coverage report
Current view: top level - sc/source/filter/xml - pivotsource.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 35 56 62.5 %
Date: 2014-04-11 Functions: 10 16 62.5 %
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             : #include "pivotsource.hxx"
      11             : 
      12             : #include <dpsave.hxx>
      13             : 
      14             : namespace sc {
      15             : 
      16           2 : PivotTableSources::SelectedPages::SelectedPages( ScDPObject* pObj, const SelectedPagesType& rSelected ) :
      17           2 :     mpDP(pObj), maSelectedPages(rSelected) {}
      18             : 
      19           7 : PivotTableSources::SheetSource::SheetSource( ScDPObject* pObj, const ScSheetSourceDesc& rDesc ) :
      20           7 :     mpDP(pObj), maDesc(rDesc) {}
      21             : 
      22           0 : PivotTableSources::DBSource::DBSource( ScDPObject* pObj, const ScImportSourceDesc& rDesc ) :
      23           0 :     mpDP(pObj), maDesc(rDesc) {}
      24             : 
      25           0 : PivotTableSources::ServiceSource::ServiceSource( ScDPObject* pObj, const ScDPServiceDesc& rDesc ) :
      26           0 :     mpDP(pObj), maDesc(rDesc) {}
      27             : 
      28           5 : PivotTableSources::PivotTableSources() {}
      29             : 
      30           7 : void PivotTableSources::appendSheetSource( ScDPObject* pObj, const ScSheetSourceDesc& rDesc )
      31             : {
      32           7 :     maSheetSources.push_back(SheetSource(pObj, rDesc));
      33           7 : }
      34             : 
      35           0 : void PivotTableSources::appendDBSource( ScDPObject* pObj, const ScImportSourceDesc& rDesc )
      36             : {
      37           0 :     maDBSources.push_back(DBSource(pObj, rDesc));
      38           0 : }
      39             : 
      40           0 : void PivotTableSources::appendServiceSource( ScDPObject* pObj, const ScDPServiceDesc& rDesc )
      41             : {
      42           0 :     maServiceSources.push_back(ServiceSource(pObj, rDesc));
      43           0 : }
      44             : 
      45           7 : void PivotTableSources::appendSelectedPages( ScDPObject* pObj, const SelectedPagesType& rSelected )
      46             : {
      47           7 :     if (rSelected.empty())
      48          12 :         return;
      49             : 
      50           2 :     maSelectedPagesList.push_back(SelectedPages(pObj, rSelected));
      51             : }
      52             : 
      53             : namespace {
      54             : 
      55             : struct SelectedPageProcessor : std::unary_function<PivotTableSources::SelectedPages, void>
      56             : {
      57           2 :     void operator() ( PivotTableSources::SelectedPages& rItem )
      58             :     {
      59             :         // Set selected pages after building all dimension members.
      60           2 :         if (!rItem.mpDP)
      61           0 :             return;
      62             : 
      63           2 :         rItem.mpDP->BuildAllDimensionMembers();
      64           2 :         ScDPSaveData* pSaveData = rItem.mpDP->GetSaveData();
      65           2 :         if (!pSaveData)
      66           0 :             return;
      67             : 
      68           2 :         PivotTableSources::SelectedPagesType::const_iterator it = rItem.maSelectedPages.begin(), itEnd = rItem.maSelectedPages.end();
      69           4 :         for (; it != itEnd; ++it)
      70             :         {
      71           2 :             const OUString& rDimName = it->first;
      72           2 :             const OUString& rSelected = it->second;
      73           2 :             ScDPSaveDimension* pDim = pSaveData->GetExistingDimensionByName(rDimName);
      74           2 :             if (!pDim)
      75           0 :                 continue;
      76             : 
      77           2 :             pDim->SetCurrentPage(&rSelected);
      78             :         }
      79             :     }
      80             : };
      81             : 
      82             : struct PivotSheetDescSetter : std::unary_function<sc::PivotTableSources::SheetSource, void>
      83             : {
      84           7 :     void operator() ( sc::PivotTableSources::SheetSource& rSrc )
      85             :     {
      86           7 :         ScDPObject* pObj = rSrc.mpDP;
      87           7 :         pObj->SetSheetDesc(rSrc.maDesc);
      88           7 :     }
      89             : };
      90             : 
      91             : struct PivotDBDescSetter : std::unary_function<sc::PivotTableSources::DBSource, void>
      92             : {
      93           0 :     void operator() ( sc::PivotTableSources::DBSource& rSrc )
      94             :     {
      95           0 :         ScDPObject* pObj = rSrc.mpDP;
      96           0 :         pObj->SetImportDesc(rSrc.maDesc);
      97           0 :     }
      98             : };
      99             : 
     100             : struct PivotServiceDataSetter : std::unary_function<sc::PivotTableSources::ServiceSource, void>
     101             : {
     102           0 :     void operator() ( sc::PivotTableSources::ServiceSource& rSrc )
     103             :     {
     104           0 :         ScDPObject* pObj = rSrc.mpDP;
     105           0 :         pObj->SetServiceData(rSrc.maDesc);
     106           0 :     }
     107             : };
     108             : 
     109             : }
     110             : 
     111           5 : void PivotTableSources::process()
     112             : {
     113           5 :     std::for_each(maSheetSources.begin(), maSheetSources.end(), PivotSheetDescSetter());
     114           5 :     std::for_each(maDBSources.begin(), maDBSources.end(), PivotDBDescSetter());
     115           5 :     std::for_each(maServiceSources.begin(), maServiceSources.end(), PivotServiceDataSetter());
     116           5 :     std::for_each(maSelectedPagesList.begin(), maSelectedPagesList.end(), SelectedPageProcessor());
     117           5 : }
     118             : 
     119         102 : }
     120             : 
     121             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10