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_DPCACHETABLE_HXX
21 : #define SC_DPCACHETABLE_HXX
22 :
23 : #include "sal/types.h"
24 : #include "osl/mutex.hxx"
25 : #include "global.hxx"
26 : #include "dpitemdata.hxx"
27 : #include "dpmacros.hxx"
28 :
29 : #include <vector>
30 : #include <boost/unordered_set.hpp>
31 : #include <boost/shared_ptr.hpp>
32 :
33 : #include <mdds/flat_segment_tree.hpp>
34 :
35 : class ScDPItemData;
36 : class ScDPCache;
37 : class ScDocument;
38 : class ScRange;
39 : struct ScDPValueData;
40 : struct ScQueryParam;
41 :
42 : /**
43 : * This class is only a wrapper to the actual cache, to provide filtering on
44 : * the raw data based on the query filter and/or page field filters.
45 : */
46 : class SC_DLLPUBLIC ScDPFilteredCache
47 : {
48 : typedef mdds::flat_segment_tree<SCROW, bool> RowFlagType;
49 :
50 : public:
51 : /** interface class used for filtering of rows. */
52 4 : class FilterBase
53 : {
54 : public:
55 4 : virtual ~FilterBase() {}
56 : /** returns true if the matching condition is met for a single cell
57 : value, or false otherwise. */
58 : virtual bool match( const ScDPItemData& rCellData ) const = 0;
59 : };
60 :
61 : /** ordinary single-item filter. */
62 : class SingleFilter : public FilterBase
63 : {
64 : public:
65 : explicit SingleFilter(const ScDPItemData &rItem);
66 0 : virtual ~SingleFilter() {}
67 :
68 : virtual bool match(const ScDPItemData& rCellData) const;
69 :
70 : const ScDPItemData& getMatchValue() const;
71 :
72 : private:
73 : explicit SingleFilter();
74 :
75 : ScDPItemData maItem;
76 : };
77 :
78 : /** multi-item (group) filter. */
79 : class GroupFilter : public FilterBase
80 : {
81 : public:
82 : GroupFilter();
83 8 : virtual ~GroupFilter() {}
84 : virtual bool match(const ScDPItemData& rCellData) const;
85 : void addMatchItem(const ScDPItemData& rItem);
86 : size_t getMatchItemCount() const;
87 :
88 : private:
89 : ::std::vector<ScDPItemData> maItems;
90 : };
91 :
92 : /** single filtering criterion. */
93 8 : struct Criterion
94 : {
95 : sal_Int32 mnFieldIndex;
96 : ::boost::shared_ptr<FilterBase> mpFilter;
97 :
98 : Criterion();
99 : };
100 :
101 : ScDPFilteredCache(const ScDPCache& rCache);
102 : ~ScDPFilteredCache();
103 :
104 : sal_Int32 getRowSize() const;
105 : sal_Int32 getColSize() const;
106 :
107 : const ScDPCache* getCache() const;
108 :
109 : void fillTable(const ScQueryParam& rQuery, bool bIgnoreEmptyRows, bool bRepeatIfEmpty);
110 :
111 : void fillTable();
112 :
113 : /** Check whether a specified row is active or not. When a row is active,
114 : it is used in calculation of the results data. A row becomes inactive
115 : when it is filtered out by page field. */
116 : bool isRowActive(sal_Int32 nRow, sal_Int32* pLastRow = NULL) const;
117 :
118 : /** Set filter on/off flag to each row to control visibility. The caller
119 : must ensure that the table is filled before calling this function. */
120 : void filterByPageDimension(const ::std::vector<Criterion>& rCriteria, const ::boost::unordered_set<sal_Int32>& rRepeatIfEmptyDims);
121 :
122 : /** Get the cell instance at specified location within the data grid. Note
123 : that the data grid doesn't include the header row. Don't delete the
124 : returned object! */
125 : const ScDPItemData* getCell(SCCOL nCol, SCROW nRow, bool bRepeatIfEmpty) const;
126 : void getValue( ScDPValueData& rVal, SCCOL nCol, SCROW nRow, bool bRepeatIfEmpty) const;
127 : rtl::OUString getFieldName(SCCOL nIndex) const;
128 :
129 : /** Get the unique entries for a field specified by index. The caller must
130 : make sure that the table is filled before calling function, or it will
131 : get an empty collection. */
132 : const ::std::vector<SCROW>& getFieldEntries( sal_Int32 nColumn ) const;
133 :
134 : /** Filter the table based on the specified criteria, and copy the
135 : result to rTabData. This method is used, for example, to generate
136 : a drill-down data table. */
137 : void filterTable(const ::std::vector<Criterion>& rCriteria,
138 : ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > >& rTabData,
139 : const ::boost::unordered_set<sal_Int32>& rRepeatIfEmptyDims);
140 :
141 : SCROW getOrder(long nDim, SCROW nIndex) const;
142 : void clear();
143 : bool empty() const;
144 :
145 : #if DEBUG_PIVOT_TABLE
146 : void dumpRowFlag(const RowFlagType& rFlag) const;
147 : void dump() const;
148 : #endif
149 :
150 : private:
151 : ScDPFilteredCache();
152 : ScDPFilteredCache(const ScDPFilteredCache&);
153 :
154 : /**
155 : * Check if a given row meets all specified criteria.
156 : *
157 : * @param nRow index of row to be tested.
158 : * @param rCriteria a list of criteria
159 : */
160 : bool isRowQualified(sal_Int32 nRow, const ::std::vector<Criterion>& rCriteria, const ::boost::unordered_set<sal_Int32>& rRepeatIfEmptyDims) const;
161 :
162 : private:
163 :
164 : /** unique field entires for each field (column). */
165 : ::std::vector< ::std::vector<SCROW> > maFieldEntries;
166 :
167 : /** Rows visible by standard filter query. */
168 : RowFlagType maShowByFilter;
169 : /** Rows visible by page dimension filtering. */
170 : RowFlagType maShowByPage;
171 :
172 : const ScDPCache& mrCache;
173 : };
174 : #endif
175 :
176 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|