LCOV - code coverage report
Current view: top level - sc/inc - dpsave.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 40 50 80.0 %
Date: 2012-08-25 Functions: 20 25 80.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #ifndef SC_DPSAVE_HXX
      30                 :            : #define SC_DPSAVE_HXX
      31                 :            : 
      32                 :            : #include <list>
      33                 :            : 
      34                 :            : #include <boost/ptr_container/ptr_vector.hpp>
      35                 :            : #include <boost/unordered_map.hpp>
      36                 :            : #include <boost/unordered_set.hpp>
      37                 :            : #include <boost/scoped_ptr.hpp>
      38                 :            : 
      39                 :            : #include <com/sun/star/sheet/XDimensionsSupplier.hpp>
      40                 :            : #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
      41                 :            : #include <rtl/ustring.hxx>
      42                 :            : #include <sal/types.h>
      43                 :            : 
      44                 :            : #include "scdllapi.h"
      45                 :            : 
      46                 :            : namespace com { namespace sun { namespace star { namespace sheet {
      47                 :            :     struct DataPilotFieldReference;
      48                 :            :     struct DataPilotFieldSortInfo;
      49                 :            :     struct DataPilotFieldAutoShowInfo;
      50                 :            :     struct DataPilotFieldLayoutInfo;
      51                 :            : } } } }
      52                 :            : 
      53                 :            : class ScDPDimensionSaveData;
      54                 :            : class ScDPTableData;
      55                 :            : 
      56                 :            : //
      57                 :            : // classes to save Data Pilot settings
      58                 :            : //
      59                 :            : 
      60                 :            : 
      61                 :            : class ScDPSaveMember
      62                 :            : {
      63                 :            : private:
      64                 :            :     ::rtl::OUString aName;
      65                 :            :     boost::scoped_ptr<rtl::OUString> mpLayoutName; // custom name to be displayed in the table.
      66                 :            :     sal_uInt16 nVisibleMode;
      67                 :            :     sal_uInt16 nShowDetailsMode;
      68                 :            : 
      69                 :            : public:
      70                 :            :     ScDPSaveMember(const ::rtl::OUString& rName);
      71                 :            :     ScDPSaveMember(const ScDPSaveMember& r);
      72                 :            :     ~ScDPSaveMember();
      73                 :            : 
      74                 :            :     bool operator== ( const ScDPSaveMember& r ) const;
      75                 :            : 
      76                 :       1523 :     const ::rtl::OUString& GetName() const
      77                 :       1523 :         { return aName; }
      78                 :            : 
      79                 :            :     SC_DLLPUBLIC bool HasIsVisible() const;
      80                 :            :     SC_DLLPUBLIC void SetIsVisible(bool bSet);
      81                 :        459 :     bool GetIsVisible() const
      82                 :        459 :         { return bool(nVisibleMode); }
      83                 :            : 
      84                 :            :     SC_DLLPUBLIC bool HasShowDetails() const;
      85                 :            :     SC_DLLPUBLIC void SetShowDetails(bool bSet);
      86                 :          6 :     bool GetShowDetails() const
      87                 :          6 :         { return bool(nShowDetailsMode); }
      88                 :            : 
      89                 :            :     void SetName( const ::rtl::OUString& rNew ); // used if the source member was renamed (groups)
      90                 :            : 
      91                 :            :     SC_DLLPUBLIC void SetLayoutName( const ::rtl::OUString& rName );
      92                 :            :     SC_DLLPUBLIC const ::rtl::OUString*  GetLayoutName() const;
      93                 :            :     void RemoveLayoutName();
      94                 :            : 
      95                 :            :     void WriteToSource( const com::sun::star::uno::Reference<com::sun::star::uno::XInterface>& xMember,
      96                 :            :                             sal_Int32 nPosition );
      97                 :            : };
      98                 :            : 
      99                 :            : 
     100                 :            : bool operator == (const ::com::sun::star::sheet::DataPilotFieldSortInfo &l, const ::com::sun::star::sheet::DataPilotFieldSortInfo &r );
     101                 :            : bool operator == (const ::com::sun::star::sheet::DataPilotFieldAutoShowInfo &l, const ::com::sun::star::sheet::DataPilotFieldAutoShowInfo &r );
     102                 :            : bool operator == (const ::com::sun::star::sheet::DataPilotFieldReference &l, const ::com::sun::star::sheet::DataPilotFieldReference &r );
     103                 :            : 
     104                 :            : class SC_DLLPUBLIC ScDPSaveDimension
     105                 :            : {
     106                 :            : private:
     107                 :            :     ::rtl::OUString aName;
     108                 :            :     ::rtl::OUString* pSelectedPage;
     109                 :            :     boost::scoped_ptr<rtl::OUString> mpLayoutName;
     110                 :            :     boost::scoped_ptr<rtl::OUString> mpSubtotalName;
     111                 :            :     bool bIsDataLayout;
     112                 :            :     bool bDupFlag;
     113                 :            :     sal_uInt16 nOrientation;
     114                 :            :     sal_uInt16 nFunction; // enum GeneralFunction, for data dimensions
     115                 :            :     long nUsedHierarchy;
     116                 :            :     sal_uInt16 nShowEmptyMode; //! at level
     117                 :            :     bool bSubTotalDefault; //! at level
     118                 :            :     long nSubTotalCount;
     119                 :            :     sal_uInt16* pSubTotalFuncs; // enum GeneralFunction
     120                 :            :     ::com::sun::star::sheet::DataPilotFieldReference* pReferenceValue;
     121                 :            :     ::com::sun::star::sheet::DataPilotFieldSortInfo* pSortInfo; // (level)
     122                 :            :     ::com::sun::star::sheet::DataPilotFieldAutoShowInfo* pAutoShowInfo; // (level)
     123                 :            :     ::com::sun::star::sheet::DataPilotFieldLayoutInfo* pLayoutInfo; // (level)
     124                 :            : 
     125                 :            : public:
     126                 :            :     typedef boost::unordered_set<rtl::OUString, rtl::OUStringHash> MemberSetType;
     127                 :            :     typedef boost::unordered_map <rtl::OUString, ScDPSaveMember*, rtl::OUStringHash> MemberHash;
     128                 :            :     typedef std::list <ScDPSaveMember*> MemberList;
     129                 :            : 
     130                 :            : private:
     131                 :            :     MemberHash maMemberHash;
     132                 :            :     MemberList maMemberList;
     133                 :            : 
     134                 :            : public:
     135                 :            :     ScDPSaveDimension(const ::rtl::OUString& rName, bool bDataLayout);
     136                 :            :     ScDPSaveDimension(const ScDPSaveDimension& r);
     137                 :            :     ~ScDPSaveDimension();
     138                 :            : 
     139                 :            :     bool operator== ( const ScDPSaveDimension& r ) const;
     140                 :            : 
     141                 :          0 :     const MemberList& GetMembers() const
     142                 :          0 :         { return maMemberList; }
     143                 :            : 
     144                 :            :     void AddMember(ScDPSaveMember* pMember);
     145                 :            : 
     146                 :          3 :     void SetDupFlag(bool bSet)
     147                 :          3 :         { bDupFlag = bSet; }
     148                 :            : 
     149                 :        521 :     bool GetDupFlag() const
     150                 :        521 :         { return bDupFlag; }
     151                 :            : 
     152                 :       1526 :     const ::rtl::OUString& GetName() const
     153                 :       1526 :         { return aName; }
     154                 :            : 
     155                 :       1093 :     bool IsDataLayout() const
     156                 :       1093 :         { return bIsDataLayout; }
     157                 :            : 
     158                 :            :     void SetName( const ::rtl::OUString& rNew ); // used if the source dim was renamed (groups)
     159                 :            : 
     160                 :            :     void SetOrientation(sal_uInt16 nNew);
     161                 :            :     void SetSubTotals(long nCount, const sal_uInt16* pFuncs);
     162                 :         10 :     long GetSubTotalsCount() const
     163                 :         10 :         { return nSubTotalCount; }
     164                 :            : 
     165                 :          8 :     sal_uInt16 GetSubTotalFunc(long nIndex) const
     166                 :          8 :         { return pSubTotalFuncs[nIndex]; }
     167                 :            : 
     168                 :            :     bool HasShowEmpty() const;
     169                 :            :     void SetShowEmpty(bool bSet);
     170                 :          9 :     bool GetShowEmpty() const
     171                 :          9 :         { return bool(nShowEmptyMode); }
     172                 :            : 
     173                 :            :     void SetFunction(sal_uInt16 nNew); // enum GeneralFunction
     174                 :          4 :     sal_uInt16 GetFunction() const
     175                 :          4 :         { return nFunction; }
     176                 :            : 
     177                 :            :     void SetUsedHierarchy(long nNew);
     178                 :          0 :     long GetUsedHierarchy() const
     179                 :          0 :         { return nUsedHierarchy; }
     180                 :            : 
     181                 :            :     void SetLayoutName(const ::rtl::OUString& rName);
     182                 :            :     const ::rtl::OUString* GetLayoutName() const;
     183                 :            :     void RemoveLayoutName();
     184                 :            :     void SetSubtotalName(const ::rtl::OUString& rName);
     185                 :            :     const ::rtl::OUString* GetSubtotalName() const;
     186                 :            :     void RemoveSubtotalName();
     187                 :            : 
     188                 :            :     bool IsMemberNameInUse(const ::rtl::OUString& rName) const;
     189                 :            : 
     190                 :         12 :     const ::com::sun::star::sheet::DataPilotFieldReference* GetReferenceValue() const
     191                 :         12 :         { return pReferenceValue; }
     192                 :            : 
     193                 :            :     void SetReferenceValue(const ::com::sun::star::sheet::DataPilotFieldReference* pNew);
     194                 :            : 
     195                 :         12 :     const ::com::sun::star::sheet::DataPilotFieldSortInfo* GetSortInfo() const
     196                 :         12 :         { return pSortInfo; }
     197                 :            : 
     198                 :            :     void SetSortInfo(const ::com::sun::star::sheet::DataPilotFieldSortInfo* pNew);
     199                 :         12 :     const ::com::sun::star::sheet::DataPilotFieldAutoShowInfo* GetAutoShowInfo() const
     200                 :         12 :         { return pAutoShowInfo; }
     201                 :            : 
     202                 :            :     void SetAutoShowInfo(const ::com::sun::star::sheet::DataPilotFieldAutoShowInfo* pNew);
     203                 :         12 :     const ::com::sun::star::sheet::DataPilotFieldLayoutInfo* GetLayoutInfo() const
     204                 :         12 :         { return pLayoutInfo; }
     205                 :            : 
     206                 :            :     void SetLayoutInfo(const ::com::sun::star::sheet::DataPilotFieldLayoutInfo* pNew);
     207                 :            : 
     208                 :            :     void SetCurrentPage( const ::rtl::OUString* pPage ); // NULL = no selection (all)
     209                 :            :     bool HasCurrentPage() const;
     210                 :            :     const ::rtl::OUString& GetCurrentPage() const;
     211                 :            : 
     212                 :        395 :     sal_uInt16 GetOrientation() const
     213                 :        395 :         { return nOrientation; }
     214                 :            : 
     215                 :            :     ScDPSaveMember* GetExistingMemberByName(const ::rtl::OUString& rName);
     216                 :            : 
     217                 :            :     /**
     218                 :            :      * Get a member object by its name.  If one doesn't exist, creat a new
     219                 :            :      * object and return it.  This class manages the life cycle of all member
     220                 :            :      * objects belonging to it, so <i>don't delete the returned instance.</i>
     221                 :            :      *
     222                 :            :      * @param rName member name
     223                 :            :      *
     224                 :            :      * @return pointer to the member object.
     225                 :            :      */
     226                 :            :     ScDPSaveMember* GetMemberByName(const ::rtl::OUString& rName);
     227                 :            : 
     228                 :            :     void SetMemberPosition( const ::rtl::OUString& rName, sal_Int32 nNewPos );
     229                 :            : 
     230                 :            :     void WriteToSource( const com::sun::star::uno::Reference<com::sun::star::uno::XInterface>& xDim );
     231                 :            : 
     232                 :            :     void UpdateMemberVisibility(const ::boost::unordered_map< ::rtl::OUString, bool, ::rtl::OUStringHash>& rData);
     233                 :            : 
     234                 :            :     bool HasInvisibleMember() const;
     235                 :            : 
     236                 :            :     void RemoveObsoleteMembers(const MemberSetType& rMembers);
     237                 :            : };
     238                 :            : 
     239                 :            : 
     240                 :            : class ScDPSaveData
     241                 :            : {
     242                 :            :     typedef boost::unordered_map<rtl::OUString, size_t, rtl::OUStringHash> DupNameCountType;
     243                 :            : public:
     244                 :            :     typedef boost::ptr_vector<ScDPSaveDimension> DimsType;
     245                 :            : 
     246                 :            : private:
     247                 :            :     DimsType aDimList;
     248                 :            :     DupNameCountType maDupNameCounts; /// keep track of number of duplicates in each name.
     249                 :            :     ScDPDimensionSaveData* pDimensionData; // settings that create new dimensions
     250                 :            :     sal_uInt16 nColumnGrandMode;
     251                 :            :     sal_uInt16 nRowGrandMode;
     252                 :            :     sal_uInt16 nIgnoreEmptyMode;
     253                 :            :     sal_uInt16 nRepeatEmptyMode;
     254                 :            :     bool bFilterButton; // not passed to DataPilotSource
     255                 :            :     bool bDrillDown; // not passed to DataPilotSource
     256                 :            : 
     257                 :            :     /** if true, all dimensions already have all of their member instances
     258                 :            :      *  created. */
     259                 :            :     bool mbDimensionMembersBuilt;
     260                 :            : 
     261                 :            :     boost::scoped_ptr<rtl::OUString> mpGrandTotalName;
     262                 :            : 
     263                 :            : public:
     264                 :            :     SC_DLLPUBLIC ScDPSaveData();
     265                 :            :     ScDPSaveData(const ScDPSaveData& r);
     266                 :            :     SC_DLLPUBLIC ~ScDPSaveData();
     267                 :            : 
     268                 :            :     ScDPSaveData& operator= ( const ScDPSaveData& r );
     269                 :            : 
     270                 :            :     bool operator== ( const ScDPSaveData& r ) const;
     271                 :            : 
     272                 :            :     SC_DLLPUBLIC void SetGrandTotalName(const ::rtl::OUString& rName);
     273                 :            :     SC_DLLPUBLIC const ::rtl::OUString* GetGrandTotalName() const;
     274                 :            : 
     275                 :            :     SC_DLLPUBLIC const DimsType& GetDimensions() const;
     276                 :            : 
     277                 :            :     /**
     278                 :            :      * Get all dimensions in a given orientation.  The order represents the
     279                 :            :      * actual order of occurrence.  The returned list also includes data
     280                 :            :      * layout dimension.
     281                 :            :      *
     282                 :            :      * @param eOrientation orientation
     283                 :            :      * @param rDims (out) list of dimensions for specified orientation
     284                 :            :      */
     285                 :            :     SC_DLLPUBLIC void GetAllDimensionsByOrientation(
     286                 :            :         com::sun::star::sheet::DataPilotFieldOrientation eOrientation,
     287                 :            :         std::vector<const ScDPSaveDimension*>& rDims) const;
     288                 :            : 
     289                 :            :     void AddDimension(ScDPSaveDimension* pDim);
     290                 :            : 
     291                 :            :     /**
     292                 :            :      * Get a dimension object by its name.  <i>If one doesn't exist for the
     293                 :            :      * given name, it creats a new one.</i>
     294                 :            :      *
     295                 :            :      * @param rName dimension name
     296                 :            :      *
     297                 :            :      * @return pointer to the dimension object.  The ScDPSaveData instance
     298                 :            :      *         manages its life cycle; hence the caller must
     299                 :            :      *         <i>not</i> delete this object.
     300                 :            :      */
     301                 :            :     SC_DLLPUBLIC ScDPSaveDimension* GetDimensionByName(const ::rtl::OUString& rName);
     302                 :            :     SC_DLLPUBLIC ScDPSaveDimension* GetDataLayoutDimension();
     303                 :            :     SC_DLLPUBLIC ScDPSaveDimension* GetExistingDataLayoutDimension() const;
     304                 :            : 
     305                 :            :     ScDPSaveDimension* DuplicateDimension(const ::rtl::OUString& rName);
     306                 :            :     SC_DLLPUBLIC ScDPSaveDimension& DuplicateDimension(const ScDPSaveDimension& rDim);
     307                 :            : 
     308                 :            :     SC_DLLPUBLIC ScDPSaveDimension* GetExistingDimensionByName(const ::rtl::OUString& rName) const;
     309                 :            :     SC_DLLPUBLIC ScDPSaveDimension* GetNewDimensionByName(const ::rtl::OUString& rName);
     310                 :            : 
     311                 :            :     void RemoveDimensionByName(const ::rtl::OUString& rName);
     312                 :            : 
     313                 :            :     ScDPSaveDimension* GetInnermostDimension(sal_uInt16 nOrientation);
     314                 :            :     ScDPSaveDimension* GetFirstDimension(::com::sun::star::sheet::DataPilotFieldOrientation eOrientation);
     315                 :            :     long GetDataDimensionCount() const;
     316                 :            : 
     317                 :            :     void SetPosition( ScDPSaveDimension* pDim, long nNew );
     318                 :            :     SC_DLLPUBLIC void SetColumnGrand( bool bSet );
     319                 :          0 :     bool GetColumnGrand() const
     320                 :          0 :         { return bool(nColumnGrandMode); }
     321                 :            : 
     322                 :            :     SC_DLLPUBLIC void SetRowGrand( bool bSet );
     323                 :          0 :     bool GetRowGrand() const
     324                 :          0 :         { return bool(nRowGrandMode); }
     325                 :            : 
     326                 :            :     void SetIgnoreEmptyRows( bool bSet );
     327                 :        179 :     bool GetIgnoreEmptyRows() const
     328                 :        179 :         { return bool(nIgnoreEmptyMode); }
     329                 :            : 
     330                 :            :     void SetRepeatIfEmpty( bool bSet );
     331                 :        179 :     bool GetRepeatIfEmpty() const
     332                 :        179 :         { return bool(nRepeatEmptyMode); }
     333                 :            : 
     334                 :            :     SC_DLLPUBLIC void SetFilterButton( bool bSet );
     335                 :        140 :     bool GetFilterButton() const
     336                 :        140 :         { return bFilterButton; }
     337                 :            : 
     338                 :            :     SC_DLLPUBLIC void SetDrillDown( bool bSet );
     339                 :          0 :     bool GetDrillDown() const
     340                 :          0 :         { return bDrillDown; }
     341                 :            : 
     342                 :            :     void WriteToSource( const com::sun::star::uno::Reference<com::sun::star::sheet::XDimensionsSupplier>& xSource );
     343                 :            :     bool IsEmpty() const;
     344                 :            : 
     345                 :        227 :     const ScDPDimensionSaveData* GetExistingDimensionData() const
     346                 :        227 :         { return pDimensionData; }
     347                 :            : 
     348                 :            :     SC_DLLPUBLIC ScDPDimensionSaveData* GetDimensionData(); // create if not there
     349                 :            :     void SetDimensionData( const ScDPDimensionSaveData* pNew ); // copied
     350                 :            :     void BuildAllDimensionMembers(ScDPTableData* pData);
     351                 :            :     void SyncAllDimensionMembers(ScDPTableData* pData);
     352                 :            : 
     353                 :            :     /**
     354                 :            :      * Check whether a dimension has one or more invisible members.
     355                 :            :      *
     356                 :            :      * @param rDimName dimension name
     357                 :            :      */
     358                 :            :     SC_DLLPUBLIC bool HasInvisibleMember(const ::rtl::OUString& rDimName) const;
     359                 :            : 
     360                 :            : private:
     361                 :            :     void CheckDuplicateName(ScDPSaveDimension& rDim);
     362                 :            :     void RemoveDuplicateNameCount(const rtl::OUString& rName);
     363                 :            : 
     364                 :            :     /**
     365                 :            :      * Append a new original dimension. Not to be called to insert a duplicate
     366                 :            :      * dimension.
     367                 :            :      *
     368                 :            :      * @param rName Dimension name. The name must be the original dimension
     369                 :            :      *              name; not a duplicate dimension name.
     370                 :            :      * @param bDataLayout true if this is a data layout dimension, false
     371                 :            :      *                    otherwise.
     372                 :            :      *
     373                 :            :      * @return pointer to the new dimension just inserted.
     374                 :            :      */
     375                 :            :     ScDPSaveDimension* AppendNewDimension(const rtl::OUString& rName, bool bDataLayout);
     376                 :            : };
     377                 :            : 
     378                 :            : #endif
     379                 :            : 
     380                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10