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

Generated by: LCOV version 1.10