LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sc/inc - dpobject.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 8 15 53.3 %
Date: 2013-07-09 Functions: 8 19 42.1 %
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_DPOBJECT_HXX
      21             : #define SC_DPOBJECT_HXX
      22             : 
      23             : #include "scdllapi.h"
      24             : #include "global.hxx"
      25             : #include "address.hxx"
      26             : #include "dpoutput.hxx"
      27             : #include "dptypes.hxx"
      28             : #include "pivot.hxx"
      29             : #include "calcmacros.hxx"
      30             : 
      31             : #include <com/sun/star/sheet/XDimensionsSupplier.hpp>
      32             : 
      33             : #include <set>
      34             : #include <vector>
      35             : 
      36             : #include <boost/ptr_container/ptr_list.hpp>
      37             : #include <boost/ptr_container/ptr_vector.hpp>
      38             : #include <boost/ptr_container/ptr_map.hpp>
      39             : #include <boost/shared_ptr.hpp>
      40             : 
      41             : namespace com { namespace sun { namespace star {
      42             : 
      43             :     namespace container {
      44             :         class XIndexAccess;
      45             :     }
      46             : 
      47             :     namespace sdbc {
      48             :         class XRowSet;
      49             :     }
      50             : 
      51             :     namespace sheet {
      52             :         struct DataPilotTablePositionData;
      53             :         struct DataPilotTableHeaderData;
      54             :         struct DataPilotFieldFilter;
      55             :     }
      56             : }}}
      57             : 
      58             : class Rectangle;
      59             : class ScDPSaveData;
      60             : class ScDPOutput;
      61             : struct ScPivotParam;
      62             : struct ScImportSourceDesc;
      63             : class ScSheetSourceDesc;
      64             : struct ScPivotField;
      65             : class ScDPTableData;
      66             : class ScDPDimensionSaveData;
      67             : class ScRangeList;
      68             : 
      69           0 : struct ScDPServiceDesc
      70             : {
      71             :     OUString aServiceName;
      72             :     OUString aParSource;
      73             :     OUString aParName;
      74             :     OUString aParUser;
      75             :     OUString aParPass;
      76             : 
      77             :     ScDPServiceDesc( const OUString& rServ, const OUString& rSrc, const OUString& rNam,
      78             :                      const OUString& rUser, const OUString& rPass );
      79             : 
      80             :     bool operator== ( const ScDPServiceDesc& rOther ) const;
      81             : };
      82             : 
      83             : 
      84           0 : class SC_DLLPUBLIC ScDPObject
      85             : {
      86             : private:
      87             :     ScDocument*             pDoc;
      88             :                                             // settings
      89             :     ScDPSaveData*           pSaveData;
      90             :     OUString aTableName;
      91             :     OUString aTableTag;
      92             :     ScRange                 aOutRange;
      93             :     ScSheetSourceDesc*      pSheetDesc;     //  for sheet data
      94             :     ScImportSourceDesc*     pImpDesc;       //  for database data
      95             :     ScDPServiceDesc*        pServDesc;      //  for external service
      96             :     ::boost::shared_ptr<ScDPTableData>  mpTableData;
      97             :                                             // cached data
      98             :     com::sun::star::uno::Reference<com::sun::star::sheet::XDimensionsSupplier> xSource;
      99             :     ScDPOutput*             pOutput;
     100             :     sal_uInt16              mnAutoFormatIndex;
     101             :     long                    nHeaderRows;    // page fields plus filter button
     102             :     bool                    mbHeaderLayout:1;  // true : grid, false : standard
     103             :     bool                    bAllowMove:1;
     104             :     bool                    bSettingsChanged:1;
     105             :     bool                    mbEnableGetPivotData:1;
     106             : 
     107             :     SC_DLLPRIVATE ScDPTableData*    GetTableData();
     108             :     SC_DLLPRIVATE void              CreateObjects();
     109             :     SC_DLLPRIVATE void              CreateOutput();
     110             :     SC_DLLPRIVATE void ClearSource();
     111             :     SC_DLLPRIVATE bool FillLabelDataForDimension(
     112             :         const com::sun::star::uno::Reference<
     113             :             com::sun::star::container::XIndexAccess>& xDims,
     114             :         sal_Int32 nDim, ScDPLabelData& rLabelData);
     115             : 
     116             : public:
     117             :     ScDPObject(ScDocument* pD);
     118             :     ScDPObject(const ScDPObject& r);
     119             :     ~ScDPObject();
     120             : 
     121             :     void EnableGetPivotData(bool b);
     122             : 
     123             :     void                SetAllowMove(bool bSet);
     124             : 
     125             :     void                InvalidateData();
     126             :     void ClearTableData();
     127             :     void ReloadGroupTableData();
     128             : 
     129             :     void                Output( const ScAddress& rPos );
     130             :     ScRange             GetNewOutputRange( bool& rOverflow );
     131             :     const ScRange       GetOutputRangeByType( sal_Int32 nType );
     132             : 
     133             :     void                SetSaveData(const ScDPSaveData& rData);
     134         358 :     ScDPSaveData*       GetSaveData() const     { return pSaveData; }
     135             : 
     136             :     void                SetOutRange(const ScRange& rRange);
     137        1721 :     const ScRange&      GetOutRange() const     { return aOutRange; }
     138             : 
     139             :     void                SetHeaderLayout(bool bUseGrid);
     140             :     bool                GetHeaderLayout() const;
     141             : 
     142             :     void                SetSheetDesc(const ScSheetSourceDesc& rDesc, bool bFromRefUpdate = false);
     143             :     void                SetImportDesc(const ScImportSourceDesc& rDesc);
     144             :     void                SetServiceData(const ScDPServiceDesc& rDesc);
     145             : 
     146             :     void                WriteSourceDataTo( ScDPObject& rDest ) const;
     147             :     void                WriteTempDataTo( ScDPObject& rDest ) const;
     148             : 
     149          80 :     const ScSheetSourceDesc* GetSheetDesc() const   { return pSheetDesc; }
     150           0 :     const ScImportSourceDesc* GetImportSourceDesc() const   { return pImpDesc; }
     151           0 :     const ScDPServiceDesc* GetDPServiceDesc() const { return pServDesc; }
     152             : 
     153             :     com::sun::star::uno::Reference<com::sun::star::sheet::XDimensionsSupplier> GetSource();
     154             : 
     155             :     bool                IsSheetData() const;
     156           0 :     bool                IsImportData() const { return(pImpDesc != NULL); }
     157           0 :     bool                IsServiceData() const { return(pServDesc != NULL); }
     158             : 
     159             :     void SetName(const OUString& rNew);
     160        1287 :     const OUString& GetName() const { return aTableName; }
     161             :     void SetTag(const OUString& rNew);
     162          19 :     const OUString& GetTag() const { return aTableTag; }
     163             : 
     164             :     /**
     165             :      *  Data description cell displays the description of a data dimension if
     166             :      *  and only if there is only one data dimension.  It's usually located at
     167             :      *  the upper-left corner of the table output.
     168             :      */
     169             :     bool                IsDataDescriptionCell(const ScAddress& rPos);
     170             : 
     171             :     bool                IsDimNameInUse(const OUString& rName) const;
     172             :     OUString GetDimName( long nDim, bool& rIsDataLayout, sal_Int32* pFlags = NULL );
     173             :     bool                IsDuplicated( long nDim );
     174             :     long                GetDimCount();
     175             :     void                GetHeaderPositionData(const ScAddress& rPos, ::com::sun::star::sheet::DataPilotTableHeaderData& rData);
     176             :     long                GetHeaderDim( const ScAddress& rPos, sal_uInt16& rOrient );
     177             :     bool                GetHeaderDrag( const ScAddress& rPos, bool bMouseLeft, bool bMouseTop,
     178             :                                        long nDragDim,
     179             :                                        Rectangle& rPosRect, sal_uInt16& rOrient, long& rDimPos );
     180             :     bool                IsFilterButton( const ScAddress& rPos );
     181             : 
     182             :     double GetPivotData(
     183             :         const OUString& rDataFieldName,
     184             :         std::vector<com::sun::star::sheet::DataPilotFieldFilter>& rFilters);
     185             : 
     186             :     bool                ParseFilters( ScDPGetPivotDataField& rTarget,
     187             :                                       std::vector< ScDPGetPivotDataField >& rFilters,
     188             :                                       const OUString& rFilterList );
     189             : 
     190             :     void GetMemberResultNames(ScDPUniqueStringSet& rNames, long nDimension);
     191             : 
     192             :     void                ToggleDetails(const ::com::sun::star::sheet::DataPilotTableHeaderData& rElemDesc, ScDPObject* pDestObj);
     193             : 
     194             :     bool                FillOldParam(ScPivotParam& rParam) const;
     195             :     bool                FillLabelData(sal_Int32 nDim, ScDPLabelData& Labels);
     196             :     bool                FillLabelData(ScPivotParam& rParam);
     197             : 
     198             :     bool                GetHierarchiesNA( sal_Int32 nDim, com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >& xHiers );
     199             :     bool                GetHierarchies( sal_Int32 nDim, com::sun::star::uno::Sequence< OUString >& rHiers );
     200             : 
     201             :     sal_Int32           GetUsedHierarchy( sal_Int32 nDim );
     202             : 
     203             :     bool                GetMembersNA( sal_Int32 nDim, com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >& xMembers );
     204             :     bool                GetMembersNA( sal_Int32 nDim, sal_Int32 nHier, com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >& xMembers );
     205             : 
     206             :     bool                GetMemberNames( sal_Int32 nDim, ::com::sun::star::uno::Sequence< OUString >& rNames );
     207             :     bool                GetMembers( sal_Int32 nDim, sal_Int32 nHier, ::std::vector<ScDPLabelData::Member>& rMembers );
     208             : 
     209             :     void                UpdateReference( UpdateRefMode eUpdateRefMode,
     210             :                                          const ScRange& r, SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
     211             :     bool                RefsEqual( const ScDPObject& r ) const;
     212             :     void                WriteRefsTo( ScDPObject& r ) const;
     213             : 
     214             :     void                GetPositionData(const ScAddress& rPos, ::com::sun::star::sheet::DataPilotTablePositionData& rPosData);
     215             : 
     216             :     bool                GetDataFieldPositionData(const ScAddress& rPos,
     217             :                                                  ::com::sun::star::uno::Sequence<
     218             :                                                     ::com::sun::star::sheet::DataPilotFieldFilter >& rFilters);
     219             : 
     220             :     void                GetDrillDownData(const ScAddress& rPos,
     221             :                                          ::com::sun::star::uno::Sequence<
     222             :                                             ::com::sun::star::uno::Sequence<
     223             :                                                 ::com::sun::star::uno::Any > >& rTableData);
     224             : 
     225             :     // apply drop-down attribute, initialize nHeaderRows, without accessing the source
     226             :     // (button attribute must be present)
     227             :     void                RefreshAfterLoad();
     228             : 
     229             :     void                BuildAllDimensionMembers();
     230             : 
     231             :     /**
     232             :      * Remove in the save data entries for members that don't exist anymore.
     233             :      * This is called during pivot table refresh.
     234             :      */
     235             :     bool SyncAllDimensionMembers();
     236             : 
     237             :     static bool         HasRegisteredSources();
     238             :     static com::sun::star::uno::Sequence<OUString> GetRegisteredSources();
     239             :     static com::sun::star::uno::Reference<com::sun::star::sheet::XDimensionsSupplier>
     240             :                         CreateSource( const ScDPServiceDesc& rDesc );
     241             : 
     242             :     static void ConvertOrientation(
     243             :         ScDPSaveData& rSaveData,
     244             :         const ScPivotFieldVector& rFields, sal_uInt16 nOrient,
     245             :         const com::sun::star::uno::Reference<
     246             :             com::sun::star::sheet::XDimensionsSupplier>& xSource,
     247             :         const ScDPLabelDataVector& rLabels,
     248             :         const ScPivotFieldVector* pRefColFields = NULL,
     249             :         const ScPivotFieldVector* pRefRowFields = NULL,
     250             :         const ScPivotFieldVector* pRefPageFields = NULL );
     251             : 
     252             :     static bool         IsOrientationAllowed( sal_uInt16 nOrient, sal_Int32 nDimFlags );
     253             : 
     254             : #if DEBUG_PIVOT_TABLE
     255             :     void DumpCache() const;
     256             : #endif
     257             : };
     258             : 
     259             : 
     260             : class ScDPCollection
     261             : {
     262             :     friend class ScDPCache;
     263             : public:
     264             : 
     265             :     /**
     266             :      * Stores and manages all caches from internal sheets.
     267             :      */
     268         132 :     class SheetCaches
     269             :     {
     270             :         friend class ScDPCollection;
     271             :         typedef boost::ptr_map<size_t, ScDPCache> CachesType;
     272             :         typedef std::vector<ScRange> RangeIndexType;
     273             :         CachesType maCaches;
     274             :         RangeIndexType maRanges;
     275             :         ScDocument* mpDoc;
     276             :     public:
     277             :         SheetCaches(ScDocument* pDoc);
     278             :         bool hasCache(const ScRange& rRange) const;
     279             :         const ScDPCache* getCache(const ScRange& rRange, const ScDPDimensionSaveData* pDimData);
     280             :         size_t size() const;
     281             : 
     282             :         void updateReference(
     283             :             UpdateRefMode eMode, const ScRange& r, SCsCOL nDx, SCsROW nDy, SCsTAB nDz);
     284             : 
     285             :     private:
     286             :         ScDPCache* getExistingCache(const ScRange& rRange);
     287             : 
     288             :         void updateCache(const ScRange& rRange, const ScDPDimensionSaveData* pDimData, std::set<ScDPObject*>& rRefs);
     289             :         bool remove(const ScDPCache* p);
     290             :     };
     291             : 
     292             :     /**
     293             :      * Data caches for range name based source data.
     294             :      */
     295         132 :     class NameCaches
     296             :     {
     297             :         friend class ScDPCollection;
     298             :         typedef ::boost::ptr_map<OUString, ScDPCache> CachesType;
     299             :         CachesType maCaches;
     300             :         ScDocument* mpDoc;
     301             :     public:
     302             :         NameCaches(ScDocument* pDoc);
     303             :         bool hasCache(const OUString& rName) const;
     304             :         const ScDPCache* getCache(
     305             :             const OUString& rName, const ScRange& rRange, const ScDPDimensionSaveData* pDimData);
     306             :         size_t size() const;
     307             :     private:
     308             :         ScDPCache* getExistingCache(const OUString& rName);
     309             : 
     310             :         void updateCache(
     311             :             const OUString& rName, const ScRange& rRange,
     312             :             const ScDPDimensionSaveData* pDimData, std::set<ScDPObject*>& rRefs);
     313             :         bool remove(const ScDPCache* p);
     314             :     };
     315             : 
     316             :     /**
     317             :      * Defines connection type to external data source.  Used as a key to look
     318             :      * up database cache.
     319             :      */
     320           0 :     struct DBType
     321             :     {
     322             :         sal_Int32 mnSdbType;
     323             :         OUString maDBName;
     324             :         OUString maCommand;
     325             :         DBType(sal_Int32 nSdbType, const OUString& rDBName, const OUString& rCommand);
     326             : 
     327             :         struct less : public ::std::binary_function<DBType, DBType, bool>
     328             :         {
     329             :             bool operator() (const DBType& left, const DBType& right) const;
     330             :         };
     331             :     };
     332             : 
     333             :     /**
     334             :      * Data caches for external database sources.
     335             :      */
     336         132 :     class DBCaches
     337             :     {
     338             :         friend class ScDPCollection;
     339             :         typedef ::boost::ptr_map<DBType, ScDPCache, DBType::less> CachesType;
     340             :         CachesType maCaches;
     341             :         ScDocument* mpDoc;
     342             :     public:
     343             :         DBCaches(ScDocument* pDoc);
     344             :         bool hasCache(sal_Int32 nSdbType, const OUString& rDBName, const OUString& rCommand) const;
     345             :         const ScDPCache* getCache(
     346             :             sal_Int32 nSdbType, const OUString& rDBName, const OUString& rCommand,
     347             :             const ScDPDimensionSaveData* pDimData);
     348             : 
     349             :     private:
     350             :         ScDPCache* getExistingCache(
     351             :             sal_Int32 nSdbType, const OUString& rDBName, const OUString& rCommand);
     352             : 
     353             :         com::sun::star::uno::Reference<com::sun::star::sdbc::XRowSet> createRowSet(
     354             :             sal_Int32 nSdbType, const OUString& rDBName, const OUString& rCommand);
     355             : 
     356             :         void updateCache(sal_Int32 nSdbType, const OUString& rDBName, const OUString& rCommand,
     357             :                          const ScDPDimensionSaveData* pDimData, std::set<ScDPObject*>& rRefs);
     358             :         bool remove(const ScDPCache* p);
     359             :     };
     360             : 
     361             :     ScDPCollection(ScDocument* pDocument);
     362             :     ScDPCollection(const ScDPCollection& r);
     363             :     ~ScDPCollection();
     364             : 
     365             :     sal_uLong ReloadCache(ScDPObject* pDPObj, std::set<ScDPObject*>& rRefs);
     366             :     bool ReloadGroupsInCache(ScDPObject* pDPObj, std::set<ScDPObject*>& rRefs);
     367             : 
     368             :     SC_DLLPUBLIC size_t GetCount() const;
     369             :     SC_DLLPUBLIC ScDPObject* operator[](size_t nIndex);
     370             :     SC_DLLPUBLIC const ScDPObject* operator[](size_t nIndex) const;
     371             : 
     372             :     const ScDPObject* GetByName(const OUString& rName) const;
     373             : 
     374             :     void DeleteOnTab( SCTAB nTab );
     375             :     void UpdateReference( UpdateRefMode eUpdateRefMode,
     376             :                           const ScRange& r, SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
     377             :     void CopyToTab( SCTAB nOld, SCTAB nNew );
     378             :     bool RefsEqual( const ScDPCollection& r ) const;
     379             :     void WriteRefsTo( ScDPCollection& r ) const;
     380             : 
     381             :     /**
     382             :      * Create a new name that's not yet used by any existing data pilot
     383             :      * objects.  All data pilot names are 'DataPilot' + <num>, and the nMin
     384             :      * specifies the minimum number allowed.
     385             :      *
     386             :      * @param nMin minimum number allowed.
     387             :      *
     388             :      * @return new name for data pilot object.
     389             :      */
     390             :     OUString CreateNewName( sal_uInt16 nMin = 1 ) const;
     391             : 
     392             :     void FreeTable(ScDPObject* pDPObj);
     393             :     SC_DLLPUBLIC bool InsertNewTable(ScDPObject* pDPObj);
     394             : 
     395             :     SheetCaches& GetSheetCaches();
     396             :     NameCaches& GetNameCaches();
     397             :     DBCaches& GetDBCaches();
     398             : 
     399             :     ScRangeList GetAllTableRanges( SCTAB nTab ) const;
     400             :     bool IntersectsTableByColumns( SCCOL nCol1, SCCOL nCol2, SCROW nRow, SCTAB nTab ) const;
     401             :     bool IntersectsTableByRows( SCCOL nCol, SCROW nRow1, SCROW nRow2, SCTAB nTab ) const;
     402             :     bool HasTable( const ScRange& rRange ) const;
     403             : 
     404             : private:
     405             :     /** Only to be called from ScDPCache::RemoveReference(). */
     406             :     void RemoveCache(const ScDPCache* pCache);
     407             : 
     408             :     void GetAllTables(const ScRange& rSrcRange, std::set<ScDPObject*>& rRefs) const;
     409             :     void GetAllTables(const OUString& rSrcName, std::set<ScDPObject*>& rRefs) const;
     410             :     void GetAllTables(
     411             :         sal_Int32 nSdbType, const OUString& rDBName, const OUString& rCommand,
     412             :         std::set<ScDPObject*>& rRefs) const;
     413             : 
     414             : private:
     415             :     typedef ::boost::ptr_vector<ScDPObject> TablesType;
     416             : 
     417             :     ScDocument* mpDoc;
     418             :     TablesType maTables;
     419             :     SheetCaches maSheetCaches;
     420             :     NameCaches maNameCaches;
     421             :     DBCaches maDBCaches;
     422             : };
     423             : 
     424             : bool operator<(const ScDPCollection::DBType& left, const ScDPCollection::DBType& right);
     425             : 
     426             : #endif
     427             : 
     428             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10