LCOV - code coverage report
Current view: top level - sc/source/core/data - dptabdat.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 89 130 68.5 %
Date: 2014-04-11 Functions: 18 25 72.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             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "dptabdat.hxx"
      21             : 
      22             : #include "global.hxx"
      23             : #include "dpfilteredcache.hxx"
      24             : #include "dptabres.hxx"
      25             : #include "document.hxx"
      26             : #include "dpobject.hxx"
      27             : 
      28             : #include <stdio.h>
      29             : #include <rtl/math.hxx>
      30             : #include <tools/date.hxx>
      31             : #include <unotools/transliterationwrapper.hxx>
      32             : #include <unotools/collatorwrapper.hxx>
      33             : 
      34             : #include <com/sun/star/sheet/DataPilotFieldFilter.hpp>
      35             : 
      36             : using namespace ::com::sun::star;
      37             : using ::com::sun::star::uno::Sequence;
      38             : using ::com::sun::star::uno::Any;
      39             : using ::std::vector;
      40             : 
      41          84 : ScDPTableData::CalcInfo::CalcInfo() :
      42             :     pInitState( NULL ),
      43             :     pColRoot( NULL ),
      44             :     pRowRoot( NULL ),
      45          84 :     bRepeatIfEmpty(false)
      46             : {
      47          84 : }
      48             : 
      49          92 : ScDPTableData::ScDPTableData(ScDocument* pDoc) :
      50          92 :     mpDoc(pDoc)
      51             : {
      52          92 :     nLastDateVal = nLastHier = nLastLevel = nLastRet = -1;      // invalid
      53             : 
      54             :     //! reset before new calculation (in case the base date is changed)
      55          92 : }
      56             : 
      57          92 : ScDPTableData::~ScDPTableData()
      58             : {
      59          92 : }
      60             : 
      61        4530 : OUString ScDPTableData::GetFormattedString(long nDim, const ScDPItemData& rItem) const
      62             : {
      63        4530 :     const ScDPCache* pCache = GetCacheTable().getCache();
      64        4530 :     return pCache->GetFormattedString(nDim, rItem);
      65             : }
      66             : 
      67           0 : long ScDPTableData::GetDatePart( long nDateVal, long nHierarchy, long nLevel )
      68             : {
      69           0 :     if ( nDateVal == nLastDateVal && nHierarchy == nLastHier && nLevel == nLastLevel )
      70           0 :         return nLastRet;
      71             : 
      72           0 :     Date aDate( 30,12,1899 );                   //! get from source data (and cache here)
      73           0 :     aDate += nDateVal;
      74             : 
      75           0 :     long nRet = 0;
      76           0 :     switch (nHierarchy)
      77             :     {
      78             :         case SC_DAPI_HIERARCHY_QUARTER:
      79           0 :             switch (nLevel)
      80             :             {
      81           0 :                 case 0: nRet = aDate.GetYear();                 break;
      82           0 :                 case 1: nRet = (aDate.GetMonth()-1) / 3 + 1;    break;
      83           0 :                 case 2: nRet = aDate.GetMonth();                break;
      84           0 :                 case 3: nRet = aDate.GetDay();                  break;
      85             :                 default:
      86             :                     OSL_FAIL("GetDatePart: wrong level");
      87             :             }
      88           0 :             break;
      89             :         case SC_DAPI_HIERARCHY_WEEK:
      90           0 :             switch (nLevel)
      91             :             {
      92             :                 //! use settings for different definitions
      93           0 :                 case 0: nRet = aDate.GetYear();                 break;      //!...
      94           0 :                 case 1: nRet = aDate.GetWeekOfYear();           break;
      95           0 :                 case 2: nRet = (long)aDate.GetDayOfWeek();      break;
      96             :                 default:
      97             :                     OSL_FAIL("GetDatePart: wrong level");
      98             :             }
      99           0 :             break;
     100             :         default:
     101             :             OSL_FAIL("GetDatePart: wrong hierarchy");
     102             :     }
     103             : 
     104           0 :     nLastDateVal = nDateVal;
     105           0 :     nLastHier    = nHierarchy;
     106           0 :     nLastLevel   = nLevel;
     107           0 :     nLastRet     = nRet;
     108             : 
     109           0 :     return nRet;
     110             : }
     111             : 
     112           0 : bool ScDPTableData::IsRepeatIfEmpty()
     113             : {
     114           0 :     return false;
     115             : }
     116             : 
     117           0 : sal_uLong ScDPTableData::GetNumberFormat(long)
     118             : {
     119           0 :     return 0;           // default format
     120             : }
     121             : 
     122         139 : bool ScDPTableData::IsBaseForGroup(long) const
     123             : {
     124         139 :     return false;       // always false
     125             : }
     126             : 
     127         139 : long ScDPTableData::GetGroupBase(long) const
     128             : {
     129         139 :     return -1;          // always none
     130             : }
     131             : 
     132         311 : bool ScDPTableData::IsNumOrDateGroup(long) const
     133             : {
     134         311 :     return false;       // always false
     135             : }
     136             : 
     137           0 : bool ScDPTableData::IsInGroup( const ScDPItemData&, long,
     138             :                                const ScDPItemData&, long ) const
     139             : {
     140             :     OSL_FAIL("IsInGroup shouldn't be called for non-group data");
     141           0 :     return false;
     142             : }
     143             : 
     144           0 : bool ScDPTableData::HasCommonElement( const ScDPItemData&, long,
     145             :                                       const ScDPItemData&, long ) const
     146             : {
     147             :     OSL_FAIL("HasCommonElement shouldn't be called for non-group data");
     148           0 :     return false;
     149             : }
     150         444 : void ScDPTableData::FillRowDataFromCacheTable(sal_Int32 nRow, const ScDPFilteredCache& rCacheTable,
     151             :                                         const CalcInfo& rInfo, CalcRowData& rData)
     152             : {
     153             :     // column dimensions
     154         444 :     GetItemData(rCacheTable, nRow, rInfo.aColLevelDims, rData.aColData);
     155             : 
     156             :     // row dimensions
     157         444 :     GetItemData(rCacheTable, nRow, rInfo.aRowLevelDims, rData.aRowData);
     158             : 
     159             :     // page dimensions
     160         444 :     GetItemData(rCacheTable, nRow, rInfo.aPageDims, rData.aPageData);
     161             : 
     162         444 :     long nCacheColumnCount = rCacheTable.getCache()->GetColumnCount();
     163         444 :     sal_Int32 n = rInfo.aDataSrcCols.size();
     164         890 :     for (sal_Int32 i = 0; i < n; ++i)
     165             :     {
     166         446 :         long nDim = rInfo.aDataSrcCols[i];
     167         446 :         rData.aValues.push_back( ScDPValue() );
     168             :         // #i111435# GetItemData needs dimension indexes including groups,
     169             :         // so the index must be checked here (groups aren't useful as data fields).
     170         446 :         if ( nDim < nCacheColumnCount )
     171             :         {
     172         446 :             ScDPValue& rVal = rData.aValues.back();
     173         446 :             rCacheTable.getValue( rVal, static_cast<SCCOL>(nDim), static_cast<SCROW>(nRow), false);
     174             :         }
     175             :     }
     176         444 : }
     177             : 
     178         444 : void ScDPTableData::ProcessRowData(CalcInfo& rInfo, const CalcRowData& rData, bool bAutoShow)
     179             : {
     180         444 :     if (!bAutoShow)
     181             :     {
     182         439 :         LateInitParams aColParams(rInfo.aColDims, rInfo.aColLevels, false);
     183         878 :         LateInitParams aRowParams(rInfo.aRowDims, rInfo.aRowLevels, true);
     184             :         // root always init child
     185         439 :         aColParams.SetInitChild(true);
     186         439 :         aColParams.SetInitAllChildren( false);
     187         439 :         aRowParams.SetInitChild(true);
     188         439 :         aRowParams.SetInitAllChildren( false);
     189             : 
     190         439 :         rInfo.pColRoot->LateInitFrom(aColParams, rData.aColData, 0, *rInfo.pInitState);
     191         878 :         rInfo.pRowRoot->LateInitFrom(aRowParams, rData.aRowData, 0, *rInfo.pInitState);
     192             :     }
     193             : 
     194        1327 :     if ( ( !rInfo.pColRoot->GetChildDimension() || rInfo.pColRoot->GetChildDimension()->IsValidEntry(rData.aColData) ) &&
     195         833 :          ( !rInfo.pRowRoot->GetChildDimension() || rInfo.pRowRoot->GetChildDimension()->IsValidEntry(rData.aRowData) ) )
     196             :     {
     197             :         //! single process method with ColMembers, RowMembers and data !!!
     198         439 :         if (rInfo.pColRoot->GetChildDimension())
     199             :         {
     200         210 :             vector<SCROW> aEmptyData;
     201         210 :             rInfo.pColRoot->GetChildDimension()->ProcessData(rData.aColData, NULL, aEmptyData, rData.aValues);
     202             :         }
     203             : 
     204         439 :         rInfo.pRowRoot->ProcessData(rData.aRowData, rInfo.pColRoot->GetChildDimension(),
     205         878 :                                     rData.aColData, rData.aValues);
     206             :     }
     207         444 : }
     208             : 
     209          76 : void ScDPTableData::CalcResultsFromCacheTable(const ScDPFilteredCache& rCacheTable, CalcInfo& rInfo, bool bAutoShow)
     210             : {
     211          76 :     sal_Int32 nRowSize = rCacheTable.getRowSize();
     212         474 :     for (sal_Int32 nRow = 0; nRow < nRowSize; ++nRow)
     213             :     {
     214             :         sal_Int32 nLastRow;
     215         398 :         if (!rCacheTable.isRowActive(nRow, &nLastRow))
     216             :         {
     217          22 :             nRow = nLastRow;
     218          22 :             continue;
     219             :         }
     220             : 
     221         376 :         CalcRowData aData;
     222         376 :         FillRowDataFromCacheTable(nRow, rCacheTable, rInfo, aData);
     223         376 :         ProcessRowData(rInfo, aData, bAutoShow);
     224         376 :     }
     225          76 : }
     226             : 
     227        1332 : void ScDPTableData::GetItemData(const ScDPFilteredCache& rCacheTable, sal_Int32 nRow,
     228             :                                 const vector<long>& rDims, vector<SCROW>& rItemData)
     229             : {
     230        1332 :     sal_Int32 nDimSize = rDims.size();
     231        2163 :     for (sal_Int32 i = 0; i < nDimSize; ++i)
     232             :     {
     233         831 :         long nDim = rDims[i];
     234             : 
     235         831 :         if (getIsDataLayoutDimension(nDim))
     236             :         {
     237          44 :             rItemData.push_back( -1 );
     238          88 :             continue;
     239             :         }
     240             : 
     241         787 :         nDim = GetSourceDim( nDim );
     242         787 :         if ( nDim >= rCacheTable.getCache()->GetColumnCount() )
     243           0 :            continue;
     244             : 
     245         787 :         SCROW nId= rCacheTable.getCache()->GetItemDataId( static_cast<SCCOL>(nDim), static_cast<SCROW>(nRow), IsRepeatIfEmpty());
     246         787 :         rItemData.push_back( nId );
     247             :     }
     248        1332 : }
     249             : 
     250         152 : long ScDPTableData::GetMembersCount( long nDim )
     251             : {
     252         152 :     if ( nDim > MAXCOL )
     253           0 :         return 0;
     254         152 :     return GetCacheTable().getFieldEntries( nDim ).size();
     255             : }
     256             : 
     257           0 : const ScDPItemData* ScDPTableData::GetMemberByIndex( long nDim, long nIndex )
     258             : {
     259           0 :     if ( nIndex >= GetMembersCount( nDim ) )
     260           0 :         return NULL;
     261             : 
     262           0 :     const ::std::vector<SCROW>& nMembers = GetCacheTable().getFieldEntries( nDim );
     263             : 
     264           0 :     return GetCacheTable().getCache()->GetItemDataById( (SCCOL) nDim, (SCROW)nMembers[nIndex] );
     265             : }
     266             : 
     267       10853 : const ScDPItemData* ScDPTableData::GetMemberById( long nDim, long nId)
     268             : {
     269             : 
     270       10853 :     return GetCacheTable().getCache()->GetItemDataById(nDim, static_cast<SCROW>(nId));
     271             : }
     272             : 
     273         891 : const std::vector< SCROW >& ScDPTableData::GetColumnEntries( long nColumn )
     274             : {
     275         891 :     return GetCacheTable().getFieldEntries( nColumn );
     276             : }
     277             : 
     278         628 : long ScDPTableData::GetSourceDim( long nDim )
     279             : {
     280         628 :     return nDim;
     281             : 
     282             : }
     283             : 
     284        1288 : long ScDPTableData::Compare( long nDim, long nDataId1, long nDataId2)
     285             : {
     286        1288 :     if ( getIsDataLayoutDimension(nDim) )
     287          14 :         return 0;
     288             : 
     289        1274 :     long n1 = GetCacheTable().getOrder(nDim, nDataId1);
     290        1274 :     long n2 = GetCacheTable().getOrder(nDim, nDataId2);
     291        1274 :     if ( n1 > n2 )
     292        1274 :         return 1;
     293           0 :     else if ( n1 == n2 )
     294           0 :         return 0;
     295             :     else
     296           0 :         return -1;
     297         102 : }
     298             : 
     299             : #if DEBUG_PIVOT_TABLE
     300             : void ScDPTableData::Dump() const
     301             : {
     302             : }
     303             : #endif
     304             : 
     305             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10