Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / sc / inc / dpsave.hxx
blobbb1e8acb7098dc72b8f41723fb9ffeb1c425e5ed
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 INCLUDED_SC_INC_DPSAVE_HXX
21 #define INCLUDED_SC_INC_DPSAVE_HXX
23 #include <list>
24 #include <memory>
25 #include <vector>
27 #include <com/sun/star/sheet/XDimensionsSupplier.hpp>
28 #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
29 #include <rtl/ustring.hxx>
30 #include <sal/types.h>
32 #include "scdllapi.h"
33 #include "calcmacros.hxx"
35 #include <unordered_map>
36 #include <unordered_set>
38 namespace com { namespace sun { namespace star { namespace sheet {
39 struct DataPilotFieldReference;
40 struct DataPilotFieldSortInfo;
41 struct DataPilotFieldAutoShowInfo;
42 struct DataPilotFieldLayoutInfo;
43 } } } }
45 class ScDPDimensionSaveData;
46 class ScDPTableData;
48 // classes to save Data Pilot settings
50 class ScDPSaveMember
52 private:
53 OUString aName;
54 std::unique_ptr<OUString> mpLayoutName; // custom name to be displayed in the table.
55 sal_uInt16 nVisibleMode;
56 sal_uInt16 nShowDetailsMode;
58 public:
59 ScDPSaveMember(const OUString& rName);
60 ScDPSaveMember(const ScDPSaveMember& r);
61 ~ScDPSaveMember();
63 bool operator== ( const ScDPSaveMember& r ) const;
65 const OUString& GetName() const
66 { return aName; }
68 SC_DLLPUBLIC bool HasIsVisible() const;
69 SC_DLLPUBLIC void SetIsVisible(bool bSet);
70 bool GetIsVisible() const
71 { return bool(nVisibleMode); }
73 SC_DLLPUBLIC bool HasShowDetails() const;
74 SC_DLLPUBLIC void SetShowDetails(bool bSet);
75 bool GetShowDetails() const
76 { return bool(nShowDetailsMode); }
78 void SetName( const OUString& rNew ); // used if the source member was renamed (groups)
80 SC_DLLPUBLIC void SetLayoutName( const OUString& rName );
81 SC_DLLPUBLIC const OUString* GetLayoutName() const;
82 void RemoveLayoutName();
84 void WriteToSource( const css::uno::Reference<css::uno::XInterface>& xMember,
85 sal_Int32 nPosition );
87 #if DEBUG_PIVOT_TABLE
88 void Dump(int nIndent = 0) const;
89 #endif
92 class SC_DLLPUBLIC ScDPSaveDimension
94 private:
95 OUString aName;
96 std::unique_ptr<OUString> mpLayoutName;
97 std::unique_ptr<OUString> mpSubtotalName;
98 bool bIsDataLayout;
99 bool bDupFlag;
100 sal_uInt16 nOrientation;
101 sal_uInt16 nFunction; // enum GeneralFunction, for data dimensions
102 long nUsedHierarchy;
103 sal_uInt16 nShowEmptyMode; //! at level
104 bool bRepeatItemLabels; //! at level
105 bool bSubTotalDefault; //! at level
106 long nSubTotalCount;
107 sal_uInt16* pSubTotalFuncs; // enum GeneralFunction
108 css::sheet::DataPilotFieldReference* pReferenceValue;
109 css::sheet::DataPilotFieldSortInfo* pSortInfo; // (level)
110 css::sheet::DataPilotFieldAutoShowInfo* pAutoShowInfo; // (level)
111 css::sheet::DataPilotFieldLayoutInfo* pLayoutInfo; // (level)
113 public:
114 typedef std::unordered_set<OUString, OUStringHash> MemberSetType;
115 typedef std::unordered_map <OUString, ScDPSaveMember*, OUStringHash> MemberHash;
116 typedef std::list <ScDPSaveMember*> MemberList;
118 private:
119 MemberHash maMemberHash;
120 MemberList maMemberList;
122 public:
123 ScDPSaveDimension(const OUString& rName, bool bDataLayout);
124 ScDPSaveDimension(const ScDPSaveDimension& r);
125 ~ScDPSaveDimension();
127 bool operator== ( const ScDPSaveDimension& r ) const;
129 const MemberList& GetMembers() const
130 { return maMemberList; }
132 void AddMember(ScDPSaveMember* pMember);
134 void SetDupFlag(bool bSet)
135 { bDupFlag = bSet; }
137 bool GetDupFlag() const
138 { return bDupFlag; }
140 const OUString& GetName() const
141 { return aName; }
143 bool IsDataLayout() const
144 { return bIsDataLayout; }
146 void SetName( const OUString& rNew ); // used if the source dim was renamed (groups)
148 void SetOrientation(sal_uInt16 nNew);
149 void SetSubTotals(long nCount, const sal_uInt16* pFuncs);
150 long GetSubTotalsCount() const
151 { return nSubTotalCount; }
153 sal_uInt16 GetSubTotalFunc(long nIndex) const
154 { return pSubTotalFuncs[nIndex]; }
156 bool HasShowEmpty() const;
157 void SetShowEmpty(bool bSet);
158 bool GetShowEmpty() const
159 { return bool(nShowEmptyMode); }
161 void SetRepeatItemLabels(bool bSet);
162 bool GetRepeatItemLabels() const
163 { return bRepeatItemLabels; }
165 void SetFunction(sal_uInt16 nNew); // enum GeneralFunction
166 sal_uInt16 GetFunction() const
167 { return nFunction; }
169 void SetUsedHierarchy(long nNew);
170 long GetUsedHierarchy() const
171 { return nUsedHierarchy; }
173 void SetLayoutName(const OUString& rName);
174 const OUString* GetLayoutName() const;
175 void RemoveLayoutName();
176 void SetSubtotalName(const OUString& rName);
177 const OUString* GetSubtotalName() const;
178 void RemoveSubtotalName();
180 bool IsMemberNameInUse(const OUString& rName) const;
182 const css::sheet::DataPilotFieldReference* GetReferenceValue() const
183 { return pReferenceValue; }
185 void SetReferenceValue(const css::sheet::DataPilotFieldReference* pNew);
187 const css::sheet::DataPilotFieldSortInfo* GetSortInfo() const
188 { return pSortInfo; }
190 void SetSortInfo(const css::sheet::DataPilotFieldSortInfo* pNew);
191 const css::sheet::DataPilotFieldAutoShowInfo* GetAutoShowInfo() const
192 { return pAutoShowInfo; }
194 void SetAutoShowInfo(const css::sheet::DataPilotFieldAutoShowInfo* pNew);
195 const css::sheet::DataPilotFieldLayoutInfo* GetLayoutInfo() const
196 { return pLayoutInfo; }
198 void SetLayoutInfo(const css::sheet::DataPilotFieldLayoutInfo* pNew);
200 void SetCurrentPage( const OUString* pPage ); // NULL = no selection (all)
201 OUString GetCurrentPage() const; // only for ODF compatibility
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, create 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 css::uno::Reference<css::uno::XInterface>& xDim );
223 void UpdateMemberVisibility(const std::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;
231 #endif
234 class ScDPSaveData
236 typedef std::unordered_map<OUString, size_t, OUStringHash> DupNameCountType;
237 public:
238 typedef std::unordered_map<OUString, size_t, OUStringHash> DimOrderType;
239 typedef std::vector<std::unique_ptr<ScDPSaveDimension>> DimsType;
241 private:
242 DimsType m_DimList;
243 DupNameCountType maDupNameCounts; /// keep track of number of duplicates in each name.
244 ScDPDimensionSaveData* pDimensionData; // settings that create new dimensions
245 sal_uInt16 nColumnGrandMode;
246 sal_uInt16 nRowGrandMode;
247 sal_uInt16 nIgnoreEmptyMode;
248 sal_uInt16 nRepeatEmptyMode;
249 bool bFilterButton; // not passed to DataPilotSource
250 bool bDrillDown; // not passed to DataPilotSource
252 /** if true, all dimensions already have all of their member instances
253 * created. */
254 bool mbDimensionMembersBuilt;
256 std::unique_ptr<OUString> mpGrandTotalName;
257 mutable std::unique_ptr<DimOrderType> mpDimOrder; // dimension order for row and column dimensions, to traverse result tree.
259 public:
260 SC_DLLPUBLIC ScDPSaveData();
261 ScDPSaveData(const ScDPSaveData& r);
262 SC_DLLPUBLIC ~ScDPSaveData();
264 ScDPSaveData& operator= ( const ScDPSaveData& r );
266 bool operator== ( const ScDPSaveData& r ) const;
268 SC_DLLPUBLIC void SetGrandTotalName(const OUString& rName);
269 SC_DLLPUBLIC const OUString* GetGrandTotalName() const;
271 const DimsType& GetDimensions() const { return m_DimList; }
274 * Get sort order map to sort row and column dimensions in order of
275 * appearance. Row dimensions get sorted before column dimensions. This
276 * is used to traverse result tree, which is structured following this
277 * order.
279 const DimOrderType& GetDimensionSortOrder() const;
282 * Get all dimensions in a given orientation. The order represents the
283 * actual order of occurrence. The returned list also includes data
284 * layout dimension.
286 * @param eOrientation orientation
287 * @param rDims (out) list of dimensions for specified orientation
289 SC_DLLPUBLIC void GetAllDimensionsByOrientation(
290 css::sheet::DataPilotFieldOrientation eOrientation,
291 std::vector<const ScDPSaveDimension*>& rDims) const;
293 void AddDimension(ScDPSaveDimension* pDim);
296 * Get a dimension object by its name. <i>If one doesn't exist for the
297 * given name, it creates a new one.</i>
299 * @param rName dimension name
301 * @return pointer to the dimension object. The ScDPSaveData instance
302 * manages its life cycle; hence the caller must
303 * <i>not</i> delete this object.
305 SC_DLLPUBLIC ScDPSaveDimension* GetDimensionByName(const OUString& rName);
306 SC_DLLPUBLIC ScDPSaveDimension* GetDataLayoutDimension();
307 SC_DLLPUBLIC ScDPSaveDimension* GetExistingDataLayoutDimension() const;
309 ScDPSaveDimension* DuplicateDimension(const OUString& rName);
310 SC_DLLPUBLIC ScDPSaveDimension& DuplicateDimension(const ScDPSaveDimension& rDim);
312 SC_DLLPUBLIC ScDPSaveDimension* GetExistingDimensionByName(const OUString& rName) const;
313 SC_DLLPUBLIC ScDPSaveDimension* GetNewDimensionByName(const OUString& rName);
315 void RemoveDimensionByName(const OUString& rName);
317 ScDPSaveDimension* GetInnermostDimension(sal_uInt16 nOrientation);
318 ScDPSaveDimension* GetFirstDimension(css::sheet::DataPilotFieldOrientation eOrientation);
319 long GetDataDimensionCount() const;
321 void SetPosition( ScDPSaveDimension* pDim, long nNew );
322 SC_DLLPUBLIC void SetColumnGrand( bool bSet );
323 bool GetColumnGrand() const
324 { return bool(nColumnGrandMode); }
326 SC_DLLPUBLIC void SetRowGrand( bool bSet );
327 bool GetRowGrand() const
328 { return bool(nRowGrandMode); }
330 void SetIgnoreEmptyRows( bool bSet );
331 bool GetIgnoreEmptyRows() const
332 { return bool(nIgnoreEmptyMode); }
334 void SetRepeatIfEmpty( bool bSet );
335 bool GetRepeatIfEmpty() const
336 { return bool(nRepeatEmptyMode); }
338 SC_DLLPUBLIC void SetFilterButton( bool bSet );
339 bool GetFilterButton() const
340 { return bFilterButton; }
342 SC_DLLPUBLIC void SetDrillDown( bool bSet );
343 bool GetDrillDown() const
344 { return bDrillDown; }
346 void WriteToSource( const css::uno::Reference<css::sheet::XDimensionsSupplier>& xSource );
347 bool IsEmpty() const;
349 const ScDPDimensionSaveData* GetExistingDimensionData() const
350 { return pDimensionData; }
352 void RemoveAllGroupDimensions( const OUString& rSrcDimName, std::vector<OUString>* pDeletedNames = nullptr );
354 SC_DLLPUBLIC ScDPDimensionSaveData* GetDimensionData(); // create if not there
355 SC_DLLPUBLIC void SetDimensionData( const ScDPDimensionSaveData* pNew ); // copied
356 void BuildAllDimensionMembers(ScDPTableData* pData);
357 void SyncAllDimensionMembers(ScDPTableData* pData);
360 * Check whether a dimension has one or more invisible members.
362 * @param rDimName dimension name
364 SC_DLLPUBLIC bool HasInvisibleMember(const OUString& rDimName) const;
366 #if DEBUG_PIVOT_TABLE
367 void Dump() const;
368 #endif
370 private:
371 void CheckDuplicateName(ScDPSaveDimension& rDim);
372 void RemoveDuplicateNameCount(const OUString& rName);
375 * Append a new original dimension. Not to be called to insert a duplicate
376 * dimension.
378 * @param rName Dimension name. The name must be the original dimension
379 * name; not a duplicate dimension name.
380 * @param bDataLayout true if this is a data layout dimension, false
381 * otherwise.
383 * @return pointer to the new dimension just inserted.
385 ScDPSaveDimension* AppendNewDimension(const OUString& rName, bool bDataLayout);
387 void DimensionsChanged();
390 #endif
392 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */