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