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