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#pragma once
21
22#include <memory>
23#include <vector>
24
25#include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
26#include <rtl/ustring.hxx>
27#include <sal/types.h>
28#include <tools/long.hxx>
29
30#include "scdllapi.h"
31#include "calcmacros.hxx"
32
33#include <unordered_map>
34#include <unordered_set>
35#include <optional>
36
37namespace com::sun::star::sheet {
38 class XDimensionsSupplier;
39 struct DataPilotFieldReference;
40 struct DataPilotFieldSortInfo;
41 struct DataPilotFieldAutoShowInfo;
42 struct DataPilotFieldLayoutInfo;
43}
44
46class ScDPTableData;
47enum class ScGeneralFunction;
48
49// classes to save Data Pilot settings
50
52{
53private:
54 OUString aName;
55 std::optional<OUString> mpLayoutName; // custom name to be displayed in the table.
56 sal_uInt16 nVisibleMode;
57 sal_uInt16 nShowDetailsMode;
58
59public:
60 ScDPSaveMember(OUString aName);
63
64 bool operator== ( const ScDPSaveMember& r ) const;
65
66 const OUString& GetName() const
67 { return aName; }
68
69 SC_DLLPUBLIC bool HasIsVisible() const;
70 SC_DLLPUBLIC void SetIsVisible(bool bSet);
71 bool GetIsVisible() const
72 { return bool(nVisibleMode); }
73
74 SC_DLLPUBLIC bool HasShowDetails() const;
75 SC_DLLPUBLIC void SetShowDetails(bool bSet);
76 bool GetShowDetails() const
77 { 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 std::optional<OUString> & GetLayoutName() const;
83 void RemoveLayoutName();
84
85 void WriteToSource( const css::uno::Reference<css::uno::XInterface>& xMember,
86 sal_Int32 nPosition );
87
88#if DUMP_PIVOT_TABLE
89 void Dump(int nIndent = 0) const;
90#endif
91};
92
94{
95private:
96 OUString aName;
97 std::optional<OUString> mpLayoutName;
98 std::optional<OUString> mpSubtotalName;
101 css::sheet::DataPilotFieldOrientation nOrientation;
102 ScGeneralFunction nFunction; // for data dimensions
104 sal_uInt16 nShowEmptyMode;
107 std::vector<ScGeneralFunction> maSubTotalFuncs;
108 std::unique_ptr<css::sheet::DataPilotFieldReference> pReferenceValue;
109 std::unique_ptr<css::sheet::DataPilotFieldSortInfo> pSortInfo; // (level)
110 std::unique_ptr<css::sheet::DataPilotFieldAutoShowInfo> pAutoShowInfo; // (level)
111 std::unique_ptr<css::sheet::DataPilotFieldLayoutInfo> pLayoutInfo; // (level)
112
113public:
114 typedef std::unordered_set<OUString> MemberSetType;
115 typedef std::vector<ScDPSaveMember*> MemberList;
116
117private:
118 std::unordered_map<OUString, std::unique_ptr<ScDPSaveMember>> maMemberHash;
120
121public:
122 ScDPSaveDimension(OUString aName, bool bDataLayout);
125
126 bool operator== ( const ScDPSaveDimension& r ) const;
127
128 const MemberList& GetMembers() const
129 { return maMemberList; }
130
131 void AddMember(std::unique_ptr<ScDPSaveMember> pMember);
132
133 void SetDupFlag(bool bSet)
134 { bDupFlag = bSet; }
135
136 bool GetDupFlag() const
137 { return bDupFlag; }
138
139 const OUString& GetName() const
140 { return aName; }
141
142 bool IsDataLayout() const
143 { return bIsDataLayout; }
144
145 void SetName( const OUString& rNew ); // used if the source dim was renamed (groups)
146
147 void SetOrientation(css::sheet::DataPilotFieldOrientation nNew);
148 void SetSubTotals(std::vector<ScGeneralFunction> && rFuncs);
150 { return maSubTotalFuncs.size(); }
151
153 { return maSubTotalFuncs[nIndex]; }
154
155 bool HasShowEmpty() const;
156 void SetShowEmpty(bool bSet);
157 bool GetShowEmpty() const
158 { return bool(nShowEmptyMode); }
159
160 void SetRepeatItemLabels(bool bSet);
162 { return bRepeatItemLabels; }
163
164 void SetFunction(ScGeneralFunction nNew);
166 { return nFunction; }
167
168 void SetUsedHierarchy(tools::Long nNew);
170 { return nUsedHierarchy; }
171
172 void SetLayoutName(const OUString& rName);
173 const std::optional<OUString> & GetLayoutName() const;
174 void RemoveLayoutName();
175 void SetSubtotalName(const OUString& rName);
176 const std::optional<OUString> & GetSubtotalName() const;
177 void RemoveSubtotalName();
178
179 bool IsMemberNameInUse(const OUString& rName) const;
180
181 const css::sheet::DataPilotFieldReference* GetReferenceValue() const
182 { return pReferenceValue.get(); }
183
184 void SetReferenceValue(const css::sheet::DataPilotFieldReference* pNew);
185
186 const css::sheet::DataPilotFieldSortInfo* GetSortInfo() const
187 { return pSortInfo.get(); }
188
189 void SetSortInfo(const css::sheet::DataPilotFieldSortInfo* pNew);
190 const css::sheet::DataPilotFieldAutoShowInfo* GetAutoShowInfo() const
191 { return pAutoShowInfo.get(); }
192
193 void SetAutoShowInfo(const css::sheet::DataPilotFieldAutoShowInfo* pNew);
194 const css::sheet::DataPilotFieldLayoutInfo* GetLayoutInfo() const
195 { return pLayoutInfo.get(); }
196
197 void SetLayoutInfo(const css::sheet::DataPilotFieldLayoutInfo* pNew);
198
199 void SetCurrentPage( const OUString* pPage ); // NULL = no selection (all)
200 OUString GetCurrentPage() const; // only for ODF compatibility
201
202 css::sheet::DataPilotFieldOrientation GetOrientation() const
203 { return nOrientation; }
204
205 ScDPSaveMember* GetExistingMemberByName(const OUString& rName);
206
216 ScDPSaveMember* GetMemberByName(const OUString& rName);
217
218 void SetMemberPosition( const OUString& rName, sal_Int32 nNewPos );
219
220 void WriteToSource( const css::uno::Reference<css::uno::XInterface>& xDim );
221
222 void UpdateMemberVisibility(const std::unordered_map< OUString, bool>& rData);
223
224 bool HasInvisibleMember() const;
225
226 void RemoveObsoleteMembers(const MemberSetType& rMembers);
227
228#if DUMP_PIVOT_TABLE
229 void Dump(int nIndent = 0) const;
230#endif
231};
232
234{
235 typedef std::unordered_map<OUString, size_t> DupNameCountType;
236public:
237 typedef std::unordered_map<OUString, size_t> DimOrderType;
238 typedef std::vector<std::unique_ptr<ScDPSaveDimension>> DimsType;
239
240private:
243 std::unique_ptr<ScDPDimensionSaveData> pDimensionData; // settings that create new dimensions
245 sal_uInt16 nRowGrandMode;
248 bool bFilterButton; // not passed to DataPilotSource
249 bool bDrillDown; // not passed to DataPilotSource
250 bool bExpandCollapse; // 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
259public:
261 ScDPSaveData(const ScDPSaveData& r);
263
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
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;
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 );
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 SC_DLLPUBLIC void SetExpandCollapse( bool bSet );
347 bool GetExpandCollapse() const
348 { return bExpandCollapse; }
349
350 void WriteToSource( const css::uno::Reference<css::sheet::XDimensionsSupplier>& xSource );
351 bool IsEmpty() const;
352
354 { return pDimensionData.get(); }
355
356 void RemoveAllGroupDimensions( const OUString& rSrcDimName, std::vector<OUString>* pDeletedNames = nullptr );
357
358 SC_DLLPUBLIC ScDPDimensionSaveData* GetDimensionData(); // create if not there
359 SC_DLLPUBLIC void SetDimensionData( const ScDPDimensionSaveData* pNew ); // copied
362
368 SC_DLLPUBLIC bool HasInvisibleMember(std::u16string_view rDimName) const;
369
370#if DUMP_PIVOT_TABLE
371 void Dump() const;
372#endif
373
374private:
376 void RemoveDuplicateNameCount(const OUString& rName);
377
389 ScDPSaveDimension* AppendNewDimension(const OUString& rName, bool bDataLayout);
390
391 void DimensionsChanged();
392};
393
394/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::vector< OUString > maMemberList
This class has to do with handling exclusively grouped dimensions? TODO: Find out what this class doe...
Definition: dpdimsave.hxx:164
std::unordered_map< OUString, size_t > DimOrderType
Definition: dpsave.hxx:237
bool bExpandCollapse
Definition: dpsave.hxx:250
void RemoveAllGroupDimensions(const OUString &rSrcDimName, std::vector< OUString > *pDeletedNames=nullptr)
Definition: dpsave.cxx:1167
void WriteToSource(const css::uno::Reference< css::sheet::XDimensionsSupplier > &xSource)
Definition: dpsave.cxx:1037
SC_DLLPUBLIC void SetIgnoreEmptyRows(bool bSet)
Definition: dpsave.cxx:997
ScDPSaveDimension * GetInnermostDimension(css::sheet::DataPilotFieldOrientation nOrientation)
Definition: dpsave.cxx:922
void RemoveDuplicateNameCount(const OUString &rName)
Definition: dpsave.cxx:1352
bool operator==(const ScDPSaveData &r) const
Definition: dpsave.cxx:734
SC_DLLPUBLIC ScDPSaveDimension * GetExistingDimensionByName(std::u16string_view rName) const
Definition: dpsave.cxx:849
void DimensionsChanged()
Definition: dpsave.cxx:1386
bool IsEmpty() const
Definition: dpsave.cxx:1157
const DimOrderType & GetDimensionSortOrder() const
Get sort order map to sort row and column dimensions in order of appearance.
Definition: dpsave.cxx:796
bool GetDrillDown() const
Definition: dpsave.hxx:343
SC_DLLPUBLIC void GetAllDimensionsByOrientation(css::sheet::DataPilotFieldOrientation eOrientation, std::vector< const ScDPSaveDimension * > &rDims) const
Get all dimensions in a given orientation.
Definition: dpsave.cxx:811
SC_DLLPUBLIC void SetExpandCollapse(bool bSet)
Definition: dpsave.cxx:1017
ScDPSaveData & operator=(const ScDPSaveData &r)
Definition: dpsave.cxx:724
bool GetFilterButton() const
Definition: dpsave.hxx:339
SC_DLLPUBLIC ScDPSaveDimension * GetNewDimensionByName(const OUString &rName)
Definition: dpsave.cxx:859
bool GetIgnoreEmptyRows() const
Definition: dpsave.hxx:331
void Dump() const
ScDPSaveDimension * GetFirstDimension(css::sheet::DataPilotFieldOrientation eOrientation)
Definition: dpsave.cxx:936
bool bDrillDown
Definition: dpsave.hxx:249
void SetPosition(ScDPSaveDimension *pDim, tools::Long nNew)
Definition: dpsave.cxx:959
SC_DLLPUBLIC bool HasInvisibleMember(std::u16string_view rDimName) const
Check whether a dimension has one or more invisible members.
Definition: dpsave.cxx:1316
sal_uInt16 nRowGrandMode
Definition: dpsave.hxx:245
ScDPSaveDimension * DuplicateDimension(std::u16string_view rName)
Definition: dpsave.cxx:889
std::unique_ptr< DimOrderType > mpDimOrder
Definition: dpsave.hxx:257
bool GetRepeatIfEmpty() const
Definition: dpsave.hxx:335
sal_uInt16 nIgnoreEmptyMode
Definition: dpsave.hxx:246
SC_DLLPUBLIC const std::optional< OUString > & GetGrandTotalName() const
Definition: dpsave.cxx:774
bool bFilterButton
Definition: dpsave.hxx:248
bool GetRowGrand() const
Definition: dpsave.hxx:327
void CheckDuplicateName(ScDPSaveDimension &rDim)
Definition: dpsave.cxx:1338
SC_DLLPUBLIC void SetRepeatIfEmpty(bool bSet)
Definition: dpsave.cxx:1002
DupNameCountType maDupNameCounts
Definition: dpsave.hxx:242
SC_DLLPUBLIC void SetFilterButton(bool bSet)
Definition: dpsave.cxx:1007
void RemoveDimensionByName(const OUString &rName)
Definition: dpsave.cxx:902
bool GetColumnGrand() const
Definition: dpsave.hxx:323
bool GetExpandCollapse() const
Definition: dpsave.hxx:347
SC_DLLPUBLIC void SetGrandTotalName(const OUString &rName)
Definition: dpsave.cxx:769
SC_DLLPUBLIC ScDPSaveDimension * GetDataLayoutDimension()
Definition: dpsave.cxx:870
std::optional< OUString > mpGrandTotalName
Definition: dpsave.hxx:256
ScDPSaveDimension * AppendNewDimension(const OUString &rName, bool bDataLayout)
Append a new original dimension.
Definition: dpsave.cxx:1371
std::vector< std::unique_ptr< ScDPSaveDimension > > DimsType
Definition: dpsave.hxx:238
void AddDimension(ScDPSaveDimension *pDim)
Definition: dpsave.cxx:827
SC_DLLPUBLIC void SetRowGrand(bool bSet)
Definition: dpsave.cxx:992
SC_DLLPUBLIC void SetColumnGrand(bool bSet)
Definition: dpsave.cxx:987
SC_DLLPUBLIC ScDPSaveDimension * GetExistingDataLayoutDimension() const
Definition: dpsave.cxx:879
void SyncAllDimensionMembers(ScDPTableData *pData)
Definition: dpsave.cxx:1265
DimsType m_DimList
Definition: dpsave.hxx:241
const DimsType & GetDimensions() const
Definition: dpsave.hxx:271
const ScDPDimensionSaveData * GetExistingDimensionData() const
Definition: dpsave.hxx:353
std::unordered_map< OUString, size_t > DupNameCountType
Definition: dpsave.hxx:235
SC_DLLPUBLIC ScDPDimensionSaveData * GetDimensionData()
Definition: dpsave.cxx:1204
SC_DLLPUBLIC void SetDimensionData(const ScDPDimensionSaveData *pNew)
Definition: dpsave.cxx:1211
SC_DLLPUBLIC tools::Long GetDataDimensionCount() const
Definition: dpsave.cxx:946
void BuildAllDimensionMembers(ScDPTableData *pData)
Definition: dpsave.cxx:1219
SC_DLLPUBLIC ScDPSaveDimension * GetDimensionByName(const OUString &rName)
Get a dimension object by its name.
Definition: dpsave.cxx:838
sal_uInt16 nColumnGrandMode
Definition: dpsave.hxx:244
SC_DLLPUBLIC void SetDrillDown(bool bSet)
Definition: dpsave.cxx:1012
bool mbDimensionMembersBuilt
if true, all dimensions already have all of their member instances created.
Definition: dpsave.hxx:254
std::unique_ptr< ScDPDimensionSaveData > pDimensionData
keep track of number of duplicates in each name.
Definition: dpsave.hxx:243
sal_uInt16 nRepeatEmptyMode
Definition: dpsave.hxx:247
SC_DLLPUBLIC ~ScDPSaveData()
Definition: dpsave.cxx:765
SC_DLLPUBLIC ScDPSaveData()
Definition: dpsave.cxx:692
tools::Long nUsedHierarchy
Definition: dpsave.hxx:103
std::optional< OUString > mpSubtotalName
Definition: dpsave.hxx:98
const css::sheet::DataPilotFieldSortInfo * GetSortInfo() const
Definition: dpsave.hxx:186
bool bSubTotalDefault
at level
Definition: dpsave.hxx:106
sal_uInt16 nShowEmptyMode
Definition: dpsave.hxx:104
std::unique_ptr< css::sheet::DataPilotFieldLayoutInfo > pLayoutInfo
Definition: dpsave.hxx:111
tools::Long GetUsedHierarchy() const
Definition: dpsave.hxx:169
OUString aName
Definition: dpsave.hxx:96
std::vector< ScGeneralFunction > maSubTotalFuncs
at level
Definition: dpsave.hxx:107
std::unordered_set< OUString > MemberSetType
Definition: dpsave.hxx:114
bool bIsDataLayout
Definition: dpsave.hxx:99
bool bRepeatItemLabels
at level
Definition: dpsave.hxx:105
ScGeneralFunction GetSubTotalFunc(tools::Long nIndex) const
Definition: dpsave.hxx:152
std::unique_ptr< css::sheet::DataPilotFieldAutoShowInfo > pAutoShowInfo
Definition: dpsave.hxx:110
ScGeneralFunction nFunction
Definition: dpsave.hxx:102
void SetDupFlag(bool bSet)
Definition: dpsave.hxx:133
css::sheet::DataPilotFieldOrientation GetOrientation() const
Definition: dpsave.hxx:202
bool GetDupFlag() const
Definition: dpsave.hxx:136
MemberList maMemberList
Definition: dpsave.hxx:119
std::unique_ptr< css::sheet::DataPilotFieldSortInfo > pSortInfo
Definition: dpsave.hxx:109
std::unordered_map< OUString, std::unique_ptr< ScDPSaveMember > > maMemberHash
Definition: dpsave.hxx:118
const css::sheet::DataPilotFieldLayoutInfo * GetLayoutInfo() const
Definition: dpsave.hxx:194
const css::sheet::DataPilotFieldAutoShowInfo * GetAutoShowInfo() const
Definition: dpsave.hxx:190
std::unique_ptr< css::sheet::DataPilotFieldReference > pReferenceValue
Definition: dpsave.hxx:108
css::sheet::DataPilotFieldOrientation nOrientation
Definition: dpsave.hxx:101
std::optional< OUString > mpLayoutName
Definition: dpsave.hxx:97
ScGeneralFunction GetFunction() const
Definition: dpsave.hxx:165
tools::Long GetSubTotalsCount() const
Definition: dpsave.hxx:149
const css::sheet::DataPilotFieldReference * GetReferenceValue() const
Definition: dpsave.hxx:181
const MemberList & GetMembers() const
Definition: dpsave.hxx:128
void Dump(int nIndent=0) const
std::vector< ScDPSaveMember * > MemberList
Definition: dpsave.hxx:115
bool GetRepeatItemLabels() const
Definition: dpsave.hxx:161
bool IsDataLayout() const
Definition: dpsave.hxx:142
const OUString & GetName() const
Definition: dpsave.hxx:139
bool GetShowEmpty() const
Definition: dpsave.hxx:157
void SetName(const OUString &rNew)
Definition: dpsave.cxx:112
OUString aName
Definition: dpsave.hxx:54
SC_DLLPUBLIC void SetIsVisible(bool bSet)
Definition: dpsave.cxx:97
const OUString & GetName() const
Definition: dpsave.hxx:66
sal_uInt16 nVisibleMode
Definition: dpsave.hxx:56
std::optional< OUString > mpLayoutName
Definition: dpsave.hxx:55
void WriteToSource(const css::uno::Reference< css::uno::XInterface > &xMember, sal_Int32 nPosition)
Definition: dpsave.cxx:135
SC_DLLPUBLIC bool HasShowDetails() const
Definition: dpsave.cxx:102
bool GetShowDetails() const
Definition: dpsave.hxx:76
SC_DLLPUBLIC bool HasIsVisible() const
Definition: dpsave.cxx:92
bool GetIsVisible() const
Definition: dpsave.hxx:71
void Dump(int nIndent=0) const
SC_DLLPUBLIC void SetLayoutName(const OUString &rName)
Definition: dpsave.cxx:120
void RemoveLayoutName()
Definition: dpsave.cxx:130
ScDPSaveMember(OUString aName)
Definition: dpsave.cxx:66
bool operator==(const ScDPSaveMember &r) const
Definition: dpsave.cxx:85
sal_uInt16 nShowDetailsMode
Definition: dpsave.hxx:57
SC_DLLPUBLIC const std::optional< OUString > & GetLayoutName() const
Definition: dpsave.cxx:125
SC_DLLPUBLIC void SetShowDetails(bool bSet)
Definition: dpsave.cxx:107
Base class that abstracts different data source types of a datapilot table.
Definition: dptabdat.hxx:57
ScGeneralFunction
the css::sheet::GeneralFunction enum is extended by constants in GeneralFunction2,...
sal_Int32 nIndex
OUString aName
long Long
#define SC_DLLPUBLIC
Definition: scdllapi.h:27
bool operator==(const XclFontData &rLeft, const XclFontData &rRight)
Definition: xlstyle.cxx:518