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 
32 namespace com::sun::star::uno
33 {
34 class Any;
35 }
36 namespace com::sun::star::uno
37 {
38 template <typename> class Sequence;
39 }
40 
41 class ScDPCache;
42 struct ScDPValue;
43 struct ScQueryParam;
44 
50 {
51  typedef mdds::flat_segment_tree<SCROW, bool> RowFlagType;
52 
53 public:
55  class FilterBase
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:
83  GroupFilter();
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 
151 private:
152  ScDPFilteredCache(const ScDPFilteredCache&) = delete;
153 
160  bool isRowQualified(sal_Int32 nRow, const ::std::vector<Criterion>& rCriteria,
161  const std::unordered_set<sal_Int32>& rRepeatIfEmptyDims) const;
162 
163 private:
165  ::std::vector<::std::vector<SCROW>> maFieldEntries;
166 
168  RowFlagType maShowByFilter;
170  RowFlagType maShowByPage;
171 
173 };
174 
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString getFieldName(SCCOL nIndex) const
virtual std::vector< ScDPItemData > getMatchValues() const override
virtual bool match(const ScDPItemData &rCellData) const override
returns true if the matching condition is met for a single cell value, or false otherwise.
::std::vector< ScDPItemData > maItems
sal_Int32 getRowSize() 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.
This class represents the cached data part of the datapilot cache table implementation.
Definition: dpcache.hxx:47
mdds::flat_segment_tree< SCROW, bool > RowFlagType
interface class used for filtering of rows.
static void dumpRowFlag(const RowFlagType &rFlag)
multi-item (group) filter.
void getValue(ScDPValue &rVal, SCCOL nCol, SCROW nRow) const
std::shared_ptr< FilterBase > mpFilter
bool isRowActive(sal_Int32 nRow, sal_Int32 *pLastRow=nullptr) const
Check whether a specified row is active or not.
virtual bool match(const ScDPItemData &rCellData) const override
returns true if the matching condition is met for a single cell value, or false otherwise.
When assigning a string value, you can also assign an interned string whose life-cycle is managed by ...
Definition: dpitemdata.hxx:28
ScDPFilteredCache(const ScDPCache &rCache)
sal_Int16 SCCOL
Definition: types.hxx:21
const ScDPItemData * getCell(SCCOL nCol, SCROW nRow, bool bRepeatIfEmpty) const
Get the cell instance at specified location within the data grid.
::std::vector<::std::vector< SCROW > > maFieldEntries
unique field entries for each field (column).
virtual bool match(const ScDPItemData &rCellData) const =0
returns true if the matching condition is met for a single cell value, or false otherwise.
void addMatchItem(const ScDPItemData &rItem)
RowFlagType maShowByPage
Rows visible by page dimension filtering.
virtual std::vector< ScDPItemData > getMatchValues() const =0
RowFlagType maShowByFilter
Rows visible by standard filter query.
sal_Int32 SCROW
Definition: types.hxx:17
sal_Int32 getColSize() const
single filtering criterion.
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.
virtual std::vector< ScDPItemData > getMatchValues() const override
const ::std::vector< SCROW > & getFieldEntries(sal_Int32 nColumn) const
Get the unique entries for a field specified by index.
SingleFilter(const ScDPItemData &rItem)
ordinary single-item filter.
This class is only a wrapper to the actual cache, to provide filtering on the raw data based on the q...
const ScDPCache & mrCache
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.
void dump() const
const ScDPCache & getCache() const