LCOV - code coverage report
Current view: top level - sc/source/filter/inc - xipivot.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 9 0.0 %
Date: 2014-04-14 Functions: 0 10 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             :  * 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             : #ifndef SC_XIPIVOT_HXX
      21             : #define SC_XIPIVOT_HXX
      22             : 
      23             : #include <list>
      24             : #include "xlpivot.hxx"
      25             : #include "xiroot.hxx"
      26             : #include <boost/shared_ptr.hpp>
      27             : 
      28             : class ScDPSaveData;
      29             : class ScDPSaveDimension;
      30             : 
      31             : 
      32             : // Pivot cache
      33             : 
      34             : 
      35             : /** Represents a data item in a pivot cache. */
      36           0 : class XclImpPCItem : public XclPCItem
      37             : {
      38             : public:
      39             :     explicit            XclImpPCItem( XclImpStream& rStrm );
      40             : 
      41             :     /** Inserts the item data into the passed document. */
      42             :     void WriteToSource( XclImpRoot& rRoot, const ScAddress& rScPos ) const;
      43             : 
      44             : private:
      45             :     /** Reads an SXDOUBLE record describing a floating-point item. */
      46             :     void                ReadSxdouble( XclImpStream& rStrm );
      47             :     /** Reads an SXBOOLEAN record describing a boolean item. */
      48             :     void                ReadSxboolean( XclImpStream& rStrm );
      49             :     /** Reads an SXERROR record describing an error code item. */
      50             :     void                ReadSxerror( XclImpStream& rStrm );
      51             :     /** Reads an SXINTEGER record describing an integer item. */
      52             :     void                ReadSxinteger( XclImpStream& rStrm );
      53             :     /** Reads an SXSTRING record describing a text item. */
      54             :     void                ReadSxstring( XclImpStream& rStrm );
      55             :     /** Reads an SXDATETIME record describing a date/time item. */
      56             :     void                ReadSxdatetime( XclImpStream& rStrm );
      57             :     /** Reads an SXEMPTY record describing an empty item. */
      58             :     void                ReadSxempty( XclImpStream& rStrm );
      59             : };
      60             : 
      61             : typedef boost::shared_ptr< XclImpPCItem > XclImpPCItemRef;
      62             : 
      63             : struct ScDPNumGroupInfo;
      64             : class XclImpPivotCache;
      65             : 
      66             : /** Represents a field in a pivot cache (a column of data items in the source area). */
      67             : class XclImpPCField : public XclPCField, protected XclImpRoot
      68             : {
      69             : public:
      70             :     /** Creates a pivot cache field by reading an SXFIELD record. */
      71             :     explicit            XclImpPCField( const XclImpRoot& rRoot,
      72             :                             XclImpPivotCache& rPCache, sal_uInt16 nFieldIdx );
      73             :     virtual             ~XclImpPCField();
      74             : 
      75             :     // general field/item access ----------------------------------------------
      76             : 
      77             :     /** Returns the name of the field, uses the passed visible name if supported. */
      78             :     const OUString& GetFieldName( const ScfStringVec& rVisNames ) const;
      79             : 
      80             :     /** Returns the base field if this is a grouping field. */
      81             :     const XclImpPCField* GetGroupBaseField() const;
      82             : 
      83             :     /** Returns the item at the specified position or 0 on error. */
      84             :     const XclImpPCItem* GetItem( sal_uInt16 nItemIdx ) const;
      85             :     /** Returns the item representing a limit value in numeric/date/time grouping fields.
      86             :         @param nItemIdx  One of EXC_SXFIELD_INDEX_MIN, EXC_SXFIELD_INDEX_MAX, or EXC_SXFIELD_INDEX_STEP. */
      87             :     const XclImpPCItem* GetLimitItem( sal_uInt16 nItemIdx ) const;
      88             : 
      89             :     /** Inserts the field name into the document. */
      90             :     void WriteFieldNameToSource( SCCOL nScCol, SCTAB nScTab );
      91             :     /** Inserts the specified item data into the document. */
      92             :     void WriteOrigItemToSource( SCROW nScRow, SCTAB nScTab, sal_uInt16 nItemIdx );
      93             :     /** Inserts the data of the last inserted item into the document. */
      94             :     void WriteLastOrigItemToSource( SCROW nScRow, SCTAB nScTab );
      95             : 
      96             :     // records ----------------------------------------------------------------
      97             : 
      98             :     /** Reads the SXFIELD record describing the field. */
      99             :     void                ReadSxfield( XclImpStream& rStrm );
     100             :     /** Reads an item data record describing a new item. */
     101             :     void                ReadItem( XclImpStream& rStrm );
     102             :     /** Reads the SXNUMGROUP record describing numeric grouping fields. */
     103             :     void                ReadSxnumgroup( XclImpStream& rStrm );
     104             :     /** Reads the SXGROUPINFO record describing the item order in grouping fields. */
     105             :     void                ReadSxgroupinfo( XclImpStream& rStrm );
     106             : 
     107             :     // grouping ---------------------------------------------------------------
     108             : 
     109             :     /** Inserts grouping information of this field into the passed ScDPSaveData. */
     110             :     void                ConvertGroupField( ScDPSaveData& rSaveData, const ScfStringVec& rVisNames ) const;
     111             : 
     112             : 
     113             : private:
     114             :     /** Inserts standard grouping information of this field into the passed ScDPSaveData. */
     115             :     void                ConvertStdGroupField( ScDPSaveData& rSaveData, const ScfStringVec& rVisNames ) const;
     116             :     /** Inserts numeric grouping information of this field into the passed ScDPSaveData. */
     117             :     void                ConvertNumGroupField( ScDPSaveData& rSaveData, const ScfStringVec& rVisNames ) const;
     118             :     /** Inserts date grouping information of this field into the passed ScDPSaveData. */
     119             :     void                ConvertDateGroupField( ScDPSaveData& rSaveData, const ScfStringVec& rVisNames ) const;
     120             : 
     121             :     /** Returns a Calc struct with numeric grouping data. */
     122             :     ScDPNumGroupInfo    GetScNumGroupInfo() const;
     123             :     /** Returns a Calc struct with date grouping data. */
     124             :     ScDPNumGroupInfo    GetScDateGroupInfo() const;
     125             : 
     126             :     /** Returns a limit value for numeric grouping fields. */
     127             :     const double*       GetNumGroupLimit( sal_uInt16 nLimitIdx ) const;
     128             :     /** Returns a limit value for date grouping fields (minimum/maximum only). */
     129             :     const DateTime*     GetDateGroupLimit( sal_uInt16 nLimitIdx ) const;
     130             :     /** Returns the step value for date grouping fields. */
     131             :     const sal_Int16*    GetDateGroupStep() const;
     132             : 
     133             : private:
     134             :     typedef ::std::vector< XclImpPCItemRef > XclImpPCItemVec;
     135             : 
     136             :     XclImpPivotCache&   mrPCache;           /// Parent pivot cache containing this field.
     137             :     XclImpPCItemVec     maItems;            /// List of all displayed data items.
     138             :     XclImpPCItemVec     maOrigItems;        /// List of all source data items.
     139             :     XclImpPCItemVec     maNumGroupItems;    /// List of items containing numeric grouping limits.
     140             :     mutable SCCOL       mnSourceScCol;      /// Column index of source data for this field.
     141             :     bool                mbNumGroupInfoRead; /// true = Numeric grouping info read (SXNUMGROUP record).
     142             : };
     143             : 
     144             : typedef boost::shared_ptr< XclImpPCField > XclImpPCFieldRef;
     145             : 
     146             : class XclImpPivotCache : protected XclImpRoot
     147             : {
     148             : public:
     149             :     explicit            XclImpPivotCache( const XclImpRoot& rRoot );
     150             :     virtual             ~XclImpPivotCache();
     151             : 
     152             :     // data access ------------------------------------------------------------
     153             : 
     154             :     /** Returns the data source range read from the DCONREF record. */
     155           0 :     inline const ScRange& GetSourceRange() const { return maSrcRange; }
     156             : 
     157           0 :     const OUString& GetSourceRangeName() const { return maSrcRangeName; }
     158             : 
     159             :     /** Returns the number of pivot cache fields. */
     160             :     sal_uInt16          GetFieldCount() const;
     161             :     /** Returns read-only access to a pivot cache field. */
     162             :     const XclImpPCField* GetField( sal_uInt16 nFieldIdx ) const;
     163             : 
     164             :     // records ----------------------------------------------------------------
     165             : 
     166             :     /** Reads an SXIDSTM record containing a pivot cache stream identifier and the pivot cache. */
     167             :     void                ReadSxidstm( XclImpStream& rStrm );
     168             :     /** Reads an SXVS record containing the source type of the pivot cache. */
     169             :     void                ReadSxvs( XclImpStream& rStrm );
     170             :     /** Reads a DCONREF record containing the source range of the pivot cache. */
     171             :     void                ReadDconref( XclImpStream& rStrm );
     172             :     /**
     173             :      * Read DECONNAME record which contains the defined name of the source
     174             :      * range.
     175             :      */
     176             :     void                ReadDConName( XclImpStream& rStrm );
     177             :     /** Reads the entire pivot cache stream. Uses decrypter from passed stream. */
     178             :     void                ReadPivotCacheStream( XclImpStream& rStrm );
     179             : 
     180             :     bool                HasCacheRecords() const;
     181             :     bool                IsRefreshOnLoad() const;
     182             :     bool                IsValid() const;
     183             : 
     184             : private:
     185             :     typedef ::std::vector< XclImpPCFieldRef > XclImpPCFieldVec;
     186             : 
     187             :     XclPCInfo           maPCInfo;           /// Pivot cache settings (SXDB record).
     188             :     XclImpPCFieldVec    maFields;           /// List of pivot cache fields.
     189             :     ScRange             maSrcRange;         /// Source range in the spreadsheet.
     190             :     OUString            maUrl;              /// URL of the source data.
     191             :     OUString            maTabName;          /// Sheet name of the source data.
     192             :     OUString            maSrcRangeName;     /// Name of the source data range.
     193             :     sal_uInt16          mnStrmId;           /// Pivot cache stream identifier.
     194             :     sal_uInt16          mnSrcType;          /// Source data type.
     195             :     bool                mbSelfRef;          /// true = Source data from own document.
     196             : };
     197             : 
     198             : typedef boost::shared_ptr< XclImpPivotCache > XclImpPivotCacheRef;
     199             : 
     200             : 
     201             : // Pivot table
     202             : 
     203             : 
     204             : class XclImpPivotTable;
     205             : 
     206           0 : class XclImpPTItem
     207             : {
     208             : public:
     209             :     explicit            XclImpPTItem( const XclImpPCField* pCacheField );
     210             : 
     211             :     /** Returns the internal name of the item or 0, if no name could be found. */
     212             :     const OUString* GetItemName() const;
     213             : 
     214             :     /** Reads an SXVI record containing data of this item. */
     215             :     void                ReadSxvi( XclImpStream& rStrm );
     216             : 
     217             :     /** Inserts this item into the passed ScDPSaveDimension. */
     218             :     void                ConvertItem( ScDPSaveDimension& rSaveDim ) const;
     219             : 
     220             : private:
     221             :     XclPTItemInfo       maItemInfo;         /// General data for this item.
     222             :     const XclImpPCField* mpCacheField;      /// Corresponding pivot cache field.
     223             : };
     224             : 
     225             : typedef boost::shared_ptr< XclImpPTItem > XclImpPTItemRef;
     226             : 
     227           0 : class XclImpPTField
     228             : {
     229             : public:
     230             :     explicit            XclImpPTField( const XclImpPivotTable& rPTable, sal_uInt16 nCacheIdx );
     231             : 
     232             :     // general field/item access ----------------------------------------------
     233             : 
     234             :     /** Returns the corresponding pivot cache field of this field. */
     235             :     const XclImpPCField* GetCacheField() const;
     236             :     /** Returns the name of this field that is used to create the Calc dimensions. */
     237             :     OUString        GetFieldName() const;
     238             :     /** Returns the internally set visible name of this field. */
     239             :     OUString        GetVisFieldName() const;
     240             : 
     241             :     /** Returns the specified item. */
     242             :     const XclImpPTItem* GetItem( sal_uInt16 nItemIdx ) const;
     243             :     /** Returns the internal name of the specified item. */
     244             :     const OUString* GetItemName( sal_uInt16 nItemIdx ) const;
     245             : 
     246             :     /** Returns the flags of the axes this field is part of. */
     247           0 :     inline sal_uInt16   GetAxes() const { return maFieldInfo.mnAxes; }
     248             :     /** Sets the flags of the axes this field is part of. */
     249           0 :     inline void         SetAxes( sal_uInt16 nAxes ) { maFieldInfo.mnAxes = nAxes; }
     250             : 
     251             :     // records ----------------------------------------------------------------
     252             : 
     253             :     /** Reads an SXVD record describing the field. */
     254             :     void                ReadSxvd( XclImpStream& rStrm );
     255             :     /** Reads an SXVDEX record describing extended options of the field. */
     256             :     void                ReadSxvdex( XclImpStream& rStrm );
     257             :     /** Reads an SXVI record describing a new item of this field. */
     258             :     void                ReadSxvi( XclImpStream& rStrm );
     259             : 
     260             :     // row/column fields ------------------------------------------------------
     261             : 
     262             :     void                ConvertRowColField( ScDPSaveData& rSaveData ) const;
     263             : 
     264             :     // page fields ------------------------------------------------------------
     265             : 
     266             :     void                SetPageFieldInfo( const XclPTPageFieldInfo& rPageInfo );
     267             :     void                ConvertPageField( ScDPSaveData& rSaveData ) const;
     268             : 
     269             :     // hidden fields ----------------------------------------------------------
     270             : 
     271             :     void                ConvertHiddenField( ScDPSaveData& rSaveData ) const;
     272             : 
     273             :     // data fields ------------------------------------------------------------
     274             : 
     275             :     bool                HasDataFieldInfo() const;
     276             :     void                AddDataFieldInfo( const XclPTDataFieldInfo& rDataInfo );
     277             :     void                ConvertDataField( ScDPSaveData& rSaveData ) const;
     278             : 
     279             : 
     280             : private:
     281             :     ScDPSaveDimension*  ConvertRCPField( ScDPSaveData& rSaveData ) const;
     282             :     void                ConvertFieldInfo( ScDPSaveDimension& rSaveDim ) const;
     283             : 
     284             :     void                ConvertDataField( ScDPSaveDimension& rSaveDim, const XclPTDataFieldInfo& rDataInfo ) const;
     285             :     void                ConvertDataFieldInfo( ScDPSaveDimension& rSaveDim, const XclPTDataFieldInfo& rDataInfo ) const;
     286             :     void                ConvertItems( ScDPSaveDimension& rSaveDim ) const;
     287             : 
     288             : private:
     289             :     typedef ::std::list< XclPTDataFieldInfo >   XclPTDataFieldInfoList;
     290             :     typedef ::std::vector< XclImpPTItemRef >    XclImpPTItemVec;
     291             : 
     292             :     const XclImpPivotTable& mrPTable;       /// Parent pivot table containing this field.
     293             :     XclPTFieldInfo      maFieldInfo;        /// General field info (SXVD record).
     294             :     XclPTFieldExtInfo   maFieldExtInfo;     /// Extended field info (SXVDEX record).
     295             :     XclPTPageFieldInfo  maPageInfo;         /// Page field info (entry from SXPI record).
     296             :     XclPTDataFieldInfoList maDataInfoList;  /// List of extended data field info (SXDI records).
     297             :     XclImpPTItemVec     maItems;            /// List of all items of this field.
     298             : };
     299             : 
     300             : typedef boost::shared_ptr< XclImpPTField > XclImpPTFieldRef;
     301             : 
     302             : class XclImpPivotTable : protected XclImpRoot
     303             : {
     304             : public:
     305             :     explicit            XclImpPivotTable( const XclImpRoot& rRoot );
     306             :     virtual             ~XclImpPivotTable();
     307             : 
     308             :     // cache/field access, misc. ----------------------------------------------
     309             : 
     310           0 :     inline XclImpPivotCacheRef GetPivotCache() const { return mxPCache; }
     311           0 :     inline const ScfStringVec& GetVisFieldNames() const { return maVisFieldNames; }
     312             : 
     313             :     sal_uInt16          GetFieldCount() const;
     314             :     const XclImpPTField* GetField( sal_uInt16 nFieldIdx ) const;
     315             :     XclImpPTField*      GetFieldAcc( sal_uInt16 nFieldIdx );
     316             :     const OUString&     GetFieldName( sal_uInt16 nFieldIdx ) const;
     317             : 
     318             :     const XclImpPTField* GetDataField( sal_uInt16 nDataFieldIdx ) const;
     319             :     OUString GetDataFieldName( sal_uInt16 nDataFieldIdx ) const;
     320             : 
     321             :     // records ----------------------------------------------------------------
     322             : 
     323             :     /** Reads an SXVIEW record starting a new pivot table. */
     324             :     void                ReadSxview( XclImpStream& rStrm );
     325             :     /** Reads an SXVD record describing a new field. */
     326             :     void                ReadSxvd( XclImpStream& rStrm );
     327             :     /** Reads an SXVI record describing a new item of the current field. */
     328             :     void                ReadSxvi( XclImpStream& rStrm );
     329             :     /** Reads an SXVDEX record describing extended options of the current field. */
     330             :     void                ReadSxvdex( XclImpStream& rStrm );
     331             :     /** Reads an SXIVD record containing the row field or column field order. */
     332             :     void                ReadSxivd( XclImpStream& rStrm );
     333             :     /** Reads an SXPI record containing page field data. */
     334             :     void                ReadSxpi( XclImpStream& rStrm );
     335             :     /** Reads an SXDI record containing data field data. */
     336             :     void                ReadSxdi( XclImpStream& rStrm );
     337             :     /** Reads an SXEX record containing additional settings for the pivot table. */
     338             :     void                ReadSxex( XclImpStream& rStrm );
     339             :     /** Reads an SXVIEWEX9 record that specifies the pivot tables
     340             :      *  autoformat. */
     341             :     void                ReadSxViewEx9( XclImpStream& rStrm );
     342             : 
     343             :     /** Inserts the pivot table into the Calc document. */
     344             :     void                Convert();
     345             : 
     346             :     void                MaybeRefresh();
     347             : 
     348             :     void                ApplyMergeFlags(const ScRange& rOutRange, const ScDPSaveData& rSaveData);
     349             : 
     350             : 
     351             : private:
     352             :     typedef ::std::vector< XclImpPTFieldRef > XclImpPTFieldVec;
     353             : 
     354             :     XclImpPivotCacheRef mxPCache;           /// Pivot cache containing field/item names.
     355             : 
     356             :     XclPTInfo           maPTInfo;           /// General info about the pivot table (SXVIEW record).
     357             :     XclPTExtInfo        maPTExtInfo;        /// Extended info about the pivot table (SXEX record).
     358             :     XclPTViewEx9Info    maPTViewEx9Info;     /// (SXVIEWEX9 record)
     359             :     XclImpPTFieldVec    maFields;           /// Vector containing all fields.
     360             :     XclImpPTFieldRef    mxCurrField;        /// Current field for importing additional info.
     361             :     ScfStringVec        maVisFieldNames;    /// Vector containing all visible field names.
     362             :     ScfUInt16Vec        maRowFields;        /// Row field indexes.
     363             :     ScfUInt16Vec        maColFields;        /// Column field indexes.
     364             :     ScfUInt16Vec        maPageFields;       /// Page field indexes.
     365             :     ScfUInt16Vec        maOrigDataFields;   /// Original data field indexes.
     366             :     ScfUInt16Vec        maFiltDataFields;   /// Filtered data field indexes.
     367             :     XclImpPTField       maDataOrientField;  /// Special data field orientation field.
     368             :     ScRange             maOutScRange;       /// Output range in the Calc document.
     369             :     ScDPObject*         mpDPObj;
     370             : };
     371             : 
     372             : typedef boost::shared_ptr< XclImpPivotTable > XclImpPivotTableRef;
     373             : 
     374             : 
     375             : /** The main class for pivot table import.
     376             : 
     377             :     This class contains functions to read all records related to pivot tables
     378             :     and pivot caches.
     379             :  */
     380             : class XclImpPivotTableManager : protected XclImpRoot
     381             : {
     382             : public:
     383             :     explicit            XclImpPivotTableManager( const XclImpRoot& rRoot );
     384             :     virtual             ~XclImpPivotTableManager();
     385             : 
     386             :     // pivot cache records ----------------------------------------------------
     387             : 
     388             :     /** Returns the pivot cache with the specified 0-based index. */
     389             :     XclImpPivotCacheRef GetPivotCache( sal_uInt16 nCacheIdx );
     390             : 
     391             :     /** Reads an SXIDSTM record containing a pivot cache stream identifier and the pivot cache. */
     392             :     void                ReadSxidstm( XclImpStream& rStrm );
     393             :     /** Reads an SXVS record containing the source type of a pivot cache. */
     394             :     void                ReadSxvs( XclImpStream& rStrm );
     395             :     /** Reads a DCONREF record containing the source range of a pivot cache. */
     396             :     void                ReadDconref( XclImpStream& rStrm );
     397             :     void                ReadDConName( XclImpStream& rStrm );
     398             : 
     399             :     // pivot table records ----------------------------------------------------
     400             : 
     401             :     /** Reads an SXVIEW record describing a new pivot table. */
     402             :     void                ReadSxview( XclImpStream& rStrm );
     403             :     /** Reads an SXVD record describing a new field. */
     404             :     void                ReadSxvd( XclImpStream& rStrm );
     405             :     /** Reads an SXVDEX record describing extended options of a field. */
     406             :     void                ReadSxvdex( XclImpStream& rStrm );
     407             :     /** Reads an SXIVD record containing the row field or column field order. */
     408             :     void                ReadSxivd( XclImpStream& rStrm );
     409             :     /** Reads an SXPI record containing page field data. */
     410             :     void                ReadSxpi( XclImpStream& rStrm );
     411             :     /** Reads an SXDI record containing data field data. */
     412             :     void                ReadSxdi( XclImpStream& rStrm );
     413             :     /** Reads an SXVI record describing a new item of the current field. */
     414             :     void                ReadSxvi( XclImpStream& rStrm );
     415             :     /** Reads an SXEX record containing additional settings for a pivot table. */
     416             :     void                ReadSxex( XclImpStream& rStrm );
     417             :     /** Reads an SXVIEWEX9 record that specifies the pivot tables
     418             :      *  autoformat. */
     419             :     void                ReadSxViewEx9( XclImpStream& rStrm );
     420             : 
     421             :     /** Reads all used pivot caches and creates additional sheets for external data sources. */
     422             :     void                ReadPivotCaches( XclImpStream& rStrm );
     423             :     /** Inserts all pivot tables into the Calc document. */
     424             :     void                ConvertPivotTables();
     425             : 
     426             :     void                MaybeRefreshPivotTables();
     427             : 
     428             : private:
     429             :     typedef ::std::vector< XclImpPivotCacheRef >    XclImpPivotCacheVec;
     430             :     typedef ::std::vector< XclImpPivotTableRef >    XclImpPivotTableVec;
     431             : 
     432             :     XclImpPivotCacheVec maPCaches;          /// List of all pivot caches.
     433             :     XclImpPivotTableVec maPTables;          /// List of all pivot tables.
     434             : };
     435             : 
     436             : #endif
     437             : 
     438             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10