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 SC_DPSAVE_HXX
21 : #define SC_DPSAVE_HXX
22 :
23 : #include <list>
24 :
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>
29 :
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>
34 :
35 : #include "scdllapi.h"
36 :
37 : namespace com { namespace sun { namespace star { namespace sheet {
38 : struct DataPilotFieldReference;
39 : struct DataPilotFieldSortInfo;
40 : struct DataPilotFieldAutoShowInfo;
41 : struct DataPilotFieldLayoutInfo;
42 : } } } }
43 :
44 : class ScDPDimensionSaveData;
45 : class ScDPTableData;
46 :
47 : //
48 : // classes to save Data Pilot settings
49 : //
50 :
51 :
52 : class ScDPSaveMember
53 : {
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;
59 :
60 : public:
61 : ScDPSaveMember(const OUString& rName);
62 : ScDPSaveMember(const ScDPSaveMember& r);
63 : ~ScDPSaveMember();
64 :
65 : bool operator== ( const ScDPSaveMember& r ) const;
66 :
67 1277 : const OUString& GetName() const
68 1277 : { return aName; }
69 :
70 : SC_DLLPUBLIC bool HasIsVisible() const;
71 : SC_DLLPUBLIC void SetIsVisible(bool bSet);
72 310 : bool GetIsVisible() const
73 310 : { return bool(nVisibleMode); }
74 :
75 : SC_DLLPUBLIC bool HasShowDetails() const;
76 : SC_DLLPUBLIC void SetShowDetails(bool bSet);
77 6 : bool GetShowDetails() const
78 6 : { return bool(nShowDetailsMode); }
79 :
80 : void SetName( const OUString& rNew ); // used if the source member was renamed (groups)
81 :
82 : SC_DLLPUBLIC void SetLayoutName( const OUString& rName );
83 : SC_DLLPUBLIC const OUString* GetLayoutName() const;
84 : void RemoveLayoutName();
85 :
86 : void WriteToSource( const com::sun::star::uno::Reference<com::sun::star::uno::XInterface>& xMember,
87 : sal_Int32 nPosition );
88 : };
89 :
90 :
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 );
94 :
95 : class SC_DLLPUBLIC ScDPSaveDimension
96 : {
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)
114 :
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;
119 :
120 : private:
121 : MemberHash maMemberHash;
122 : MemberList maMemberList;
123 :
124 : public:
125 : ScDPSaveDimension(const OUString& rName, bool bDataLayout);
126 : ScDPSaveDimension(const ScDPSaveDimension& r);
127 : ~ScDPSaveDimension();
128 :
129 : bool operator== ( const ScDPSaveDimension& r ) const;
130 :
131 0 : const MemberList& GetMembers() const
132 0 : { return maMemberList; }
133 :
134 : void AddMember(ScDPSaveMember* pMember);
135 :
136 1 : void SetDupFlag(bool bSet)
137 1 : { bDupFlag = bSet; }
138 :
139 275 : bool GetDupFlag() const
140 275 : { return bDupFlag; }
141 :
142 1100 : const OUString& GetName() const
143 1100 : { return aName; }
144 :
145 661 : bool IsDataLayout() const
146 661 : { return bIsDataLayout; }
147 :
148 : void SetName( const OUString& rNew ); // used if the source dim was renamed (groups)
149 :
150 : void SetOrientation(sal_uInt16 nNew);
151 : void SetSubTotals(long nCount, const sal_uInt16* pFuncs);
152 10 : long GetSubTotalsCount() const
153 10 : { return nSubTotalCount; }
154 :
155 8 : sal_uInt16 GetSubTotalFunc(long nIndex) const
156 8 : { return pSubTotalFuncs[nIndex]; }
157 :
158 : bool HasShowEmpty() const;
159 : void SetShowEmpty(bool bSet);
160 7 : bool GetShowEmpty() const
161 7 : { return bool(nShowEmptyMode); }
162 :
163 : void SetFunction(sal_uInt16 nNew); // enum GeneralFunction
164 6 : sal_uInt16 GetFunction() const
165 6 : { return nFunction; }
166 :
167 : void SetUsedHierarchy(long nNew);
168 0 : long GetUsedHierarchy() const
169 0 : { return nUsedHierarchy; }
170 :
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();
177 :
178 : bool IsMemberNameInUse(const OUString& rName) const;
179 :
180 7 : const ::com::sun::star::sheet::DataPilotFieldReference* GetReferenceValue() const
181 7 : { return pReferenceValue; }
182 :
183 : void SetReferenceValue(const ::com::sun::star::sheet::DataPilotFieldReference* pNew);
184 :
185 7 : const ::com::sun::star::sheet::DataPilotFieldSortInfo* GetSortInfo() const
186 7 : { return pSortInfo; }
187 :
188 : void SetSortInfo(const ::com::sun::star::sheet::DataPilotFieldSortInfo* pNew);
189 7 : const ::com::sun::star::sheet::DataPilotFieldAutoShowInfo* GetAutoShowInfo() const
190 7 : { return pAutoShowInfo; }
191 :
192 : void SetAutoShowInfo(const ::com::sun::star::sheet::DataPilotFieldAutoShowInfo* pNew);
193 7 : const ::com::sun::star::sheet::DataPilotFieldLayoutInfo* GetLayoutInfo() const
194 7 : { return pLayoutInfo; }
195 :
196 : void SetLayoutInfo(const ::com::sun::star::sheet::DataPilotFieldLayoutInfo* pNew);
197 :
198 : void SetCurrentPage( const OUString* pPage ); // NULL = no selection (all)
199 :
200 390 : sal_uInt16 GetOrientation() const
201 390 : { return nOrientation; }
202 :
203 : ScDPSaveMember* GetExistingMemberByName(const OUString& rName);
204 :
205 : /**
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>
209 : *
210 : * @param rName member name
211 : *
212 : * @return pointer to the member object.
213 : */
214 : ScDPSaveMember* GetMemberByName(const OUString& rName);
215 :
216 : void SetMemberPosition( const OUString& rName, sal_Int32 nNewPos );
217 :
218 : void WriteToSource( const com::sun::star::uno::Reference<com::sun::star::uno::XInterface>& xDim );
219 :
220 : void UpdateMemberVisibility(const ::boost::unordered_map< OUString, bool, OUStringHash>& rData);
221 :
222 : bool HasInvisibleMember() const;
223 :
224 : void RemoveObsoleteMembers(const MemberSetType& rMembers);
225 : };
226 :
227 :
228 : class ScDPSaveData
229 : {
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;
234 :
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
245 :
246 : /** if true, all dimensions already have all of their member instances
247 : * created. */
248 : bool mbDimensionMembersBuilt;
249 :
250 : boost::scoped_ptr<OUString> mpGrandTotalName;
251 : mutable boost::scoped_ptr<DimOrderType> mpDimOrder; // dimension order for row and column dimensions, to traverse result tree.
252 :
253 : public:
254 : SC_DLLPUBLIC ScDPSaveData();
255 : ScDPSaveData(const ScDPSaveData& r);
256 : SC_DLLPUBLIC ~ScDPSaveData();
257 :
258 : ScDPSaveData& operator= ( const ScDPSaveData& r );
259 :
260 : bool operator== ( const ScDPSaveData& r ) const;
261 :
262 : SC_DLLPUBLIC void SetGrandTotalName(const OUString& rName);
263 : SC_DLLPUBLIC const OUString* GetGrandTotalName() const;
264 :
265 : SC_DLLPUBLIC const DimsType& GetDimensions() const;
266 :
267 : /**
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.
272 : */
273 : const DimOrderType& GetDimensionSortOrder() const;
274 :
275 : /**
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.
279 : *
280 : * @param eOrientation orientation
281 : * @param rDims (out) list of dimensions for specified orientation
282 : */
283 : SC_DLLPUBLIC void GetAllDimensionsByOrientation(
284 : com::sun::star::sheet::DataPilotFieldOrientation eOrientation,
285 : std::vector<const ScDPSaveDimension*>& rDims) const;
286 :
287 : void AddDimension(ScDPSaveDimension* pDim);
288 :
289 : /**
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>
292 : *
293 : * @param rName dimension name
294 : *
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.
298 : */
299 : SC_DLLPUBLIC ScDPSaveDimension* GetDimensionByName(const OUString& rName);
300 : SC_DLLPUBLIC ScDPSaveDimension* GetDataLayoutDimension();
301 : SC_DLLPUBLIC ScDPSaveDimension* GetExistingDataLayoutDimension() const;
302 :
303 : ScDPSaveDimension* DuplicateDimension(const OUString& rName);
304 : SC_DLLPUBLIC ScDPSaveDimension& DuplicateDimension(const ScDPSaveDimension& rDim);
305 :
306 : SC_DLLPUBLIC ScDPSaveDimension* GetExistingDimensionByName(const OUString& rName) const;
307 : SC_DLLPUBLIC ScDPSaveDimension* GetNewDimensionByName(const OUString& rName);
308 :
309 : void RemoveDimensionByName(const OUString& rName);
310 :
311 : ScDPSaveDimension* GetInnermostDimension(sal_uInt16 nOrientation);
312 : ScDPSaveDimension* GetFirstDimension(::com::sun::star::sheet::DataPilotFieldOrientation eOrientation);
313 : long GetDataDimensionCount() const;
314 :
315 : void SetPosition( ScDPSaveDimension* pDim, long nNew );
316 : SC_DLLPUBLIC void SetColumnGrand( bool bSet );
317 0 : bool GetColumnGrand() const
318 0 : { return bool(nColumnGrandMode); }
319 :
320 : SC_DLLPUBLIC void SetRowGrand( bool bSet );
321 0 : bool GetRowGrand() const
322 0 : { return bool(nRowGrandMode); }
323 :
324 : void SetIgnoreEmptyRows( bool bSet );
325 149 : bool GetIgnoreEmptyRows() const
326 149 : { return bool(nIgnoreEmptyMode); }
327 :
328 : void SetRepeatIfEmpty( bool bSet );
329 149 : bool GetRepeatIfEmpty() const
330 149 : { return bool(nRepeatEmptyMode); }
331 :
332 : SC_DLLPUBLIC void SetFilterButton( bool bSet );
333 78 : bool GetFilterButton() const
334 78 : { return bFilterButton; }
335 :
336 : SC_DLLPUBLIC void SetDrillDown( bool bSet );
337 0 : bool GetDrillDown() const
338 0 : { return bDrillDown; }
339 :
340 : void WriteToSource( const com::sun::star::uno::Reference<com::sun::star::sheet::XDimensionsSupplier>& xSource );
341 : bool IsEmpty() const;
342 :
343 133 : const ScDPDimensionSaveData* GetExistingDimensionData() const
344 133 : { return pDimensionData; }
345 :
346 : void RemoveAllGroupDimensions( const OUString& rSrcDimName, std::vector<OUString>* pDeletedNames = NULL );
347 :
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);
352 :
353 : /**
354 : * Check whether a dimension has one or more invisible members.
355 : *
356 : * @param rDimName dimension name
357 : */
358 : SC_DLLPUBLIC bool HasInvisibleMember(const OUString& rDimName) const;
359 :
360 : private:
361 : void CheckDuplicateName(ScDPSaveDimension& rDim);
362 : void RemoveDuplicateNameCount(const OUString& rName);
363 :
364 : /**
365 : * Append a new original dimension. Not to be called to insert a duplicate
366 : * dimension.
367 : *
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.
372 : *
373 : * @return pointer to the new dimension just inserted.
374 : */
375 : ScDPSaveDimension* AppendNewDimension(const OUString& rName, bool bDataLayout);
376 :
377 : void DimensionsChanged();
378 : };
379 :
380 : #endif
381 :
382 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|