xref: /trunk/main/sc/inc/dpsave.hxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef SC_DPSAVE_HXX
29 #define SC_DPSAVE_HXX
30 
31 #include <tools/string.hxx>
32 #include <tools/list.hxx>
33 #include <com/sun/star/sheet/XDimensionsSupplier.hpp>
34 #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
35 #include "scdllapi.h"
36 #include <hash_map>
37 #include <list>
38 #include <memory>
39 
40 namespace com { namespace sun { namespace star { namespace sheet {
41     struct DataPilotFieldReference;
42     struct DataPilotFieldSortInfo;
43     struct DataPilotFieldAutoShowInfo;
44     struct DataPilotFieldLayoutInfo;
45 } } } }
46 
47 class ScDPDimensionSaveData;
48 class ScDPTableData;
49 class ScDPObject;
50 
51 // --------------------------------------------------------------------
52 //
53 //  classes to save Data Pilot settings
54 //
55 
56 
57 class ScDPSaveMember
58 {
59 private:
60     String      aName;
61     ::std::auto_ptr<rtl::OUString> mpLayoutName; // custom name to be displayed in the table.
62     sal_uInt16      nVisibleMode;
63     sal_uInt16      nShowDetailsMode;
64 
65 public:
66                             ScDPSaveMember(const String& rName);
67                             ScDPSaveMember(const ScDPSaveMember& r);
68                             ~ScDPSaveMember();
69 
70     sal_Bool                    operator== ( const ScDPSaveMember& r ) const;
71 
72     const String&           GetName() const { return aName; }
73     SC_DLLPUBLIC sal_Bool   HasIsVisible() const;
74     SC_DLLPUBLIC void       SetIsVisible(sal_Bool bSet);
75     sal_Bool                GetIsVisible() const { return sal_Bool(nVisibleMode); }
76     SC_DLLPUBLIC sal_Bool   HasShowDetails() const;
77     SC_DLLPUBLIC void       SetShowDetails(sal_Bool bSet);
78     sal_Bool                GetShowDetails() const { return sal_Bool(nShowDetailsMode); }
79 
80     void                    SetName( const String& 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<
87                                             com::sun::star::uno::XInterface>& xMember,
88                                             sal_Int32 nPosition );
89 };
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 class SC_DLLPUBLIC ScDPSaveDimension
96 {
97 private:
98     String      aName;
99     String*     pSelectedPage;
100     ::std::auto_ptr<rtl::OUString> mpLayoutName;
101     ::std::auto_ptr<rtl::OUString> mpSubtotalName;
102     sal_Bool        bIsDataLayout;
103     sal_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     sal_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 std::hash_map <String, ScDPSaveMember*, rtl::OUStringHash> MemberHash;
118     typedef std::list <ScDPSaveMember*>                                MemberList;
119 private:
120     MemberHash maMemberHash;
121     MemberList maMemberList;
122 public:
123                             ScDPSaveDimension(const String& rName, sal_Bool bDataLayout);
124                             ScDPSaveDimension(const ScDPSaveDimension& r);
125                             ~ScDPSaveDimension();
126 
127     sal_Bool                    operator== ( const ScDPSaveDimension& r ) const;
128 
129     const MemberList&       GetMembers() const { return maMemberList; }
130     void                    AddMember(ScDPSaveMember* pMember);
131 
132     void                    SetDupFlag(sal_Bool bSet)   { bDupFlag = bSet; }
133     sal_Bool                    GetDupFlag() const      { return bDupFlag; }
134 
135     const String&           GetName() const         { return aName; }
136     sal_Bool                    IsDataLayout() const    { return bIsDataLayout; }
137 
138     void                    SetName( const String& rNew );  // used if the source dim was renamed (groups)
139 
140     void                    SetOrientation(sal_uInt16 nNew);
141     void                    SetSubTotals(long nCount, const sal_uInt16* pFuncs);
142     long                    GetSubTotalsCount() const { return nSubTotalCount; }
143     sal_uInt16                  GetSubTotalFunc(long nIndex) const { return pSubTotalFuncs[nIndex]; }
144     bool                    HasShowEmpty() const;
145     void                    SetShowEmpty(sal_Bool bSet);
146     sal_Bool                    GetShowEmpty() const { return sal_Bool(nShowEmptyMode); }
147     void                    SetFunction(sal_uInt16 nNew);       // enum GeneralFunction
148     sal_uInt16                  GetFunction() const { return nFunction; }
149     void                    SetUsedHierarchy(long nNew);
150     long                    GetUsedHierarchy() const { return nUsedHierarchy; }
151 
152     void                    SetLayoutName(const ::rtl::OUString& rName);
153     const ::rtl::OUString*  GetLayoutName() const;
154     void                    RemoveLayoutName();
155     void                    SetSubtotalName(const ::rtl::OUString& rName);
156     const ::rtl::OUString*  GetSubtotalName() const;
157 
158     bool                    IsMemberNameInUse(const ::rtl::OUString& rName) const;
159 
160     const ::com::sun::star::sheet::DataPilotFieldReference* GetReferenceValue() const   { return pReferenceValue; }
161     void                    SetReferenceValue(const ::com::sun::star::sheet::DataPilotFieldReference* pNew);
162 
163     const ::com::sun::star::sheet::DataPilotFieldSortInfo* GetSortInfo() const          { return pSortInfo; }
164     void                    SetSortInfo(const ::com::sun::star::sheet::DataPilotFieldSortInfo* pNew);
165     const ::com::sun::star::sheet::DataPilotFieldAutoShowInfo* GetAutoShowInfo() const  { return pAutoShowInfo; }
166     void                    SetAutoShowInfo(const ::com::sun::star::sheet::DataPilotFieldAutoShowInfo* pNew);
167     const ::com::sun::star::sheet::DataPilotFieldLayoutInfo* GetLayoutInfo() const      { return pLayoutInfo; }
168     void                    SetLayoutInfo(const ::com::sun::star::sheet::DataPilotFieldLayoutInfo* pNew);
169 
170     void                    SetCurrentPage( const String* pPage );      // NULL = no selection (all)
171     sal_Bool                    HasCurrentPage() const;
172     const String&           GetCurrentPage() const;
173 
174     sal_uInt16                  GetOrientation() const  { return nOrientation; }
175 
176     ScDPSaveMember*         GetExistingMemberByName(const String& rName);
177     ScDPSaveMember*         GetMemberByName(const String& rName);
178 
179     void                    SetMemberPosition( const String& rName, sal_Int32 nNewPos );
180 
181     void                    WriteToSource( const com::sun::star::uno::Reference<
182                                             com::sun::star::uno::XInterface>& xDim );
183     void                    Refresh( const com::sun::star::uno::Reference<
184                                     com::sun::star::sheet::XDimensionsSupplier>& xSource ,
185                                     const   std::list<String> & deletedDims);
186 
187     void                    UpdateMemberVisibility(const ::std::hash_map< ::rtl::OUString, bool, ::rtl::OUStringHash>& rData);
188 
189     bool                    HasInvisibleMember() const;
190 };
191 
192 
193 class ScDPSaveData
194 {
195 private:
196     List        aDimList;
197     ScDPDimensionSaveData* pDimensionData;      // settings that create new dimensions
198     sal_uInt16      nColumnGrandMode;
199     sal_uInt16      nRowGrandMode;
200     sal_uInt16      nIgnoreEmptyMode;
201     sal_uInt16      nRepeatEmptyMode;
202     sal_Bool        bFilterButton;      // not passed to DataPilotSource
203     sal_Bool        bDrillDown;         // not passed to DataPilotSource
204     // Wang Xu Ming -- 2009-8-17
205     // DataPilot Migration - Cache&&Performance
206     long      mnCacheId;
207     // End Comments
208 
209     /** if true, all dimensions already have all of their member instances
210      *  created. */
211     bool        mbDimensionMembersBuilt;
212 
213     ::std::auto_ptr<rtl::OUString> mpGrandTotalName;
214 
215 public:
216     SC_DLLPUBLIC                        ScDPSaveData();
217                             ScDPSaveData(const ScDPSaveData& r);
218     SC_DLLPUBLIC                        ~ScDPSaveData();
219 
220     ScDPSaveData&           operator= ( const ScDPSaveData& r );
221 
222     sal_Bool                    operator== ( const ScDPSaveData& r ) const;
223 
224     SC_DLLPUBLIC void                    SetGrandTotalName(const ::rtl::OUString& rName);
225     SC_DLLPUBLIC const ::rtl::OUString*  GetGrandTotalName() const;
226 
227     const List&             GetDimensions() const { return aDimList; }
228     void                    AddDimension(ScDPSaveDimension* pDim) { aDimList.Insert(pDim, LIST_APPEND); }
229 
230     ScDPSaveDimension*      GetDimensionByName(const String& rName);
231     SC_DLLPUBLIC ScDPSaveDimension*     GetDataLayoutDimension();
232     SC_DLLPUBLIC ScDPSaveDimension*      GetExistingDataLayoutDimension() const;
233 
234     ScDPSaveDimension*      DuplicateDimension(const String& rName);
235     SC_DLLPUBLIC ScDPSaveDimension&      DuplicateDimension(const ScDPSaveDimension& rDim);
236 
237     SC_DLLPUBLIC ScDPSaveDimension*     GetExistingDimensionByName(const String& rName) const;
238     SC_DLLPUBLIC ScDPSaveDimension*     GetNewDimensionByName(const String& rName);
239 
240     void                    RemoveDimensionByName(const String& rName);
241 
242     ScDPSaveDimension*      GetInnermostDimension(sal_uInt16 nOrientation);
243     ScDPSaveDimension*      GetFirstDimension(::com::sun::star::sheet::DataPilotFieldOrientation eOrientation);
244     long                    GetDataDimensionCount() const;
245 
246 
247     void                    SetPosition( ScDPSaveDimension* pDim, long nNew );
248     SC_DLLPUBLIC void                   SetColumnGrand( sal_Bool bSet );
249     sal_Bool                    GetColumnGrand() const { return sal_Bool(nColumnGrandMode); }
250     SC_DLLPUBLIC void                   SetRowGrand( sal_Bool bSet );
251     sal_Bool                    GetRowGrand() const { return sal_Bool(nRowGrandMode); }
252     void                    SetIgnoreEmptyRows( sal_Bool bSet );
253     sal_Bool                    GetIgnoreEmptyRows() const { return sal_Bool(nIgnoreEmptyMode); }
254     void                    SetRepeatIfEmpty( sal_Bool bSet );
255     sal_Bool                    GetRepeatIfEmpty() const { return sal_Bool(nRepeatEmptyMode); }
256 
257     SC_DLLPUBLIC void                    SetFilterButton( sal_Bool bSet );
258     sal_Bool                    GetFilterButton() const { return bFilterButton; }
259     SC_DLLPUBLIC void                    SetDrillDown( sal_Bool bSet );
260     sal_Bool                    GetDrillDown() const { return bDrillDown; }
261 
262     void                    WriteToSource( const com::sun::star::uno::Reference<
263         com::sun::star::sheet::XDimensionsSupplier>& xSource );
264     // Wang Xu Ming -- 2009-8-17
265     // DataPilot Migration - Cache&&Performance
266     void                    Refresh( const com::sun::star::uno::Reference<
267                                             com::sun::star::sheet::XDimensionsSupplier>& xSource );
268     sal_Bool                    IsEmpty() const;
269     inline long GetCacheId() const{ return mnCacheId; }
270     inline void SetCacheId( long nCacheId ){ mnCacheId = nCacheId; }
271     // End Comments
272     const ScDPDimensionSaveData* GetExistingDimensionData() const   { return pDimensionData; }
273     SC_DLLPUBLIC ScDPDimensionSaveData*  GetDimensionData();     // create if not there
274     void                    SetDimensionData( const ScDPDimensionSaveData* pNew );      // copied
275     void                    BuildAllDimensionMembers(ScDPTableData* pData);
276     void                    BuildAllDimensionMembersFromSource(ScDPObject* pDPObj);
277 
278     /**
279      * Check whether a dimension has one or more invisible members.
280      *
281      * @param rDimName dimension name
282      */
283     SC_DLLPUBLIC bool       HasInvisibleMember(const ::rtl::OUString& rDimName) const;
284 };
285 
286 
287 #endif
288 
289