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