Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sc / inc / dptabdat.hxx
blob7b7acd022860c72b9706ddef70a7bef2dba98c28
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SC_INC_DPTABDAT_HXX
21 #define INCLUDED_SC_INC_DPTABDAT_HXX
23 #include "dpoutput.hxx"
24 #include "dpfilteredcache.hxx"
25 #include "dpcache.hxx"
26 #include "calcmacros.hxx"
28 #include <svl/zforlist.hxx>
30 #include <unordered_set>
31 #include <vector>
33 namespace com { namespace sun { namespace star { namespace sheet {
34 struct DataPilotFieldFilter;
35 }}}}
37 #define SC_DAPI_HIERARCHY_FLAT 0
38 #define SC_DAPI_HIERARCHY_QUARTER 1
39 #define SC_DAPI_HIERARCHY_WEEK 2
41 #define SC_DAPI_FLAT_LEVELS 1 // single level for flat dates
42 #define SC_DAPI_QUARTER_LEVELS 4 // levels in year/quarter/month/day hierarchy
43 #define SC_DAPI_WEEK_LEVELS 3 // levels in year/week/day hierarchy
45 #define SC_DAPI_LEVEL_YEAR 0
46 #define SC_DAPI_LEVEL_QUARTER 1
47 #define SC_DAPI_LEVEL_MONTH 2
48 #define SC_DAPI_LEVEL_DAY 3
49 #define SC_DAPI_LEVEL_WEEK 4
50 #define SC_DAPI_LEVEL_WEEKDAY 5
52 class ScDPResultMember;
53 class ScDPDimension;
54 class ScDPLevel;
55 class ScDPInitState;
56 class ScDocument;
58 /**
59 * Base class that abstracts different data source types of a datapilot
60 * table.
62 class SC_DLLPUBLIC ScDPTableData
64 // cached data for GetDatePart
65 long nLastDateVal;
66 long nLastHier;
67 long nLastLevel;
68 long nLastRet;
69 const ScDocument* mpDoc;
70 public:
72 /** This structure stores dimension information used when calculating
73 results. These data are read only during result calculation, so it
74 should be passed as a const instance. */
75 struct CalcInfo
77 ::std::vector<long> aColLevelDims;
78 ::std::vector<ScDPDimension*> aColDims;
79 ::std::vector<ScDPLevel*> aColLevels;
80 ::std::vector<long> aRowLevelDims;
81 ::std::vector<ScDPDimension*> aRowDims;
82 ::std::vector<ScDPLevel*> aRowLevels;
83 ::std::vector<long> aPageDims;
84 ::std::vector<long> aDataSrcCols;
86 ScDPInitState* pInitState;
87 ScDPResultMember* pColRoot;
88 ScDPResultMember* pRowRoot;
90 CalcInfo();
93 ScDPTableData(const ScDPTableData&) = delete;
94 const ScDPTableData& operator=(const ScDPTableData&) = delete;
95 ScDPTableData(const ScDocument* pDoc);
96 virtual ~ScDPTableData();
98 OUString GetFormattedString(long nDim, const ScDPItemData& rItem, bool bLocaleIndependent) const;
100 long GetDatePart( long nDateVal, long nHierarchy, long nLevel );
102 //! use (new) typed collection instead of ScStrCollection
103 //! or separate Str and ValueCollection
105 virtual long GetColumnCount() = 0;
106 virtual const std::vector< SCROW >& GetColumnEntries( long nColumn ) ;
107 virtual OUString getDimensionName(long nColumn) = 0;
108 virtual bool getIsDataLayoutDimension(long nColumn) = 0;
109 virtual bool IsDateDimension(long nDim) = 0;
110 virtual sal_uInt32 GetNumberFormat(long nDim);
111 sal_uInt32 GetNumberFormatByIdx( NfIndexTableOffset );
112 virtual void DisposeData() = 0;
113 virtual void SetEmptyFlags( bool bIgnoreEmptyRows, bool bRepeatIfEmpty ) = 0;
115 virtual bool IsRepeatIfEmpty();
117 virtual void CreateCacheTable() = 0;
118 virtual void FilterCacheTable(const std::vector<ScDPFilteredCache::Criterion>& rCriteria, const std::unordered_set<sal_Int32>& rDataDims) = 0;
119 virtual void GetDrillDownData(const std::vector<ScDPFilteredCache::Criterion>& rCriteria,
120 const std::unordered_set<sal_Int32>& rCatDims,
121 css::uno::Sequence< css::uno::Sequence< css::uno::Any > >& rData) = 0;
122 virtual void CalcResults(CalcInfo& rInfo, bool bAutoShow) = 0;
123 virtual const ScDPFilteredCache& GetCacheTable() const = 0;
124 virtual void ReloadCacheTable() = 0;
126 // override in ScDPGroupTableData:
127 virtual bool IsBaseForGroup(long nDim) const;
128 virtual long GetGroupBase(long nGroupDim) const;
129 virtual bool IsNumOrDateGroup(long nDim) const;
130 virtual bool IsInGroup( const ScDPItemData& rGroupData, long nGroupIndex,
131 const ScDPItemData& rBaseData, long nBaseIndex ) const;
132 virtual bool HasCommonElement( const ScDPItemData& rFirstData, long nFirstIndex,
133 const ScDPItemData& rSecondData, long nSecondIndex ) const;
135 virtual long GetMembersCount( long nDim );
136 const ScDPItemData* GetMemberByIndex( long nDim, long nIndex );
137 virtual const ScDPItemData* GetMemberById( long nDim, long nId);
138 virtual long GetSourceDim( long nDim );
139 virtual long Compare( long nDim, long nDataId1, long nDataId2);
141 #if DUMP_PIVOT_TABLE
142 virtual void Dump() const;
143 #endif
145 protected:
146 /** This structure stores vector arrays that hold intermediate data for
147 each row during cache table iteration. */
148 struct CalcRowData
150 ::std::vector< SCROW > aColData;
151 ::std::vector< SCROW > aRowData;
152 ::std::vector< SCROW > aPageData;
153 ::std::vector<ScDPValue> aValues;
156 void FillRowDataFromCacheTable(sal_Int32 nRow, const ScDPFilteredCache& rCacheTable, const CalcInfo& rInfo, CalcRowData& rData);
157 static void ProcessRowData(CalcInfo& rInfo, const CalcRowData& rData, bool bAutoShow);
158 void CalcResultsFromCacheTable(const ScDPFilteredCache& rCacheTable, CalcInfo& rInfo, bool bAutoShow);
160 private:
161 void GetItemData(const ScDPFilteredCache& rCacheTable, sal_Int32 nRow,
162 const ::std::vector<long>& rDims, ::std::vector< SCROW >& rItemData);
164 #endif
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */