Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef SC_DPTABRES_HXX
30 : : #define SC_DPTABRES_HXX
31 : :
32 : : #include "global.hxx"
33 : : #include "dpcachetable.hxx"
34 : :
35 : : #include <tools/string.hxx>
36 : : #include <com/sun/star/sheet/MemberResult.hpp>
37 : : #include <com/sun/star/sheet/DataResult.hpp>
38 : : #include <com/sun/star/uno/Sequence.hxx>
39 : :
40 : : #include <boost/unordered_map.hpp>
41 : : #include <boost/unordered_set.hpp>
42 : : #include <vector>
43 : : #include <memory>
44 : : #include <map>
45 : :
46 : : namespace com { namespace sun { namespace star { namespace sheet {
47 : : struct DataPilotFieldReference;
48 : : } } } }
49 : :
50 : :
51 : : class ScAddress;
52 : : class ScDocument;
53 : : class ScDPSource;
54 : : class ScDPDimension;
55 : : class ScDPLevel;
56 : : class ScDPMember;
57 : : class ScDPAggData;
58 : : class ScDPResultMember;
59 : : class ScDPResultVisibilityData;
60 : :
61 : : struct ScDPValueData;
62 : : class ScDPItemData;
63 : : //
64 : : // Member names that are being processed for InitFrom/LateInitFrom
65 : : // (needed for initialization of grouped items)
66 : : //
67 : :
68 : : class ScDPInitState
69 : : {
70 : : long* pIndex; // array
71 : : SCROW* pData; // array
72 : : long nCount;
73 : :
74 : : public:
75 : : ScDPInitState();
76 : : ~ScDPInitState();
77 : :
78 : : void AddMember( long nSourceIndex,SCROW nMember);
79 : : void RemoveMember();
80 : :
81 : 189 : long GetCount() const { return nCount; }
82 : 189 : const long* GetSource() const { return pIndex; }
83 : 189 : const SCROW* GetNameIds() const { return pData; }
84 : : };
85 : :
86 : : typedef ::std::vector<sal_Int32> ScMemberSortOrder;
87 : :
88 : : //
89 : : // selected subtotal information, passed down the dimensions
90 : : //
91 : :
92 : : struct ScDPSubTotalState
93 : : {
94 : : ScSubTotalFunc eColForce;
95 : : ScSubTotalFunc eRowForce;
96 : : long nColSubTotalFunc;
97 : : long nRowSubTotalFunc;
98 : :
99 : 4193 : ScDPSubTotalState() :
100 : : eColForce( SUBTOTAL_FUNC_NONE ),
101 : : eRowForce( SUBTOTAL_FUNC_NONE ),
102 : : nColSubTotalFunc( -1 ),
103 : 4193 : nRowSubTotalFunc( -1 )
104 : 4193 : {}
105 : : };
106 : :
107 : : //
108 : : // indexes when calculating running totals
109 : : // Col/RowVisible: simple counts from 0 - without sort order applied - visible index
110 : : // (only used for running total / relative index)
111 : : // Col/RowIndexes: with sort order applied - member index
112 : : // (used otherwise - so other members' children can be accessed)
113 : : //
114 : :
115 : : class ScDPRunningTotalState
116 : : {
117 : : ScDPResultMember* pColResRoot;
118 : : ScDPResultMember* pRowResRoot;
119 : : long* pColVisible;
120 : : long* pColIndexes;
121 : : long* pRowVisible;
122 : : long* pRowIndexes;
123 : : long nColIndexPos;
124 : : long nRowIndexPos;
125 : :
126 : : public:
127 : : ScDPRunningTotalState( ScDPResultMember* pColRoot, ScDPResultMember* pRowRoot );
128 : : ~ScDPRunningTotalState();
129 : :
130 : 0 : ScDPResultMember* GetColResRoot() const { return pColResRoot; }
131 : 0 : ScDPResultMember* GetRowResRoot() const { return pRowResRoot; }
132 : :
133 : 0 : const long* GetColVisible() const { return pColVisible; }
134 : 0 : const long* GetColIndexes() const { return pColIndexes; }
135 : 0 : const long* GetRowVisible() const { return pRowVisible; }
136 : 0 : const long* GetRowIndexes() const { return pRowIndexes; }
137 : :
138 : : void AddColIndex( long nVisible, long nSorted );
139 : : void AddRowIndex( long nVisible, long nSorted );
140 : : void RemoveColIndex();
141 : : void RemoveRowIndex();
142 : : };
143 : :
144 : : struct ScDPRelativePos
145 : : {
146 : : long nBasePos; // simple count, without sort order applied
147 : : long nDirection;
148 : :
149 : : ScDPRelativePos( long nBase, long nDir );
150 : : };
151 : :
152 : : //
153 : : // aggregated data
154 : : //! separate header file?
155 : : //
156 : :
157 : : // Possible values for the nCount member:
158 : : // (greater than 0 counts the collected values)
159 : : const long SC_DPAGG_EMPTY = 0; // empty during data collection
160 : : const long SC_DPAGG_DATA_ERROR = -1; // error during data collection
161 : : const long SC_DPAGG_RESULT_EMPTY = -2; // empty result calculated
162 : : const long SC_DPAGG_RESULT_VALID = -3; // valid result calculated
163 : : const long SC_DPAGG_RESULT_ERROR = -4; // error in calculated result
164 : :
165 : : class ScDPAggData
166 : : {
167 : : private:
168 : : double fVal;
169 : : double fAux;
170 : : long nCount;
171 : : ScDPAggData* pChild;
172 : :
173 : : public:
174 : 6977 : ScDPAggData() : fVal(0.0), fAux(0.0), nCount(SC_DPAGG_EMPTY), pChild(NULL) {}
175 [ + + ]: 6977 : ~ScDPAggData() { delete pChild; }
176 : :
177 : : void Update( const ScDPValueData& rNext, ScSubTotalFunc eFunc, const ScDPSubTotalState& rSubState );
178 : : void Calculate( ScSubTotalFunc eFunc, const ScDPSubTotalState& rSubState );
179 : : sal_Bool IsCalculated() const;
180 : :
181 : : double GetResult() const;
182 : : sal_Bool HasError() const;
183 : : sal_Bool HasData() const;
184 : :
185 : : void SetResult( double fNew );
186 : : void SetEmpty( sal_Bool bSet );
187 : : void SetError();
188 : :
189 : : double GetAuxiliary() const;
190 : : void SetAuxiliary( double fNew );
191 : :
192 : : void Reset(); // also deletes children
193 : :
194 : 81 : const ScDPAggData* GetExistingChild() const { return pChild; }
195 : : ScDPAggData* GetChild();
196 : : };
197 : :
198 : : //
199 : : // Row and grand total state, passed down (column total is at result member)
200 : : //
201 : :
202 : : class ScDPRowTotals
203 : : {
204 : : ScDPAggData aRowTotal;
205 : : ScDPAggData aGrandTotal;
206 : : sal_Bool bIsInColRoot;
207 : :
208 : : public:
209 : : ScDPRowTotals();
210 : : ~ScDPRowTotals();
211 : :
212 : : ScDPAggData* GetRowTotal( long nMeasure );
213 : : ScDPAggData* GetGrandTotal( long nMeasure );
214 : :
215 : 0 : sal_Bool IsInColRoot() const { return bIsInColRoot; }
216 : 756 : void SetInColRoot(sal_Bool bSet) { bIsInColRoot = bSet; }
217 : : };
218 : :
219 : : // --------------------------------------------------------------------
220 : : //
221 : : // results for a hierarchy dimension
222 : : //
223 : :
224 : : class ScDPResultDimension;
225 : : class ScDPDataDimension;
226 : : class ScDPDataMember;
227 : :
228 : : #define SC_DPMEASURE_ALL -1
229 : : #define SC_DPMEASURE_ANY -2
230 : :
231 : : struct MemberHashIndexFunc : public std::unary_function< const SCROW &, size_t >
232 : : {
233 : 1977 : size_t operator() (const SCROW &rDataIndex) const { return rDataIndex; }
234 : : };
235 : :
236 : : class ScDPParentDimData
237 : : {
238 : : public:
239 : : const SCROW mnOrder; //! Ref
240 : : const ScDPDimension* mpParentDim; //! Ref
241 : : const ScDPLevel* mpParentLevel; //! Ref
242 : : const ScDPMember* mpMemberDesc; //! Ref
243 : :
244 : 280 : ScDPParentDimData():mnOrder(-1), mpParentDim( NULL), mpParentLevel( NULL ), mpMemberDesc( NULL ){}
245 : 1985 : ScDPParentDimData( const SCROW nIndex, ScDPDimension* pDim, const ScDPLevel* pLev, const ScDPMember* pMember ): mnOrder( nIndex ), mpParentDim( pDim), mpParentLevel( pLev ), mpMemberDesc( pMember ){}
246 : : };
247 : :
248 : : typedef std::vector <ScDPParentDimData *> DimMemberArray;
249 : : typedef boost::unordered_map < SCROW, ScDPParentDimData *, MemberHashIndexFunc> DimMemberHash;
250 : :
251 : : class ResultMembers
252 : : {
253 : : DimMemberHash maMemberHash;
254 : : sal_Bool mbHasHideDetailsMember;
255 : : public:
256 : : ScDPParentDimData* FindMember( const SCROW& nIndex ) const;
257 : : void InsertMember( ScDPParentDimData* pNew );
258 : 1200 : sal_Bool IsHasHideDetailsMembers() const { return mbHasHideDetailsMember; }
259 : 1200 : void SetHasHideDetailsMembers( sal_Bool b ) { mbHasHideDetailsMember=b; }
260 : : ResultMembers();
261 : : virtual ~ResultMembers();
262 : : };
263 : :
264 : : class LateInitParams
265 : : {
266 : : private:
267 : : const ::std::vector<ScDPDimension*>& mppDim;
268 : : const ::std::vector<ScDPLevel*>& mppLev;
269 : :
270 : : sal_Bool mbRow;
271 : : sal_Bool mbInitChild;
272 : : sal_Bool mbAllChildren;
273 : : public:
274 : : LateInitParams( const ::std::vector<ScDPDimension*>& ppDim, const ::std::vector<ScDPLevel*>& ppLev,
275 : : sal_Bool bRow, sal_Bool bInitChild = sal_True , sal_Bool bAllChildren = false);
276 : : ~LateInitParams();
277 : :
278 : 1500 : void SetInitChild( sal_Bool b ) { mbInitChild = b; }
279 : 1704 : void SetInitAllChildren( sal_Bool b ) { mbAllChildren = b; }
280 : :
281 : 1480 : inline ScDPDimension* GetDim( size_t nPos ) const { return mppDim[nPos];}
282 : 1480 : inline ScDPLevel* GetLevel( size_t nPos ) const { return mppLev[nPos];}
283 : :
284 : 1302 : inline sal_Bool GetInitChild() const {return mbInitChild; }
285 : 1200 : inline sal_Bool GetInitAllChild() const { return mbAllChildren; }
286 : 1302 : inline sal_Bool IsRow() const { return mbRow; }
287 : : sal_Bool IsEnd( size_t nPos ) const ;
288 : : };
289 : :
290 : : class ScDPResultData
291 : : {
292 : : private:
293 : : ScDPSource* pSource; //! Ref
294 : : //! keep things like measure lists here
295 : :
296 : : long nMeasCount;
297 : : ScSubTotalFunc* pMeasFuncs;
298 : : ::com::sun::star::sheet::DataPilotFieldReference* pMeasRefs;
299 : : sal_uInt16* pMeasRefOrient;
300 : : std::vector<rtl::OUString> maMeasureNames;
301 : : bool bLateInit:1;
302 : : bool bDataAtCol:1;
303 : : bool bDataAtRow:1;
304 : :
305 : : //! add "displayed values" settings
306 : : mutable std::vector< ResultMembers* > mpDimMembers;
307 : : public:
308 : : ScDPResultData( ScDPSource* pSrc ); //! Ref
309 : : ~ScDPResultData();
310 : :
311 : : void SetMeasureData( long nCount, const ScSubTotalFunc* pFunctions,
312 : : const ::com::sun::star::sheet::DataPilotFieldReference* pRefs,
313 : : const sal_uInt16* pRefOrient, std::vector<rtl::OUString>& rNames );
314 : : void SetDataLayoutOrientation( sal_uInt16 nOrient );
315 : : void SetLateInit( bool bSet );
316 : :
317 : 152 : long GetMeasureCount() const { return nMeasCount; }
318 : : ScSubTotalFunc GetMeasureFunction(long nMeasure) const;
319 : : rtl::OUString GetMeasureString(long nMeasure, bool bForce, ScSubTotalFunc eForceFunc, bool& rbTotalResult) const;
320 : : rtl::OUString GetMeasureDimensionName(long nMeasure) const;
321 : : const ::com::sun::star::sheet::DataPilotFieldReference& GetMeasureRefVal(long nMeasure) const;
322 : : sal_uInt16 GetMeasureRefOrient(long nMeasure) const;
323 : :
324 : : bool IsDataAtCol() const { return bDataAtCol; }
325 : : bool IsDataAtRow() const { return bDataAtRow; }
326 : 8472 : bool IsLateInit() const { return bLateInit; }
327 : :
328 : : long GetColStartMeasure() const;
329 : : long GetRowStartMeasure() const;
330 : :
331 : 10714 : long GetCountForMeasure( long nMeas ) const
332 [ + + ]: 10714 : { return ( nMeas == SC_DPMEASURE_ALL ) ? nMeasCount : 1; }
333 : :
334 : : bool IsBaseForGroup( long nDim ) const; // any group
335 : : long GetGroupBase( long nGroupDim ) const;
336 : : bool IsNumOrDateGroup( long nDim ) const;
337 : : bool IsInGroup( SCROW nGroupDataId, long nGroupIndex,
338 : : const ScDPItemData& rBaseData, long nBaseIndex ) const;
339 : : bool HasCommonElement( SCROW nFirstDataId, long nFirstIndex,
340 : : const ScDPItemData& rSecondData, long nSecondIndex ) const;
341 : :
342 : : ResultMembers* GetDimResultMembers( long nDim , ScDPDimension* pDim , ScDPLevel* pLevel) const ;
343 : :
344 : : const ScDPSource* GetSource() const;
345 : : };
346 : :
347 : :
348 : : class ScDPResultMember
349 : : {
350 : : private:
351 : : const ScDPResultData* pResultData;
352 : : ScDPParentDimData aParentDimData;
353 : : ScDPResultDimension* pChildDimension;
354 : : ScDPDataMember* pDataRoot;
355 : : sal_Bool bHasElements;
356 : : sal_Bool bForceSubTotal;
357 : : sal_Bool bHasHiddenDetails;
358 : : sal_Bool bInitialized;
359 : : sal_Bool bAutoHidden;
360 : : ScDPAggData aColTotal; // to store column totals
361 : :
362 : : sal_uInt16 nMemberStep; // step to show details
363 : : public:
364 : : ScDPResultMember( const ScDPResultData* pData, const ScDPParentDimData& rParentDimData,
365 : : sal_Bool bForceSub ); //! Ref
366 : : ScDPResultMember( const ScDPResultData* pData, sal_Bool bForceSub );
367 : : ~ScDPResultMember();
368 : :
369 : : void InitFrom( const ::std::vector<ScDPDimension*>& ppDim,
370 : : const ::std::vector<ScDPLevel*>& ppLev,
371 : : size_t nPos,
372 : : ScDPInitState& rInitState,
373 : : sal_Bool bInitChild = sal_True );
374 : : void LateInitFrom(
375 : : LateInitParams& rParams,
376 : : const ::std::vector< SCROW >& pItemData,
377 : : size_t nPos,
378 : : ScDPInitState& rInitState);
379 : : void CheckShowEmpty( sal_Bool bShow = false );
380 : : String GetName() const;
381 : : void FillItemData( ScDPItemData& rData ) const;
382 : : sal_Bool IsValid() const;
383 : : sal_Bool IsVisible() const;
384 : : long GetSize(long nMeasure) const;
385 : : sal_Bool HasHiddenDetails() const;
386 : : sal_Bool IsSubTotalInTitle(long nMeasure) const;
387 : :
388 : : long GetSubTotalCount( long* pUserSubStart = NULL ) const;
389 : :
390 : : sal_Bool IsNamedItem( SCROW nIndex ) const;
391 : : bool IsValidEntry( const ::std::vector< SCROW >& aMembers ) const;
392 : :
393 : 2320 : void SetHasElements() { bHasElements = sal_True; }
394 : 0 : void SetAutoHidden() { bAutoHidden = sal_True; }
395 : :
396 : : void ProcessData( const ::std::vector<SCROW>& aChildMembers,
397 : : const ScDPResultDimension* pDataDim,
398 : : const ::std::vector<SCROW>& aDataMembers,
399 : : const ::std::vector<ScDPValueData>& aValues );
400 : : void FillMemberResults( com::sun::star::uno::Sequence<
401 : : com::sun::star::sheet::MemberResult>* pSequences,
402 : : long& rPos, long nMeasure, sal_Bool bRoot,
403 : : const String* pMemberName,
404 : : const String* pMemberCaption );
405 : :
406 : : void FillDataResults( const ScDPResultMember* pRefMember,
407 : : com::sun::star::uno::Sequence<
408 : : com::sun::star::uno::Sequence<
409 : : com::sun::star::sheet::DataResult> >& rSequence,
410 : : long& rRow, long nMeasure ) const;
411 : :
412 : : void UpdateDataResults( const ScDPResultMember* pRefMember, long nMeasure ) const;
413 : : void UpdateRunningTotals( const ScDPResultMember* pRefMember, long nMeasure,
414 : : ScDPRunningTotalState& rRunning, ScDPRowTotals& rTotals ) const;
415 : :
416 : : void SortMembers( ScDPResultMember* pRefMember );
417 : : void DoAutoShow( ScDPResultMember* pRefMember );
418 : :
419 : : void ResetResults( sal_Bool bRoot );
420 : :
421 : : void DumpState( const ScDPResultMember* pRefMember, ScDocument* pDoc, ScAddress& rPos ) const;
422 : :
423 : : //! this will be removed!
424 : 10795 : const ScDPResultDimension* GetChildDimension() const { return pChildDimension; }
425 : 6251 : ScDPResultDimension* GetChildDimension() { return pChildDimension; }
426 : :
427 : 0 : ScDPDataMember* GetDataRoot() const { return pDataRoot; }
428 : :
429 : 1168 : const ScDPDimension* GetParentDim() const { return aParentDimData.mpParentDim; } //! Ref
430 : 36960 : const ScDPLevel* GetParentLevel() const { return aParentDimData.mpParentLevel; } //! Ref
431 : 48411 : const ScDPMember* GetDPMember()const { return aParentDimData.mpMemberDesc; } //! Ref
432 : 66 : inline SCROW GetOrder() const { return aParentDimData.mnOrder; } //! Ref
433 : 1509 : inline sal_Bool IsRoot() const { return GetParentLevel() == NULL; }
434 : : SCROW GetDataId( ) const ;
435 : : ScDPAggData* GetColTotal( long nMeasure ) const;
436 : :
437 : : void FillVisibilityData(ScDPResultVisibilityData& rData) const;
438 : : };
439 : :
440 : : class ScDPDataMember
441 : : {
442 : : private:
443 : : const ScDPResultData* pResultData;
444 : : const ScDPResultMember* pResultMember; //! Ref?
445 : : ScDPDataDimension* pChildDimension;
446 : : ScDPAggData aAggregate;
447 : :
448 : : void UpdateValues( const ::std::vector<ScDPValueData>& aValues, const ScDPSubTotalState& rSubState );
449 : :
450 : : public:
451 : : ScDPDataMember( const ScDPResultData* pData, const ScDPResultMember* pRes );
452 : : ~ScDPDataMember();
453 : :
454 : : void InitFrom( const ScDPResultDimension* pDim );
455 : :
456 : : String GetName() const;
457 : : sal_Bool IsVisible() const;
458 : : sal_Bool HasData( long nMeasure, const ScDPSubTotalState& rSubState ) const;
459 : :
460 : : sal_Bool IsNamedItem( SCROW r ) const;
461 : : sal_Bool HasHiddenDetails() const;
462 : :
463 : : void ProcessData( const ::std::vector< SCROW >& aChildMembers, const ::std::vector<ScDPValueData>& aValues,
464 : : const ScDPSubTotalState& rSubState );
465 : : sal_Bool HasError( long nMeasure, const ScDPSubTotalState& rSubState ) const;
466 : : double GetAggregate( long nMeasure, const ScDPSubTotalState& rSubState ) const;
467 : : const ScDPAggData* GetConstAggData( long nMeasure, const ScDPSubTotalState& rSubState ) const;
468 : : ScDPAggData* GetAggData( long nMeasure, const ScDPSubTotalState& rSubState );
469 : :
470 : : void FillDataRow( const ScDPResultMember* pRefMember,
471 : : com::sun::star::uno::Sequence<com::sun::star::sheet::DataResult>& rSequence,
472 : : long& rCol, long nMeasure, sal_Bool bIsSubTotalRow,
473 : : const ScDPSubTotalState& rSubState ) const;
474 : :
475 : : void UpdateDataRow( const ScDPResultMember* pRefMember, long nMeasure, sal_Bool bIsSubTotalRow,
476 : : const ScDPSubTotalState& rSubState );
477 : : void UpdateRunningTotals( const ScDPResultMember* pRefMember, long nMeasure, sal_Bool bIsSubTotalRow,
478 : : const ScDPSubTotalState& rSubState, ScDPRunningTotalState& rRunning,
479 : : ScDPRowTotals& rTotals, const ScDPResultMember& rRowParent );
480 : :
481 : : void SortMembers( ScDPResultMember* pRefMember );
482 : : void DoAutoShow( ScDPResultMember* pRefMember );
483 : :
484 : : void ResetResults();
485 : :
486 : : void DumpState( const ScDPResultMember* pRefMember, ScDocument* pDoc, ScAddress& rPos ) const;
487 : :
488 : : //! this will be removed!
489 : 2510 : const ScDPDataDimension* GetChildDimension() const { return pChildDimension; }
490 : 6597 : ScDPDataDimension* GetChildDimension() { return pChildDimension; }
491 : : };
492 : :
493 : : typedef std::vector<ScDPDataMember*> ScDPDataMembers;
494 : :
495 : :
496 : : // result dimension contains only members
497 : :
498 : : class ScDPResultDimension
499 : : {
500 : : public:
501 : : typedef std::vector<ScDPResultMember*> MemberArray;
502 : : typedef std::map<SCROW, ScDPResultMember*> MemberHash;
503 : : private:
504 : : const ScDPResultData* pResultData;
505 : : MemberArray maMemberArray;
506 : : MemberHash maMemberHash;
507 : : rtl::OUString aDimensionName; //! or ptr to IntDimension?
508 : : long nSortMeasure;
509 : : ScMemberSortOrder aMemberOrder; // used when sorted by measure
510 : : bool bIsDataLayout:1; //! or ptr to IntDimension?
511 : : bool bSortByData:1;
512 : : bool bSortAscending:1;
513 : : bool bAutoShow:1;
514 : : bool bAutoTopItems:1;
515 : : bool bInitialized:1;
516 : : long nAutoMeasure;
517 : : long nAutoCount;
518 : :
519 : : ScDPResultMember* FindMember( SCROW iData ) const;
520 : : ScDPResultMember* AddMember( const ScDPParentDimData& aData );
521 : : ScDPResultMember* InsertMember( ScDPParentDimData* pMemberData );
522 : : void InitWithMembers( LateInitParams& rParams,
523 : : const ::std::vector< SCROW >& pItemData,
524 : : size_t nPos,
525 : : ScDPInitState& rInitState );
526 : : public:
527 : : ScDPResultDimension( const ScDPResultData* pData );
528 : : ~ScDPResultDimension();
529 : :
530 : : // allocates new members
531 : : void InitFrom( const ::std::vector<ScDPDimension*>& ppDim,
532 : : const ::std::vector<ScDPLevel*>& ppLev,
533 : : size_t nPos,
534 : : ScDPInitState& rInitState , sal_Bool bInitChild = sal_True );
535 : : void LateInitFrom( LateInitParams& rParams,
536 : : const ::std::vector< SCROW >& pItemData,
537 : : size_t nPos,
538 : : ScDPInitState& rInitState );
539 : : void CheckShowEmpty( sal_Bool bShow = false );
540 : :
541 : : long GetSize(long nMeasure) const;
542 : :
543 : : bool IsValidEntry( const ::std::vector<SCROW>& aMembers ) const;
544 : :
545 : : // modifies existing members, allocates data dimensions
546 : : void ProcessData( const ::std::vector<SCROW>& aMembers,
547 : : const ScDPResultDimension* pDataDim,
548 : : const ::std::vector<SCROW>& aDataMembers,
549 : : const ::std::vector<ScDPValueData>& aValues ) const; //! Test
550 : : void FillMemberResults( com::sun::star::uno::Sequence<
551 : : com::sun::star::sheet::MemberResult>* pSequences,
552 : : long nStart, long nMeasure );
553 : :
554 : : void FillDataResults( const ScDPResultMember* pRefMember,
555 : : com::sun::star::uno::Sequence<
556 : : com::sun::star::uno::Sequence<
557 : : com::sun::star::sheet::DataResult> >& rSequence,
558 : : long nRow, long nMeasure ) const;
559 : :
560 : : void UpdateDataResults( const ScDPResultMember* pRefMember, long nMeasure ) const;
561 : : void UpdateRunningTotals( const ScDPResultMember* pRefMember, long nMeasure,
562 : : ScDPRunningTotalState& rRunning, ScDPRowTotals& rTotals ) const;
563 : :
564 : : void SortMembers( ScDPResultMember* pRefMember );
565 : : long GetSortedIndex( long nUnsorted ) const;
566 : :
567 : : void DoAutoShow( ScDPResultMember* pRefMember );
568 : :
569 : : void ResetResults();
570 : :
571 : : // called for the reference dimension
572 : : ScDPDataMember* GetRowReferenceMember( const ScDPRelativePos* pMemberPos, const String* pName,
573 : : const long* pRowIndexes, const long* pColIndexes ) const;
574 : :
575 : : // uses row root member from ScDPRunningTotalState
576 : : static ScDPDataMember* GetColReferenceMember( const ScDPRelativePos* pMemberPos, const String* pName,
577 : : long nRefDimPos, const ScDPRunningTotalState& rRunning );
578 : :
579 : : void DumpState( const ScDPResultMember* pRefMember, ScDocument* pDoc, ScAddress& rPos ) const;
580 : :
581 : : // for ScDPDataDimension::InitFrom
582 : : long GetMemberCount() const;
583 : : const ScDPResultMember* GetMember(long n) const;
584 : : ScDPResultMember* GetMember(long n);
585 : :
586 : 2824 : const ScMemberSortOrder& GetMemberOrder() const { return aMemberOrder; }
587 : 0 : ScMemberSortOrder& GetMemberOrder() { return aMemberOrder; }
588 : :
589 : 2442 : sal_Bool IsDataLayout() const { return bIsDataLayout; }
590 : 6320 : String GetName() const { return aDimensionName; }
591 : :
592 : 104 : sal_Bool IsSortByData() const { return bSortByData; }
593 : 0 : sal_Bool IsSortAscending() const { return bSortAscending; }
594 : 0 : long GetSortMeasure() const { return nSortMeasure; }
595 : :
596 : 2 : sal_Bool IsAutoShow() const { return bAutoShow; }
597 : 0 : sal_Bool IsAutoTopItems() const { return bAutoTopItems; }
598 : 0 : long GetAutoMeasure() const { return nAutoMeasure; }
599 : 2 : long GetAutoCount() const { return nAutoCount; }
600 : :
601 : : ScDPResultDimension* GetFirstChildDimension() const;
602 : :
603 : : void FillVisibilityData(ScDPResultVisibilityData& rData) const;
604 : : };
605 : :
606 : : class ScDPDataDimension
607 : : {
608 : : private:
609 : : const ScDPResultData* pResultData;
610 : : const ScDPResultDimension* pResultDimension; // column
611 : : ScDPDataMembers maMembers;
612 : : sal_Bool bIsDataLayout; //! or ptr to IntDimension?
613 : :
614 : : public:
615 : : ScDPDataDimension( const ScDPResultData* pData );
616 : : ~ScDPDataDimension();
617 : :
618 : : void InitFrom( const ScDPResultDimension* pDim ); // recursive
619 : : void ProcessData( const ::std::vector< SCROW >& aDataMembers, const ::std::vector<ScDPValueData>& aValues,
620 : : const ScDPSubTotalState& rSubState );
621 : : void FillDataRow( const ScDPResultDimension* pRefDim,
622 : : com::sun::star::uno::Sequence<com::sun::star::sheet::DataResult>& rSequence,
623 : : long nCol, long nMeasure, sal_Bool bIsSubTotalRow,
624 : : const ScDPSubTotalState& rSubState ) const;
625 : :
626 : : void UpdateDataRow( const ScDPResultDimension* pRefDim, long nMeasure, sal_Bool bIsSubTotalRow,
627 : : const ScDPSubTotalState& rSubState ) const;
628 : : void UpdateRunningTotals( const ScDPResultDimension* pRefDim, long nMeasure, sal_Bool bIsSubTotalRow,
629 : : const ScDPSubTotalState& rSubState, ScDPRunningTotalState& rRunning,
630 : : ScDPRowTotals& rTotals, const ScDPResultMember& rRowParent ) const;
631 : :
632 : : void SortMembers( ScDPResultDimension* pRefDim );
633 : : long GetSortedIndex( long nUnsorted ) const;
634 : :
635 : : void DoAutoShow( ScDPResultDimension* pRefDim );
636 : :
637 : : void ResetResults();
638 : :
639 : : void DumpState( const ScDPResultDimension* pRefDim, ScDocument* pDoc, ScAddress& rPos ) const;
640 : :
641 : : long GetMemberCount() const;
642 : : const ScDPDataMember* GetMember(long n) const;
643 : : ScDPDataMember* GetMember(long n);
644 : : };
645 : :
646 : : // ----------------------------------------------------------------------------
647 : :
648 : : /**
649 : : * This class collects visible members of each dimension and uses that
650 : : * information to create filtering criteria (e.g. for drill-down data).
651 : : */
652 : : class ScDPResultVisibilityData
653 : : {
654 : : public:
655 : : ScDPResultVisibilityData( ScDPSource* pSource);
656 : : ~ScDPResultVisibilityData();
657 : :
658 : : void addVisibleMember(const String& rDimName, const ScDPItemData& rMemberItem);
659 : : void fillFieldFilters(::std::vector<ScDPCacheTable::Criterion>& rFilters) const;
660 : :
661 : : private:
662 : : struct MemberHash
663 : : {
664 : : size_t operator()(const ScDPItemData& r) const;
665 : : };
666 : : typedef ::boost::unordered_set<ScDPItemData, MemberHash> VisibleMemberType;
667 : : typedef ::boost::unordered_map<String, VisibleMemberType, ScStringHashCode> DimMemberType;
668 : : DimMemberType maDimensions;
669 : :
670 : : ScDPSource* mpSource;
671 : : };
672 : :
673 : : #endif
674 : :
675 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|