1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef SC_DPDIMSAVE_HXX 29 #define SC_DPDIMSAVE_HXX 30 31 #include <vector> 32 #include <map> 33 #include <tools/string.hxx> 34 #include "dpgroup.hxx" // for ScDPNumGroupInfo 35 #include "scdllapi.h" 36 37 class ScDPGroupTableData; 38 class ScDPGroupDimension; 39 class ScDPObject; 40 class ScStrCollection; 41 class SvNumberFormatter; 42 43 class ScDPSaveGroupDimension; 44 45 // -------------------------------------------------------------------- 46 // 47 // Classes to save Data Pilot settings that create new dimensions (fields). 48 // These have to be applied before the other ScDPSaveData settings. 49 // 50 51 // ============================================================================ 52 53 class SC_DLLPUBLIC ScDPSaveGroupItem 54 { 55 String aGroupName; // name of group 56 ::std::vector<String> aElements; // names of items in original dimension 57 58 public: 59 ScDPSaveGroupItem( const String& rName ); 60 ~ScDPSaveGroupItem(); 61 62 void AddToData( ScDPGroupDimension& rDataDim, SvNumberFormatter* pFormatter ) const; 63 64 void AddElement( const String& rName ); 65 void AddElementsFromGroup( const ScDPSaveGroupItem& rGroup ); 66 const String& GetGroupName() const { return aGroupName; } 67 bool RemoveElement( const String& rName ); // returns true if found (removed) 68 69 bool IsEmpty() const; 70 size_t GetElementCount() const; 71 const String* GetElementByIndex( size_t nIndex ) const; 72 73 void Rename( const String& rNewName ); 74 75 // remove this group's elements from their groups in rDimension 76 // (rDimension must be a different dimension from the one which contains this) 77 void RemoveElementsFromGroups( ScDPSaveGroupDimension& rDimension ) const; 78 }; 79 80 typedef ::std::vector<ScDPSaveGroupItem> ScDPSaveGroupItemVec; 81 82 // ============================================================================ 83 84 class SC_DLLPUBLIC ScDPSaveGroupDimension 85 { 86 String aSourceDim; // always the real source from the original data 87 String aGroupDimName; 88 ScDPSaveGroupItemVec aGroups; 89 ScDPNumGroupInfo aDateInfo; 90 sal_Int32 nDatePart; 91 92 public: 93 ScDPSaveGroupDimension( const String& rSource, const String& rName ); 94 ScDPSaveGroupDimension( const String& rSource, const String& rName, const ScDPNumGroupInfo& rDateInfo, sal_Int32 nPart ); 95 ~ScDPSaveGroupDimension(); 96 97 void AddToData( ScDPGroupTableData& rData ) const; 98 99 void SetDateInfo( const ScDPNumGroupInfo& rInfo, sal_Int32 nPart ); 100 101 void AddGroupItem( const ScDPSaveGroupItem& rItem ); 102 const String& GetGroupDimName() const { return aGroupDimName; } 103 const String& GetSourceDimName() const { return aSourceDim; } 104 105 sal_Int32 GetDatePart() const { return nDatePart; } 106 const ScDPNumGroupInfo& GetDateInfo() const { return aDateInfo; } 107 108 String CreateGroupName( const String& rPrefix ); 109 const ScDPSaveGroupItem* GetNamedGroup( const String& rGroupName ) const; 110 ScDPSaveGroupItem* GetNamedGroupAcc( const String& rGroupName ); 111 void RemoveFromGroups( const String& rItemName ); 112 void RemoveGroup( const String& rGroupName ); 113 bool IsEmpty() const; 114 bool HasOnlyHidden( const ScStrCollection& rVisible ); 115 116 long GetGroupCount() const; 117 const ScDPSaveGroupItem* GetGroupByIndex( long nIndex ) const; 118 ScDPSaveGroupItem* GetGroupAccByIndex( long nIndex ); 119 120 void Rename( const String& rNewName ); 121 }; 122 123 // ============================================================================ 124 125 class SC_DLLPUBLIC ScDPSaveNumGroupDimension 126 { 127 String aDimensionName; 128 ScDPNumGroupInfo aGroupInfo; 129 ScDPNumGroupInfo aDateInfo; 130 sal_Int32 nDatePart; 131 132 public: 133 ScDPSaveNumGroupDimension( const String& rName, const ScDPNumGroupInfo& rInfo ); 134 ScDPSaveNumGroupDimension( const String& rName, const ScDPNumGroupInfo& rDateInfo, sal_Int32 nPart ); 135 ~ScDPSaveNumGroupDimension(); 136 137 void AddToData( ScDPGroupTableData& rData ) const; 138 139 const String& GetDimensionName() const { return aDimensionName; } 140 const ScDPNumGroupInfo& GetInfo() const { return aGroupInfo; } 141 142 sal_Int32 GetDatePart() const { return nDatePart; } 143 const ScDPNumGroupInfo& GetDateInfo() const { return aDateInfo; } 144 145 void SetGroupInfo( const ScDPNumGroupInfo& rNew ); 146 void SetDateInfo( const ScDPNumGroupInfo& rInfo, sal_Int32 nPart ); 147 }; 148 149 // ============================================================================ 150 151 class SC_DLLPUBLIC ScDPDimensionSaveData 152 { 153 public: 154 ScDPDimensionSaveData(); 155 ~ScDPDimensionSaveData(); 156 157 bool operator==( const ScDPDimensionSaveData& r ) const; 158 159 void WriteToData( ScDPGroupTableData& rData ) const; 160 161 String CreateGroupDimName( const String& rSourceName, const ScDPObject& rObject, bool bAllowSource, const ::std::vector< String >* pDeletedNames ); 162 String CreateDateGroupDimName( sal_Int32 nDatePart, const ScDPObject& rObject, bool bAllowSource, const ::std::vector< String >* pDeletedNames ); 163 164 void AddGroupDimension( const ScDPSaveGroupDimension& rGroupDim ); 165 void ReplaceGroupDimension( const ScDPSaveGroupDimension& rGroupDim ); 166 void RemoveGroupDimension( const String& rGroupDimName ); 167 168 void AddNumGroupDimension( const ScDPSaveNumGroupDimension& rGroupDim ); 169 void ReplaceNumGroupDimension( const ScDPSaveNumGroupDimension& rGroupDim ); 170 void RemoveNumGroupDimension( const String& rGroupDimName ); 171 172 const ScDPSaveGroupDimension* GetGroupDimForBase( const String& rBaseDimName ) const; 173 const ScDPSaveGroupDimension* GetNamedGroupDim( const String& rGroupDimName ) const; 174 const ScDPSaveGroupDimension* GetFirstNamedGroupDim( const String& rBaseDimName ) const; 175 const ScDPSaveGroupDimension* GetNextNamedGroupDim( const String& rGroupDimName ) const; 176 const ScDPSaveNumGroupDimension* GetNumGroupDim( const String& rGroupDimName ) const; 177 178 ScDPSaveGroupDimension* GetGroupDimAccForBase( const String& rBaseDimName ); 179 ScDPSaveGroupDimension* GetNamedGroupDimAcc( const String& rGroupDimName ); 180 ScDPSaveGroupDimension* GetFirstNamedGroupDimAcc( const String& rBaseDimName ); 181 ScDPSaveGroupDimension* GetNextNamedGroupDimAcc( const String& rGroupDimName ); 182 183 ScDPSaveNumGroupDimension* GetNumGroupDimAcc( const String& rGroupDimName ); 184 185 bool HasGroupDimensions() const; 186 187 sal_Int32 CollectDateParts( const String& rBaseDimName ) const; 188 189 private: 190 typedef ::std::vector< ScDPSaveGroupDimension > ScDPSaveGroupDimVec; 191 typedef ::std::map< String, ScDPSaveNumGroupDimension > ScDPSaveNumGroupDimMap; 192 193 ScDPDimensionSaveData& operator=( const ScDPDimensionSaveData& ); 194 195 ScDPSaveGroupDimVec maGroupDims; 196 ScDPSaveNumGroupDimMap maNumGroupDims; 197 }; 198 199 // ============================================================================ 200 201 #endif 202 203