Impress Remote 1.0.5, tag sdremote-1.0.5
[LibreOffice.git] / sc / inc / dpsave.hxx
blob5bca23b4d93955a54a0ddcf64f39dff9ec8c89ae
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 SC_DPSAVE_HXX
21 #define SC_DPSAVE_HXX
23 #include <list>
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>
35 #include "scdllapi.h"
37 namespace com { namespace sun { namespace star { namespace sheet {
38 struct DataPilotFieldReference;
39 struct DataPilotFieldSortInfo;
40 struct DataPilotFieldAutoShowInfo;
41 struct DataPilotFieldLayoutInfo;
42 } } } }
44 class ScDPDimensionSaveData;
45 class ScDPTableData;
48 // classes to save Data Pilot settings
52 class ScDPSaveMember
54 private:
55 ::rtl::OUString aName;
56 boost::scoped_ptr<rtl::OUString> mpLayoutName; // custom name to be displayed in the table.
57 sal_uInt16 nVisibleMode;
58 sal_uInt16 nShowDetailsMode;
60 public:
61 ScDPSaveMember(const ::rtl::OUString& rName);
62 ScDPSaveMember(const ScDPSaveMember& r);
63 ~ScDPSaveMember();
65 bool operator== ( const ScDPSaveMember& r ) const;
67 const ::rtl::OUString& GetName() const
68 { return aName; }
70 SC_DLLPUBLIC bool HasIsVisible() const;
71 SC_DLLPUBLIC void SetIsVisible(bool bSet);
72 bool GetIsVisible() const
73 { return bool(nVisibleMode); }
75 SC_DLLPUBLIC bool HasShowDetails() const;
76 SC_DLLPUBLIC void SetShowDetails(bool bSet);
77 bool GetShowDetails() const
78 { return bool(nShowDetailsMode); }
80 void SetName( const ::rtl::OUString& rNew ); // used if the source member was renamed (groups)
82 SC_DLLPUBLIC void SetLayoutName( const ::rtl::OUString& rName );
83 SC_DLLPUBLIC const ::rtl::OUString* GetLayoutName() const;
84 void RemoveLayoutName();
86 void WriteToSource( const com::sun::star::uno::Reference<com::sun::star::uno::XInterface>& xMember,
87 sal_Int32 nPosition );
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 );
95 class SC_DLLPUBLIC ScDPSaveDimension
97 private:
98 ::rtl::OUString aName;
99 ::rtl::OUString* pSelectedPage;
100 boost::scoped_ptr<rtl::OUString> mpLayoutName;
101 boost::scoped_ptr<rtl::OUString> mpSubtotalName;
102 bool bIsDataLayout;
103 bool bDupFlag;
104 sal_uInt16 nOrientation;
105 sal_uInt16 nFunction; // enum GeneralFunction, for data dimensions
106 long nUsedHierarchy;
107 sal_uInt16 nShowEmptyMode; //! at level
108 bool bSubTotalDefault; //! at level
109 long nSubTotalCount;
110 sal_uInt16* pSubTotalFuncs; // enum GeneralFunction
111 ::com::sun::star::sheet::DataPilotFieldReference* pReferenceValue;
112 ::com::sun::star::sheet::DataPilotFieldSortInfo* pSortInfo; // (level)
113 ::com::sun::star::sheet::DataPilotFieldAutoShowInfo* pAutoShowInfo; // (level)
114 ::com::sun::star::sheet::DataPilotFieldLayoutInfo* pLayoutInfo; // (level)
116 public:
117 typedef boost::unordered_set<rtl::OUString, rtl::OUStringHash> MemberSetType;
118 typedef boost::unordered_map <rtl::OUString, ScDPSaveMember*, rtl::OUStringHash> MemberHash;
119 typedef std::list <ScDPSaveMember*> MemberList;
121 private:
122 MemberHash maMemberHash;
123 MemberList maMemberList;
125 public:
126 ScDPSaveDimension(const ::rtl::OUString& rName, bool bDataLayout);
127 ScDPSaveDimension(const ScDPSaveDimension& r);
128 ~ScDPSaveDimension();
130 bool operator== ( const ScDPSaveDimension& r ) const;
132 const MemberList& GetMembers() const
133 { return maMemberList; }
135 void AddMember(ScDPSaveMember* pMember);
137 void SetDupFlag(bool bSet)
138 { bDupFlag = bSet; }
140 bool GetDupFlag() const
141 { return bDupFlag; }
143 const ::rtl::OUString& GetName() const
144 { return aName; }
146 bool IsDataLayout() const
147 { return bIsDataLayout; }
149 void SetName( const ::rtl::OUString& rNew ); // used if the source dim was renamed (groups)
151 void SetOrientation(sal_uInt16 nNew);
152 void SetSubTotals(long nCount, const sal_uInt16* pFuncs);
153 long GetSubTotalsCount() const
154 { return nSubTotalCount; }
156 sal_uInt16 GetSubTotalFunc(long nIndex) const
157 { return pSubTotalFuncs[nIndex]; }
159 bool HasShowEmpty() const;
160 void SetShowEmpty(bool bSet);
161 bool GetShowEmpty() const
162 { return bool(nShowEmptyMode); }
164 void SetFunction(sal_uInt16 nNew); // enum GeneralFunction
165 sal_uInt16 GetFunction() const
166 { return nFunction; }
168 void SetUsedHierarchy(long nNew);
169 long GetUsedHierarchy() const
170 { return nUsedHierarchy; }
172 void SetLayoutName(const ::rtl::OUString& rName);
173 const ::rtl::OUString* GetLayoutName() const;
174 void RemoveLayoutName();
175 void SetSubtotalName(const ::rtl::OUString& rName);
176 const ::rtl::OUString* GetSubtotalName() const;
177 void RemoveSubtotalName();
179 bool IsMemberNameInUse(const ::rtl::OUString& rName) const;
181 const ::com::sun::star::sheet::DataPilotFieldReference* GetReferenceValue() const
182 { return pReferenceValue; }
184 void SetReferenceValue(const ::com::sun::star::sheet::DataPilotFieldReference* pNew);
186 const ::com::sun::star::sheet::DataPilotFieldSortInfo* GetSortInfo() const
187 { return pSortInfo; }
189 void SetSortInfo(const ::com::sun::star::sheet::DataPilotFieldSortInfo* pNew);
190 const ::com::sun::star::sheet::DataPilotFieldAutoShowInfo* GetAutoShowInfo() const
191 { return pAutoShowInfo; }
193 void SetAutoShowInfo(const ::com::sun::star::sheet::DataPilotFieldAutoShowInfo* pNew);
194 const ::com::sun::star::sheet::DataPilotFieldLayoutInfo* GetLayoutInfo() const
195 { return pLayoutInfo; }
197 void SetLayoutInfo(const ::com::sun::star::sheet::DataPilotFieldLayoutInfo* pNew);
199 void SetCurrentPage( const ::rtl::OUString* pPage ); // NULL = no selection (all)
201 sal_uInt16 GetOrientation() const
202 { return nOrientation; }
204 ScDPSaveMember* GetExistingMemberByName(const ::rtl::OUString& rName);
207 * Get a member object by its name. If one doesn't exist, creat a new
208 * object and return it. This class manages the life cycle of all member
209 * objects belonging to it, so <i>don't delete the returned instance.</i>
211 * @param rName member name
213 * @return pointer to the member object.
215 ScDPSaveMember* GetMemberByName(const ::rtl::OUString& rName);
217 void SetMemberPosition( const ::rtl::OUString& rName, sal_Int32 nNewPos );
219 void WriteToSource( const com::sun::star::uno::Reference<com::sun::star::uno::XInterface>& xDim );
221 void UpdateMemberVisibility(const ::boost::unordered_map< ::rtl::OUString, bool, ::rtl::OUStringHash>& rData);
223 bool HasInvisibleMember() const;
225 void RemoveObsoleteMembers(const MemberSetType& rMembers);
229 class ScDPSaveData
231 typedef boost::unordered_map<rtl::OUString, size_t, rtl::OUStringHash> DupNameCountType;
232 public:
233 typedef boost::ptr_vector<ScDPSaveDimension> DimsType;
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
246 /** if true, all dimensions already have all of their member instances
247 * created. */
248 bool mbDimensionMembersBuilt;
250 boost::scoped_ptr<rtl::OUString> mpGrandTotalName;
252 public:
253 SC_DLLPUBLIC ScDPSaveData();
254 ScDPSaveData(const ScDPSaveData& r);
255 SC_DLLPUBLIC ~ScDPSaveData();
257 ScDPSaveData& operator= ( const ScDPSaveData& r );
259 bool operator== ( const ScDPSaveData& r ) const;
261 SC_DLLPUBLIC void SetGrandTotalName(const ::rtl::OUString& rName);
262 SC_DLLPUBLIC const ::rtl::OUString* GetGrandTotalName() const;
264 SC_DLLPUBLIC const DimsType& GetDimensions() const;
267 * Get all dimensions in a given orientation. The order represents the
268 * actual order of occurrence. The returned list also includes data
269 * layout dimension.
271 * @param eOrientation orientation
272 * @param rDims (out) list of dimensions for specified orientation
274 SC_DLLPUBLIC void GetAllDimensionsByOrientation(
275 com::sun::star::sheet::DataPilotFieldOrientation eOrientation,
276 std::vector<const ScDPSaveDimension*>& rDims) const;
278 void AddDimension(ScDPSaveDimension* pDim);
281 * Get a dimension object by its name. <i>If one doesn't exist for the
282 * given name, it creats a new one.</i>
284 * @param rName dimension name
286 * @return pointer to the dimension object. The ScDPSaveData instance
287 * manages its life cycle; hence the caller must
288 * <i>not</i> delete this object.
290 SC_DLLPUBLIC ScDPSaveDimension* GetDimensionByName(const ::rtl::OUString& rName);
291 SC_DLLPUBLIC ScDPSaveDimension* GetDataLayoutDimension();
292 SC_DLLPUBLIC ScDPSaveDimension* GetExistingDataLayoutDimension() const;
294 ScDPSaveDimension* DuplicateDimension(const ::rtl::OUString& rName);
295 SC_DLLPUBLIC ScDPSaveDimension& DuplicateDimension(const ScDPSaveDimension& rDim);
297 SC_DLLPUBLIC ScDPSaveDimension* GetExistingDimensionByName(const ::rtl::OUString& rName) const;
298 SC_DLLPUBLIC ScDPSaveDimension* GetNewDimensionByName(const ::rtl::OUString& rName);
300 void RemoveDimensionByName(const ::rtl::OUString& rName);
302 ScDPSaveDimension* GetInnermostDimension(sal_uInt16 nOrientation);
303 ScDPSaveDimension* GetFirstDimension(::com::sun::star::sheet::DataPilotFieldOrientation eOrientation);
304 long GetDataDimensionCount() const;
306 void SetPosition( ScDPSaveDimension* pDim, long nNew );
307 SC_DLLPUBLIC void SetColumnGrand( bool bSet );
308 bool GetColumnGrand() const
309 { return bool(nColumnGrandMode); }
311 SC_DLLPUBLIC void SetRowGrand( bool bSet );
312 bool GetRowGrand() const
313 { return bool(nRowGrandMode); }
315 void SetIgnoreEmptyRows( bool bSet );
316 bool GetIgnoreEmptyRows() const
317 { return bool(nIgnoreEmptyMode); }
319 void SetRepeatIfEmpty( bool bSet );
320 bool GetRepeatIfEmpty() const
321 { return bool(nRepeatEmptyMode); }
323 SC_DLLPUBLIC void SetFilterButton( bool bSet );
324 bool GetFilterButton() const
325 { return bFilterButton; }
327 SC_DLLPUBLIC void SetDrillDown( bool bSet );
328 bool GetDrillDown() const
329 { return bDrillDown; }
331 void WriteToSource( const com::sun::star::uno::Reference<com::sun::star::sheet::XDimensionsSupplier>& xSource );
332 bool IsEmpty() const;
334 const ScDPDimensionSaveData* GetExistingDimensionData() const
335 { return pDimensionData; }
337 void RemoveAllGroupDimensions( const rtl::OUString& rSrcDimName, std::vector<rtl::OUString>* pDeletedNames = NULL );
339 SC_DLLPUBLIC ScDPDimensionSaveData* GetDimensionData(); // create if not there
340 void SetDimensionData( const ScDPDimensionSaveData* pNew ); // copied
341 void BuildAllDimensionMembers(ScDPTableData* pData);
342 void SyncAllDimensionMembers(ScDPTableData* pData);
345 * Check whether a dimension has one or more invisible members.
347 * @param rDimName dimension name
349 SC_DLLPUBLIC bool HasInvisibleMember(const ::rtl::OUString& rDimName) const;
351 private:
352 void CheckDuplicateName(ScDPSaveDimension& rDim);
353 void RemoveDuplicateNameCount(const rtl::OUString& rName);
356 * Append a new original dimension. Not to be called to insert a duplicate
357 * dimension.
359 * @param rName Dimension name. The name must be the original dimension
360 * name; not a duplicate dimension name.
361 * @param bDataLayout true if this is a data layout dimension, false
362 * otherwise.
364 * @return pointer to the new dimension just inserted.
366 ScDPSaveDimension* AppendNewDimension(const rtl::OUString& rName, bool bDataLayout);
369 #endif
371 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */