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/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>
36 #include "calcmacros.hxx"
38 namespace com
{ namespace sun
{ namespace star
{ namespace sheet
{
39 struct DataPilotFieldReference
;
40 struct DataPilotFieldSortInfo
;
41 struct DataPilotFieldAutoShowInfo
;
42 struct DataPilotFieldLayoutInfo
;
45 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;
94 bool operator == (const ::com::sun::star::sheet::DataPilotFieldSortInfo
&l
, const ::com::sun::star::sheet::DataPilotFieldSortInfo
&r
);
95 bool operator == (const ::com::sun::star::sheet::DataPilotFieldAutoShowInfo
&l
, const ::com::sun::star::sheet::DataPilotFieldAutoShowInfo
&r
);
96 bool operator == (const ::com::sun::star::sheet::DataPilotFieldReference
&l
, const ::com::sun::star::sheet::DataPilotFieldReference
&r
);
98 class SC_DLLPUBLIC ScDPSaveDimension
102 boost::scoped_ptr
<OUString
> mpLayoutName
;
103 boost::scoped_ptr
<OUString
> mpSubtotalName
;
106 sal_uInt16 nOrientation
;
107 sal_uInt16 nFunction
; // enum GeneralFunction, for data dimensions
109 sal_uInt16 nShowEmptyMode
; //! 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 boost::unordered_set
<OUString
, OUStringHash
> MemberSetType
;
120 typedef boost::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 SetFunction(sal_uInt16 nNew
); // enum GeneralFunction
167 sal_uInt16
GetFunction() const
168 { return nFunction
; }
170 void SetUsedHierarchy(long nNew
);
171 long GetUsedHierarchy() const
172 { return nUsedHierarchy
; }
174 void SetLayoutName(const OUString
& rName
);
175 const OUString
* GetLayoutName() const;
176 void RemoveLayoutName();
177 void SetSubtotalName(const OUString
& rName
);
178 const OUString
* GetSubtotalName() const;
179 void RemoveSubtotalName();
181 bool IsMemberNameInUse(const OUString
& rName
) const;
183 const ::com::sun::star::sheet::DataPilotFieldReference
* GetReferenceValue() const
184 { return pReferenceValue
; }
186 void SetReferenceValue(const ::com::sun::star::sheet::DataPilotFieldReference
* pNew
);
188 const ::com::sun::star::sheet::DataPilotFieldSortInfo
* GetSortInfo() const
189 { return pSortInfo
; }
191 void SetSortInfo(const ::com::sun::star::sheet::DataPilotFieldSortInfo
* pNew
);
192 const ::com::sun::star::sheet::DataPilotFieldAutoShowInfo
* GetAutoShowInfo() const
193 { return pAutoShowInfo
; }
195 void SetAutoShowInfo(const ::com::sun::star::sheet::DataPilotFieldAutoShowInfo
* pNew
);
196 const ::com::sun::star::sheet::DataPilotFieldLayoutInfo
* GetLayoutInfo() const
197 { return pLayoutInfo
; }
199 void SetLayoutInfo(const ::com::sun::star::sheet::DataPilotFieldLayoutInfo
* pNew
);
201 void SetCurrentPage( const OUString
* pPage
); // NULL = no selection (all)
203 sal_uInt16
GetOrientation() const
204 { return nOrientation
; }
206 ScDPSaveMember
* GetExistingMemberByName(const OUString
& rName
);
209 * Get a member object by its name. If one doesn't exist, creat a new
210 * object and return it. This class manages the life cycle of all member
211 * objects belonging to it, so <i>don't delete the returned instance.</i>
213 * @param rName member name
215 * @return pointer to the member object.
217 ScDPSaveMember
* GetMemberByName(const OUString
& rName
);
219 void SetMemberPosition( const OUString
& rName
, sal_Int32 nNewPos
);
221 void WriteToSource( const com::sun::star::uno::Reference
<com::sun::star::uno::XInterface
>& xDim
);
223 void UpdateMemberVisibility(const ::boost::unordered_map
< OUString
, bool, OUStringHash
>& rData
);
225 bool HasInvisibleMember() const;
227 void RemoveObsoleteMembers(const MemberSetType
& rMembers
);
229 #if DEBUG_PIVOT_TABLE
230 void Dump(int nIndent
= 0) const;
237 typedef boost::unordered_map
<OUString
, size_t, OUStringHash
> DupNameCountType
;
239 typedef boost::unordered_map
<OUString
, size_t, OUStringHash
> DimOrderType
;
240 typedef boost::ptr_vector
<ScDPSaveDimension
> DimsType
;
244 DupNameCountType maDupNameCounts
; /// keep track of number of duplicates in each name.
245 ScDPDimensionSaveData
* pDimensionData
; // settings that create new dimensions
246 sal_uInt16 nColumnGrandMode
;
247 sal_uInt16 nRowGrandMode
;
248 sal_uInt16 nIgnoreEmptyMode
;
249 sal_uInt16 nRepeatEmptyMode
;
250 bool bFilterButton
; // not passed to DataPilotSource
251 bool bDrillDown
; // not passed to DataPilotSource
253 /** if true, all dimensions already have all of their member instances
255 bool mbDimensionMembersBuilt
;
257 boost::scoped_ptr
<OUString
> mpGrandTotalName
;
258 mutable boost::scoped_ptr
<DimOrderType
> mpDimOrder
; // dimension order for row and column dimensions, to traverse result tree.
261 SC_DLLPUBLIC
ScDPSaveData();
262 ScDPSaveData(const ScDPSaveData
& r
);
263 SC_DLLPUBLIC
~ScDPSaveData();
265 ScDPSaveData
& operator= ( const ScDPSaveData
& r
);
267 bool operator== ( const ScDPSaveData
& r
) const;
269 SC_DLLPUBLIC
void SetGrandTotalName(const OUString
& rName
);
270 SC_DLLPUBLIC
const OUString
* GetGrandTotalName() const;
272 SC_DLLPUBLIC
const DimsType
& GetDimensions() const;
275 * Get sort order map to sort row and column dimensions in order of
276 * appearance. Row dimensions get sorted before column dimensions. This
277 * is used to traverse result tree, which is structured following this
280 const DimOrderType
& GetDimensionSortOrder() const;
283 * Get all dimensions in a given orientation. The order represents the
284 * actual order of occurrence. The returned list also includes data
287 * @param eOrientation orientation
288 * @param rDims (out) list of dimensions for specified orientation
290 SC_DLLPUBLIC
void GetAllDimensionsByOrientation(
291 com::sun::star::sheet::DataPilotFieldOrientation eOrientation
,
292 std::vector
<const ScDPSaveDimension
*>& rDims
) const;
294 void AddDimension(ScDPSaveDimension
* pDim
);
297 * Get a dimension object by its name. <i>If one doesn't exist for the
298 * given name, it creates a new one.</i>
300 * @param rName dimension name
302 * @return pointer to the dimension object. The ScDPSaveData instance
303 * manages its life cycle; hence the caller must
304 * <i>not</i> delete this object.
306 SC_DLLPUBLIC ScDPSaveDimension
* GetDimensionByName(const OUString
& rName
);
307 SC_DLLPUBLIC ScDPSaveDimension
* GetDataLayoutDimension();
308 SC_DLLPUBLIC ScDPSaveDimension
* GetExistingDataLayoutDimension() const;
310 ScDPSaveDimension
* DuplicateDimension(const OUString
& rName
);
311 SC_DLLPUBLIC ScDPSaveDimension
& DuplicateDimension(const ScDPSaveDimension
& rDim
);
313 SC_DLLPUBLIC ScDPSaveDimension
* GetExistingDimensionByName(const OUString
& rName
) const;
314 SC_DLLPUBLIC ScDPSaveDimension
* GetNewDimensionByName(const OUString
& rName
);
316 void RemoveDimensionByName(const OUString
& rName
);
318 ScDPSaveDimension
* GetInnermostDimension(sal_uInt16 nOrientation
);
319 ScDPSaveDimension
* GetFirstDimension(::com::sun::star::sheet::DataPilotFieldOrientation eOrientation
);
320 long GetDataDimensionCount() const;
322 void SetPosition( ScDPSaveDimension
* pDim
, long nNew
);
323 SC_DLLPUBLIC
void SetColumnGrand( bool bSet
);
324 bool GetColumnGrand() const
325 { return bool(nColumnGrandMode
); }
327 SC_DLLPUBLIC
void SetRowGrand( bool bSet
);
328 bool GetRowGrand() const
329 { return bool(nRowGrandMode
); }
331 void SetIgnoreEmptyRows( bool bSet
);
332 bool GetIgnoreEmptyRows() const
333 { return bool(nIgnoreEmptyMode
); }
335 void SetRepeatIfEmpty( bool bSet
);
336 bool GetRepeatIfEmpty() const
337 { return bool(nRepeatEmptyMode
); }
339 SC_DLLPUBLIC
void SetFilterButton( bool bSet
);
340 bool GetFilterButton() const
341 { return bFilterButton
; }
343 SC_DLLPUBLIC
void SetDrillDown( bool bSet
);
344 bool GetDrillDown() const
345 { return bDrillDown
; }
347 void WriteToSource( const com::sun::star::uno::Reference
<com::sun::star::sheet::XDimensionsSupplier
>& xSource
);
348 bool IsEmpty() const;
350 const ScDPDimensionSaveData
* GetExistingDimensionData() const
351 { return pDimensionData
; }
353 void RemoveAllGroupDimensions( const OUString
& rSrcDimName
, std::vector
<OUString
>* pDeletedNames
= NULL
);
355 SC_DLLPUBLIC ScDPDimensionSaveData
* GetDimensionData(); // create if not there
356 void SetDimensionData( const ScDPDimensionSaveData
* pNew
); // copied
357 void BuildAllDimensionMembers(ScDPTableData
* pData
);
358 void SyncAllDimensionMembers(ScDPTableData
* pData
);
361 * Check whether a dimension has one or more invisible members.
363 * @param rDimName dimension name
365 SC_DLLPUBLIC
bool HasInvisibleMember(const OUString
& rDimName
) const;
367 #if DEBUG_PIVOT_TABLE
372 void CheckDuplicateName(ScDPSaveDimension
& rDim
);
373 void RemoveDuplicateNameCount(const OUString
& rName
);
376 * Append a new original dimension. Not to be called to insert a duplicate
379 * @param rName Dimension name. The name must be the original dimension
380 * name; not a duplicate dimension name.
381 * @param bDataLayout true if this is a data layout dimension, false
384 * @return pointer to the new dimension just inserted.
386 ScDPSaveDimension
* AppendNewDimension(const OUString
& rName
, bool bDataLayout
);
388 void DimensionsChanged();
393 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */