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_DPGROUP_HXX 29 #define SC_DPGROUP_HXX 30 31 #include <vector> 32 #include <hash_set> 33 #include <boost/shared_ptr.hpp> 34 35 #include "dptabdat.hxx" 36 #include "scdllapi.h" 37 // Wang Xu Ming -- 2009-8-17 38 // DataPilot Migration - Cache&&Performance 39 #include "dpglobal.hxx" 40 // End Comments 41 class ScDocument; 42 class SvNumberFormatter; 43 44 // -------------------------------------------------------------------- 45 46 //! API struct? 47 struct ScDPNumGroupInfo 48 { 49 sal_Bool Enable; 50 sal_Bool DateValues; 51 sal_Bool AutoStart; 52 sal_Bool AutoEnd; 53 double Start; 54 double End; 55 double Step; 56 57 ScDPNumGroupInfo() : Enable(sal_False), DateValues(sal_False), AutoStart(sal_False), AutoEnd(sal_False), 58 Start(0.0), End(0.0), Step(0.0) {} 59 }; 60 61 // -------------------------------------------------------------------- 62 63 // ScDPDateGroupHelper is used as part of ScDPGroupDimension (additional dim.) 64 // or ScDPNumGroupDimension (innermost, replaces the original dim.). 65 // Source index, name and result collection are stored at the parent. 66 67 class ScDPDateGroupHelper 68 { 69 ScDPNumGroupInfo aNumInfo; // only start and end (incl. auto flags) are used 70 sal_Int32 nDatePart; // single part 71 72 public: 73 ScDPDateGroupHelper( const ScDPNumGroupInfo& rInfo, sal_Int32 nPart ); 74 ~ScDPDateGroupHelper(); 75 76 sal_Int32 GetDatePart() const { return nDatePart; } 77 const ScDPNumGroupInfo& GetNumInfo() const { return aNumInfo; } 78 79 // Wang Xu Ming -- 2009-9-8 80 // DataPilot Migration - Cache&&Performance 81 void FillColumnEntries( SCCOL nSourceDim, ScDPTableDataCache* pCahe , std::vector< SCROW >& rEntries, 82 const std::vector< SCROW >& rOriginal ) const; 83 // End Comments 84 }; 85 86 // -------------------------------------------------------------------- 87 88 typedef ::std::vector<ScDPItemData> ScDPItemDataVec; 89 90 class ScDPGroupItem 91 { 92 ScDPItemData aGroupName; // name of group item 93 ScDPItemDataVec aElements; // names of items in original dimension 94 95 public: 96 ScDPGroupItem( const ScDPItemData& rName ); 97 ~ScDPGroupItem(); 98 99 void AddElement( const ScDPItemData& rName ); 100 101 const ScDPItemData& GetName() const { return aGroupName; } 102 bool HasElement( const ScDPItemData& rData ) const; 103 bool HasCommonElement( const ScDPGroupItem& rOther ) const; 104 105 void FillGroupFilter( ScDPCacheTable::GroupFilter& rFilter ) const; 106 }; 107 108 typedef ::std::vector<ScDPGroupItem> ScDPGroupItemVec; 109 110 class ScDPGroupDimension 111 { 112 long nSourceDim; 113 long nGroupDim; 114 String aGroupName; 115 ScDPDateGroupHelper* pDateHelper; 116 ScDPGroupItemVec aItems; 117 // Wang Xu Ming -- 2009-9-4 118 // DataPilot Migration - Cache&&Performance 119 mutable ::std::vector< SCROW > maMemberEntries; 120 // End Comments 121 public: 122 ScDPGroupDimension( long nSource, const String& rNewName ); 123 ScDPGroupDimension( const ScDPGroupDimension& rOther ); 124 ~ScDPGroupDimension(); 125 126 ScDPGroupDimension& operator=( const ScDPGroupDimension& rOther ); 127 128 void AddItem( const ScDPGroupItem& rItem ); 129 void SetGroupDim( long nDim ); // called from AddGroupDimension 130 131 long GetSourceDim() const { return nSourceDim; } 132 long GetGroupDim() const { return nGroupDim; } 133 const String& GetName() const { return aGroupName; } 134 135 // Wang Xu Ming -- 2009-9-2 136 // DataPilot Migration - Cache&&Performance 137 const std::vector< SCROW >& GetColumnEntries( const ScDPCacheTable& rCacheTable, const std::vector< SCROW >& rOriginal ) const; 138 // End Comments 139 const ScDPGroupItem* GetGroupForData( const ScDPItemData& rData ) const; // rData = entry in original dim. 140 const ScDPGroupItem* GetGroupForName( const ScDPItemData& rName ) const; // rName = entry in group dim. 141 const ScDPGroupItem* GetGroupByIndex( size_t nIndex ) const; 142 143 const ScDPDateGroupHelper* GetDateHelper() const { return pDateHelper; } 144 145 void MakeDateHelper( const ScDPNumGroupInfo& rInfo, sal_Int32 nPart ); 146 147 void DisposeData(); 148 149 size_t GetItemCount() const { return aItems.size(); } 150 }; 151 152 typedef ::std::vector<ScDPGroupDimension> ScDPGroupDimensionVec; 153 154 // -------------------------------------------------------------------- 155 156 class SC_DLLPUBLIC ScDPNumGroupDimension 157 { 158 ScDPNumGroupInfo aGroupInfo; // settings 159 ScDPDateGroupHelper* pDateHelper; 160 // Wang Xu Ming -- 2009-9-4 161 // DataPilot Migration - Cache&&Performance 162 mutable ::std::vector< SCROW > maMemberEntries; 163 // End Comments 164 mutable bool bHasNonInteger; // initialized in GetNumEntries 165 mutable sal_Unicode cDecSeparator; // initialized in GetNumEntries 166 167 public: 168 ScDPNumGroupDimension(); 169 ScDPNumGroupDimension( const ScDPNumGroupInfo& rInfo ); 170 ScDPNumGroupDimension( const ScDPNumGroupDimension& rOther ); 171 ~ScDPNumGroupDimension(); 172 173 ScDPNumGroupDimension& operator=( const ScDPNumGroupDimension& rOther ); 174 175 const ScDPNumGroupInfo& GetInfo() const { return aGroupInfo; } 176 bool HasNonInteger() const { return bHasNonInteger; } 177 sal_Unicode GetDecSeparator() const { return cDecSeparator; } 178 179 const ScDPDateGroupHelper* GetDateHelper() const { return pDateHelper; } 180 181 const std::vector< SCROW >& GetNumEntries( SCCOL nSourceDim, ScDPTableDataCache* pCache, 182 const std::vector< SCROW >& rOriginal ) const; 183 184 void MakeDateHelper( const ScDPNumGroupInfo& rInfo, sal_Int32 nPart ); 185 186 void DisposeData(); 187 }; 188 189 // -------------------------------------------------------------------- 190 // 191 // proxy implementation of ScDPTableData to add grouped items 192 // 193 194 class ScDPGroupTableData : public ScDPTableData 195 { 196 typedef ::std::hash_set< ::rtl::OUString, ::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > StringHashSet; 197 198 ::boost::shared_ptr<ScDPTableData> pSourceData; 199 long nSourceCount; 200 ScDPGroupDimensionVec aGroups; 201 ScDPNumGroupDimension* pNumGroups; // array[nSourceCount] 202 ScDocument* pDoc; 203 StringHashSet aGroupNames; 204 205 // Wang Xu Ming -- 2009-8-17 206 // DataPilot Migration - Cache&&Performance 207 void FillGroupValues( SCROW* pItemDataIndex, long nCount, const long* pDims ); 208 virtual long GetSourceDim( long nDim ); 209 // End Comments 210 211 bool IsNumGroupDimension( long nDimension ) const; 212 void GetNumGroupInfo( long nDimension, ScDPNumGroupInfo& rInfo, 213 bool& rNonInteger, sal_Unicode& rDecimal ); 214 215 void ModifyFilterCriteria(::std::vector<ScDPCacheTable::Criterion>& rCriteria); 216 217 public: 218 // takes ownership of pSource 219 ScDPGroupTableData( const ::boost::shared_ptr<ScDPTableData>& pSource, ScDocument* pDocument ); 220 virtual ~ScDPGroupTableData(); 221 222 void AddGroupDimension( const ScDPGroupDimension& rGroup ); 223 void SetNumGroupDimension( long nIndex, const ScDPNumGroupDimension& rGroup ); 224 long GetDimensionIndex( const String& rName ); 225 226 ScDocument* GetDocument() { return pDoc; } 227 228 virtual long GetColumnCount(); 229 // Wang Xu Ming -- 2009-8-17 230 // DataPilot Migration - Cache&&Performance 231 virtual long GetMembersCount( long nDim ); 232 virtual const std::vector< SCROW >& GetColumnEntries( long nColumn ) ; 233 virtual const ScDPItemData* GetMemberById( long nDim, long nId); 234 virtual long Compare( long nDim, long nDataId1, long nDataId2); 235 236 // End Comments 237 virtual String getDimensionName(long nColumn); 238 virtual sal_Bool getIsDataLayoutDimension(long nColumn); 239 virtual sal_Bool IsDateDimension(long nDim); 240 virtual sal_uLong GetNumberFormat(long nDim); 241 virtual void DisposeData(); 242 virtual void SetEmptyFlags( sal_Bool bIgnoreEmptyRows, sal_Bool bRepeatIfEmpty ); 243 244 virtual bool IsRepeatIfEmpty(); 245 246 virtual void CreateCacheTable(); 247 virtual void FilterCacheTable(const ::std::vector<ScDPCacheTable::Criterion>& rCriteria, const ::std::hash_set<sal_Int32>& rDataDims); 248 virtual void GetDrillDownData(const ::std::vector<ScDPCacheTable::Criterion>& rCriteria, 249 const ::std::hash_set<sal_Int32>& rCatDims, 250 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > >& rData); 251 virtual void CalcResults(CalcInfo& rInfo, bool bAutoShow); 252 virtual const ScDPCacheTable& GetCacheTable() const; 253 254 virtual sal_Bool IsBaseForGroup(long nDim) const; 255 virtual long GetGroupBase(long nGroupDim) const; 256 virtual sal_Bool IsNumOrDateGroup(long nDim) const; 257 virtual sal_Bool IsInGroup( const ScDPItemData& rGroupData, long nGroupIndex, 258 const ScDPItemData& rBaseData, long nBaseIndex ) const; 259 virtual sal_Bool HasCommonElement( const ScDPItemData& rFirstData, long nFirstIndex, 260 const ScDPItemData& rSecondData, long nSecondIndex ) const; 261 }; 262 263 264 #endif 265 266