Branch libreoffice-24-8-3
[LibreOffice.git] / sc / inc / dpdimsave.hxx
blob0a7903ed9178b0ea35f6c40c5248436126141ad8
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 #pragma once
22 #include <tools/long.hxx>
24 #include <vector>
25 #include <map>
26 #include <string_view>
28 #include "dpitemdata.hxx"
29 #include "dpnumgroupinfo.hxx"
30 #include "scdllapi.h"
31 #include "dptypes.hxx"
33 class ScDPGroupTableData;
34 class ScDPGroupDimension;
35 class ScDPObject;
36 class ScDPCache;
37 class SvNumberFormatter;
39 class ScDPSaveGroupDimension;
41 /**
42 * Classes to save Data Pilot settings that create new dimensions (fields).
43 * These have to be applied before the other ScDPSaveData settings.
46 class SAL_DLLPUBLIC_RTTI ScDPSaveGroupItem
48 OUString aGroupName; ///< name of group
49 std::vector<OUString> aElements; ///< names of items in original dimension
50 mutable std::vector<ScDPItemData> maItems; ///< items converted from the strings.
52 public:
53 SC_DLLPUBLIC ScDPSaveGroupItem( OUString aName );
54 SC_DLLPUBLIC ~ScDPSaveGroupItem();
56 ScDPSaveGroupItem(ScDPSaveGroupItem const &) = default;
57 ScDPSaveGroupItem(ScDPSaveGroupItem &&) = default;
58 ScDPSaveGroupItem & operator =(ScDPSaveGroupItem const &) = default;
59 ScDPSaveGroupItem & operator =(ScDPSaveGroupItem &&) = default;
61 void AddToData(ScDPGroupDimension& rDataDim) const;
63 SC_DLLPUBLIC void AddElement( const OUString& rName );
64 void AddElementsFromGroup( const ScDPSaveGroupItem& rGroup );
65 const OUString& GetGroupName() const { return aGroupName; }
67 /// @return true if found (removed)
68 bool RemoveElement( const OUString& rName );
70 SC_DLLPUBLIC bool IsEmpty() const;
71 SC_DLLPUBLIC size_t GetElementCount() const;
72 SC_DLLPUBLIC const OUString* GetElementByIndex(size_t nIndex) const;
74 void Rename( const OUString& rNewName );
76 /** remove this group's elements from their groups in rDimension
77 (rDimension must be a different dimension from the one which contains this)*/
78 void RemoveElementsFromGroups( ScDPSaveGroupDimension& rDimension ) const;
80 void ConvertElementsToItems(SvNumberFormatter* pFormatter) const;
81 bool HasInGroup(const ScDPItemData& rItem) const;
84 typedef ::std::vector<ScDPSaveGroupItem> ScDPSaveGroupItemVec;
86 /**
87 * Represents a new group dimension whose dimension ID is higher than the
88 * highest source dimension ID.
90 class ScDPSaveGroupDimension
92 OUString aSourceDim; ///< always the real source from the original data
93 OUString aGroupDimName;
94 ScDPSaveGroupItemVec aGroups;
95 mutable ScDPNumGroupInfo aDateInfo;
96 sal_Int32 nDatePart;
98 public:
99 SC_DLLPUBLIC ScDPSaveGroupDimension( OUString aSource, OUString aName );
100 ScDPSaveGroupDimension( OUString aSource, OUString aName, const ScDPNumGroupInfo& rDateInfo, sal_Int32 nPart );
102 void AddToData( ScDPGroupTableData& rData ) const;
103 void AddToCache(ScDPCache& rCache) const;
104 SC_DLLPUBLIC void SetDateInfo( const ScDPNumGroupInfo& rInfo, sal_Int32 nPart );
106 SC_DLLPUBLIC void AddGroupItem( const ScDPSaveGroupItem& rItem );
107 const OUString& GetGroupDimName() const { return aGroupDimName; }
108 const OUString& GetSourceDimName() const { return aSourceDim; }
110 sal_Int32 GetDatePart() const { return nDatePart; }
111 const ScDPNumGroupInfo& GetDateInfo() const { return aDateInfo; }
113 OUString CreateGroupName( std::u16string_view rPrefix );
114 const ScDPSaveGroupItem* GetNamedGroup( const OUString& rGroupName ) const;
115 ScDPSaveGroupItem* GetNamedGroupAcc( const OUString& rGroupName );
116 void RemoveFromGroups( const OUString& rItemName );
117 void RemoveGroup(const OUString& rGroupName);
118 bool IsEmpty() const;
119 bool HasOnlyHidden(const ScDPUniqueStringSet& rVisible);
121 SC_DLLPUBLIC tools::Long GetGroupCount() const;
122 SC_DLLPUBLIC const ScDPSaveGroupItem& GetGroupByIndex( tools::Long nIndex ) const;
124 void Rename( const OUString& rNewName );
126 private:
127 bool IsInGroup(const ScDPItemData& rItem) const;
131 * Represents a group dimension that introduces a new hierarchy for an
132 * existing dimension. Unlike the ScDPSaveGroupDimension counterpart, it
133 * re-uses the source dimension name and ID.
135 class SC_DLLPUBLIC ScDPSaveNumGroupDimension
137 OUString aDimensionName;
138 mutable ScDPNumGroupInfo aGroupInfo;
139 mutable ScDPNumGroupInfo aDateInfo;
140 sal_Int32 nDatePart;
142 public:
143 ScDPSaveNumGroupDimension( OUString aName, const ScDPNumGroupInfo& rInfo );
144 ScDPSaveNumGroupDimension( OUString aName, const ScDPNumGroupInfo& rDateInfo, sal_Int32 nPart );
146 void AddToData( ScDPGroupTableData& rData ) const;
147 void AddToCache(ScDPCache& rCache) const;
149 const OUString& GetDimensionName() const { return aDimensionName; }
150 const ScDPNumGroupInfo& GetInfo() const { return aGroupInfo; }
152 sal_Int32 GetDatePart() const { return nDatePart; }
153 const ScDPNumGroupInfo& GetDateInfo() const { return aDateInfo; }
155 void SetGroupInfo( const ScDPNumGroupInfo& rNew );
156 void SetDateInfo( const ScDPNumGroupInfo& rInfo, sal_Int32 nPart );
160 * This class has to do with handling exclusively grouped dimensions? TODO:
161 * Find out what this class does and document it here.
163 class ScDPDimensionSaveData
165 public:
166 ScDPDimensionSaveData();
167 ScDPDimensionSaveData(ScDPDimensionSaveData const &) = default;
169 bool operator==( const ScDPDimensionSaveData& r ) const;
171 void WriteToData( ScDPGroupTableData& rData ) const;
173 void WriteToCache(ScDPCache& rCache) const;
175 OUString CreateGroupDimName(
176 const OUString& rSourceName, const ScDPObject& rObject, bool bAllowSource,
177 const ::std::vector<OUString>* pDeletedNames );
179 OUString CreateDateGroupDimName(
180 sal_Int32 nDatePart, const ScDPObject& rObject, bool bAllowSource,
181 const ::std::vector<OUString>* pDeletedNames );
183 SC_DLLPUBLIC void AddGroupDimension( const ScDPSaveGroupDimension& rGroupDim );
184 void ReplaceGroupDimension( const ScDPSaveGroupDimension& rGroupDim );
185 void RemoveGroupDimension( const OUString& rGroupDimName );
187 SC_DLLPUBLIC void AddNumGroupDimension( const ScDPSaveNumGroupDimension& rGroupDim );
188 void ReplaceNumGroupDimension( const ScDPSaveNumGroupDimension& rGroupDim );
189 void RemoveNumGroupDimension( const OUString& rGroupDimName );
191 SC_DLLPUBLIC const ScDPSaveGroupDimension* GetGroupDimForBase( const OUString& rBaseDimName ) const;
192 SC_DLLPUBLIC const ScDPSaveGroupDimension* GetNamedGroupDim( const OUString& rGroupDimName ) const;
193 const ScDPSaveGroupDimension* GetFirstNamedGroupDim( const OUString& rBaseDimName ) const;
194 const ScDPSaveGroupDimension* GetNextNamedGroupDim( const OUString& rGroupDimName ) const;
195 SC_DLLPUBLIC const ScDPSaveNumGroupDimension* GetNumGroupDim( const OUString& rGroupDimName ) const;
197 ScDPSaveGroupDimension* GetGroupDimAccForBase( const OUString& rBaseDimName );
198 ScDPSaveGroupDimension* GetNamedGroupDimAcc( const OUString& rGroupDimName );
199 ScDPSaveGroupDimension* GetFirstNamedGroupDimAcc( const OUString& rBaseDimName );
200 ScDPSaveGroupDimension* GetNextNamedGroupDimAcc( const OUString& rGroupDimName );
202 ScDPSaveNumGroupDimension* GetNumGroupDimAcc( const OUString& rGroupDimName );
204 SC_DLLPUBLIC bool HasGroupDimensions() const;
206 sal_Int32 CollectDateParts( const OUString& rBaseDimName ) const;
208 private:
209 typedef ::std::vector< ScDPSaveGroupDimension > ScDPSaveGroupDimVec;
210 typedef ::std::map<OUString, ScDPSaveNumGroupDimension> ScDPSaveNumGroupDimMap;
212 ScDPDimensionSaveData& operator=( const ScDPDimensionSaveData& ) = delete;
214 ScDPSaveGroupDimVec maGroupDims;
215 ScDPSaveNumGroupDimMap maNumGroupDims;
218 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */