Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_SC_INC_DPSAVE_HXX
21 : #define INCLUDED_SC_INC_DPSAVE_HXX
22 :
23 : #include <list>
24 :
25 : #include <boost/ptr_container/ptr_vector.hpp>
26 : #include <boost/scoped_ptr.hpp>
27 :
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>
32 :
33 : #include "scdllapi.h"
34 : #include "calcmacros.hxx"
35 :
36 : #include <unordered_map>
37 : #include <unordered_set>
38 :
39 : namespace com { namespace sun { namespace star { namespace sheet {
40 : struct DataPilotFieldReference;
41 : struct DataPilotFieldSortInfo;
42 : struct DataPilotFieldAutoShowInfo;
43 : struct DataPilotFieldLayoutInfo;
44 : } } } }
45 :
46 : class ScDPDimensionSaveData;
47 : class ScDPTableData;
48 :
49 : // classes to save Data Pilot settings
50 :
51 : class ScDPSaveMember
52 : {
53 : private:
54 : OUString aName;
55 : boost::scoped_ptr<OUString> mpLayoutName; // custom name to be displayed in the table.
56 : sal_uInt16 nVisibleMode;
57 : sal_uInt16 nShowDetailsMode;
58 :
59 : public:
60 : ScDPSaveMember(const OUString& rName);
61 : ScDPSaveMember(const ScDPSaveMember& r);
62 : ~ScDPSaveMember();
63 :
64 : bool operator== ( const ScDPSaveMember& r ) const;
65 :
66 8088 : const OUString& GetName() const
67 8088 : { return aName; }
68 :
69 : SC_DLLPUBLIC bool HasIsVisible() const;
70 : SC_DLLPUBLIC void SetIsVisible(bool bSet);
71 5799 : bool GetIsVisible() const
72 5799 : { return bool(nVisibleMode); }
73 :
74 : SC_DLLPUBLIC bool HasShowDetails() const;
75 : SC_DLLPUBLIC void SetShowDetails(bool bSet);
76 6 : bool GetShowDetails() const
77 6 : { return bool(nShowDetailsMode); }
78 :
79 : void SetName( const OUString& rNew ); // used if the source member was renamed (groups)
80 :
81 : SC_DLLPUBLIC void SetLayoutName( const OUString& rName );
82 : SC_DLLPUBLIC const OUString* GetLayoutName() const;
83 : void RemoveLayoutName();
84 :
85 : void WriteToSource( const com::sun::star::uno::Reference<com::sun::star::uno::XInterface>& xMember,
86 : sal_Int32 nPosition );
87 :
88 : #if DEBUG_PIVOT_TABLE
89 : void Dump(int nIndent = 0) const;
90 : #endif
91 : };
92 :
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 );
96 :
97 : class SC_DLLPUBLIC ScDPSaveDimension
98 : {
99 : private:
100 : OUString aName;
101 : boost::scoped_ptr<OUString> mpLayoutName;
102 : boost::scoped_ptr<OUString> mpSubtotalName;
103 : bool bIsDataLayout;
104 : bool bDupFlag;
105 : sal_uInt16 nOrientation;
106 : sal_uInt16 nFunction; // enum GeneralFunction, for data dimensions
107 : long nUsedHierarchy;
108 : sal_uInt16 nShowEmptyMode; //! at level
109 : bool bRepeatItemLabels; //! at level
110 : bool bSubTotalDefault; //! at level
111 : long nSubTotalCount;
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)
117 :
118 : public:
119 : typedef std::unordered_set<OUString, OUStringHash> MemberSetType;
120 : typedef std::unordered_map <OUString, ScDPSaveMember*, OUStringHash> MemberHash;
121 : typedef std::list <ScDPSaveMember*> MemberList;
122 :
123 : private:
124 : MemberHash maMemberHash;
125 : MemberList maMemberList;
126 :
127 : public:
128 : ScDPSaveDimension(const OUString& rName, bool bDataLayout);
129 : ScDPSaveDimension(const ScDPSaveDimension& r);
130 : ~ScDPSaveDimension();
131 :
132 : bool operator== ( const ScDPSaveDimension& r ) const;
133 :
134 2 : const MemberList& GetMembers() const
135 2 : { return maMemberList; }
136 :
137 : void AddMember(ScDPSaveMember* pMember);
138 :
139 4 : void SetDupFlag(bool bSet)
140 4 : { bDupFlag = bSet; }
141 :
142 337 : bool GetDupFlag() const
143 337 : { return bDupFlag; }
144 :
145 2359 : const OUString& GetName() const
146 2359 : { return aName; }
147 :
148 1060 : bool IsDataLayout() const
149 1060 : { return bIsDataLayout; }
150 :
151 : void SetName( const OUString& rNew ); // used if the source dim was renamed (groups)
152 :
153 : void SetOrientation(sal_uInt16 nNew);
154 : void SetSubTotals(long nCount, const sal_uInt16* pFuncs);
155 10 : long GetSubTotalsCount() const
156 10 : { return nSubTotalCount; }
157 :
158 5 : sal_uInt16 GetSubTotalFunc(long nIndex) const
159 5 : { return pSubTotalFuncs[nIndex]; }
160 :
161 : bool HasShowEmpty() const;
162 : void SetShowEmpty(bool bSet);
163 10 : bool GetShowEmpty() const
164 10 : { return bool(nShowEmptyMode); }
165 :
166 : void SetRepeatItemLabels(bool bSet);
167 7 : bool GetRepeatItemLabels() const
168 7 : { return bRepeatItemLabels; }
169 :
170 : void SetFunction(sal_uInt16 nNew); // enum GeneralFunction
171 56 : sal_uInt16 GetFunction() const
172 56 : { return nFunction; }
173 :
174 : void SetUsedHierarchy(long nNew);
175 0 : long GetUsedHierarchy() const
176 0 : { return nUsedHierarchy; }
177 :
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();
184 :
185 : bool IsMemberNameInUse(const OUString& rName) const;
186 :
187 7 : const ::com::sun::star::sheet::DataPilotFieldReference* GetReferenceValue() const
188 7 : { return pReferenceValue; }
189 :
190 : void SetReferenceValue(const ::com::sun::star::sheet::DataPilotFieldReference* pNew);
191 :
192 7 : const ::com::sun::star::sheet::DataPilotFieldSortInfo* GetSortInfo() const
193 7 : { return pSortInfo; }
194 :
195 : void SetSortInfo(const ::com::sun::star::sheet::DataPilotFieldSortInfo* pNew);
196 7 : const ::com::sun::star::sheet::DataPilotFieldAutoShowInfo* GetAutoShowInfo() const
197 7 : { return pAutoShowInfo; }
198 :
199 : void SetAutoShowInfo(const ::com::sun::star::sheet::DataPilotFieldAutoShowInfo* pNew);
200 7 : const ::com::sun::star::sheet::DataPilotFieldLayoutInfo* GetLayoutInfo() const
201 7 : { return pLayoutInfo; }
202 :
203 : void SetLayoutInfo(const ::com::sun::star::sheet::DataPilotFieldLayoutInfo* pNew);
204 :
205 : void SetCurrentPage( const OUString* pPage ); // NULL = no selection (all)
206 : OUString GetCurrentPage() const; // only for ODF compatibility
207 :
208 1075 : sal_uInt16 GetOrientation() const
209 1075 : { return nOrientation; }
210 :
211 : ScDPSaveMember* GetExistingMemberByName(const OUString& rName);
212 :
213 : /**
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>
217 : *
218 : * @param rName member name
219 : *
220 : * @return pointer to the member object.
221 : */
222 : ScDPSaveMember* GetMemberByName(const OUString& rName);
223 :
224 : void SetMemberPosition( const OUString& rName, sal_Int32 nNewPos );
225 :
226 : void WriteToSource( const com::sun::star::uno::Reference<com::sun::star::uno::XInterface>& xDim );
227 :
228 : void UpdateMemberVisibility(const std::unordered_map< OUString, bool, OUStringHash>& rData);
229 :
230 : bool HasInvisibleMember() const;
231 :
232 : void RemoveObsoleteMembers(const MemberSetType& rMembers);
233 :
234 : #if DEBUG_PIVOT_TABLE
235 : void Dump(int nIndent = 0) const;
236 : #endif
237 : };
238 :
239 : class ScDPSaveData
240 : {
241 : typedef std::unordered_map<OUString, size_t, OUStringHash> DupNameCountType;
242 : public:
243 : typedef std::unordered_map<OUString, size_t, OUStringHash> DimOrderType;
244 : typedef boost::ptr_vector<ScDPSaveDimension> DimsType;
245 :
246 : private:
247 : DimsType aDimList;
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
256 :
257 : /** if true, all dimensions already have all of their member instances
258 : * created. */
259 : bool mbDimensionMembersBuilt;
260 :
261 : boost::scoped_ptr<OUString> mpGrandTotalName;
262 : mutable boost::scoped_ptr<DimOrderType> mpDimOrder; // dimension order for row and column dimensions, to traverse result tree.
263 :
264 : public:
265 : SC_DLLPUBLIC ScDPSaveData();
266 : ScDPSaveData(const ScDPSaveData& r);
267 : SC_DLLPUBLIC ~ScDPSaveData();
268 :
269 : ScDPSaveData& operator= ( const ScDPSaveData& r );
270 :
271 : bool operator== ( const ScDPSaveData& r ) const;
272 :
273 : SC_DLLPUBLIC void SetGrandTotalName(const OUString& rName);
274 : SC_DLLPUBLIC const OUString* GetGrandTotalName() const;
275 :
276 82 : const DimsType& GetDimensions() const { return aDimList;}
277 :
278 : /**
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
282 : * order.
283 : */
284 : const DimOrderType& GetDimensionSortOrder() const;
285 :
286 : /**
287 : * Get all dimensions in a given orientation. The order represents the
288 : * actual order of occurrence. The returned list also includes data
289 : * layout dimension.
290 : *
291 : * @param eOrientation orientation
292 : * @param rDims (out) list of dimensions for specified orientation
293 : */
294 : SC_DLLPUBLIC void GetAllDimensionsByOrientation(
295 : com::sun::star::sheet::DataPilotFieldOrientation eOrientation,
296 : std::vector<const ScDPSaveDimension*>& rDims) const;
297 :
298 : void AddDimension(ScDPSaveDimension* pDim);
299 :
300 : /**
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>
303 : *
304 : * @param rName dimension name
305 : *
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.
309 : */
310 : SC_DLLPUBLIC ScDPSaveDimension* GetDimensionByName(const OUString& rName);
311 : SC_DLLPUBLIC ScDPSaveDimension* GetDataLayoutDimension();
312 : SC_DLLPUBLIC ScDPSaveDimension* GetExistingDataLayoutDimension() const;
313 :
314 : ScDPSaveDimension* DuplicateDimension(const OUString& rName);
315 : SC_DLLPUBLIC ScDPSaveDimension& DuplicateDimension(const ScDPSaveDimension& rDim);
316 :
317 : SC_DLLPUBLIC ScDPSaveDimension* GetExistingDimensionByName(const OUString& rName) const;
318 : SC_DLLPUBLIC ScDPSaveDimension* GetNewDimensionByName(const OUString& rName);
319 :
320 : void RemoveDimensionByName(const OUString& rName);
321 :
322 : ScDPSaveDimension* GetInnermostDimension(sal_uInt16 nOrientation);
323 : ScDPSaveDimension* GetFirstDimension(::com::sun::star::sheet::DataPilotFieldOrientation eOrientation);
324 : long GetDataDimensionCount() const;
325 :
326 : void SetPosition( ScDPSaveDimension* pDim, long nNew );
327 : SC_DLLPUBLIC void SetColumnGrand( bool bSet );
328 0 : bool GetColumnGrand() const
329 0 : { return bool(nColumnGrandMode); }
330 :
331 : SC_DLLPUBLIC void SetRowGrand( bool bSet );
332 0 : bool GetRowGrand() const
333 0 : { return bool(nRowGrandMode); }
334 :
335 : void SetIgnoreEmptyRows( bool bSet );
336 173 : bool GetIgnoreEmptyRows() const
337 173 : { return bool(nIgnoreEmptyMode); }
338 :
339 : void SetRepeatIfEmpty( bool bSet );
340 173 : bool GetRepeatIfEmpty() const
341 173 : { return bool(nRepeatEmptyMode); }
342 :
343 : SC_DLLPUBLIC void SetFilterButton( bool bSet );
344 88 : bool GetFilterButton() const
345 88 : { return bFilterButton; }
346 :
347 : SC_DLLPUBLIC void SetDrillDown( bool bSet );
348 0 : bool GetDrillDown() const
349 0 : { return bDrillDown; }
350 :
351 : void WriteToSource( const com::sun::star::uno::Reference<com::sun::star::sheet::XDimensionsSupplier>& xSource );
352 : bool IsEmpty() const;
353 :
354 154 : const ScDPDimensionSaveData* GetExistingDimensionData() const
355 154 : { return pDimensionData; }
356 :
357 : void RemoveAllGroupDimensions( const OUString& rSrcDimName, std::vector<OUString>* pDeletedNames = NULL );
358 :
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);
363 :
364 : /**
365 : * Check whether a dimension has one or more invisible members.
366 : *
367 : * @param rDimName dimension name
368 : */
369 : SC_DLLPUBLIC bool HasInvisibleMember(const OUString& rDimName) const;
370 :
371 : #if DEBUG_PIVOT_TABLE
372 : void Dump() const;
373 : #endif
374 :
375 : private:
376 : void CheckDuplicateName(ScDPSaveDimension& rDim);
377 : void RemoveDuplicateNameCount(const OUString& rName);
378 :
379 : /**
380 : * Append a new original dimension. Not to be called to insert a duplicate
381 : * dimension.
382 : *
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
386 : * otherwise.
387 : *
388 : * @return pointer to the new dimension just inserted.
389 : */
390 : ScDPSaveDimension* AppendNewDimension(const OUString& rName, bool bDataLayout);
391 :
392 : void DimensionsChanged();
393 : };
394 :
395 : #endif
396 :
397 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|