LibreOffice Module sc (master)  1
dpsave.hxx
Go to the documentation of this file.
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 <memory>
24 #include <vector>
25 
26 #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
27 #include <rtl/ustring.hxx>
28 #include <sal/types.h>
29 #include <tools/long.hxx>
30 
31 #include "scdllapi.h"
32 #include "calcmacros.hxx"
33 
34 #include <unordered_map>
35 #include <unordered_set>
36 #include <optional>
37 
38 namespace com::sun::star::sheet {
39  class XDimensionsSupplier;
40  struct DataPilotFieldReference;
41  struct DataPilotFieldSortInfo;
42  struct DataPilotFieldAutoShowInfo;
43  struct DataPilotFieldLayoutInfo;
44 }
45 
47 class ScDPTableData;
48 enum class ScGeneralFunction;
49 
50 // classes to save Data Pilot settings
51 
53 {
54 private:
55  OUString aName;
56  std::optional<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);
64 
65  bool operator== ( const ScDPSaveMember& r ) const;
66 
67  const OUString& GetName() const
68  { return aName; }
69 
70  SC_DLLPUBLIC bool HasIsVisible() const;
71  SC_DLLPUBLIC void SetIsVisible(bool bSet);
72  bool GetIsVisible() const
73  { return bool(nVisibleMode); }
74 
75  SC_DLLPUBLIC bool HasShowDetails() const;
76  SC_DLLPUBLIC void SetShowDetails(bool bSet);
77  bool GetShowDetails() const
78  { 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 std::optional<OUString> & GetLayoutName() const;
84  void RemoveLayoutName();
85 
86  void WriteToSource( const css::uno::Reference<css::uno::XInterface>& xMember,
87  sal_Int32 nPosition );
88 
89 #if DUMP_PIVOT_TABLE
90  void Dump(int nIndent = 0) const;
91 #endif
92 };
93 
95 {
96 private:
97  OUString aName;
98  std::optional<OUString> mpLayoutName;
99  std::optional<OUString> mpSubtotalName;
101  bool bDupFlag;
102  css::sheet::DataPilotFieldOrientation nOrientation;
103  ScGeneralFunction nFunction; // for data dimensions
105  sal_uInt16 nShowEmptyMode;
108  std::vector<ScGeneralFunction> maSubTotalFuncs;
109  std::unique_ptr<css::sheet::DataPilotFieldReference> pReferenceValue;
110  std::unique_ptr<css::sheet::DataPilotFieldSortInfo> pSortInfo; // (level)
111  std::unique_ptr<css::sheet::DataPilotFieldAutoShowInfo> pAutoShowInfo; // (level)
112  std::unique_ptr<css::sheet::DataPilotFieldLayoutInfo> pLayoutInfo; // (level)
113 
114 public:
115  typedef std::unordered_set<OUString> MemberSetType;
116  typedef std::vector<ScDPSaveMember*> MemberList;
117 
118 private:
119  std::unordered_map<OUString, std::unique_ptr<ScDPSaveMember>> maMemberHash;
120  MemberList maMemberList;
121 
122 public:
123  ScDPSaveDimension(const OUString& rName, bool bDataLayout);
126 
127  bool operator== ( const ScDPSaveDimension& r ) const;
128 
129  const MemberList& GetMembers() const
130  { return maMemberList; }
131 
132  void AddMember(std::unique_ptr<ScDPSaveMember> pMember);
133 
134  void SetDupFlag(bool bSet)
135  { bDupFlag = bSet; }
136 
137  bool GetDupFlag() const
138  { return bDupFlag; }
139 
140  const OUString& GetName() const
141  { return aName; }
142 
143  bool IsDataLayout() const
144  { return bIsDataLayout; }
145 
146  void SetName( const OUString& rNew ); // used if the source dim was renamed (groups)
147 
148  void SetOrientation(css::sheet::DataPilotFieldOrientation nNew);
149  void SetSubTotals(std::vector<ScGeneralFunction> const & rFuncs);
151  { return maSubTotalFuncs.size(); }
152 
154  { return maSubTotalFuncs[nIndex]; }
155 
156  bool HasShowEmpty() const;
157  void SetShowEmpty(bool bSet);
158  bool GetShowEmpty() const
159  { return bool(nShowEmptyMode); }
160 
161  void SetRepeatItemLabels(bool bSet);
162  bool GetRepeatItemLabels() const
163  { return bRepeatItemLabels; }
164 
165  void SetFunction(ScGeneralFunction nNew);
167  { return nFunction; }
168 
169  void SetUsedHierarchy(tools::Long nNew);
171  { return nUsedHierarchy; }
172 
173  void SetLayoutName(const OUString& rName);
174  const std::optional<OUString> & GetLayoutName() const;
175  void RemoveLayoutName();
176  void SetSubtotalName(const OUString& rName);
177  const std::optional<OUString> & GetSubtotalName() const;
178  void RemoveSubtotalName();
179 
180  bool IsMemberNameInUse(const OUString& rName) const;
181 
182  const css::sheet::DataPilotFieldReference* GetReferenceValue() const
183  { return pReferenceValue.get(); }
184 
185  void SetReferenceValue(const css::sheet::DataPilotFieldReference* pNew);
186 
187  const css::sheet::DataPilotFieldSortInfo* GetSortInfo() const
188  { return pSortInfo.get(); }
189 
190  void SetSortInfo(const css::sheet::DataPilotFieldSortInfo* pNew);
191  const css::sheet::DataPilotFieldAutoShowInfo* GetAutoShowInfo() const
192  { return pAutoShowInfo.get(); }
193 
194  void SetAutoShowInfo(const css::sheet::DataPilotFieldAutoShowInfo* pNew);
195  const css::sheet::DataPilotFieldLayoutInfo* GetLayoutInfo() const
196  { return pLayoutInfo.get(); }
197 
198  void SetLayoutInfo(const css::sheet::DataPilotFieldLayoutInfo* pNew);
199 
200  void SetCurrentPage( const OUString* pPage ); // NULL = no selection (all)
201  OUString GetCurrentPage() const; // only for ODF compatibility
202 
203  css::sheet::DataPilotFieldOrientation GetOrientation() const
204  { return nOrientation; }
205 
206  ScDPSaveMember* GetExistingMemberByName(const OUString& rName);
207 
217  ScDPSaveMember* GetMemberByName(const OUString& rName);
218 
219  void SetMemberPosition( const OUString& rName, sal_Int32 nNewPos );
220 
221  void WriteToSource( const css::uno::Reference<css::uno::XInterface>& xDim );
222 
223  void UpdateMemberVisibility(const std::unordered_map< OUString, bool>& rData);
224 
225  bool HasInvisibleMember() const;
226 
227  void RemoveObsoleteMembers(const MemberSetType& rMembers);
228 
229 #if DUMP_PIVOT_TABLE
230  void Dump(int nIndent = 0) const;
231 #endif
232 };
233 
235 {
236  typedef std::unordered_map<OUString, size_t> DupNameCountType;
237 public:
238  typedef std::unordered_map<OUString, size_t> DimOrderType;
239  typedef std::vector<std::unique_ptr<ScDPSaveDimension>> DimsType;
240 
241 private:
242  DimsType m_DimList;
243  DupNameCountType maDupNameCounts;
244  std::unique_ptr<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
251 
255 
256  std::optional<OUString> mpGrandTotalName;
257  mutable std::unique_ptr<DimOrderType> mpDimOrder; // dimension order for row and column dimensions, to traverse result tree.
258 
259 public:
261  ScDPSaveData(const ScDPSaveData& r);
263 
264  ScDPSaveData& operator= ( const ScDPSaveData& r );
265 
266  bool operator== ( const ScDPSaveData& r ) const;
267 
268  SC_DLLPUBLIC void SetGrandTotalName(const OUString& rName);
269  SC_DLLPUBLIC const std::optional<OUString> & GetGrandTotalName() const;
270 
271  const DimsType& GetDimensions() const { return m_DimList; }
272 
279  const DimOrderType& GetDimensionSortOrder() const;
280 
290  css::sheet::DataPilotFieldOrientation eOrientation,
291  std::vector<const ScDPSaveDimension*>& rDims) const;
292 
293  void AddDimension(ScDPSaveDimension* pDim);
294 
305  SC_DLLPUBLIC ScDPSaveDimension* GetDimensionByName(const OUString& rName);
308 
309  ScDPSaveDimension* DuplicateDimension(std::u16string_view rName);
311 
312  SC_DLLPUBLIC ScDPSaveDimension* GetExistingDimensionByName(std::u16string_view rName) const;
313  SC_DLLPUBLIC ScDPSaveDimension* GetNewDimensionByName(const OUString& rName);
314 
315  void RemoveDimensionByName(const OUString& rName);
316 
317  ScDPSaveDimension* GetInnermostDimension(css::sheet::DataPilotFieldOrientation nOrientation);
318  ScDPSaveDimension* GetFirstDimension(css::sheet::DataPilotFieldOrientation eOrientation);
320 
321  void SetPosition( ScDPSaveDimension* pDim, tools::Long nNew );
322  SC_DLLPUBLIC void SetColumnGrand( bool bSet );
323  bool GetColumnGrand() const
324  { return bool(nColumnGrandMode); }
325 
326  SC_DLLPUBLIC void SetRowGrand( bool bSet );
327  bool GetRowGrand() const
328  { return bool(nRowGrandMode); }
329 
330  SC_DLLPUBLIC void SetIgnoreEmptyRows( bool bSet );
331  bool GetIgnoreEmptyRows() const
332  { return bool(nIgnoreEmptyMode); }
333 
334  SC_DLLPUBLIC void SetRepeatIfEmpty( bool bSet );
335  bool GetRepeatIfEmpty() const
336  { return bool(nRepeatEmptyMode); }
337 
338  SC_DLLPUBLIC void SetFilterButton( bool bSet );
339  bool GetFilterButton() const
340  { return bFilterButton; }
341 
342  SC_DLLPUBLIC void SetDrillDown( bool bSet );
343  bool GetDrillDown() const
344  { return bDrillDown; }
345 
346  void WriteToSource( const css::uno::Reference<css::sheet::XDimensionsSupplier>& xSource );
347  bool IsEmpty() const;
348 
350  { return pDimensionData.get(); }
351 
352  void RemoveAllGroupDimensions( const OUString& rSrcDimName, std::vector<OUString>* pDeletedNames = nullptr );
353 
354  SC_DLLPUBLIC ScDPDimensionSaveData* GetDimensionData(); // create if not there
355  SC_DLLPUBLIC void SetDimensionData( const ScDPDimensionSaveData* pNew ); // copied
358 
364  SC_DLLPUBLIC bool HasInvisibleMember(std::u16string_view rDimName) const;
365 
366 #if DUMP_PIVOT_TABLE
367  void Dump() const;
368 #endif
369 
370 private:
372  void RemoveDuplicateNameCount(const OUString& rName);
373 
385  ScDPSaveDimension* AppendNewDimension(const OUString& rName, bool bDataLayout);
386 
387  void DimensionsChanged();
388 };
389 
390 #endif
391 
392 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool operator==(const XclFontData &rLeft, const XclFontData &rRight)
Definition: xlstyle.cxx:517
SC_DLLPUBLIC bool HasInvisibleMember(std::u16string_view rDimName) const
Check whether a dimension has one or more invisible members.
Definition: dpsave.cxx:1295
SC_DLLPUBLIC void SetRepeatIfEmpty(bool bSet)
Definition: dpsave.cxx:998
const ScDPDimensionSaveData * GetExistingDimensionData() const
Definition: dpsave.hxx:349
void WriteToSource(const css::uno::Reference< css::uno::XInterface > &xMember, sal_Int32 nPosition)
Definition: dpsave.cxx:133
bool GetRowGrand() const
Definition: dpsave.hxx:327
void BuildAllDimensionMembers(ScDPTableData *pData)
Definition: dpsave.cxx:1210
css::sheet::DataPilotFieldOrientation nOrientation
Definition: dpsave.hxx:102
This class has to do with handling exclusively grouped dimensions? TODO: Find out what this class doe...
Definition: dpdimsave.hxx:164
bool operator==(const ScDPSaveMember &r) const
Definition: dpsave.cxx:83
SC_DLLPUBLIC const std::optional< OUString > & GetGrandTotalName() const
Definition: dpsave.cxx:770
std::unique_ptr< DimOrderType > mpDimOrder
Definition: dpsave.hxx:257
const MemberList & GetMembers() const
Definition: dpsave.hxx:129
std::optional< OUString > mpLayoutName
Definition: dpsave.hxx:56
css::sheet::DataPilotFieldOrientation GetOrientation() const
Definition: dpsave.hxx:203
void CheckDuplicateName(ScDPSaveDimension &rDim)
Definition: dpsave.cxx:1317
std::unique_ptr< css::sheet::DataPilotFieldSortInfo > pSortInfo
Definition: dpsave.hxx:110
sal_uInt16 nShowDetailsMode
Definition: dpsave.hxx:58
MemberList maMemberList
Definition: dpsave.hxx:120
bool GetIsVisible() const
Definition: dpsave.hxx:72
ScGeneralFunction GetSubTotalFunc(tools::Long nIndex) const
Definition: dpsave.hxx:153
long Long
const css::sheet::DataPilotFieldLayoutInfo * GetLayoutInfo() const
Definition: dpsave.hxx:195
std::unordered_map< OUString, std::unique_ptr< ScDPSaveMember > > maMemberHash
Definition: dpsave.hxx:119
SC_DLLPUBLIC ScDPDimensionSaveData * GetDimensionData()
Definition: dpsave.cxx:1195
bool IsDataLayout() const
Definition: dpsave.hxx:143
void AddDimension(ScDPSaveDimension *pDim)
Definition: dpsave.cxx:823
SC_DLLPUBLIC void SetIsVisible(bool bSet)
Definition: dpsave.cxx:95
std::unordered_set< OUString > MemberSetType
Definition: dpsave.hxx:115
ScDPSaveData & operator=(const ScDPSaveData &r)
Definition: dpsave.cxx:720
std::optional< OUString > mpGrandTotalName
Definition: dpsave.hxx:256
SC_DLLPUBLIC void GetAllDimensionsByOrientation(css::sheet::DataPilotFieldOrientation eOrientation, std::vector< const ScDPSaveDimension * > &rDims) const
Get all dimensions in a given orientation.
Definition: dpsave.cxx:807
tools::Long GetUsedHierarchy() const
Definition: dpsave.hxx:170
ScGeneralFunction nFunction
Definition: dpsave.hxx:103
void RemoveDimensionByName(const OUString &rName)
Definition: dpsave.cxx:898
bool operator==(const ScDPSaveData &r) const
Definition: dpsave.cxx:730
const DimOrderType & GetDimensionSortOrder() const
Get sort order map to sort row and column dimensions in order of appearance.
Definition: dpsave.cxx:792
const OUString & GetName() const
Definition: dpsave.hxx:67
ScGeneralFunction GetFunction() const
Definition: dpsave.hxx:166
bool GetIgnoreEmptyRows() const
Definition: dpsave.hxx:331
bool IsEmpty() const
Definition: dpsave.cxx:1148
std::unordered_map< OUString, size_t > DimOrderType
Definition: dpsave.hxx:238
std::vector< ScDPSaveMember * > MemberList
Definition: dpsave.hxx:116
sal_uInt16 nVisibleMode
Definition: dpsave.hxx:57
bool GetRepeatItemLabels() const
Definition: dpsave.hxx:162
ScDPSaveDimension * GetInnermostDimension(css::sheet::DataPilotFieldOrientation nOrientation)
Definition: dpsave.cxx:918
std::unique_ptr< ScDPDimensionSaveData > pDimensionData
keep track of number of duplicates in each name.
Definition: dpsave.hxx:244
bool GetDrillDown() const
Definition: dpsave.hxx:343
void SyncAllDimensionMembers(ScDPTableData *pData)
Definition: dpsave.cxx:1256
ScDPSaveDimension * GetFirstDimension(css::sheet::DataPilotFieldOrientation eOrientation)
Definition: dpsave.cxx:932
SC_DLLPUBLIC tools::Long GetDataDimensionCount() const
Definition: dpsave.cxx:942
void RemoveDuplicateNameCount(const OUString &rName)
Definition: dpsave.cxx:1331
SC_DLLPUBLIC ScDPSaveDimension * GetNewDimensionByName(const OUString &rName)
Definition: dpsave.cxx:855
const css::sheet::DataPilotFieldSortInfo * GetSortInfo() const
Definition: dpsave.hxx:187
DupNameCountType maDupNameCounts
Definition: dpsave.hxx:243
tools::Long GetSubTotalsCount() const
Definition: dpsave.hxx:150
SC_DLLPUBLIC void SetDimensionData(const ScDPDimensionSaveData *pNew)
Definition: dpsave.cxx:1202
ScDPSaveDimension * AppendNewDimension(const OUString &rName, bool bDataLayout)
Append a new original dimension.
Definition: dpsave.cxx:1350
SC_DLLPUBLIC ScDPSaveDimension * GetExistingDataLayoutDimension() const
Definition: dpsave.cxx:875
SC_DLLPUBLIC void SetLayoutName(const OUString &rName)
Definition: dpsave.cxx:118
void SetName(const OUString &rNew)
Definition: dpsave.cxx:110
void Dump() const
sal_uInt16 nRowGrandMode
Definition: dpsave.hxx:246
bool GetRepeatIfEmpty() const
Definition: dpsave.hxx:335
SC_DLLPUBLIC ~ScDPSaveData()
Definition: dpsave.cxx:761
SC_DLLPUBLIC void SetIgnoreEmptyRows(bool bSet)
Definition: dpsave.cxx:993
sal_uInt16 nIgnoreEmptyMode
Definition: dpsave.hxx:247
SC_DLLPUBLIC ScDPSaveDimension * GetExistingDimensionByName(std::u16string_view rName) const
Definition: dpsave.cxx:845
void SetDupFlag(bool bSet)
Definition: dpsave.hxx:134
SC_DLLPUBLIC void SetFilterButton(bool bSet)
Definition: dpsave.cxx:1003
OUString aName
Definition: dpsave.hxx:97
ScDPSaveDimension * DuplicateDimension(std::u16string_view rName)
Definition: dpsave.cxx:885
sal_uInt16 nColumnGrandMode
Definition: dpsave.hxx:245
bool GetFilterButton() const
Definition: dpsave.hxx:339
void SetPosition(ScDPSaveDimension *pDim, tools::Long nNew)
Definition: dpsave.cxx:955
bool mbDimensionMembersBuilt
if true, all dimensions already have all of their member instances created.
Definition: dpsave.hxx:254
SC_DLLPUBLIC void SetShowDetails(bool bSet)
Definition: dpsave.cxx:105
std::optional< OUString > mpSubtotalName
Definition: dpsave.hxx:99
bool GetColumnGrand() const
Definition: dpsave.hxx:323
SC_DLLPUBLIC void SetGrandTotalName(const OUString &rName)
Definition: dpsave.cxx:765
SC_DLLPUBLIC void SetDrillDown(bool bSet)
Definition: dpsave.cxx:1008
Base class that abstracts different data source types of a datapilot table.
Definition: dptabdat.hxx:57
void DimensionsChanged()
Definition: dpsave.cxx:1365
SC_DLLPUBLIC bool HasIsVisible() const
Definition: dpsave.cxx:90
tools::Long nUsedHierarchy
Definition: dpsave.hxx:104
bool GetShowDetails() const
Definition: dpsave.hxx:77
const DimsType & GetDimensions() const
Definition: dpsave.hxx:271
std::unordered_map< OUString, size_t > DupNameCountType
Definition: dpsave.hxx:236
sal_uInt16 nShowEmptyMode
Definition: dpsave.hxx:105
sal_uInt16 nRepeatEmptyMode
Definition: dpsave.hxx:248
std::unique_ptr< css::sheet::DataPilotFieldReference > pReferenceValue
Definition: dpsave.hxx:109
bool GetShowEmpty() const
Definition: dpsave.hxx:158
std::unique_ptr< css::sheet::DataPilotFieldLayoutInfo > pLayoutInfo
Definition: dpsave.hxx:112
ScGeneralFunction
the css::sheet::GeneralFunction enum is extended by constants in GeneralFunction2, which causes some type-safety issues.
const OUString & GetName() const
Definition: dpsave.hxx:140
std::vector< std::unique_ptr< ScDPSaveDimension > > DimsType
Definition: dpsave.hxx:239
std::unique_ptr< css::sheet::DataPilotFieldAutoShowInfo > pAutoShowInfo
Definition: dpsave.hxx:111
bool bSubTotalDefault
at level
Definition: dpsave.hxx:107
const css::sheet::DataPilotFieldAutoShowInfo * GetAutoShowInfo() const
Definition: dpsave.hxx:191
bool bDrillDown
Definition: dpsave.hxx:250
SC_DLLPUBLIC void SetColumnGrand(bool bSet)
Definition: dpsave.cxx:983
DimsType m_DimList
Definition: dpsave.hxx:242
bool GetDupFlag() const
Definition: dpsave.hxx:137
SC_DLLPUBLIC void SetRowGrand(bool bSet)
Definition: dpsave.cxx:988
void WriteToSource(const css::uno::Reference< css::sheet::XDimensionsSupplier > &xSource)
Definition: dpsave.cxx:1028
void Dump(int nIndent=0) const
bool bRepeatItemLabels
at level
Definition: dpsave.hxx:106
SC_DLLPUBLIC const std::optional< OUString > & GetLayoutName() const
Definition: dpsave.cxx:123
OUString aName
Definition: dpsave.hxx:55
void RemoveAllGroupDimensions(const OUString &rSrcDimName, std::vector< OUString > *pDeletedNames=nullptr)
Definition: dpsave.cxx:1158
std::optional< OUString > mpLayoutName
Definition: dpsave.hxx:98
void RemoveLayoutName()
Definition: dpsave.cxx:128
#define SC_DLLPUBLIC
Definition: scdllapi.h:28
SC_DLLPUBLIC ScDPSaveDimension * GetDimensionByName(const OUString &rName)
Get a dimension object by its name.
Definition: dpsave.cxx:834
const css::sheet::DataPilotFieldReference * GetReferenceValue() const
Definition: dpsave.hxx:182
SC_DLLPUBLIC ScDPSaveDimension * GetDataLayoutDimension()
Definition: dpsave.cxx:866
ScDPSaveMember(const OUString &rName)
Definition: dpsave.cxx:64
std::vector< ScGeneralFunction > maSubTotalFuncs
at level
Definition: dpsave.hxx:108
bool bFilterButton
Definition: dpsave.hxx:249
SC_DLLPUBLIC ScDPSaveData()
Definition: dpsave.cxx:690
SC_DLLPUBLIC bool HasShowDetails() const
Definition: dpsave.cxx:100