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