1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 INCLUDED_SC_INC_DPSAVE_HXX
21 #define INCLUDED_SC_INC_DPSAVE_HXX
25 #include <boost/ptr_container/ptr_vector.hpp>
26 #include <boost/scoped_ptr.hpp>
28 #include <com/sun/star/sheet/XDimensionsSupplier.hpp>
29 #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
30 #include <rtl/ustring.hxx>
31 #include <sal/types.h>
34 #include "calcmacros.hxx"
36 #include <unordered_map>
37 #include <unordered_set>
39 namespace com
{ namespace sun
{ namespace star
{ namespace sheet
{
40 struct DataPilotFieldReference
;
41 struct DataPilotFieldSortInfo
;
42 struct DataPilotFieldAutoShowInfo
;
43 struct DataPilotFieldLayoutInfo
;
46 class ScDPDimensionSaveData
;
49 // classes to save Data Pilot settings
55 boost::scoped_ptr
<OUString
> mpLayoutName
; // custom name to be displayed in the table.
56 sal_uInt16 nVisibleMode
;
57 sal_uInt16 nShowDetailsMode
;
60 ScDPSaveMember(const OUString
& rName
);
61 ScDPSaveMember(const ScDPSaveMember
& r
);
64 bool operator== ( const ScDPSaveMember
& r
) const;
66 const OUString
& GetName() const
69 SC_DLLPUBLIC
bool HasIsVisible() const;
70 SC_DLLPUBLIC
void SetIsVisible(bool bSet
);
71 bool GetIsVisible() const
72 { return bool(nVisibleMode
); }
74 SC_DLLPUBLIC
bool HasShowDetails() const;
75 SC_DLLPUBLIC
void SetShowDetails(bool bSet
);
76 bool GetShowDetails() const
77 { return bool(nShowDetailsMode
); }
79 void SetName( const OUString
& rNew
); // used if the source member was renamed (groups)
81 SC_DLLPUBLIC
void SetLayoutName( const OUString
& rName
);
82 SC_DLLPUBLIC
const OUString
* GetLayoutName() const;
83 void RemoveLayoutName();
85 void WriteToSource( const com::sun::star::uno::Reference
<com::sun::star::uno::XInterface
>& xMember
,
86 sal_Int32 nPosition
);
89 void Dump(int nIndent
= 0) const;
93 bool operator == (const ::com::sun::star::sheet::DataPilotFieldSortInfo
&l
, const ::com::sun::star::sheet::DataPilotFieldSortInfo
&r
);
94 bool operator == (const ::com::sun::star::sheet::DataPilotFieldAutoShowInfo
&l
, const ::com::sun::star::sheet::DataPilotFieldAutoShowInfo
&r
);
95 bool operator == (const ::com::sun::star::sheet::DataPilotFieldReference
&l
, const ::com::sun::star::sheet::DataPilotFieldReference
&r
);
97 class SC_DLLPUBLIC ScDPSaveDimension
101 boost::scoped_ptr
<OUString
> mpLayoutName
;
102 boost::scoped_ptr
<OUString
> mpSubtotalName
;
105 sal_uInt16 nOrientation
;
106 sal_uInt16 nFunction
; // enum GeneralFunction, for data dimensions
108 sal_uInt16 nShowEmptyMode
; //! at level
109 bool bRepeatItemLabels
; //! at level
110 bool bSubTotalDefault
; //! at level
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)
119 typedef std::unordered_set
<OUString
, OUStringHash
> MemberSetType
;
120 typedef std::unordered_map
<OUString
, ScDPSaveMember
*, OUStringHash
> MemberHash
;
121 typedef std::list
<ScDPSaveMember
*> MemberList
;
124 MemberHash maMemberHash
;
125 MemberList maMemberList
;
128 ScDPSaveDimension(const OUString
& rName
, bool bDataLayout
);
129 ScDPSaveDimension(const ScDPSaveDimension
& r
);
130 ~ScDPSaveDimension();
132 bool operator== ( const ScDPSaveDimension
& r
) const;
134 const MemberList
& GetMembers() const
135 { return maMemberList
; }
137 void AddMember(ScDPSaveMember
* pMember
);
139 void SetDupFlag(bool bSet
)
142 bool GetDupFlag() const
145 const OUString
& GetName() const
148 bool IsDataLayout() const
149 { return bIsDataLayout
; }
151 void SetName( const OUString
& rNew
); // used if the source dim was renamed (groups)
153 void SetOrientation(sal_uInt16 nNew
);
154 void SetSubTotals(long nCount
, const sal_uInt16
* pFuncs
);
155 long GetSubTotalsCount() const
156 { return nSubTotalCount
; }
158 sal_uInt16
GetSubTotalFunc(long nIndex
) const
159 { return pSubTotalFuncs
[nIndex
]; }
161 bool HasShowEmpty() const;
162 void SetShowEmpty(bool bSet
);
163 bool GetShowEmpty() const
164 { return bool(nShowEmptyMode
); }
166 void SetRepeatItemLabels(bool bSet
);
167 bool GetRepeatItemLabels() const
168 { return bRepeatItemLabels
; }
170 void SetFunction(sal_uInt16 nNew
); // enum GeneralFunction
171 sal_uInt16
GetFunction() const
172 { return nFunction
; }
174 void SetUsedHierarchy(long nNew
);
175 long GetUsedHierarchy() const
176 { return nUsedHierarchy
; }
178 void SetLayoutName(const OUString
& rName
);
179 const OUString
* GetLayoutName() const;
180 void RemoveLayoutName();
181 void SetSubtotalName(const OUString
& rName
);
182 const OUString
* GetSubtotalName() const;
183 void RemoveSubtotalName();
185 bool IsMemberNameInUse(const OUString
& rName
) const;
187 const ::com::sun::star::sheet::DataPilotFieldReference
* GetReferenceValue() const
188 { return pReferenceValue
; }
190 void SetReferenceValue(const ::com::sun::star::sheet::DataPilotFieldReference
* pNew
);
192 const ::com::sun::star::sheet::DataPilotFieldSortInfo
* GetSortInfo() const
193 { return pSortInfo
; }
195 void SetSortInfo(const ::com::sun::star::sheet::DataPilotFieldSortInfo
* pNew
);
196 const ::com::sun::star::sheet::DataPilotFieldAutoShowInfo
* GetAutoShowInfo() const
197 { return pAutoShowInfo
; }
199 void SetAutoShowInfo(const ::com::sun::star::sheet::DataPilotFieldAutoShowInfo
* pNew
);
200 const ::com::sun::star::sheet::DataPilotFieldLayoutInfo
* GetLayoutInfo() const
201 { return pLayoutInfo
; }
203 void SetLayoutInfo(const ::com::sun::star::sheet::DataPilotFieldLayoutInfo
* pNew
);
205 void SetCurrentPage( const OUString
* pPage
); // NULL = no selection (all)
206 OUString
GetCurrentPage() const; // only for ODF compatibility
208 sal_uInt16
GetOrientation() const
209 { return nOrientation
; }
211 ScDPSaveMember
* GetExistingMemberByName(const OUString
& rName
);
214 * Get a member object by its name. If one doesn't exist, create a new
215 * object and return it. This class manages the life cycle of all member
216 * objects belonging to it, so <i>don't delete the returned instance.</i>
218 * @param rName member name
220 * @return pointer to the member object.
222 ScDPSaveMember
* GetMemberByName(const OUString
& rName
);
224 void SetMemberPosition( const OUString
& rName
, sal_Int32 nNewPos
);
226 void WriteToSource( const com::sun::star::uno::Reference
<com::sun::star::uno::XInterface
>& xDim
);
228 void UpdateMemberVisibility(const std::unordered_map
< OUString
, bool, OUStringHash
>& rData
);
230 bool HasInvisibleMember() const;
232 void RemoveObsoleteMembers(const MemberSetType
& rMembers
);
234 #if DEBUG_PIVOT_TABLE
235 void Dump(int nIndent
= 0) const;
241 typedef std::unordered_map
<OUString
, size_t, OUStringHash
> DupNameCountType
;
243 typedef std::unordered_map
<OUString
, size_t, OUStringHash
> DimOrderType
;
244 typedef boost::ptr_vector
<ScDPSaveDimension
> DimsType
;
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
257 /** if true, all dimensions already have all of their member instances
259 bool mbDimensionMembersBuilt
;
261 boost::scoped_ptr
<OUString
> mpGrandTotalName
;
262 mutable boost::scoped_ptr
<DimOrderType
> mpDimOrder
; // dimension order for row and column dimensions, to traverse result tree.
265 SC_DLLPUBLIC
ScDPSaveData();
266 ScDPSaveData(const ScDPSaveData
& r
);
267 SC_DLLPUBLIC
~ScDPSaveData();
269 ScDPSaveData
& operator= ( const ScDPSaveData
& r
);
271 bool operator== ( const ScDPSaveData
& r
) const;
273 SC_DLLPUBLIC
void SetGrandTotalName(const OUString
& rName
);
274 SC_DLLPUBLIC
const OUString
* GetGrandTotalName() const;
276 const DimsType
& GetDimensions() const { return aDimList
;}
279 * Get sort order map to sort row and column dimensions in order of
280 * appearance. Row dimensions get sorted before column dimensions. This
281 * is used to traverse result tree, which is structured following this
284 const DimOrderType
& GetDimensionSortOrder() const;
287 * Get all dimensions in a given orientation. The order represents the
288 * actual order of occurrence. The returned list also includes data
291 * @param eOrientation orientation
292 * @param rDims (out) list of dimensions for specified orientation
294 SC_DLLPUBLIC
void GetAllDimensionsByOrientation(
295 com::sun::star::sheet::DataPilotFieldOrientation eOrientation
,
296 std::vector
<const ScDPSaveDimension
*>& rDims
) const;
298 void AddDimension(ScDPSaveDimension
* pDim
);
301 * Get a dimension object by its name. <i>If one doesn't exist for the
302 * given name, it creates a new one.</i>
304 * @param rName dimension name
306 * @return pointer to the dimension object. The ScDPSaveData instance
307 * manages its life cycle; hence the caller must
308 * <i>not</i> delete this object.
310 SC_DLLPUBLIC ScDPSaveDimension
* GetDimensionByName(const OUString
& rName
);
311 SC_DLLPUBLIC ScDPSaveDimension
* GetDataLayoutDimension();
312 SC_DLLPUBLIC ScDPSaveDimension
* GetExistingDataLayoutDimension() const;
314 ScDPSaveDimension
* DuplicateDimension(const OUString
& rName
);
315 SC_DLLPUBLIC ScDPSaveDimension
& DuplicateDimension(const ScDPSaveDimension
& rDim
);
317 SC_DLLPUBLIC ScDPSaveDimension
* GetExistingDimensionByName(const OUString
& rName
) const;
318 SC_DLLPUBLIC ScDPSaveDimension
* GetNewDimensionByName(const OUString
& rName
);
320 void RemoveDimensionByName(const OUString
& rName
);
322 ScDPSaveDimension
* GetInnermostDimension(sal_uInt16 nOrientation
);
323 ScDPSaveDimension
* GetFirstDimension(::com::sun::star::sheet::DataPilotFieldOrientation eOrientation
);
324 long GetDataDimensionCount() const;
326 void SetPosition( ScDPSaveDimension
* pDim
, long nNew
);
327 SC_DLLPUBLIC
void SetColumnGrand( bool bSet
);
328 bool GetColumnGrand() const
329 { return bool(nColumnGrandMode
); }
331 SC_DLLPUBLIC
void SetRowGrand( bool bSet
);
332 bool GetRowGrand() const
333 { return bool(nRowGrandMode
); }
335 void SetIgnoreEmptyRows( bool bSet
);
336 bool GetIgnoreEmptyRows() const
337 { return bool(nIgnoreEmptyMode
); }
339 void SetRepeatIfEmpty( bool bSet
);
340 bool GetRepeatIfEmpty() const
341 { return bool(nRepeatEmptyMode
); }
343 SC_DLLPUBLIC
void SetFilterButton( bool bSet
);
344 bool GetFilterButton() const
345 { return bFilterButton
; }
347 SC_DLLPUBLIC
void SetDrillDown( bool bSet
);
348 bool GetDrillDown() const
349 { return bDrillDown
; }
351 void WriteToSource( const com::sun::star::uno::Reference
<com::sun::star::sheet::XDimensionsSupplier
>& xSource
);
352 bool IsEmpty() const;
354 const ScDPDimensionSaveData
* GetExistingDimensionData() const
355 { return pDimensionData
; }
357 void RemoveAllGroupDimensions( const OUString
& rSrcDimName
, std::vector
<OUString
>* pDeletedNames
= NULL
);
359 SC_DLLPUBLIC ScDPDimensionSaveData
* GetDimensionData(); // create if not there
360 void SetDimensionData( const ScDPDimensionSaveData
* pNew
); // copied
361 void BuildAllDimensionMembers(ScDPTableData
* pData
);
362 void SyncAllDimensionMembers(ScDPTableData
* pData
);
365 * Check whether a dimension has one or more invisible members.
367 * @param rDimName dimension name
369 SC_DLLPUBLIC
bool HasInvisibleMember(const OUString
& rDimName
) const;
371 #if DEBUG_PIVOT_TABLE
376 void CheckDuplicateName(ScDPSaveDimension
& rDim
);
377 void RemoveDuplicateNameCount(const OUString
& rName
);
380 * Append a new original dimension. Not to be called to insert a duplicate
383 * @param rName Dimension name. The name must be the original dimension
384 * name; not a duplicate dimension name.
385 * @param bDataLayout true if this is a data layout dimension, false
388 * @return pointer to the new dimension just inserted.
390 ScDPSaveDimension
* AppendNewDimension(const OUString
& rName
, bool bDataLayout
);
392 void DimensionsChanged();
397 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */