1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef SC_DPDIMSAVE_HXX 25 #define SC_DPDIMSAVE_HXX 26 27 #include <vector> 28 #include <map> 29 #include <tools/string.hxx> 30 #include "dpgroup.hxx" // for ScDPNumGroupInfo 31 #include "scdllapi.h" 32 33 class ScDPGroupTableData; 34 class ScDPGroupDimension; 35 class ScDPObject; 36 class ScStrCollection; 37 class SvNumberFormatter; 38 39 class ScDPSaveGroupDimension; 40 41 // -------------------------------------------------------------------- 42 // 43 // Classes to save Data Pilot settings that create new dimensions (fields). 44 // These have to be applied before the other ScDPSaveData settings. 45 // 46 47 // ============================================================================ 48 49 class SC_DLLPUBLIC ScDPSaveGroupItem 50 { 51 String aGroupName; // name of group 52 ::std::vector<String> aElements; // names of items in original dimension 53 54 public: 55 ScDPSaveGroupItem( const String& rName ); 56 ~ScDPSaveGroupItem(); 57 58 void AddToData( ScDPGroupDimension& rDataDim, SvNumberFormatter* pFormatter ) const; 59 60 void AddElement( const String& rName ); 61 void AddElementsFromGroup( const ScDPSaveGroupItem& rGroup ); GetGroupName() const62 const String& GetGroupName() const { return aGroupName; } 63 bool RemoveElement( const String& rName ); // returns true if found (removed) 64 65 bool IsEmpty() const; 66 size_t GetElementCount() const; 67 const String* GetElementByIndex( size_t nIndex ) const; 68 69 void Rename( const String& rNewName ); 70 71 // remove this group's elements from their groups in rDimension 72 // (rDimension must be a different dimension from the one which contains this) 73 void RemoveElementsFromGroups( ScDPSaveGroupDimension& rDimension ) const; 74 }; 75 76 typedef ::std::vector<ScDPSaveGroupItem> ScDPSaveGroupItemVec; 77 78 // ============================================================================ 79 80 class SC_DLLPUBLIC ScDPSaveGroupDimension 81 { 82 String aSourceDim; // always the real source from the original data 83 String aGroupDimName; 84 ScDPSaveGroupItemVec aGroups; 85 ScDPNumGroupInfo aDateInfo; 86 sal_Int32 nDatePart; 87 88 public: 89 ScDPSaveGroupDimension( const String& rSource, const String& rName ); 90 ScDPSaveGroupDimension( const String& rSource, const String& rName, const ScDPNumGroupInfo& rDateInfo, sal_Int32 nPart ); 91 ~ScDPSaveGroupDimension(); 92 93 void AddToData( ScDPGroupTableData& rData ) const; 94 95 void SetDateInfo( const ScDPNumGroupInfo& rInfo, sal_Int32 nPart ); 96 97 void AddGroupItem( const ScDPSaveGroupItem& rItem ); GetGroupDimName() const98 const String& GetGroupDimName() const { return aGroupDimName; } GetSourceDimName() const99 const String& GetSourceDimName() const { return aSourceDim; } 100 GetDatePart() const101 sal_Int32 GetDatePart() const { return nDatePart; } GetDateInfo() const102 const ScDPNumGroupInfo& GetDateInfo() const { return aDateInfo; } 103 104 String CreateGroupName( const String& rPrefix ); 105 const ScDPSaveGroupItem* GetNamedGroup( const String& rGroupName ) const; 106 ScDPSaveGroupItem* GetNamedGroupAcc( const String& rGroupName ); 107 void RemoveFromGroups( const String& rItemName ); 108 void RemoveGroup( const String& rGroupName ); 109 bool IsEmpty() const; 110 bool HasOnlyHidden( const ScStrCollection& rVisible ); 111 112 long GetGroupCount() const; 113 const ScDPSaveGroupItem* GetGroupByIndex( long nIndex ) const; 114 ScDPSaveGroupItem* GetGroupAccByIndex( long nIndex ); 115 116 void Rename( const String& rNewName ); 117 }; 118 119 // ============================================================================ 120 121 class SC_DLLPUBLIC ScDPSaveNumGroupDimension 122 { 123 String aDimensionName; 124 ScDPNumGroupInfo aGroupInfo; 125 ScDPNumGroupInfo aDateInfo; 126 sal_Int32 nDatePart; 127 128 public: 129 ScDPSaveNumGroupDimension( const String& rName, const ScDPNumGroupInfo& rInfo ); 130 ScDPSaveNumGroupDimension( const String& rName, const ScDPNumGroupInfo& rDateInfo, sal_Int32 nPart ); 131 ~ScDPSaveNumGroupDimension(); 132 133 void AddToData( ScDPGroupTableData& rData ) const; 134 GetDimensionName() const135 const String& GetDimensionName() const { return aDimensionName; } GetInfo() const136 const ScDPNumGroupInfo& GetInfo() const { return aGroupInfo; } 137 GetDatePart() const138 sal_Int32 GetDatePart() const { return nDatePart; } GetDateInfo() const139 const ScDPNumGroupInfo& GetDateInfo() const { return aDateInfo; } 140 141 void SetGroupInfo( const ScDPNumGroupInfo& rNew ); 142 void SetDateInfo( const ScDPNumGroupInfo& rInfo, sal_Int32 nPart ); 143 }; 144 145 // ============================================================================ 146 147 class SC_DLLPUBLIC ScDPDimensionSaveData 148 { 149 public: 150 ScDPDimensionSaveData(); 151 ~ScDPDimensionSaveData(); 152 153 bool operator==( const ScDPDimensionSaveData& r ) const; 154 155 void WriteToData( ScDPGroupTableData& rData ) const; 156 157 String CreateGroupDimName( const String& rSourceName, const ScDPObject& rObject, bool bAllowSource, const ::std::vector< String >* pDeletedNames ); 158 String CreateDateGroupDimName( sal_Int32 nDatePart, const ScDPObject& rObject, bool bAllowSource, const ::std::vector< String >* pDeletedNames ); 159 160 void AddGroupDimension( const ScDPSaveGroupDimension& rGroupDim ); 161 void ReplaceGroupDimension( const ScDPSaveGroupDimension& rGroupDim ); 162 void RemoveGroupDimension( const String& rGroupDimName ); 163 164 void AddNumGroupDimension( const ScDPSaveNumGroupDimension& rGroupDim ); 165 void ReplaceNumGroupDimension( const ScDPSaveNumGroupDimension& rGroupDim ); 166 void RemoveNumGroupDimension( const String& rGroupDimName ); 167 168 const ScDPSaveGroupDimension* GetGroupDimForBase( const String& rBaseDimName ) const; 169 const ScDPSaveGroupDimension* GetNamedGroupDim( const String& rGroupDimName ) const; 170 const ScDPSaveGroupDimension* GetFirstNamedGroupDim( const String& rBaseDimName ) const; 171 const ScDPSaveGroupDimension* GetNextNamedGroupDim( const String& rGroupDimName ) const; 172 const ScDPSaveNumGroupDimension* GetNumGroupDim( const String& rGroupDimName ) const; 173 174 ScDPSaveGroupDimension* GetGroupDimAccForBase( const String& rBaseDimName ); 175 ScDPSaveGroupDimension* GetNamedGroupDimAcc( const String& rGroupDimName ); 176 ScDPSaveGroupDimension* GetFirstNamedGroupDimAcc( const String& rBaseDimName ); 177 ScDPSaveGroupDimension* GetNextNamedGroupDimAcc( const String& rGroupDimName ); 178 179 ScDPSaveNumGroupDimension* GetNumGroupDimAcc( const String& rGroupDimName ); 180 181 bool HasGroupDimensions() const; 182 183 sal_Int32 CollectDateParts( const String& rBaseDimName ) const; 184 185 private: 186 typedef ::std::vector< ScDPSaveGroupDimension > ScDPSaveGroupDimVec; 187 typedef ::std::map< String, ScDPSaveNumGroupDimension > ScDPSaveNumGroupDimMap; 188 189 ScDPDimensionSaveData& operator=( const ScDPDimensionSaveData& ); 190 191 ScDPSaveGroupDimVec maGroupDims; 192 ScDPSaveNumGroupDimMap maNumGroupDims; 193 }; 194 195 // ============================================================================ 196 197 #endif 198 199