xref: /aoo42x/main/sc/inc/dpgroup.hxx (revision 38d50f7b)
1*38d50f7bSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*38d50f7bSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*38d50f7bSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*38d50f7bSAndrew Rist  * distributed with this work for additional information
6*38d50f7bSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*38d50f7bSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*38d50f7bSAndrew Rist  * "License"); you may not use this file except in compliance
9*38d50f7bSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*38d50f7bSAndrew Rist  *
11*38d50f7bSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*38d50f7bSAndrew Rist  *
13*38d50f7bSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*38d50f7bSAndrew Rist  * software distributed under the License is distributed on an
15*38d50f7bSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*38d50f7bSAndrew Rist  * KIND, either express or implied.  See the License for the
17*38d50f7bSAndrew Rist  * specific language governing permissions and limitations
18*38d50f7bSAndrew Rist  * under the License.
19*38d50f7bSAndrew Rist  *
20*38d50f7bSAndrew Rist  *************************************************************/
21*38d50f7bSAndrew Rist 
22*38d50f7bSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef SC_DPGROUP_HXX
25cdf0e10cSrcweir #define SC_DPGROUP_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <vector>
28cdf0e10cSrcweir #include <hash_set>
29cdf0e10cSrcweir #include <boost/shared_ptr.hpp>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include "dptabdat.hxx"
32cdf0e10cSrcweir #include "scdllapi.h"
33cdf0e10cSrcweir // Wang Xu Ming -- 2009-8-17
34cdf0e10cSrcweir // DataPilot Migration - Cache&&Performance
35cdf0e10cSrcweir #include "dpglobal.hxx"
36cdf0e10cSrcweir // End Comments
37cdf0e10cSrcweir class ScDocument;
38cdf0e10cSrcweir class SvNumberFormatter;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir // --------------------------------------------------------------------
41cdf0e10cSrcweir 
42cdf0e10cSrcweir //! API struct?
43cdf0e10cSrcweir struct ScDPNumGroupInfo
44cdf0e10cSrcweir {
45cdf0e10cSrcweir     sal_Bool Enable;
46cdf0e10cSrcweir     sal_Bool DateValues;
47cdf0e10cSrcweir     sal_Bool AutoStart;
48cdf0e10cSrcweir     sal_Bool AutoEnd;
49cdf0e10cSrcweir     double   Start;
50cdf0e10cSrcweir     double   End;
51cdf0e10cSrcweir     double   Step;
52cdf0e10cSrcweir 
ScDPNumGroupInfoScDPNumGroupInfo53cdf0e10cSrcweir     ScDPNumGroupInfo() : Enable(sal_False), DateValues(sal_False), AutoStart(sal_False), AutoEnd(sal_False),
54cdf0e10cSrcweir                          Start(0.0), End(0.0), Step(0.0) {}
55cdf0e10cSrcweir };
56cdf0e10cSrcweir 
57cdf0e10cSrcweir // --------------------------------------------------------------------
58cdf0e10cSrcweir 
59cdf0e10cSrcweir //  ScDPDateGroupHelper is used as part of ScDPGroupDimension (additional dim.)
60cdf0e10cSrcweir //  or ScDPNumGroupDimension (innermost, replaces the original dim.).
61cdf0e10cSrcweir //  Source index, name and result collection are stored at the parent.
62cdf0e10cSrcweir 
63cdf0e10cSrcweir class ScDPDateGroupHelper
64cdf0e10cSrcweir {
65cdf0e10cSrcweir     ScDPNumGroupInfo    aNumInfo;       // only start and end (incl. auto flags) are used
66cdf0e10cSrcweir     sal_Int32           nDatePart;      // single part
67cdf0e10cSrcweir 
68cdf0e10cSrcweir public:
69cdf0e10cSrcweir                 ScDPDateGroupHelper( const ScDPNumGroupInfo& rInfo, sal_Int32 nPart );
70cdf0e10cSrcweir                 ~ScDPDateGroupHelper();
71cdf0e10cSrcweir 
GetDatePart() const72cdf0e10cSrcweir     sal_Int32   GetDatePart() const { return nDatePart; }
GetNumInfo() const73cdf0e10cSrcweir     const ScDPNumGroupInfo& GetNumInfo() const { return aNumInfo; }
74cdf0e10cSrcweir 
75cdf0e10cSrcweir     // Wang Xu Ming -- 2009-9-8
76cdf0e10cSrcweir     // DataPilot Migration - Cache&&Performance
77cdf0e10cSrcweir     void        FillColumnEntries( SCCOL nSourceDim, ScDPTableDataCache* pCahe , std::vector< SCROW >& rEntries,
78cdf0e10cSrcweir         const std::vector< SCROW >& rOriginal  ) const;
79cdf0e10cSrcweir     // End Comments
80cdf0e10cSrcweir };
81cdf0e10cSrcweir 
82cdf0e10cSrcweir // --------------------------------------------------------------------
83cdf0e10cSrcweir 
84cdf0e10cSrcweir typedef ::std::vector<ScDPItemData> ScDPItemDataVec;
85cdf0e10cSrcweir 
86cdf0e10cSrcweir class ScDPGroupItem
87cdf0e10cSrcweir {
88cdf0e10cSrcweir     ScDPItemData    aGroupName;     // name of group item
89cdf0e10cSrcweir     ScDPItemDataVec aElements;      // names of items in original dimension
90cdf0e10cSrcweir 
91cdf0e10cSrcweir public:
92cdf0e10cSrcweir                 ScDPGroupItem( const ScDPItemData& rName );
93cdf0e10cSrcweir                 ~ScDPGroupItem();
94cdf0e10cSrcweir 
95cdf0e10cSrcweir     void        AddElement( const ScDPItemData& rName );
96cdf0e10cSrcweir 
GetName() const97cdf0e10cSrcweir     const ScDPItemData& GetName() const     { return aGroupName; }
98cdf0e10cSrcweir     bool        HasElement( const ScDPItemData& rData ) const;
99cdf0e10cSrcweir     bool        HasCommonElement( const ScDPGroupItem& rOther ) const;
100cdf0e10cSrcweir 
101cdf0e10cSrcweir     void        FillGroupFilter( ScDPCacheTable::GroupFilter& rFilter ) const;
102cdf0e10cSrcweir };
103cdf0e10cSrcweir 
104cdf0e10cSrcweir typedef ::std::vector<ScDPGroupItem> ScDPGroupItemVec;
105cdf0e10cSrcweir 
106cdf0e10cSrcweir class ScDPGroupDimension
107cdf0e10cSrcweir {
108cdf0e10cSrcweir     long                        nSourceDim;
109cdf0e10cSrcweir     long                        nGroupDim;
110cdf0e10cSrcweir     String                      aGroupName;
111cdf0e10cSrcweir     ScDPDateGroupHelper*        pDateHelper;
112cdf0e10cSrcweir     ScDPGroupItemVec            aItems;
113cdf0e10cSrcweir     // Wang Xu Ming -- 2009-9-4
114cdf0e10cSrcweir     // DataPilot Migration - Cache&&Performance
115cdf0e10cSrcweir    mutable  ::std::vector< SCROW >            maMemberEntries;
116cdf0e10cSrcweir     // End Comments
117cdf0e10cSrcweir public:
118cdf0e10cSrcweir                 ScDPGroupDimension( long nSource, const String& rNewName );
119cdf0e10cSrcweir                 ScDPGroupDimension( const ScDPGroupDimension& rOther );
120cdf0e10cSrcweir                 ~ScDPGroupDimension();
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 	ScDPGroupDimension&	operator=( const ScDPGroupDimension& rOther );
123cdf0e10cSrcweir 
124cdf0e10cSrcweir     void        AddItem( const ScDPGroupItem& rItem );
125cdf0e10cSrcweir     void        SetGroupDim( long nDim );           // called from AddGroupDimension
126cdf0e10cSrcweir 
GetSourceDim() const127cdf0e10cSrcweir     long        GetSourceDim() const    { return nSourceDim; }
GetGroupDim() const128cdf0e10cSrcweir     long        GetGroupDim() const     { return nGroupDim; }
GetName() const129cdf0e10cSrcweir     const      String& GetName() const       { return aGroupName; }
130cdf0e10cSrcweir 
131cdf0e10cSrcweir // Wang Xu Ming -- 2009-9-2
132cdf0e10cSrcweir // DataPilot Migration - Cache&&Performance
133cdf0e10cSrcweir     const std::vector< SCROW >&  GetColumnEntries( const ScDPCacheTable&  rCacheTable, const std::vector< SCROW >& rOriginal ) const;
134cdf0e10cSrcweir // End Comments
135cdf0e10cSrcweir     const ScDPGroupItem* GetGroupForData( const ScDPItemData& rData ) const;  // rData = entry in original dim.
136cdf0e10cSrcweir     const ScDPGroupItem* GetGroupForName( const ScDPItemData& rName ) const;  // rName = entry in group dim.
137cdf0e10cSrcweir     const ScDPGroupItem* GetGroupByIndex( size_t nIndex ) const;
138cdf0e10cSrcweir 
GetDateHelper() const139cdf0e10cSrcweir     const ScDPDateGroupHelper* GetDateHelper() const    { return pDateHelper; }
140cdf0e10cSrcweir 
141cdf0e10cSrcweir     void        MakeDateHelper( const ScDPNumGroupInfo& rInfo, sal_Int32 nPart );
142cdf0e10cSrcweir 
143cdf0e10cSrcweir     void        DisposeData();
144cdf0e10cSrcweir 
GetItemCount() const145cdf0e10cSrcweir     size_t      GetItemCount() const { return aItems.size(); }
146cdf0e10cSrcweir };
147cdf0e10cSrcweir 
148cdf0e10cSrcweir typedef ::std::vector<ScDPGroupDimension> ScDPGroupDimensionVec;
149cdf0e10cSrcweir 
150cdf0e10cSrcweir // --------------------------------------------------------------------
151cdf0e10cSrcweir 
152cdf0e10cSrcweir class SC_DLLPUBLIC ScDPNumGroupDimension
153cdf0e10cSrcweir {
154cdf0e10cSrcweir     ScDPNumGroupInfo            aGroupInfo;         // settings
155cdf0e10cSrcweir     ScDPDateGroupHelper*        pDateHelper;
156cdf0e10cSrcweir // Wang Xu Ming -- 2009-9-4
157cdf0e10cSrcweir // DataPilot Migration - Cache&&Performance
158cdf0e10cSrcweir     mutable  ::std::vector< SCROW >            maMemberEntries;
159cdf0e10cSrcweir // End Comments
160cdf0e10cSrcweir     mutable bool                bHasNonInteger;     // initialized in GetNumEntries
161cdf0e10cSrcweir     mutable sal_Unicode         cDecSeparator;      // initialized in GetNumEntries
162cdf0e10cSrcweir 
163cdf0e10cSrcweir public:
164cdf0e10cSrcweir                 ScDPNumGroupDimension();
165cdf0e10cSrcweir                 ScDPNumGroupDimension( const ScDPNumGroupInfo& rInfo );
166cdf0e10cSrcweir                 ScDPNumGroupDimension( const ScDPNumGroupDimension& rOther );
167cdf0e10cSrcweir                 ~ScDPNumGroupDimension();
168cdf0e10cSrcweir 
169cdf0e10cSrcweir 	ScDPNumGroupDimension&	operator=( const ScDPNumGroupDimension& rOther );
170cdf0e10cSrcweir 
GetInfo() const171cdf0e10cSrcweir     const ScDPNumGroupInfo& GetInfo() const     { return aGroupInfo; }
HasNonInteger() const172cdf0e10cSrcweir     bool        HasNonInteger() const           { return bHasNonInteger; }
GetDecSeparator() const173cdf0e10cSrcweir     sal_Unicode GetDecSeparator() const         { return cDecSeparator; }
174cdf0e10cSrcweir 
GetDateHelper() const175cdf0e10cSrcweir     const ScDPDateGroupHelper* GetDateHelper() const    { return pDateHelper; }
176cdf0e10cSrcweir 
177cdf0e10cSrcweir     const std::vector< SCROW >& GetNumEntries( SCCOL nSourceDim, ScDPTableDataCache* pCache,
178cdf0e10cSrcweir                     const std::vector< SCROW >& rOriginal  ) const;
179cdf0e10cSrcweir 
180cdf0e10cSrcweir     void        MakeDateHelper( const ScDPNumGroupInfo& rInfo, sal_Int32 nPart );
181cdf0e10cSrcweir 
182cdf0e10cSrcweir     void        DisposeData();
183cdf0e10cSrcweir };
184cdf0e10cSrcweir 
185cdf0e10cSrcweir // --------------------------------------------------------------------
186cdf0e10cSrcweir //
187cdf0e10cSrcweir //  proxy implementation of ScDPTableData to add grouped items
188cdf0e10cSrcweir //
189cdf0e10cSrcweir 
190cdf0e10cSrcweir class ScDPGroupTableData : public ScDPTableData
191cdf0e10cSrcweir {
192cdf0e10cSrcweir     typedef ::std::hash_set< ::rtl::OUString, ::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > StringHashSet;
193cdf0e10cSrcweir 
194cdf0e10cSrcweir     ::boost::shared_ptr<ScDPTableData> pSourceData;
195cdf0e10cSrcweir     long                    nSourceCount;
196cdf0e10cSrcweir     ScDPGroupDimensionVec   aGroups;
197cdf0e10cSrcweir     ScDPNumGroupDimension*  pNumGroups;     // array[nSourceCount]
198cdf0e10cSrcweir     ScDocument*             pDoc;
199cdf0e10cSrcweir     StringHashSet           aGroupNames;
200cdf0e10cSrcweir 
201cdf0e10cSrcweir // Wang Xu Ming -- 2009-8-17
202cdf0e10cSrcweir // DataPilot Migration - Cache&&Performance
203cdf0e10cSrcweir     void       					 FillGroupValues( SCROW* pItemDataIndex, long nCount, const long* pDims );
204cdf0e10cSrcweir     virtual long 				GetSourceDim( long nDim );
205cdf0e10cSrcweir // End Comments
206cdf0e10cSrcweir 
207cdf0e10cSrcweir     bool        IsNumGroupDimension( long nDimension ) const;
208cdf0e10cSrcweir     void        GetNumGroupInfo( long nDimension, ScDPNumGroupInfo& rInfo,
209cdf0e10cSrcweir                                     bool& rNonInteger, sal_Unicode& rDecimal );
210cdf0e10cSrcweir 
211cdf0e10cSrcweir     void        ModifyFilterCriteria(::std::vector<ScDPCacheTable::Criterion>& rCriteria);
212cdf0e10cSrcweir 
213cdf0e10cSrcweir public:
214cdf0e10cSrcweir                 // takes ownership of pSource
215cdf0e10cSrcweir                 ScDPGroupTableData( const ::boost::shared_ptr<ScDPTableData>& pSource, ScDocument* pDocument );
216cdf0e10cSrcweir     virtual     ~ScDPGroupTableData();
217cdf0e10cSrcweir 
218cdf0e10cSrcweir     void        AddGroupDimension( const ScDPGroupDimension& rGroup );
219cdf0e10cSrcweir     void        SetNumGroupDimension( long nIndex, const ScDPNumGroupDimension& rGroup );
220cdf0e10cSrcweir     long        GetDimensionIndex( const String& rName );
221cdf0e10cSrcweir 
GetDocument()222cdf0e10cSrcweir     ScDocument* GetDocument()   { return pDoc; }
223cdf0e10cSrcweir 
224cdf0e10cSrcweir     virtual long                    GetColumnCount();
225cdf0e10cSrcweir // Wang Xu Ming -- 2009-8-17
226cdf0e10cSrcweir // DataPilot Migration - Cache&&Performance
227cdf0e10cSrcweir     virtual   long                            	            GetMembersCount( long nDim );
228cdf0e10cSrcweir     virtual    const std::vector< SCROW >& GetColumnEntries( long nColumn ) ;
229cdf0e10cSrcweir     virtual const ScDPItemData* GetMemberById( long nDim, long nId);
230cdf0e10cSrcweir     virtual long Compare( long nDim, long nDataId1, long nDataId2);
231cdf0e10cSrcweir 
232cdf0e10cSrcweir // End Comments
233cdf0e10cSrcweir     virtual String                  getDimensionName(long nColumn);
234cdf0e10cSrcweir     virtual sal_Bool                    getIsDataLayoutDimension(long nColumn);
235cdf0e10cSrcweir     virtual sal_Bool                    IsDateDimension(long nDim);
236cdf0e10cSrcweir     virtual sal_uLong                  GetNumberFormat(long nDim);
237cdf0e10cSrcweir     virtual void                    DisposeData();
238cdf0e10cSrcweir     virtual void                    SetEmptyFlags( sal_Bool bIgnoreEmptyRows, sal_Bool bRepeatIfEmpty );
239cdf0e10cSrcweir 
240cdf0e10cSrcweir     virtual bool                    IsRepeatIfEmpty();
241cdf0e10cSrcweir 
242cdf0e10cSrcweir     virtual void                    CreateCacheTable();
243cdf0e10cSrcweir     virtual void                    FilterCacheTable(const ::std::vector<ScDPCacheTable::Criterion>& rCriteria, const ::std::hash_set<sal_Int32>& rDataDims);
244cdf0e10cSrcweir     virtual void                    GetDrillDownData(const ::std::vector<ScDPCacheTable::Criterion>& rCriteria,
245cdf0e10cSrcweir                                                      const ::std::hash_set<sal_Int32>& rCatDims,
246cdf0e10cSrcweir                                                      ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > >& rData);
247cdf0e10cSrcweir     virtual void                    CalcResults(CalcInfo& rInfo, bool bAutoShow);
248cdf0e10cSrcweir     virtual const ScDPCacheTable&   GetCacheTable() const;
249cdf0e10cSrcweir 
250cdf0e10cSrcweir     virtual sal_Bool                    IsBaseForGroup(long nDim) const;
251cdf0e10cSrcweir     virtual long                    GetGroupBase(long nGroupDim) const;
252cdf0e10cSrcweir     virtual sal_Bool                    IsNumOrDateGroup(long nDim) const;
253cdf0e10cSrcweir     virtual sal_Bool                    IsInGroup( const ScDPItemData& rGroupData, long nGroupIndex,
254cdf0e10cSrcweir                                                const ScDPItemData& rBaseData, long nBaseIndex ) const;
255cdf0e10cSrcweir     virtual sal_Bool                    HasCommonElement( const ScDPItemData& rFirstData, long nFirstIndex,
256cdf0e10cSrcweir                                                       const ScDPItemData& rSecondData, long nSecondIndex ) const;
257cdf0e10cSrcweir };
258cdf0e10cSrcweir 
259cdf0e10cSrcweir 
260cdf0e10cSrcweir #endif
261cdf0e10cSrcweir 
262