Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef SC_DPCACHETABLE_HXX
30 : : #define SC_DPCACHETABLE_HXX
31 : :
32 : : #include "sal/types.h"
33 : : #include "osl/mutex.hxx"
34 : : #include "global.hxx"
35 : : #include "dpitemdata.hxx"
36 : :
37 : : #include <vector>
38 : : #include <boost/unordered_set.hpp>
39 : : #include <boost/shared_ptr.hpp>
40 : : #include <com/sun/star/uno/Reference.hxx>
41 : :
42 : : namespace com { namespace sun { namespace star {
43 : : namespace sdbc {
44 : : class XRowSet;
45 : : }
46 : : namespace sheet {
47 : : struct DataPilotFieldFilter;
48 : : }
49 : : }}}
50 : :
51 : : class Date;
52 : : class ScDPItemData;
53 : : class ScDPCache;
54 : : class ScDocument;
55 : : class ScRange;
56 : : struct ScDPValueData;
57 : : struct ScQueryParam;
58 : :
59 : : /**
60 : : * Despite the name, this class is only a wrapper to the actual cache, to
61 : : * provide filtering on the raw data based on the query filter and/or page
62 : : * field filters. I will rename this class to a more appropriate name in the
63 : : * future.
64 : : */
65 : : class SC_DLLPUBLIC ScDPCacheTable
66 : : {
67 : : struct RowFlag
68 : : {
69 : : bool mbShowByFilter:1;
70 : : bool mbShowByPage:1;
71 : : bool isActive() const;
72 : : RowFlag();
73 : : };
74 : : public:
75 : :
76 : : /** interface class used for filtering of rows. */
77 : 1236 : class FilterBase
78 : : {
79 : : public:
80 [ - + ]: 1236 : virtual ~FilterBase() {}
81 : : /** returns true if the matching condition is met for a single cell
82 : : value, or false otherwise. */
83 : : virtual bool match( const ScDPItemData& rCellData ) const = 0;
84 : : };
85 : :
86 : : /** ordinary single-item filter. */
87 : : class SingleFilter : public FilterBase
88 : : {
89 : : public:
90 : : explicit SingleFilter(const ScDPItemData &rItem);
91 [ + - ][ - + ]: 1132 : virtual ~SingleFilter() {}
92 : :
93 : : virtual bool match(const ScDPItemData& rCellData) const;
94 : :
95 : : const ScDPItemData& getMatchValue() const;
96 : :
97 : : private:
98 : : explicit SingleFilter();
99 : :
100 : : ScDPItemData maItem;
101 : : };
102 : :
103 : : /** multi-item (group) filter. */
104 : : class GroupFilter : public FilterBase
105 : : {
106 : : public:
107 : : GroupFilter();
108 [ - + ]: 1340 : virtual ~GroupFilter() {}
109 : : virtual bool match(const ScDPItemData& rCellData) const;
110 : : void addMatchItem(const ScDPItemData& rItem);
111 : : size_t getMatchItemCount() const;
112 : :
113 : : private:
114 : : ::std::vector<ScDPItemData> maItems;
115 : : };
116 : :
117 : : /** single filtering criterion. */
118 : 3178 : struct Criterion
119 : : {
120 : : sal_Int32 mnFieldIndex;
121 : : ::boost::shared_ptr<FilterBase> mpFilter;
122 : :
123 : : Criterion();
124 : : };
125 : :
126 : : ScDPCacheTable(const ScDPCache* pCache);
127 : : ~ScDPCacheTable();
128 : :
129 : : sal_Int32 getRowSize() const;
130 : : sal_Int32 getColSize() const;
131 : :
132 : : const ScDPCache* getCache() const;
133 : :
134 : : /** Fill the internal table from the cell range provided. This function
135 : : assumes that the first row is the column header. */
136 : : void fillTable(const ScQueryParam& rQuery, bool bIgnoreEmptyRows, bool bRepeatIfEmpty);
137 : :
138 : : /** Fill the internal table from database connection object. This function
139 : : assumes that the first row is the column header. */
140 : : void fillTable();
141 : :
142 : : /** Check whether a specified row is active or not. When a row is active,
143 : : it is used in calculation of the results data. A row becomes inactive
144 : : when it is filtered out by page field. */
145 : : bool isRowActive(sal_Int32 nRow) const;
146 : :
147 : : /** Set filter on/off flag to each row to control visibility. The caller
148 : : must ensure that the table is filled before calling this function. */
149 : : void filterByPageDimension(const ::std::vector<Criterion>& rCriteria, const ::boost::unordered_set<sal_Int32>& rRepeatIfEmptyDims);
150 : :
151 : : /** Get the cell instance at specified location within the data grid. Note
152 : : that the data grid doesn't include the header row. Don't delete the
153 : : returned object! */
154 : : const ScDPItemData* getCell(SCCOL nCol, SCROW nRow, bool bRepeatIfEmpty) const;
155 : : void getValue( ScDPValueData& rVal, SCCOL nCol, SCROW nRow, bool bRepeatIfEmpty) const;
156 : : rtl::OUString getFieldName(SCCOL nIndex) const;
157 : :
158 : : /** Get the unique entries for a field specified by index. The caller must
159 : : make sure that the table is filled before calling function, or it will
160 : : get an empty collection. */
161 : : const ::std::vector<SCROW>& getFieldEntries( sal_Int32 nColumn ) const;
162 : :
163 : : /** Filter the table based on the specified criteria, and copy the
164 : : result to rTabData. This method is used, for example, to generate
165 : : a drill-down data table. */
166 : : void filterTable(const ::std::vector<Criterion>& rCriteria,
167 : : ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > >& rTabData,
168 : : const ::boost::unordered_set<sal_Int32>& rRepeatIfEmptyDims);
169 : :
170 : : SCROW getOrder(long nDim, SCROW nIndex) const;
171 : : void clear();
172 : : bool empty() const;
173 : : bool hasCache() const;
174 : :
175 : : private:
176 : : ScDPCacheTable();
177 : : ScDPCacheTable(const ScDPCacheTable&);
178 : :
179 : : /**
180 : : * Check if a given row meets all specified criteria.
181 : : *
182 : : * @param nRow index of row to be tested.
183 : : * @param rCriteria a list of criteria
184 : : */
185 : : bool isRowQualified(sal_Int32 nRow, const ::std::vector<Criterion>& rCriteria, const ::boost::unordered_set<sal_Int32>& rRepeatIfEmptyDims) const;
186 : :
187 : : private:
188 : : /** unique field entires for each field (column). */
189 : : ::std::vector< ::std::vector<SCROW> > maFieldEntries;
190 : :
191 : : /** Row flags. The first row below the header row has the index of 0. */
192 : : ::std::vector<RowFlag> maRowFlags;
193 : :
194 : : const ScDPCache* mpCache;
195 : : };
196 : : #endif
197 : :
198 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|