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

Generated by: LCOV version 1.11