build fix
[LibreOffice.git] / sc / inc / dptabdat.hxx
blob0f8a0f0e0da68fb0cb243a26210ee011a3a7fb18
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 "address.hxx"
24 #include "dpoutput.hxx"
25 #include "dpfilteredcache.hxx"
26 #include "dpcache.hxx"
27 #include "calcmacros.hxx"
29 #include <svl/zforlist.hxx>
31 #include <set>
32 #include <unordered_set>
33 #include <unordered_map>
34 #include <vector>
36 namespace com { namespace sun { namespace star { namespace sheet {
37 struct DataPilotFieldFilter;
38 }}}}
40 #define SC_DAPI_HIERARCHY_FLAT 0
41 #define SC_DAPI_HIERARCHY_QUARTER 1
42 #define SC_DAPI_HIERARCHY_WEEK 2
44 #define SC_DAPI_FLAT_LEVELS 1 // single level for flat dates
45 #define SC_DAPI_QUARTER_LEVELS 4 // levels in year/quarter/month/day hierarchy
46 #define SC_DAPI_WEEK_LEVELS 3 // levels in year/week/day hierarchy
48 #define SC_DAPI_LEVEL_YEAR 0
49 #define SC_DAPI_LEVEL_QUARTER 1
50 #define SC_DAPI_LEVEL_MONTH 2
51 #define SC_DAPI_LEVEL_DAY 3
52 #define SC_DAPI_LEVEL_WEEK 4
53 #define SC_DAPI_LEVEL_WEEKDAY 5
55 class ScDPResultMember;
56 class ScDPDimension;
57 class ScDPLevel;
58 class ScDPInitState;
59 class ScDPResultMember;
60 class ScDocument;
62 /**
63 * Base class that abstracts different data source types of a datapilot
64 * table.
66 class SC_DLLPUBLIC ScDPTableData
68 // cached data for GetDatePart
69 long nLastDateVal;
70 long nLastHier;
71 long nLastLevel;
72 long nLastRet;
73 const ScDocument* mpDoc;
74 public:
76 /** This structure stores dimension information used when calculating
77 results. These data are read only during result calculation, so it
78 should be passed as a const instance. */
79 struct CalcInfo
81 ::std::vector<long> aColLevelDims;
82 ::std::vector<ScDPDimension*> aColDims;
83 ::std::vector<ScDPLevel*> aColLevels;
84 ::std::vector<long> aRowLevelDims;
85 ::std::vector<ScDPDimension*> aRowDims;
86 ::std::vector<ScDPLevel*> aRowLevels;
87 ::std::vector<long> aPageDims;
88 ::std::vector<long> aDataSrcCols;
90 ScDPInitState* pInitState;
91 ScDPResultMember* pColRoot;
92 ScDPResultMember* pRowRoot;
94 CalcInfo();
97 ScDPTableData(const ScDPTableData&) = delete;
98 const ScDPTableData& operator=(const ScDPTableData&) = delete;
99 ScDPTableData(ScDocument* pDoc);
100 virtual ~ScDPTableData();
102 OUString GetFormattedString(long nDim, const ScDPItemData& rItem, bool bLocaleIndependent) const;
104 long GetDatePart( long nDateVal, long nHierarchy, long nLevel );
106 //! use (new) typed collection instead of ScStrCollection
107 //! or separate Str and ValueCollection
109 virtual long GetColumnCount() = 0;
110 virtual const std::vector< SCROW >& GetColumnEntries( long nColumn ) ;
111 virtual OUString getDimensionName(long nColumn) = 0;
112 virtual bool getIsDataLayoutDimension(long nColumn) = 0;
113 virtual bool IsDateDimension(long nDim) = 0;
114 virtual sal_uLong GetNumberFormat(long nDim);
115 sal_uInt32 GetNumberFormatByIdx( NfIndexTableOffset );
116 virtual void DisposeData() = 0;
117 virtual void SetEmptyFlags( bool bIgnoreEmptyRows, bool bRepeatIfEmpty ) = 0;
119 virtual bool IsRepeatIfEmpty();
121 virtual void CreateCacheTable() = 0;
122 virtual void FilterCacheTable(const std::vector<ScDPFilteredCache::Criterion>& rCriteria, const std::unordered_set<sal_Int32>& rDataDims) = 0;
123 virtual void GetDrillDownData(const std::vector<ScDPFilteredCache::Criterion>& rCriteria,
124 const std::unordered_set<sal_Int32>& rCatDims,
125 css::uno::Sequence< css::uno::Sequence< css::uno::Any > >& rData) = 0;
126 virtual void CalcResults(CalcInfo& rInfo, bool bAutoShow) = 0;
127 virtual const ScDPFilteredCache& GetCacheTable() const = 0;
128 virtual void ReloadCacheTable() = 0;
130 // override in ScDPGroupTableData:
131 virtual bool IsBaseForGroup(long nDim) const;
132 virtual long GetGroupBase(long nGroupDim) const;
133 virtual bool IsNumOrDateGroup(long nDim) const;
134 virtual bool IsInGroup( const ScDPItemData& rGroupData, long nGroupIndex,
135 const ScDPItemData& rBaseData, long nBaseIndex ) const;
136 virtual bool HasCommonElement( const ScDPItemData& rFirstData, long nFirstIndex,
137 const ScDPItemData& rSecondData, long nSecondIndex ) const;
139 virtual long GetMembersCount( long nDim );
140 const ScDPItemData* GetMemberByIndex( long nDim, long nIndex );
141 virtual const ScDPItemData* GetMemberById( long nDim, long nId);
142 virtual long GetSourceDim( long nDim );
143 virtual long Compare( long nDim, long nDataId1, long nDataId2);
145 #if DUMP_PIVOT_TABLE
146 virtual void Dump() const;
147 #endif
149 protected:
150 /** This structure stores vector arrays that hold intermediate data for
151 each row during cache table iteration. */
152 struct CalcRowData
154 ::std::vector< SCROW > aColData;
155 ::std::vector< SCROW > aRowData;
156 ::std::vector< SCROW > aPageData;
157 ::std::vector<ScDPValue> aValues;
160 void FillRowDataFromCacheTable(sal_Int32 nRow, const ScDPFilteredCache& rCacheTable, const CalcInfo& rInfo, CalcRowData& rData);
161 static void ProcessRowData(CalcInfo& rInfo, const CalcRowData& rData, bool bAutoShow);
162 void CalcResultsFromCacheTable(const ScDPFilteredCache& rCacheTable, CalcInfo& rInfo, bool bAutoShow);
164 private:
165 void GetItemData(const ScDPFilteredCache& rCacheTable, sal_Int32 nRow,
166 const ::std::vector<long>& rDims, ::std::vector< SCROW >& rItemData);
168 #endif
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */