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

Generated by: LCOV version 1.10