LCOV - code coverage report
Current view: top level - sc/inc - dpsave.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 43 51 84.3 %
Date: 2014-11-03 Functions: 22 26 84.6 %
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_INC_DPSAVE_HXX
      21             : #define INCLUDED_SC_INC_DPSAVE_HXX
      22             : 
      23             : #include <list>
      24             : 
      25             : #include <boost/ptr_container/ptr_vector.hpp>
      26             : #include <boost/unordered_map.hpp>
      27             : #include <boost/unordered_set.hpp>
      28             : #include <boost/scoped_ptr.hpp>
      29             : 
      30             : #include <com/sun/star/sheet/XDimensionsSupplier.hpp>
      31             : #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
      32             : #include <rtl/ustring.hxx>
      33             : #include <sal/types.h>
      34             : 
      35             : #include "scdllapi.h"
      36             : #include "calcmacros.hxx"
      37             : 
      38             : namespace com { namespace sun { namespace star { namespace sheet {
      39             :     struct DataPilotFieldReference;
      40             :     struct DataPilotFieldSortInfo;
      41             :     struct DataPilotFieldAutoShowInfo;
      42             :     struct DataPilotFieldLayoutInfo;
      43             : } } } }
      44             : 
      45             : class ScDPDimensionSaveData;
      46             : class ScDPTableData;
      47             : 
      48             : // classes to save Data Pilot settings
      49             : 
      50             : class ScDPSaveMember
      51             : {
      52             : private:
      53             :     OUString aName;
      54             :     boost::scoped_ptr<OUString> mpLayoutName; // custom name to be displayed in the table.
      55             :     sal_uInt16 nVisibleMode;
      56             :     sal_uInt16 nShowDetailsMode;
      57             : 
      58             : public:
      59             :     ScDPSaveMember(const OUString& rName);
      60             :     ScDPSaveMember(const ScDPSaveMember& r);
      61             :     ~ScDPSaveMember();
      62             : 
      63             :     bool operator== ( const ScDPSaveMember& r ) const;
      64             : 
      65       15966 :     const OUString& GetName() const
      66       15966 :         { return aName; }
      67             : 
      68             :     SC_DLLPUBLIC bool HasIsVisible() const;
      69             :     SC_DLLPUBLIC void SetIsVisible(bool bSet);
      70       11444 :     bool GetIsVisible() const
      71       11444 :         { return bool(nVisibleMode); }
      72             : 
      73             :     SC_DLLPUBLIC bool HasShowDetails() const;
      74             :     SC_DLLPUBLIC void SetShowDetails(bool bSet);
      75          12 :     bool GetShowDetails() const
      76          12 :         { return bool(nShowDetailsMode); }
      77             : 
      78             :     void SetName( const OUString& rNew ); // used if the source member was renamed (groups)
      79             : 
      80             :     SC_DLLPUBLIC void SetLayoutName( const OUString& rName );
      81             :     SC_DLLPUBLIC const OUString*  GetLayoutName() const;
      82             :     void RemoveLayoutName();
      83             : 
      84             :     void WriteToSource( const com::sun::star::uno::Reference<com::sun::star::uno::XInterface>& xMember,
      85             :                             sal_Int32 nPosition );
      86             : 
      87             : #if DEBUG_PIVOT_TABLE
      88             :     void Dump(int nIndent = 0) const;
      89             : #endif
      90             : };
      91             : 
      92             : bool operator == (const ::com::sun::star::sheet::DataPilotFieldSortInfo &l, const ::com::sun::star::sheet::DataPilotFieldSortInfo &r );
      93             : bool operator == (const ::com::sun::star::sheet::DataPilotFieldAutoShowInfo &l, const ::com::sun::star::sheet::DataPilotFieldAutoShowInfo &r );
      94             : bool operator == (const ::com::sun::star::sheet::DataPilotFieldReference &l, const ::com::sun::star::sheet::DataPilotFieldReference &r );
      95             : 
      96             : class SC_DLLPUBLIC ScDPSaveDimension
      97             : {
      98             : private:
      99             :     OUString aName;
     100             :     boost::scoped_ptr<OUString> mpLayoutName;
     101             :     boost::scoped_ptr<OUString> mpSubtotalName;
     102             :     bool bIsDataLayout;
     103             :     bool bDupFlag;
     104             :     sal_uInt16 nOrientation;
     105             :     sal_uInt16 nFunction; // enum GeneralFunction, for data dimensions
     106             :     long nUsedHierarchy;
     107             :     sal_uInt16 nShowEmptyMode; //! at level
     108             :     bool bSubTotalDefault; //! at level
     109             :     long nSubTotalCount;
     110             :     sal_uInt16* pSubTotalFuncs; // enum GeneralFunction
     111             :     ::com::sun::star::sheet::DataPilotFieldReference* pReferenceValue;
     112             :     ::com::sun::star::sheet::DataPilotFieldSortInfo* pSortInfo; // (level)
     113             :     ::com::sun::star::sheet::DataPilotFieldAutoShowInfo* pAutoShowInfo; // (level)
     114             :     ::com::sun::star::sheet::DataPilotFieldLayoutInfo* pLayoutInfo; // (level)
     115             : 
     116             : public:
     117             :     typedef boost::unordered_set<OUString, OUStringHash> MemberSetType;
     118             :     typedef boost::unordered_map <OUString, ScDPSaveMember*, OUStringHash> MemberHash;
     119             :     typedef std::list <ScDPSaveMember*> MemberList;
     120             : 
     121             : private:
     122             :     MemberHash maMemberHash;
     123             :     MemberList maMemberList;
     124             : 
     125             : public:
     126             :     ScDPSaveDimension(const OUString& rName, bool bDataLayout);
     127             :     ScDPSaveDimension(const ScDPSaveDimension& r);
     128             :     ~ScDPSaveDimension();
     129             : 
     130             :     bool operator== ( const ScDPSaveDimension& r ) const;
     131             : 
     132           4 :     const MemberList& GetMembers() const
     133           4 :         { return maMemberList; }
     134             : 
     135             :     void AddMember(ScDPSaveMember* pMember);
     136             : 
     137           8 :     void SetDupFlag(bool bSet)
     138           8 :         { bDupFlag = bSet; }
     139             : 
     140         648 :     bool GetDupFlag() const
     141         648 :         { return bDupFlag; }
     142             : 
     143        4536 :     const OUString& GetName() const
     144        4536 :         { return aName; }
     145             : 
     146        1994 :     bool IsDataLayout() const
     147        1994 :         { return bIsDataLayout; }
     148             : 
     149             :     void SetName( const OUString& rNew ); // used if the source dim was renamed (groups)
     150             : 
     151             :     void SetOrientation(sal_uInt16 nNew);
     152             :     void SetSubTotals(long nCount, const sal_uInt16* pFuncs);
     153          20 :     long GetSubTotalsCount() const
     154          20 :         { return nSubTotalCount; }
     155             : 
     156          16 :     sal_uInt16 GetSubTotalFunc(long nIndex) const
     157          16 :         { return pSubTotalFuncs[nIndex]; }
     158             : 
     159             :     bool HasShowEmpty() const;
     160             :     void SetShowEmpty(bool bSet);
     161          17 :     bool GetShowEmpty() const
     162          17 :         { return bool(nShowEmptyMode); }
     163             : 
     164             :     void SetFunction(sal_uInt16 nNew); // enum GeneralFunction
     165          88 :     sal_uInt16 GetFunction() const
     166          88 :         { return nFunction; }
     167             : 
     168             :     void SetUsedHierarchy(long nNew);
     169           0 :     long GetUsedHierarchy() const
     170           0 :         { return nUsedHierarchy; }
     171             : 
     172             :     void SetLayoutName(const OUString& rName);
     173             :     const OUString* GetLayoutName() const;
     174             :     void RemoveLayoutName();
     175             :     void SetSubtotalName(const OUString& rName);
     176             :     const OUString* GetSubtotalName() const;
     177             :     void RemoveSubtotalName();
     178             : 
     179             :     bool IsMemberNameInUse(const OUString& rName) const;
     180             : 
     181          14 :     const ::com::sun::star::sheet::DataPilotFieldReference* GetReferenceValue() const
     182          14 :         { return pReferenceValue; }
     183             : 
     184             :     void SetReferenceValue(const ::com::sun::star::sheet::DataPilotFieldReference* pNew);
     185             : 
     186          14 :     const ::com::sun::star::sheet::DataPilotFieldSortInfo* GetSortInfo() const
     187          14 :         { return pSortInfo; }
     188             : 
     189             :     void SetSortInfo(const ::com::sun::star::sheet::DataPilotFieldSortInfo* pNew);
     190          14 :     const ::com::sun::star::sheet::DataPilotFieldAutoShowInfo* GetAutoShowInfo() const
     191          14 :         { return pAutoShowInfo; }
     192             : 
     193             :     void SetAutoShowInfo(const ::com::sun::star::sheet::DataPilotFieldAutoShowInfo* pNew);
     194          14 :     const ::com::sun::star::sheet::DataPilotFieldLayoutInfo* GetLayoutInfo() const
     195          14 :         { return pLayoutInfo; }
     196             : 
     197             :     void SetLayoutInfo(const ::com::sun::star::sheet::DataPilotFieldLayoutInfo* pNew);
     198             : 
     199             :     void SetCurrentPage( const OUString* pPage ); // NULL = no selection (all)
     200             : 
     201        1882 :     sal_uInt16 GetOrientation() const
     202        1882 :         { return nOrientation; }
     203             : 
     204             :     ScDPSaveMember* GetExistingMemberByName(const OUString& rName);
     205             : 
     206             :     /**
     207             :      * Get a member object by its name.  If one doesn't exist, creat a new
     208             :      * object and return it.  This class manages the life cycle of all member
     209             :      * objects belonging to it, so <i>don't delete the returned instance.</i>
     210             :      *
     211             :      * @param rName member name
     212             :      *
     213             :      * @return pointer to the member object.
     214             :      */
     215             :     ScDPSaveMember* GetMemberByName(const OUString& rName);
     216             : 
     217             :     void SetMemberPosition( const OUString& rName, sal_Int32 nNewPos );
     218             : 
     219             :     void WriteToSource( const com::sun::star::uno::Reference<com::sun::star::uno::XInterface>& xDim );
     220             : 
     221             :     void UpdateMemberVisibility(const ::boost::unordered_map< OUString, bool, OUStringHash>& rData);
     222             : 
     223             :     bool HasInvisibleMember() const;
     224             : 
     225             :     void RemoveObsoleteMembers(const MemberSetType& rMembers);
     226             : 
     227             : #if DEBUG_PIVOT_TABLE
     228             :     void Dump(int nIndent = 0) const;
     229             : #endif
     230             : };
     231             : 
     232             : class ScDPSaveData
     233             : {
     234             :     typedef boost::unordered_map<OUString, size_t, OUStringHash> DupNameCountType;
     235             : public:
     236             :     typedef boost::unordered_map<OUString, size_t, OUStringHash> DimOrderType;
     237             :     typedef boost::ptr_vector<ScDPSaveDimension> DimsType;
     238             : 
     239             : private:
     240             :     DimsType aDimList;
     241             :     DupNameCountType maDupNameCounts; /// keep track of number of duplicates in each name.
     242             :     ScDPDimensionSaveData* pDimensionData; // settings that create new dimensions
     243             :     sal_uInt16 nColumnGrandMode;
     244             :     sal_uInt16 nRowGrandMode;
     245             :     sal_uInt16 nIgnoreEmptyMode;
     246             :     sal_uInt16 nRepeatEmptyMode;
     247             :     bool bFilterButton; // not passed to DataPilotSource
     248             :     bool bDrillDown; // not passed to DataPilotSource
     249             : 
     250             :     /** if true, all dimensions already have all of their member instances
     251             :      *  created. */
     252             :     bool mbDimensionMembersBuilt;
     253             : 
     254             :     boost::scoped_ptr<OUString> mpGrandTotalName;
     255             :     mutable boost::scoped_ptr<DimOrderType> mpDimOrder; // dimension order for row and column dimensions, to traverse result tree.
     256             : 
     257             : public:
     258             :     SC_DLLPUBLIC ScDPSaveData();
     259             :     ScDPSaveData(const ScDPSaveData& r);
     260             :     SC_DLLPUBLIC ~ScDPSaveData();
     261             : 
     262             :     ScDPSaveData& operator= ( const ScDPSaveData& r );
     263             : 
     264             :     bool operator== ( const ScDPSaveData& r ) const;
     265             : 
     266             :     SC_DLLPUBLIC void SetGrandTotalName(const OUString& rName);
     267             :     SC_DLLPUBLIC const OUString* GetGrandTotalName() const;
     268             : 
     269         164 :     const DimsType& GetDimensions() const { return aDimList;}
     270             : 
     271             :     /**
     272             :      * Get sort order map to sort row and column dimensions in order of
     273             :      * appearance. Row dimensions get sorted before column dimensions.  This
     274             :      * is used to traverse result tree, which is structured following this
     275             :      * order.
     276             :      */
     277             :     const DimOrderType& GetDimensionSortOrder() const;
     278             : 
     279             :     /**
     280             :      * Get all dimensions in a given orientation.  The order represents the
     281             :      * actual order of occurrence.  The returned list also includes data
     282             :      * layout dimension.
     283             :      *
     284             :      * @param eOrientation orientation
     285             :      * @param rDims (out) list of dimensions for specified orientation
     286             :      */
     287             :     SC_DLLPUBLIC void GetAllDimensionsByOrientation(
     288             :         com::sun::star::sheet::DataPilotFieldOrientation eOrientation,
     289             :         std::vector<const ScDPSaveDimension*>& rDims) const;
     290             : 
     291             :     void AddDimension(ScDPSaveDimension* pDim);
     292             : 
     293             :     /**
     294             :      * Get a dimension object by its name.  <i>If one doesn't exist for the
     295             :      * given name, it creates a new one.</i>
     296             :      *
     297             :      * @param rName dimension name
     298             :      *
     299             :      * @return pointer to the dimension object.  The ScDPSaveData instance
     300             :      *         manages its life cycle; hence the caller must
     301             :      *         <i>not</i> delete this object.
     302             :      */
     303             :     SC_DLLPUBLIC ScDPSaveDimension* GetDimensionByName(const OUString& rName);
     304             :     SC_DLLPUBLIC ScDPSaveDimension* GetDataLayoutDimension();
     305             :     SC_DLLPUBLIC ScDPSaveDimension* GetExistingDataLayoutDimension() const;
     306             : 
     307             :     ScDPSaveDimension* DuplicateDimension(const OUString& rName);
     308             :     SC_DLLPUBLIC ScDPSaveDimension& DuplicateDimension(const ScDPSaveDimension& rDim);
     309             : 
     310             :     SC_DLLPUBLIC ScDPSaveDimension* GetExistingDimensionByName(const OUString& rName) const;
     311             :     SC_DLLPUBLIC ScDPSaveDimension* GetNewDimensionByName(const OUString& rName);
     312             : 
     313             :     void RemoveDimensionByName(const OUString& rName);
     314             : 
     315             :     ScDPSaveDimension* GetInnermostDimension(sal_uInt16 nOrientation);
     316             :     ScDPSaveDimension* GetFirstDimension(::com::sun::star::sheet::DataPilotFieldOrientation eOrientation);
     317             :     long GetDataDimensionCount() const;
     318             : 
     319             :     void SetPosition( ScDPSaveDimension* pDim, long nNew );
     320             :     SC_DLLPUBLIC void SetColumnGrand( bool bSet );
     321           0 :     bool GetColumnGrand() const
     322           0 :         { return bool(nColumnGrandMode); }
     323             : 
     324             :     SC_DLLPUBLIC void SetRowGrand( bool bSet );
     325           0 :     bool GetRowGrand() const
     326           0 :         { return bool(nRowGrandMode); }
     327             : 
     328             :     void SetIgnoreEmptyRows( bool bSet );
     329         340 :     bool GetIgnoreEmptyRows() const
     330         340 :         { return bool(nIgnoreEmptyMode); }
     331             : 
     332             :     void SetRepeatIfEmpty( bool bSet );
     333         340 :     bool GetRepeatIfEmpty() const
     334         340 :         { return bool(nRepeatEmptyMode); }
     335             : 
     336             :     SC_DLLPUBLIC void SetFilterButton( bool bSet );
     337         174 :     bool GetFilterButton() const
     338         174 :         { return bFilterButton; }
     339             : 
     340             :     SC_DLLPUBLIC void SetDrillDown( bool bSet );
     341           0 :     bool GetDrillDown() const
     342           0 :         { return bDrillDown; }
     343             : 
     344             :     void WriteToSource( const com::sun::star::uno::Reference<com::sun::star::sheet::XDimensionsSupplier>& xSource );
     345             :     bool IsEmpty() const;
     346             : 
     347         302 :     const ScDPDimensionSaveData* GetExistingDimensionData() const
     348         302 :         { return pDimensionData; }
     349             : 
     350             :     void RemoveAllGroupDimensions( const OUString& rSrcDimName, std::vector<OUString>* pDeletedNames = NULL );
     351             : 
     352             :     SC_DLLPUBLIC ScDPDimensionSaveData* GetDimensionData(); // create if not there
     353             :     void SetDimensionData( const ScDPDimensionSaveData* pNew ); // copied
     354             :     void BuildAllDimensionMembers(ScDPTableData* pData);
     355             :     void SyncAllDimensionMembers(ScDPTableData* pData);
     356             : 
     357             :     /**
     358             :      * Check whether a dimension has one or more invisible members.
     359             :      *
     360             :      * @param rDimName dimension name
     361             :      */
     362             :     SC_DLLPUBLIC bool HasInvisibleMember(const OUString& rDimName) const;
     363             : 
     364             : #if DEBUG_PIVOT_TABLE
     365             :     void Dump() const;
     366             : #endif
     367             : 
     368             : private:
     369             :     void CheckDuplicateName(ScDPSaveDimension& rDim);
     370             :     void RemoveDuplicateNameCount(const OUString& rName);
     371             : 
     372             :     /**
     373             :      * Append a new original dimension. Not to be called to insert a duplicate
     374             :      * dimension.
     375             :      *
     376             :      * @param rName Dimension name. The name must be the original dimension
     377             :      *              name; not a duplicate dimension name.
     378             :      * @param bDataLayout true if this is a data layout dimension, false
     379             :      *                    otherwise.
     380             :      *
     381             :      * @return pointer to the new dimension just inserted.
     382             :      */
     383             :     ScDPSaveDimension* AppendNewDimension(const OUString& rName, bool bDataLayout);
     384             : 
     385             :     void DimensionsChanged();
     386             : };
     387             : 
     388             : #endif
     389             : 
     390             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10