bump product version to 4.1.6.2
[LibreOffice.git] / sc / inc / dpsave.hxx
blob905bfc86e5f9f878c53b9a6b32bf407b0b50f225
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef SC_DPSAVE_HXX
21 #define SC_DPSAVE_HXX
23 #include <list>
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>
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>
35 #include "scdllapi.h"
37 namespace com { namespace sun { namespace star { namespace sheet {
38 struct DataPilotFieldReference;
39 struct DataPilotFieldSortInfo;
40 struct DataPilotFieldAutoShowInfo;
41 struct DataPilotFieldLayoutInfo;
42 } } } }
44 class ScDPDimensionSaveData;
45 class ScDPTableData;
48 // classes to save Data Pilot settings
52 class ScDPSaveMember
54 private:
55 OUString aName;
56 boost::scoped_ptr<OUString> mpLayoutName; // custom name to be displayed in the table.
57 sal_uInt16 nVisibleMode;
58 sal_uInt16 nShowDetailsMode;
60 public:
61 ScDPSaveMember(const OUString& rName);
62 ScDPSaveMember(const ScDPSaveMember& r);
63 ~ScDPSaveMember();
65 bool operator== ( const ScDPSaveMember& r ) const;
67 const OUString& GetName() const
68 { return aName; }
70 SC_DLLPUBLIC bool HasIsVisible() const;
71 SC_DLLPUBLIC void SetIsVisible(bool bSet);
72 bool GetIsVisible() const
73 { return bool(nVisibleMode); }
75 SC_DLLPUBLIC bool HasShowDetails() const;
76 SC_DLLPUBLIC void SetShowDetails(bool bSet);
77 bool GetShowDetails() const
78 { return bool(nShowDetailsMode); }
80 void SetName( const OUString& rNew ); // used if the source member was renamed (groups)
82 SC_DLLPUBLIC void SetLayoutName( const OUString& rName );
83 SC_DLLPUBLIC const OUString* GetLayoutName() const;
84 void RemoveLayoutName();
86 void WriteToSource( const com::sun::star::uno::Reference<com::sun::star::uno::XInterface>& xMember,
87 sal_Int32 nPosition );
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 );
95 class SC_DLLPUBLIC ScDPSaveDimension
97 private:
98 OUString aName;
99 boost::scoped_ptr<OUString> mpLayoutName;
100 boost::scoped_ptr<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)
115 public:
116 typedef boost::unordered_set<OUString, OUStringHash> MemberSetType;
117 typedef boost::unordered_map <OUString, ScDPSaveMember*, OUStringHash> MemberHash;
118 typedef std::list <ScDPSaveMember*> MemberList;
120 private:
121 MemberHash maMemberHash;
122 MemberList maMemberList;
124 public:
125 ScDPSaveDimension(const OUString& rName, bool bDataLayout);
126 ScDPSaveDimension(const ScDPSaveDimension& r);
127 ~ScDPSaveDimension();
129 bool operator== ( const ScDPSaveDimension& r ) const;
131 const MemberList& GetMembers() const
132 { return maMemberList; }
134 void AddMember(ScDPSaveMember* pMember);
136 void SetDupFlag(bool bSet)
137 { bDupFlag = bSet; }
139 bool GetDupFlag() const
140 { return bDupFlag; }
142 const OUString& GetName() const
143 { return aName; }
145 bool IsDataLayout() const
146 { return bIsDataLayout; }
148 void SetName( const OUString& rNew ); // used if the source dim was renamed (groups)
150 void SetOrientation(sal_uInt16 nNew);
151 void SetSubTotals(long nCount, const sal_uInt16* pFuncs);
152 long GetSubTotalsCount() const
153 { return nSubTotalCount; }
155 sal_uInt16 GetSubTotalFunc(long nIndex) const
156 { return pSubTotalFuncs[nIndex]; }
158 bool HasShowEmpty() const;
159 void SetShowEmpty(bool bSet);
160 bool GetShowEmpty() const
161 { return bool(nShowEmptyMode); }
163 void SetFunction(sal_uInt16 nNew); // enum GeneralFunction
164 sal_uInt16 GetFunction() const
165 { return nFunction; }
167 void SetUsedHierarchy(long nNew);
168 long GetUsedHierarchy() const
169 { return nUsedHierarchy; }
171 void SetLayoutName(const OUString& rName);
172 const OUString* GetLayoutName() const;
173 void RemoveLayoutName();
174 void SetSubtotalName(const OUString& rName);
175 const OUString* GetSubtotalName() const;
176 void RemoveSubtotalName();
178 bool IsMemberNameInUse(const OUString& rName) const;
180 const ::com::sun::star::sheet::DataPilotFieldReference* GetReferenceValue() const
181 { return pReferenceValue; }
183 void SetReferenceValue(const ::com::sun::star::sheet::DataPilotFieldReference* pNew);
185 const ::com::sun::star::sheet::DataPilotFieldSortInfo* GetSortInfo() const
186 { return pSortInfo; }
188 void SetSortInfo(const ::com::sun::star::sheet::DataPilotFieldSortInfo* pNew);
189 const ::com::sun::star::sheet::DataPilotFieldAutoShowInfo* GetAutoShowInfo() const
190 { return pAutoShowInfo; }
192 void SetAutoShowInfo(const ::com::sun::star::sheet::DataPilotFieldAutoShowInfo* pNew);
193 const ::com::sun::star::sheet::DataPilotFieldLayoutInfo* GetLayoutInfo() const
194 { return pLayoutInfo; }
196 void SetLayoutInfo(const ::com::sun::star::sheet::DataPilotFieldLayoutInfo* pNew);
198 void SetCurrentPage( const OUString* pPage ); // NULL = no selection (all)
200 sal_uInt16 GetOrientation() const
201 { return nOrientation; }
203 ScDPSaveMember* GetExistingMemberByName(const OUString& rName);
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>
210 * @param rName member name
212 * @return pointer to the member object.
214 ScDPSaveMember* GetMemberByName(const OUString& rName);
216 void SetMemberPosition( const OUString& rName, sal_Int32 nNewPos );
218 void WriteToSource( const com::sun::star::uno::Reference<com::sun::star::uno::XInterface>& xDim );
220 void UpdateMemberVisibility(const ::boost::unordered_map< OUString, bool, OUStringHash>& rData);
222 bool HasInvisibleMember() const;
224 void RemoveObsoleteMembers(const MemberSetType& rMembers);
228 class ScDPSaveData
230 typedef boost::unordered_map<OUString, size_t, OUStringHash> DupNameCountType;
231 public:
232 typedef boost::unordered_map<OUString, size_t, OUStringHash> DimOrderType;
233 typedef boost::ptr_vector<ScDPSaveDimension> DimsType;
235 private:
236 DimsType aDimList;
237 DupNameCountType maDupNameCounts; /// keep track of number of duplicates in each name.
238 ScDPDimensionSaveData* pDimensionData; // settings that create new dimensions
239 sal_uInt16 nColumnGrandMode;
240 sal_uInt16 nRowGrandMode;
241 sal_uInt16 nIgnoreEmptyMode;
242 sal_uInt16 nRepeatEmptyMode;
243 bool bFilterButton; // not passed to DataPilotSource
244 bool bDrillDown; // not passed to DataPilotSource
246 /** if true, all dimensions already have all of their member instances
247 * created. */
248 bool mbDimensionMembersBuilt;
250 boost::scoped_ptr<OUString> mpGrandTotalName;
251 mutable boost::scoped_ptr<DimOrderType> mpDimOrder; // dimension order for row and column dimensions, to traverse result tree.
253 public:
254 SC_DLLPUBLIC ScDPSaveData();
255 ScDPSaveData(const ScDPSaveData& r);
256 SC_DLLPUBLIC ~ScDPSaveData();
258 ScDPSaveData& operator= ( const ScDPSaveData& r );
260 bool operator== ( const ScDPSaveData& r ) const;
262 SC_DLLPUBLIC void SetGrandTotalName(const OUString& rName);
263 SC_DLLPUBLIC const OUString* GetGrandTotalName() const;
265 SC_DLLPUBLIC const DimsType& GetDimensions() const;
268 * Get sort order map to sort row and column dimensions in order of
269 * appearance. Row dimensions get sorted before column dimensions. This
270 * is used to traverse result tree, which is structured following this
271 * order.
273 const DimOrderType& GetDimensionSortOrder() const;
276 * Get all dimensions in a given orientation. The order represents the
277 * actual order of occurrence. The returned list also includes data
278 * layout dimension.
280 * @param eOrientation orientation
281 * @param rDims (out) list of dimensions for specified orientation
283 SC_DLLPUBLIC void GetAllDimensionsByOrientation(
284 com::sun::star::sheet::DataPilotFieldOrientation eOrientation,
285 std::vector<const ScDPSaveDimension*>& rDims) const;
287 void AddDimension(ScDPSaveDimension* pDim);
290 * Get a dimension object by its name. <i>If one doesn't exist for the
291 * given name, it creates a new one.</i>
293 * @param rName dimension name
295 * @return pointer to the dimension object. The ScDPSaveData instance
296 * manages its life cycle; hence the caller must
297 * <i>not</i> delete this object.
299 SC_DLLPUBLIC ScDPSaveDimension* GetDimensionByName(const OUString& rName);
300 SC_DLLPUBLIC ScDPSaveDimension* GetDataLayoutDimension();
301 SC_DLLPUBLIC ScDPSaveDimension* GetExistingDataLayoutDimension() const;
303 ScDPSaveDimension* DuplicateDimension(const OUString& rName);
304 SC_DLLPUBLIC ScDPSaveDimension& DuplicateDimension(const ScDPSaveDimension& rDim);
306 SC_DLLPUBLIC ScDPSaveDimension* GetExistingDimensionByName(const OUString& rName) const;
307 SC_DLLPUBLIC ScDPSaveDimension* GetNewDimensionByName(const OUString& rName);
309 void RemoveDimensionByName(const OUString& rName);
311 ScDPSaveDimension* GetInnermostDimension(sal_uInt16 nOrientation);
312 ScDPSaveDimension* GetFirstDimension(::com::sun::star::sheet::DataPilotFieldOrientation eOrientation);
313 long GetDataDimensionCount() const;
315 void SetPosition( ScDPSaveDimension* pDim, long nNew );
316 SC_DLLPUBLIC void SetColumnGrand( bool bSet );
317 bool GetColumnGrand() const
318 { return bool(nColumnGrandMode); }
320 SC_DLLPUBLIC void SetRowGrand( bool bSet );
321 bool GetRowGrand() const
322 { return bool(nRowGrandMode); }
324 void SetIgnoreEmptyRows( bool bSet );
325 bool GetIgnoreEmptyRows() const
326 { return bool(nIgnoreEmptyMode); }
328 void SetRepeatIfEmpty( bool bSet );
329 bool GetRepeatIfEmpty() const
330 { return bool(nRepeatEmptyMode); }
332 SC_DLLPUBLIC void SetFilterButton( bool bSet );
333 bool GetFilterButton() const
334 { return bFilterButton; }
336 SC_DLLPUBLIC void SetDrillDown( bool bSet );
337 bool GetDrillDown() const
338 { return bDrillDown; }
340 void WriteToSource( const com::sun::star::uno::Reference<com::sun::star::sheet::XDimensionsSupplier>& xSource );
341 bool IsEmpty() const;
343 const ScDPDimensionSaveData* GetExistingDimensionData() const
344 { return pDimensionData; }
346 void RemoveAllGroupDimensions( const OUString& rSrcDimName, std::vector<OUString>* pDeletedNames = NULL );
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);
354 * Check whether a dimension has one or more invisible members.
356 * @param rDimName dimension name
358 SC_DLLPUBLIC bool HasInvisibleMember(const OUString& rDimName) const;
360 private:
361 void CheckDuplicateName(ScDPSaveDimension& rDim);
362 void RemoveDuplicateNameCount(const OUString& rName);
365 * Append a new original dimension. Not to be called to insert a duplicate
366 * dimension.
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.
373 * @return pointer to the new dimension just inserted.
375 ScDPSaveDimension* AppendNewDimension(const OUString& rName, bool bDataLayout);
377 void DimensionsChanged();
380 #endif
382 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */