LibreOffice Module sc (master) 1
dpfilteredcache.hxx
Go to the documentation of this file.
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#pragma once
21
22#include <sal/types.h>
23#include "dpitemdata.hxx"
24#include "calcmacros.hxx"
25#include "types.hxx"
26
27#include <unordered_set>
28#include <vector>
29
30#include <mdds/flat_segment_tree.hpp>
31
32namespace com::sun::star::uno
33{
34class Any;
35}
36namespace com::sun::star::uno
37{
38template <typename> class Sequence;
39}
40
41class ScDPCache;
42struct ScDPValue;
43struct ScQueryParam;
44
50{
51 typedef mdds::flat_segment_tree<SCROW, bool> RowFlagType;
52
53public:
56 {
57 public:
58 virtual ~FilterBase() {}
61 virtual bool match(const ScDPItemData& rCellData) const = 0;
62
63 virtual std::vector<ScDPItemData> getMatchValues() const = 0;
64 };
65
67 class SingleFilter final : public FilterBase
68 {
69 public:
70 explicit SingleFilter(const ScDPItemData& rItem);
71
72 virtual bool match(const ScDPItemData& rCellData) const override;
73 virtual std::vector<ScDPItemData> getMatchValues() const override;
74
75 private:
77 };
78
80 class GroupFilter final : public FilterBase
81 {
82 public:
84 virtual bool match(const ScDPItemData& rCellData) const override;
85 virtual std::vector<ScDPItemData> getMatchValues() const override;
86 void addMatchItem(const ScDPItemData& rItem);
87 size_t getMatchItemCount() const;
88
89 private:
90 ::std::vector<ScDPItemData> maItems;
91 };
92
94 struct Criterion
95 {
96 sal_Int32 mnFieldIndex;
97 std::shared_ptr<FilterBase> mpFilter;
98
99 Criterion();
100 };
101
102 ScDPFilteredCache(const ScDPCache& rCache);
104
105 sal_Int32 getRowSize() const;
106 sal_Int32 getColSize() const;
107
108 const ScDPCache& getCache() const { return mrCache; }
109
110 void fillTable(const ScQueryParam& rQuery, bool bIgnoreEmptyRows, bool bRepeatIfEmpty);
111
112 void fillTable();
113
117 bool isRowActive(sal_Int32 nRow, sal_Int32* pLastRow = nullptr) const;
118
121 void filterByPageDimension(const std::vector<Criterion>& rCriteria,
122 const std::unordered_set<sal_Int32>& rRepeatIfEmptyDims);
123
127 const ScDPItemData* getCell(SCCOL nCol, SCROW nRow, bool bRepeatIfEmpty) const;
128 void getValue(ScDPValue& rVal, SCCOL nCol, SCROW nRow) const;
129 OUString getFieldName(SCCOL nIndex) const;
130
134 const ::std::vector<SCROW>& getFieldEntries(sal_Int32 nColumn) const;
135
139 void filterTable(const std::vector<Criterion>& rCriteria,
140 css::uno::Sequence<css::uno::Sequence<css::uno::Any>>& rTabData,
141 const std::unordered_set<sal_Int32>& rRepeatIfEmptyDims);
142
143 void clear();
144 bool empty() const;
145
146#if DUMP_PIVOT_TABLE
147 static void dumpRowFlag(const RowFlagType& rFlag);
148 void dump() const;
149#endif
150
151private:
153
160 bool isRowQualified(sal_Int32 nRow, const ::std::vector<Criterion>& rCriteria,
161 const std::unordered_set<sal_Int32>& rRepeatIfEmptyDims) const;
162
163private:
165 ::std::vector<::std::vector<SCROW>> maFieldEntries;
166
171
173};
174
175/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
This class represents the cached data part of the datapilot cache table implementation.
Definition: dpcache.hxx:48
interface class used for filtering of rows.
virtual std::vector< ScDPItemData > getMatchValues() const =0
virtual bool match(const ScDPItemData &rCellData) const =0
returns true if the matching condition is met for a single cell value, or false otherwise.
multi-item (group) filter.
virtual std::vector< ScDPItemData > getMatchValues() const override
::std::vector< ScDPItemData > maItems
void addMatchItem(const ScDPItemData &rItem)
virtual bool match(const ScDPItemData &rCellData) const override
returns true if the matching condition is met for a single cell value, or false otherwise.
ordinary single-item filter.
virtual bool match(const ScDPItemData &rCellData) const override
returns true if the matching condition is met for a single cell value, or false otherwise.
virtual std::vector< ScDPItemData > getMatchValues() const override
SingleFilter(const ScDPItemData &rItem)
This class is only a wrapper to the actual cache, to provide filtering on the raw data based on the q...
sal_Int32 getColSize() const
void filterTable(const std::vector< Criterion > &rCriteria, css::uno::Sequence< css::uno::Sequence< css::uno::Any > > &rTabData, const std::unordered_set< sal_Int32 > &rRepeatIfEmptyDims)
Filter the table based on the specified criteria, and copy the result to rTabData.
RowFlagType maShowByFilter
Rows visible by standard filter query.
ScDPFilteredCache(const ScDPFilteredCache &)=delete
mdds::flat_segment_tree< SCROW, bool > RowFlagType
const ScDPItemData * getCell(SCCOL nCol, SCROW nRow, bool bRepeatIfEmpty) const
Get the cell instance at specified location within the data grid.
bool isRowQualified(sal_Int32 nRow, const ::std::vector< Criterion > &rCriteria, const std::unordered_set< sal_Int32 > &rRepeatIfEmptyDims) const
Check if a given row meets all specified criteria.
void dump() const
RowFlagType maShowByPage
Rows visible by page dimension filtering.
ScDPFilteredCache(const ScDPCache &rCache)
void filterByPageDimension(const std::vector< Criterion > &rCriteria, const std::unordered_set< sal_Int32 > &rRepeatIfEmptyDims)
Set filter on/off flag to each row to control visibility.
sal_Int32 getRowSize() const
OUString getFieldName(SCCOL nIndex) const
static void dumpRowFlag(const RowFlagType &rFlag)
const ScDPCache & mrCache
const ::std::vector< SCROW > & getFieldEntries(sal_Int32 nColumn) const
Get the unique entries for a field specified by index.
void getValue(ScDPValue &rVal, SCCOL nCol, SCROW nRow) const
bool isRowActive(sal_Int32 nRow, sal_Int32 *pLastRow=nullptr) const
Check whether a specified row is active or not.
::std::vector<::std::vector< SCROW > > maFieldEntries
unique field entries for each field (column).
const ScDPCache & getCache() const
When assigning a string value, you can also assign an interned string whose life-cycle is managed by ...
Definition: dpitemdata.hxx:29
single filtering criterion.
std::shared_ptr< FilterBase > mpFilter
sal_Int16 SCCOL
Definition: types.hxx:21
sal_Int32 SCROW
Definition: types.hxx:17