/src/libreoffice/sc/inc/dpdimsave.hxx
Line | Count | Source |
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 <tools/long.hxx> |
23 | | |
24 | | #include <vector> |
25 | | #include <map> |
26 | | #include <string_view> |
27 | | |
28 | | #include "dpitemdata.hxx" |
29 | | #include "dpnumgroupinfo.hxx" |
30 | | #include "dpcache.hxx" |
31 | | #include "scdllapi.h" |
32 | | #include "dptypes.hxx" |
33 | | |
34 | | class ScDPGroupTableData; |
35 | | class ScDPGroupDimension; |
36 | | class ScDPObject; |
37 | | class ScDPCache; |
38 | | class SvNumberFormatter; |
39 | | class ScTokenArray; |
40 | | |
41 | | class ScDPSaveGroupDimension; |
42 | | |
43 | | /** |
44 | | * Classes to save Data Pilot settings that create new dimensions (fields). |
45 | | * These have to be applied before the other ScDPSaveData settings. |
46 | | */ |
47 | | |
48 | | class SAL_DLLPUBLIC_RTTI ScDPSaveGroupItem |
49 | | { |
50 | | OUString aGroupName; ///< name of group |
51 | | std::vector<OUString> aElements; ///< names of items in original dimension |
52 | | mutable std::vector<ScDPItemData> maItems; ///< items converted from the strings. |
53 | | |
54 | | public: |
55 | | SC_DLLPUBLIC ScDPSaveGroupItem( OUString aName ); |
56 | | SC_DLLPUBLIC ~ScDPSaveGroupItem(); |
57 | | |
58 | 106 | ScDPSaveGroupItem(ScDPSaveGroupItem const &) = default; |
59 | 16 | ScDPSaveGroupItem(ScDPSaveGroupItem &&) = default; |
60 | 26 | ScDPSaveGroupItem & operator =(ScDPSaveGroupItem const &) = default; |
61 | 0 | ScDPSaveGroupItem & operator =(ScDPSaveGroupItem &&) = default; |
62 | | |
63 | | void AddToData(ScDPGroupDimension& rDataDim) const; |
64 | | |
65 | | SC_DLLPUBLIC void AddElement( const OUString& rName ); |
66 | | void AddElementsFromGroup( const ScDPSaveGroupItem& rGroup ); |
67 | 52 | const OUString& GetGroupName() const { return aGroupName; } |
68 | | |
69 | | /// @return true if found (removed) |
70 | | bool RemoveElement( const OUString& rName ); |
71 | | |
72 | | SC_DLLPUBLIC bool IsEmpty() const; |
73 | | SC_DLLPUBLIC size_t GetElementCount() const; |
74 | | SC_DLLPUBLIC const OUString* GetElementByIndex(size_t nIndex) const; |
75 | | |
76 | | void Rename( const OUString& rNewName ); |
77 | | |
78 | | /** remove this group's elements from their groups in rDimension |
79 | | (rDimension must be a different dimension from the one which contains this)*/ |
80 | | void RemoveElementsFromGroups( ScDPSaveGroupDimension& rDimension ) const; |
81 | | |
82 | | void ConvertElementsToItems(SvNumberFormatter* pFormatter) const; |
83 | | bool HasInGroup(const ScDPItemData& rItem) const; |
84 | | }; |
85 | | |
86 | | typedef ::std::vector<ScDPSaveGroupItem> ScDPSaveGroupItemVec; |
87 | | |
88 | | /** |
89 | | * Represents a new group dimension whose dimension ID is higher than the |
90 | | * highest source dimension ID. |
91 | | */ |
92 | | class ScDPSaveGroupDimension |
93 | | { |
94 | | OUString aSourceDim; ///< always the real source from the original data |
95 | | OUString aGroupDimName; |
96 | | ScDPSaveGroupItemVec aGroups; |
97 | | mutable ScDPNumGroupInfo aDateInfo; |
98 | | sal_Int32 nDatePart; |
99 | | |
100 | | public: |
101 | | SC_DLLPUBLIC ScDPSaveGroupDimension( OUString aSource, OUString aName ); |
102 | | ScDPSaveGroupDimension( OUString aSource, OUString aName, const ScDPNumGroupInfo& rDateInfo, sal_Int32 nPart ); |
103 | | |
104 | | void AddToData( ScDPGroupTableData& rData ) const; |
105 | | void AddToCache(ScDPCache& rCache) const; |
106 | | SC_DLLPUBLIC void SetDateInfo( const ScDPNumGroupInfo& rInfo, sal_Int32 nPart ); |
107 | | |
108 | | SC_DLLPUBLIC void AddGroupItem( const ScDPSaveGroupItem& rItem ); |
109 | 90 | const OUString& GetGroupDimName() const { return aGroupDimName; } |
110 | 26 | const OUString& GetSourceDimName() const { return aSourceDim; } |
111 | | |
112 | 36 | sal_Int32 GetDatePart() const { return nDatePart; } |
113 | 18 | const ScDPNumGroupInfo& GetDateInfo() const { return aDateInfo; } |
114 | | |
115 | | OUString CreateGroupName( std::u16string_view rPrefix ); |
116 | | const ScDPSaveGroupItem* GetNamedGroup( const OUString& rGroupName ) const; |
117 | | ScDPSaveGroupItem* GetNamedGroupAcc( const OUString& rGroupName ); |
118 | | void RemoveFromGroups( const OUString& rItemName ); |
119 | | void RemoveGroup(const OUString& rGroupName); |
120 | | bool IsEmpty() const; |
121 | | bool HasOnlyHidden(const ScDPUniqueStringSet& rVisible); |
122 | | |
123 | | SC_DLLPUBLIC tools::Long GetGroupCount() const; |
124 | | SC_DLLPUBLIC const ScDPSaveGroupItem& GetGroupByIndex( tools::Long nIndex ) const; |
125 | | |
126 | | void Rename( const OUString& rNewName ); |
127 | | |
128 | | private: |
129 | | bool IsInGroup(const ScDPItemData& rItem) const; |
130 | | }; |
131 | | |
132 | | /** |
133 | | * Represents a group dimension that introduces a new hierarchy for an |
134 | | * existing dimension. Unlike the ScDPSaveGroupDimension counterpart, it |
135 | | * re-uses the source dimension name and ID. |
136 | | */ |
137 | | class SC_DLLPUBLIC ScDPSaveNumGroupDimension |
138 | | { |
139 | | OUString aDimensionName; |
140 | | mutable ScDPNumGroupInfo aGroupInfo; |
141 | | mutable ScDPNumGroupInfo aDateInfo; |
142 | | sal_Int32 nDatePart; |
143 | | |
144 | | public: |
145 | | ScDPSaveNumGroupDimension( OUString aName, const ScDPNumGroupInfo& rInfo ); |
146 | | ScDPSaveNumGroupDimension( OUString aName, const ScDPNumGroupInfo& rDateInfo, sal_Int32 nPart ); |
147 | | |
148 | | void AddToData( ScDPGroupTableData& rData ) const; |
149 | | void AddToCache(ScDPCache& rCache) const; |
150 | | |
151 | 0 | const OUString& GetDimensionName() const { return aDimensionName; } |
152 | 0 | const ScDPNumGroupInfo& GetInfo() const { return aGroupInfo; } |
153 | | |
154 | 0 | sal_Int32 GetDatePart() const { return nDatePart; } |
155 | 0 | const ScDPNumGroupInfo& GetDateInfo() const { return aDateInfo; } |
156 | | |
157 | | void SetGroupInfo( const ScDPNumGroupInfo& rNew ); |
158 | | void SetDateInfo( const ScDPNumGroupInfo& rInfo, sal_Int32 nPart ); |
159 | | }; |
160 | | |
161 | | /** |
162 | | * This class has to do with handling exclusively grouped dimensions? TODO: |
163 | | * Find out what this class does and document it here. |
164 | | */ |
165 | | class ScDPDimensionSaveData |
166 | | { |
167 | | public: |
168 | | ScDPDimensionSaveData(); |
169 | 36 | ScDPDimensionSaveData(ScDPDimensionSaveData const &) = default; |
170 | | |
171 | | bool operator==( const ScDPDimensionSaveData& r ) const; |
172 | | |
173 | | void WriteToData( ScDPGroupTableData& rData ) const; |
174 | | |
175 | | void WriteToCache(ScDPCache& rCache) const; |
176 | | |
177 | | OUString CreateGroupDimName( |
178 | | const OUString& rSourceName, const ScDPObject& rObject, bool bAllowSource, |
179 | | const ::std::vector<OUString>* pDeletedNames ); |
180 | | |
181 | | OUString CreateDateGroupDimName( |
182 | | sal_Int32 nDatePart, const ScDPObject& rObject, bool bAllowSource, |
183 | | const ::std::vector<OUString>* pDeletedNames ); |
184 | | |
185 | | SC_DLLPUBLIC void AddGroupDimension( const ScDPSaveGroupDimension& rGroupDim ); |
186 | | void ReplaceGroupDimension( const ScDPSaveGroupDimension& rGroupDim ); |
187 | | void RemoveGroupDimension( const OUString& rGroupDimName ); |
188 | | |
189 | | SC_DLLPUBLIC void AddNumGroupDimension( const ScDPSaveNumGroupDimension& rGroupDim ); |
190 | | void ReplaceNumGroupDimension( const ScDPSaveNumGroupDimension& rGroupDim ); |
191 | | void RemoveNumGroupDimension( const OUString& rGroupDimName ); |
192 | | |
193 | | SC_DLLPUBLIC const ScDPSaveGroupDimension* GetGroupDimForBase( const OUString& rBaseDimName ) const; |
194 | | SC_DLLPUBLIC const ScDPSaveGroupDimension* GetNamedGroupDim( const OUString& rGroupDimName ) const; |
195 | | const ScDPSaveGroupDimension* GetFirstNamedGroupDim( const OUString& rBaseDimName ) const; |
196 | | const ScDPSaveGroupDimension* GetNextNamedGroupDim( const OUString& rGroupDimName ) const; |
197 | | SC_DLLPUBLIC const ScDPSaveNumGroupDimension* GetNumGroupDim( const OUString& rGroupDimName ) const; |
198 | | |
199 | | ScDPSaveGroupDimension* GetGroupDimAccForBase( const OUString& rBaseDimName ); |
200 | | ScDPSaveGroupDimension* GetNamedGroupDimAcc( const OUString& rGroupDimName ); |
201 | | ScDPSaveGroupDimension* GetFirstNamedGroupDimAcc( const OUString& rBaseDimName ); |
202 | | ScDPSaveGroupDimension* GetNextNamedGroupDimAcc( const OUString& rGroupDimName ); |
203 | | |
204 | | ScDPSaveNumGroupDimension* GetNumGroupDimAcc( const OUString& rGroupDimName ); |
205 | | |
206 | | SC_DLLPUBLIC bool HasGroupDimensions() const; |
207 | | |
208 | | sal_Int32 CollectDateParts( const OUString& rBaseDimName ) const; |
209 | | |
210 | | private: |
211 | | typedef ::std::vector< ScDPSaveGroupDimension > ScDPSaveGroupDimVec; |
212 | | typedef ::std::map<OUString, ScDPSaveNumGroupDimension> ScDPSaveNumGroupDimMap; |
213 | | |
214 | | ScDPDimensionSaveData& operator=( const ScDPDimensionSaveData& ) = delete; |
215 | | |
216 | | ScDPSaveGroupDimVec maGroupDims; |
217 | | ScDPSaveNumGroupDimMap maNumGroupDims; |
218 | | }; |
219 | | |
220 | | /** |
221 | | * Stores calculated field data shared between ScDPCache and ScDPSaveData. |
222 | | * Uses shared_ptr<ScDPCache::CalculatedField> so that all references to the |
223 | | * same cache automatically see the same calculated field objects. |
224 | | */ |
225 | | class ScDPDimCalcSaveData |
226 | | { |
227 | | public: |
228 | | ScDPDimCalcSaveData(); |
229 | 0 | ScDPDimCalcSaveData(const ScDPDimCalcSaveData&) = default; |
230 | | |
231 | | bool operator==(const ScDPDimCalcSaveData& r) const; |
232 | | |
233 | | void WriteToCache(ScDPCache& rCache) const; |
234 | | |
235 | | SC_DLLPUBLIC void SetCalculatedField(const std::shared_ptr<ScDPCache::CalculatedField>& pField); |
236 | | void RemoveCalculatedField(const OUString& rFieldName); |
237 | | |
238 | | const std::vector<std::shared_ptr<ScDPCache::CalculatedField>>& GetCalculatedFields() const |
239 | 0 | { |
240 | 0 | return maCalculatedFields; |
241 | 0 | } |
242 | | |
243 | | private: |
244 | | ScDPDimCalcSaveData& operator=( const ScDPDimCalcSaveData& ) = delete; |
245 | | |
246 | | std::vector<std::shared_ptr<ScDPCache::CalculatedField>> maCalculatedFields; |
247 | | }; |
248 | | |
249 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |