1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 INCLUDED_SC_INC_DPFILTEREDCACHE_HXX
21 #define INCLUDED_SC_INC_DPFILTEREDCACHE_HXX
23 #include <sal/types.h>
24 #include "dpitemdata.hxx"
25 #include "calcmacros.hxx"
29 #include <unordered_set>
32 #include <mdds/flat_segment_tree.hpp>
34 namespace com
{ namespace sun
{ namespace star
{ namespace uno
{ class Any
; } } } }
35 namespace com
{ namespace sun
{ namespace star
{ namespace uno
{ template <typename
> class Sequence
; } } } }
42 * This class is only a wrapper to the actual cache, to provide filtering on
43 * the raw data based on the query filter and/or page field filters.
45 class ScDPFilteredCache
47 typedef mdds::flat_segment_tree
<SCROW
, bool> RowFlagType
;
50 /** interface class used for filtering of rows. */
54 virtual ~FilterBase() {}
55 /** returns true if the matching condition is met for a single cell
56 value, or false otherwise. */
57 virtual bool match( const ScDPItemData
& rCellData
) const = 0;
59 virtual std::vector
<ScDPItemData
> getMatchValues() const = 0;
62 /** ordinary single-item filter. */
63 class SingleFilter final
: public FilterBase
66 explicit SingleFilter(const ScDPItemData
&rItem
);
68 virtual bool match(const ScDPItemData
& rCellData
) const override
;
69 virtual std::vector
<ScDPItemData
> getMatchValues() const override
;
72 ScDPItemData
const maItem
;
75 /** multi-item (group) filter. */
76 class GroupFilter final
: public FilterBase
80 virtual bool match(const ScDPItemData
& rCellData
) const override
;
81 virtual std::vector
<ScDPItemData
> getMatchValues() const override
;
82 void addMatchItem(const ScDPItemData
& rItem
);
83 size_t getMatchItemCount() const;
86 ::std::vector
<ScDPItemData
> maItems
;
89 /** single filtering criterion. */
92 sal_Int32 mnFieldIndex
;
93 std::shared_ptr
<FilterBase
> mpFilter
;
98 ScDPFilteredCache(const ScDPCache
& rCache
);
101 sal_Int32
getRowSize() const;
102 sal_Int32
getColSize() const;
104 const ScDPCache
& getCache() const { return mrCache
;}
106 void fillTable(const ScQueryParam
& rQuery
, bool bIgnoreEmptyRows
, bool bRepeatIfEmpty
);
110 /** Check whether a specified row is active or not. When a row is active,
111 it is used in calculation of the results data. A row becomes inactive
112 when it is filtered out by page field. */
113 bool isRowActive(sal_Int32 nRow
, sal_Int32
* pLastRow
= nullptr) const;
115 /** Set filter on/off flag to each row to control visibility. The caller
116 must ensure that the table is filled before calling this function. */
117 void filterByPageDimension(const std::vector
<Criterion
>& rCriteria
, const std::unordered_set
<sal_Int32
>& rRepeatIfEmptyDims
);
119 /** Get the cell instance at specified location within the data grid. Note
120 that the data grid doesn't include the header row. Don't delete the
122 const ScDPItemData
* getCell(SCCOL nCol
, SCROW nRow
, bool bRepeatIfEmpty
) const;
123 void getValue( ScDPValue
& rVal
, SCCOL nCol
, SCROW nRow
) const;
124 OUString
getFieldName(SCCOL nIndex
) const;
126 /** Get the unique entries for a field specified by index. The caller must
127 make sure that the table is filled before calling function, or it will
128 get an empty collection. */
129 const ::std::vector
<SCROW
>& getFieldEntries( sal_Int32 nColumn
) const;
131 /** Filter the table based on the specified criteria, and copy the
132 result to rTabData. This method is used, for example, to generate
133 a drill-down data table. */
134 void filterTable(const std::vector
<Criterion
>& rCriteria
,
135 css::uno::Sequence
< css::uno::Sequence
< css::uno::Any
> >& rTabData
,
136 const std::unordered_set
<sal_Int32
>& rRepeatIfEmptyDims
);
142 static void dumpRowFlag( const RowFlagType
& rFlag
);
147 ScDPFilteredCache(const ScDPFilteredCache
&) = delete;
150 * Check if a given row meets all specified criteria.
152 * @param nRow index of row to be tested.
153 * @param rCriteria a list of criteria
155 bool isRowQualified(sal_Int32 nRow
, const ::std::vector
<Criterion
>& rCriteria
, const std::unordered_set
<sal_Int32
>& rRepeatIfEmptyDims
) const;
159 /** unique field entries for each field (column). */
160 ::std::vector
< ::std::vector
<SCROW
> > maFieldEntries
;
162 /** Rows visible by standard filter query. */
163 RowFlagType maShowByFilter
;
164 /** Rows visible by page dimension filtering. */
165 RowFlagType maShowByPage
;
167 const ScDPCache
& mrCache
;
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */