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 <map>
32 : #include <unordered_map>
33 : #include <unordered_set>
34 : #include <vector>
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 182 : 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 79 : 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 2721 : ScDPSubTotalState() :
91 : eColForce( SUBTOTAL_FUNC_NONE ),
92 : eRowForce( SUBTOTAL_FUNC_NONE ),
93 : nColSubTotalFunc( -1 ),
94 2721 : nRowSubTotalFunc( -1 )
95 2721 : {}
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 91 : 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 20 : ScDPResultMember* GetRowResRoot() const { return pRowResRoot; }
116 :
117 20 : const IndexArray& GetColVisible() const { return maColVisible;}
118 20 : const IndexArray& GetColSorted() const { return maColSorted;}
119 20 : const IndexArray& GetRowVisible() const { return maRowVisible;}
120 20 : 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 4343 : ScDPAggData() : fVal(0.0), fAux(0.0), nCount(SC_DPAGG_EMPTY), pChild(NULL) {}
166 4267 : ~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 87 : 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 10 : bool IsInColRoot() const { return bIsInColRoot; }
209 490 : 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 1552 : 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::unordered_map < SCROW, ScDPParentDimData *, MemberHashIndexFunc> DimMemberHash;
238 :
239 : class ResultMembers
240 : {
241 : DimMemberHash maMemberHash;
242 : bool mbHasHideDetailsMember;
243 : public:
244 : ScDPParentDimData* FindMember( SCROW nIndex ) const;
245 : void InsertMember( ScDPParentDimData* pNew );
246 747 : bool IsHasHideDetailsMembers() const { return mbHasHideDetailsMember; }
247 747 : void SetHasHideDetailsMembers( bool b ) { mbHasHideDetailsMember = b; }
248 : ResultMembers();
249 : virtual ~ResultMembers();
250 : };
251 :
252 : class LateInitParams
253 : {
254 : private:
255 : const ::std::vector<ScDPDimension*>& mppDim;
256 : const ::std::vector<ScDPLevel*>& mppLev;
257 :
258 : bool mbRow:1;
259 : bool mbInitChild:1;
260 : bool mbAllChildren:1;
261 : public:
262 : LateInitParams( const ::std::vector<ScDPDimension*>& ppDim, const ::std::vector<ScDPLevel*>& ppLev,
263 : bool bRow, bool bInitChild = true, bool bAllChildren = false);
264 : ~LateInitParams();
265 :
266 982 : void SetInitChild( bool b ) { mbInitChild = b; }
267 1098 : void SetInitAllChildren( bool b ) { mbAllChildren = b; }
268 :
269 918 : inline ScDPDimension* GetDim( size_t nPos ) const { return mppDim[nPos];}
270 918 : inline ScDPLevel* GetLevel( size_t nPos ) const { return mppLev[nPos];}
271 :
272 805 : bool GetInitChild() const {return mbInitChild; }
273 747 : bool GetInitAllChild() const { return mbAllChildren; }
274 805 : bool IsRow() const { return mbRow; }
275 : bool IsEnd( size_t nPos ) const ;
276 : };
277 :
278 : /**
279 : * The term 'measure' here roughly equals "data dimension" ?
280 : */
281 : class ScDPResultData
282 : {
283 : ScDPSource& mrSource;
284 : //! keep things like measure lists here
285 :
286 : std::vector<ScSubTotalFunc> maMeasureFuncs;
287 : std::vector<com::sun::star::sheet::DataPilotFieldReference> maMeasureRefs;
288 : std::vector<sal_uInt16> maMeasureRefOrients;
289 : std::vector<OUString> maMeasureNames;
290 :
291 : bool bLateInit:1;
292 : bool bDataAtCol:1;
293 : bool bDataAtRow:1;
294 :
295 : //! add "displayed values" settings
296 : mutable std::vector<ResultMembers*> maDimMembers;
297 : public:
298 : ScDPResultData( ScDPSource& rSrc );
299 : ~ScDPResultData();
300 :
301 : void SetMeasureData(
302 : std::vector<ScSubTotalFunc>& rFunctions,
303 : std::vector<com::sun::star::sheet::DataPilotFieldReference>& rRefs,
304 : std::vector<sal_uInt16>& rRefOrient, std::vector<OUString>& rNames );
305 :
306 : void SetDataLayoutOrientation( sal_uInt16 nOrient );
307 : void SetLateInit( bool bSet );
308 :
309 96 : long GetMeasureCount() const { return maMeasureFuncs.size(); }
310 : ScSubTotalFunc GetMeasureFunction(long nMeasure) const;
311 : OUString GetMeasureString(long nMeasure, bool bForce, ScSubTotalFunc eForceFunc, bool& rbTotalResult) const;
312 : OUString GetMeasureDimensionName(long nMeasure) const;
313 : const ::com::sun::star::sheet::DataPilotFieldReference& GetMeasureRefVal(long nMeasure) const;
314 : sal_uInt16 GetMeasureRefOrient(long nMeasure) const;
315 :
316 : bool IsDataAtCol() const { return bDataAtCol; }
317 : bool IsDataAtRow() const { return bDataAtRow; }
318 5325 : bool IsLateInit() const { return bLateInit; }
319 :
320 : long GetColStartMeasure() const;
321 : long GetRowStartMeasure() const;
322 :
323 6629 : long GetCountForMeasure( long nMeas ) const { return (nMeas == SC_DPMEASURE_ALL) ? maMeasureFuncs.size() : 1; }
324 :
325 : bool IsBaseForGroup( long nDim ) const; // any group
326 : long GetGroupBase( long nGroupDim ) const;
327 : bool IsNumOrDateGroup( long nDim ) const;
328 : bool IsInGroup( SCROW nGroupDataId, long nGroupIndex,
329 : const ScDPItemData& rBaseData, long nBaseIndex ) const;
330 : bool HasCommonElement( SCROW nFirstDataId, long nFirstIndex,
331 : const ScDPItemData& rSecondData, long nSecondIndex ) const;
332 :
333 : ResultMembers* GetDimResultMembers(long nDim, ScDPDimension* pDim, ScDPLevel* pLevel) const;
334 :
335 2297 : const ScDPSource& GetSource() const { return mrSource;}
336 : };
337 :
338 : class ScDPResultMember
339 : {
340 : private:
341 : const ScDPResultData* pResultData;
342 : ScDPParentDimData aParentDimData;
343 : ScDPResultDimension* pChildDimension;
344 : ScDPDataMember* pDataRoot;
345 : bool bHasElements:1;
346 : bool bForceSubTotal:1;
347 : bool bHasHiddenDetails:1;
348 : bool bInitialized:1;
349 : bool bAutoHidden:1;
350 : ScDPAggData aColTotal; // to store column totals
351 :
352 : sal_uInt16 nMemberStep; // step to show details
353 : public:
354 : ScDPResultMember(
355 : const ScDPResultData* pData, const ScDPParentDimData& rParentDimData, bool bForceSub ); //! Ref
356 : ScDPResultMember( const ScDPResultData* pData, bool bForceSub );
357 : ~ScDPResultMember();
358 :
359 : void InitFrom( const ::std::vector<ScDPDimension*>& ppDim,
360 : const ::std::vector<ScDPLevel*>& ppLev,
361 : size_t nPos,
362 : ScDPInitState& rInitState,
363 : bool bInitChild = true );
364 : void LateInitFrom(
365 : LateInitParams& rParams,
366 : const ::std::vector< SCROW >& pItemData,
367 : size_t nPos,
368 : ScDPInitState& rInitState);
369 : void CheckShowEmpty( bool bShow = false );
370 : OUString GetName() const;
371 : OUString GetDisplayName() const;
372 :
373 : void FillItemData( ScDPItemData& rData ) const;
374 : bool IsValid() const;
375 : bool IsVisible() const;
376 : long GetSize(long nMeasure) const;
377 : // bHasHiddenDetails is set only if the "show details" flag is off,
378 : // and there was a child dimension to skip
379 4 : bool HasHiddenDetails() const { return bHasHiddenDetails; }
380 : bool IsSubTotalInTitle(long nMeasure) const;
381 :
382 : long GetSubTotalCount( long* pUserSubStart = NULL ) const;
383 :
384 : bool IsNamedItem( SCROW nIndex ) const;
385 : bool IsValidEntry( const ::std::vector< SCROW >& aMembers ) const;
386 :
387 1498 : void SetHasElements() { bHasElements = true; }
388 0 : void SetAutoHidden() { bAutoHidden = true; }
389 :
390 : void ProcessData( const ::std::vector<SCROW>& aChildMembers,
391 : const ScDPResultDimension* pDataDim,
392 : const ::std::vector<SCROW>& aDataMembers,
393 : const ::std::vector<ScDPValue>& aValues );
394 : void FillMemberResults(
395 : com::sun::star::uno::Sequence<
396 : com::sun::star::sheet::MemberResult>* pSequences,
397 : long& rPos, long nMeasure, bool bRoot, const OUString* pMemberName, const OUString* pMemberCaption );
398 :
399 : void FillDataResults(
400 : const ScDPResultMember* pRefMember, ScDPResultFilterContext& rFilterCxt,
401 : com::sun::star::uno::Sequence<
402 : com::sun::star::uno::Sequence<
403 : com::sun::star::sheet::DataResult> >& rSequence,
404 : long nMeasure) const;
405 :
406 : void UpdateDataResults( const ScDPResultMember* pRefMember, long nMeasure ) const;
407 : void UpdateRunningTotals( const ScDPResultMember* pRefMember, long nMeasure,
408 : ScDPRunningTotalState& rRunning, ScDPRowTotals& rTotals ) const;
409 :
410 : void SortMembers( ScDPResultMember* pRefMember );
411 : void DoAutoShow( ScDPResultMember* pRefMember );
412 :
413 : void ResetResults();
414 :
415 : #if DEBUG_PIVOT_TABLE
416 : void DumpState( const ScDPResultMember* pRefMember, ScDocument* pDoc, ScAddress& rPos ) const;
417 :
418 : void Dump(int nIndent) const;
419 : #endif
420 :
421 : //! this will be removed!
422 6640 : const ScDPResultDimension* GetChildDimension() const { return pChildDimension; }
423 4017 : ScDPResultDimension* GetChildDimension() { return pChildDimension; }
424 :
425 16 : ScDPDataMember* GetDataRoot() const { return pDataRoot; }
426 :
427 709 : const ScDPDimension* GetParentDim() const { return aParentDimData.mpParentDim; } //! Ref
428 22861 : const ScDPLevel* GetParentLevel() const { return aParentDimData.mpParentLevel; } //! Ref
429 32277 : const ScDPMember* GetDPMember()const { return aParentDimData.mpMemberDesc; } //! Ref
430 38 : SCROW GetOrder() const { return aParentDimData.mnOrder; } //! Ref
431 978 : bool IsRoot() const { return GetParentLevel() == NULL; }
432 : SCROW GetDataId( ) const ;
433 : ScDPAggData* GetColTotal( long nMeasure ) const;
434 :
435 : void FillVisibilityData(ScDPResultVisibilityData& rData) const;
436 : };
437 :
438 : class ScDPDataMember
439 : {
440 : private:
441 : const ScDPResultData* pResultData;
442 : const ScDPResultMember* pResultMember; //! Ref?
443 : ScDPDataDimension* pChildDimension;
444 : ScDPAggData aAggregate;
445 :
446 : void UpdateValues( const ::std::vector<ScDPValue>& aValues, const ScDPSubTotalState& rSubState );
447 :
448 : public:
449 : ScDPDataMember( const ScDPResultData* pData, const ScDPResultMember* pRes );
450 : ~ScDPDataMember();
451 :
452 : void InitFrom( const ScDPResultDimension* pDim );
453 :
454 : OUString GetName() const;
455 : bool IsVisible() const;
456 : bool HasData( long nMeasure, const ScDPSubTotalState& rSubState ) const;
457 :
458 : bool IsNamedItem( SCROW nRow ) const;
459 : bool HasHiddenDetails() const;
460 :
461 : void ProcessData( const ::std::vector< SCROW >& aChildMembers, const ::std::vector<ScDPValue>& aValues,
462 : const ScDPSubTotalState& rSubState );
463 : bool HasError( long nMeasure, const ScDPSubTotalState& rSubState ) const;
464 : double GetAggregate( long nMeasure, const ScDPSubTotalState& rSubState ) const;
465 : const ScDPAggData* GetConstAggData( long nMeasure, const ScDPSubTotalState& rSubState ) const;
466 : ScDPAggData* GetAggData( long nMeasure, const ScDPSubTotalState& rSubState );
467 :
468 : void FillDataRow(
469 : const ScDPResultMember* pRefMember,
470 : ScDPResultFilterContext& rFilterCxt,
471 : com::sun::star::uno::Sequence<com::sun::star::sheet::DataResult>& rSequence,
472 : long nMeasure, bool bIsSubTotalRow,
473 : const ScDPSubTotalState& rSubState) const;
474 :
475 : void UpdateDataRow( const ScDPResultMember* pRefMember, long nMeasure, bool bIsSubTotalRow,
476 : const ScDPSubTotalState& rSubState );
477 : void UpdateRunningTotals( const ScDPResultMember* pRefMember, long nMeasure, 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 : #if DEBUG_PIVOT_TABLE
487 : void DumpState( const ScDPResultMember* pRefMember, ScDocument* pDoc, ScAddress& rPos ) const;
488 : void Dump(int nIndent) const;
489 : #endif
490 :
491 : //! this will be removed!
492 1531 : const ScDPDataDimension* GetChildDimension() const { return pChildDimension; }
493 4034 : ScDPDataDimension* GetChildDimension() { return pChildDimension; }
494 : };
495 :
496 : typedef std::vector<ScDPDataMember*> ScDPDataMembers;
497 :
498 : // result dimension contains only members
499 :
500 : class ScDPResultDimension
501 : {
502 : public:
503 : typedef std::vector<ScDPResultMember*> MemberArray;
504 : typedef std::map<SCROW, ScDPResultMember*> MemberHash;
505 : private:
506 : const ScDPResultData* pResultData;
507 : MemberArray maMemberArray;
508 : MemberHash maMemberHash;
509 : OUString aDimensionName; //! or ptr to IntDimension?
510 : long nSortMeasure;
511 : ScMemberSortOrder aMemberOrder; // used when sorted by measure
512 : bool bIsDataLayout:1; //! or ptr to IntDimension?
513 : bool bSortByData:1;
514 : bool bSortAscending:1;
515 : bool bAutoShow:1;
516 : bool bAutoTopItems:1;
517 : bool bInitialized:1;
518 : long nAutoMeasure;
519 : long nAutoCount;
520 :
521 : ScDPResultMember* FindMember( SCROW iData ) const;
522 : ScDPResultMember* AddMember( const ScDPParentDimData& aData );
523 : ScDPResultMember* InsertMember( ScDPParentDimData* pMemberData );
524 : void InitWithMembers( LateInitParams& rParams,
525 : const ::std::vector< SCROW >& pItemData,
526 : size_t nPos,
527 : ScDPInitState& rInitState );
528 : public:
529 : ScDPResultDimension( const ScDPResultData* pData );
530 : ~ScDPResultDimension();
531 :
532 : // allocates new members
533 : void InitFrom(
534 : const ::std::vector<ScDPDimension*>& ppDim, const ::std::vector<ScDPLevel*>& ppLev,
535 : size_t nPos, ScDPInitState& rInitState, bool bInitChild = true );
536 : void LateInitFrom( LateInitParams& rParams,
537 : const ::std::vector< SCROW >& pItemData,
538 : size_t nPos,
539 : ScDPInitState& rInitState );
540 : void CheckShowEmpty( bool bShow = false );
541 :
542 : long GetSize(long nMeasure) const;
543 :
544 : bool IsValidEntry( const ::std::vector<SCROW>& aMembers ) const;
545 :
546 : // modifies existing members, allocates data dimensions
547 : void ProcessData( const ::std::vector<SCROW>& aMembers,
548 : const ScDPResultDimension* pDataDim,
549 : const ::std::vector<SCROW>& aDataMembers,
550 : const ::std::vector<ScDPValue>& aValues ) const; //! Test
551 : void FillMemberResults( com::sun::star::uno::Sequence<
552 : com::sun::star::sheet::MemberResult>* pSequences,
553 : long nStart, long nMeasure );
554 :
555 : void FillDataResults(
556 : const ScDPResultMember* pRefMember,
557 : ScDPResultFilterContext& rFilterCxt,
558 : com::sun::star::uno::Sequence<
559 : com::sun::star::uno::Sequence<
560 : com::sun::star::sheet::DataResult> >& rSequence,
561 : long nMeasure) const;
562 :
563 : void UpdateDataResults( const ScDPResultMember* pRefMember, long nMeasure ) const;
564 : void UpdateRunningTotals( const ScDPResultMember* pRefMember, long nMeasure,
565 : ScDPRunningTotalState& rRunning, ScDPRowTotals& rTotals ) const;
566 :
567 : void SortMembers( ScDPResultMember* pRefMember );
568 : long GetSortedIndex( long nUnsorted ) const;
569 :
570 : void DoAutoShow( ScDPResultMember* pRefMember );
571 :
572 : void ResetResults();
573 :
574 : // called for the reference dimension
575 : ScDPDataMember* GetRowReferenceMember(
576 : const ScDPRelativePos* pMemberPos, const OUString* pName,
577 : const long* pRowIndexes, const long* pColIndexes ) const;
578 :
579 : // uses row root member from ScDPRunningTotalState
580 : static ScDPDataMember* GetColReferenceMember(
581 : const ScDPRelativePos* pMemberPos, const OUString* pName,
582 : long nRefDimPos, const ScDPRunningTotalState& rRunning );
583 :
584 : #if DEBUG_PIVOT_TABLE
585 : void DumpState( const ScDPResultMember* pRefMember, ScDocument* pDoc, ScAddress& rPos ) const;
586 : void Dump(int nIndent) const;
587 : #endif
588 :
589 : // for ScDPDataDimension::InitFrom
590 : long GetMemberCount() const;
591 : const ScDPResultMember* GetMember(long n) const;
592 : ScDPResultMember* GetMember(long n);
593 :
594 1701 : const ScMemberSortOrder& GetMemberOrder() const { return aMemberOrder; }
595 0 : ScMemberSortOrder& GetMemberOrder() { return aMemberOrder; }
596 :
597 2211 : bool IsDataLayout() const { return bIsDataLayout; }
598 5760 : const OUString& GetName() const { return aDimensionName; }
599 :
600 62 : bool IsSortByData() const { return bSortByData; }
601 0 : bool IsSortAscending() const { return bSortAscending; }
602 0 : long GetSortMeasure() const { return nSortMeasure; }
603 :
604 1 : bool IsAutoShow() const { return bAutoShow; }
605 0 : bool IsAutoTopItems() const { return bAutoTopItems; }
606 0 : long GetAutoMeasure() const { return nAutoMeasure; }
607 1 : long GetAutoCount() const { return nAutoCount; }
608 :
609 : ScDPResultDimension* GetFirstChildDimension() const;
610 :
611 : void FillVisibilityData(ScDPResultVisibilityData& rData) const;
612 : };
613 :
614 : class ScDPDataDimension
615 : {
616 : private:
617 : const ScDPResultData* pResultData;
618 : const ScDPResultDimension* pResultDimension; // column
619 : ScDPDataMembers maMembers;
620 : bool bIsDataLayout; //! or ptr to IntDimension?
621 :
622 : public:
623 : ScDPDataDimension( const ScDPResultData* pData );
624 : ~ScDPDataDimension();
625 :
626 : void InitFrom( const ScDPResultDimension* pDim ); // recursive
627 : void ProcessData( const ::std::vector< SCROW >& aDataMembers, const ::std::vector<ScDPValue>& aValues,
628 : const ScDPSubTotalState& rSubState );
629 : void FillDataRow(
630 : const ScDPResultDimension* pRefDim,
631 : ScDPResultFilterContext& rFilterCxt,
632 : com::sun::star::uno::Sequence<com::sun::star::sheet::DataResult>& rSequence,
633 : long nMeasure, bool bIsSubTotalRow, const ScDPSubTotalState& rSubState) const;
634 :
635 : void UpdateDataRow( const ScDPResultDimension* pRefDim, long nMeasure, bool bIsSubTotalRow,
636 : const ScDPSubTotalState& rSubState ) const;
637 : void UpdateRunningTotals( const ScDPResultDimension* pRefDim, long nMeasure, bool bIsSubTotalRow,
638 : const ScDPSubTotalState& rSubState, ScDPRunningTotalState& rRunning,
639 : ScDPRowTotals& rTotals, const ScDPResultMember& rRowParent ) const;
640 :
641 : void SortMembers( ScDPResultDimension* pRefDim );
642 : long GetSortedIndex( long nUnsorted ) const;
643 :
644 : void DoAutoShow( ScDPResultDimension* pRefDim );
645 :
646 : void ResetResults();
647 :
648 : #if DEBUG_PIVOT_TABLE
649 : void DumpState( const ScDPResultDimension* pRefDim, ScDocument* pDoc, ScAddress& rPos ) const;
650 : void Dump(int nIndent) const;
651 : #endif
652 :
653 : long GetMemberCount() const;
654 : const ScDPDataMember* GetMember(long n) const;
655 : ScDPDataMember* GetMember(long n);
656 : };
657 :
658 : /**
659 : * This class collects visible members of each dimension and uses that
660 : * information to create filtering criteria (e.g. for drill-down data).
661 : */
662 : class ScDPResultVisibilityData
663 : {
664 : public:
665 : ScDPResultVisibilityData( ScDPSource* pSource);
666 : ~ScDPResultVisibilityData();
667 :
668 : void addVisibleMember(const OUString& rDimName, const ScDPItemData& rMemberItem);
669 : void fillFieldFilters(::std::vector<ScDPFilteredCache::Criterion>& rFilters) const;
670 :
671 : private:
672 : struct MemberHash
673 : {
674 : size_t operator()(const ScDPItemData& r) const;
675 : };
676 : typedef std::unordered_set<ScDPItemData, MemberHash> VisibleMemberType;
677 : typedef std::unordered_map<OUString, VisibleMemberType, OUStringHash> DimMemberType;
678 : DimMemberType maDimensions;
679 :
680 : ScDPSource* mpSource;
681 : };
682 :
683 : #endif
684 :
685 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|