Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / inc / dptabdat.hxx
blob3239a80afa95e47261632fe582432594c62ba9a7
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 SC_DPTABDAT_HXX
21 #define SC_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 <vector>
32 #include <set>
33 #include <boost/unordered_set.hpp>
34 #include <boost/unordered_map.hpp>
35 #include <boost/noncopyable.hpp>
37 namespace com { namespace sun { namespace star { namespace sheet {
38 struct DataPilotFieldFilter;
39 }}}}
42 #define SC_DAPI_HIERARCHY_FLAT 0
43 #define SC_DAPI_HIERARCHY_QUARTER 1
44 #define SC_DAPI_HIERARCHY_WEEK 2
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
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
57 class ScDPResultMember;
58 class ScDPDimension;
59 class ScDPLevel;
60 class ScDPInitState;
61 class ScDPResultMember;
62 class ScDocument;
64 /**
65 * Base class that abstracts different data source types of a datapilot
66 * table.
68 class SC_DLLPUBLIC ScDPTableData : public ::boost::noncopyable
70 // cached data for GetDatePart
71 long nLastDateVal;
72 long nLastHier;
73 long nLastLevel;
74 long nLastRet;
75 const ScDocument* mpDoc;
76 public:
78 /** This structure stores dimension information used when calculating
79 results. These data are read only during result calculation, so it
80 should be passed as a const instance. */
81 struct CalcInfo
83 ::std::vector<long> aColLevelDims;
84 ::std::vector<ScDPDimension*> aColDims;
85 ::std::vector<ScDPLevel*> aColLevels;
86 ::std::vector<long> aRowLevelDims;
87 ::std::vector<ScDPDimension*> aRowDims;
88 ::std::vector<ScDPLevel*> aRowLevels;
89 ::std::vector<long> aPageDims;
90 ::std::vector<long> aDataSrcCols;
92 ScDPInitState* pInitState;
93 ScDPResultMember* pColRoot;
94 ScDPResultMember* pRowRoot;
96 bool bRepeatIfEmpty;
98 CalcInfo();
101 ScDPTableData(ScDocument* pDoc);
102 virtual ~ScDPTableData();
104 OUString GetFormattedString(long nDim, const ScDPItemData& rItem) const;
106 long GetDatePart( long nDateVal, long nHierarchy, long nLevel );
108 //! use (new) typed collection instead of ScStrCollection
109 //! or separate Str and ValueCollection
111 virtual long GetColumnCount() = 0;
112 virtual const std::vector< SCROW >& GetColumnEntries( long nColumn ) ;
113 virtual OUString getDimensionName(long nColumn) = 0;
114 virtual sal_Bool getIsDataLayoutDimension(long nColumn) = 0;
115 virtual sal_Bool IsDateDimension(long nDim) = 0;
116 virtual sal_uLong GetNumberFormat(long nDim);
117 virtual sal_uInt32 GetNumberFormatByIdx( NfIndexTableOffset );
118 virtual void DisposeData() = 0;
119 virtual void SetEmptyFlags( sal_Bool bIgnoreEmptyRows, sal_Bool bRepeatIfEmpty ) = 0;
121 virtual bool IsRepeatIfEmpty();
123 virtual void CreateCacheTable() = 0;
124 virtual void FilterCacheTable(const ::std::vector<ScDPFilteredCache::Criterion>& rCriteria, const ::boost::unordered_set<sal_Int32>& rDataDims) = 0;
125 virtual void GetDrillDownData(const ::std::vector<ScDPFilteredCache::Criterion>& rCriteria,
126 const ::boost::unordered_set<sal_Int32>& rCatDims,
127 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > >& rData) = 0;
128 virtual void CalcResults(CalcInfo& rInfo, bool bAutoShow) = 0;
129 virtual const ScDPFilteredCache& GetCacheTable() const = 0;
130 virtual void ReloadCacheTable() = 0;
132 // overloaded in ScDPGroupTableData:
133 virtual sal_Bool IsBaseForGroup(long nDim) const;
134 virtual long GetGroupBase(long nGroupDim) const;
135 virtual sal_Bool IsNumOrDateGroup(long nDim) const;
136 virtual sal_Bool IsInGroup( const ScDPItemData& rGroupData, long nGroupIndex,
137 const ScDPItemData& rBaseData, long nBaseIndex ) const;
138 virtual sal_Bool HasCommonElement( const ScDPItemData& rFirstData, long nFirstIndex,
139 const ScDPItemData& rSecondData, long nSecondIndex ) const;
141 virtual long GetMembersCount( long nDim );
142 virtual const ScDPItemData* GetMemberByIndex( long nDim, long nIndex );
143 virtual const ScDPItemData* GetMemberById( long nDim, long nId);
144 virtual long GetSourceDim( long nDim );
145 virtual long Compare( long nDim, long nDataId1, long nDataId2);
147 #if DEBUG_PIVOT_TABLE
148 virtual void Dump() const;
149 #endif
151 protected:
152 /** This structure stores vector arrays that hold intermediate data for
153 each row during cache table iteration. */
154 struct CalcRowData
156 ::std::vector< SCROW > aColData;
157 ::std::vector< SCROW > aRowData;
158 ::std::vector< SCROW > aPageData;
159 ::std::vector<ScDPValue> aValues;
162 void FillRowDataFromCacheTable(sal_Int32 nRow, const ScDPFilteredCache& rCacheTable, const CalcInfo& rInfo, CalcRowData& rData);
163 void ProcessRowData(CalcInfo& rInfo, const CalcRowData& rData, bool bAutoShow);
164 void CalcResultsFromCacheTable(const ScDPFilteredCache& rCacheTable, CalcInfo& rInfo, bool bAutoShow);
166 private:
167 void GetItemData(const ScDPFilteredCache& rCacheTable, sal_Int32 nRow,
168 const ::std::vector<long>& rDims, ::std::vector< SCROW >& rItemData);
170 #endif
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */