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 #ifndef INCLUDED_SC_INC_DPFILTEREDCACHE_HXX
21 #define INCLUDED_SC_INC_DPFILTEREDCACHE_HXX
22 
23 #include <sal/types.h>
24 #include "dpitemdata.hxx"
25 #include "calcmacros.hxx"
26 #include "types.hxx"
27 
28 #include <unordered_set>
29 #include <vector>
30 
31 #include <mdds/flat_segment_tree.hpp>
32 
33 namespace com::sun::star::uno
34 {
35 class Any;
36 }
37 namespace com::sun::star::uno
38 {
39 template <typename> class Sequence;
40 }
41 
42 class ScDPCache;
43 struct ScDPValue;
44 struct ScQueryParam;
45 
51 {
52  typedef mdds::flat_segment_tree<SCROW, bool> RowFlagType;
53 
54 public:
56  class FilterBase
57  {
58  public:
59  virtual ~FilterBase() {}
62  virtual bool match(const ScDPItemData& rCellData) const = 0;
63 
64  virtual std::vector<ScDPItemData> getMatchValues() const = 0;
65  };
66 
68  class SingleFilter final : public FilterBase
69  {
70  public:
71  explicit SingleFilter(const ScDPItemData& rItem);
72 
73  virtual bool match(const ScDPItemData& rCellData) const override;
74  virtual std::vector<ScDPItemData> getMatchValues() const override;
75 
76  private:
78  };
79 
81  class GroupFilter final : public FilterBase
82  {
83  public:
84  GroupFilter();
85  virtual bool match(const ScDPItemData& rCellData) const override;
86  virtual std::vector<ScDPItemData> getMatchValues() const override;
87  void addMatchItem(const ScDPItemData& rItem);
88  size_t getMatchItemCount() const;
89 
90  private:
91  ::std::vector<ScDPItemData> maItems;
92  };
93 
95  struct Criterion
96  {
97  sal_Int32 mnFieldIndex;
98  std::shared_ptr<FilterBase> mpFilter;
99 
100  Criterion();
101  };
102 
103  ScDPFilteredCache(const ScDPCache& rCache);
105 
106  sal_Int32 getRowSize() const;
107  sal_Int32 getColSize() const;
108 
109  const ScDPCache& getCache() const { return mrCache; }
110 
111  void fillTable(const ScQueryParam& rQuery, bool bIgnoreEmptyRows, bool bRepeatIfEmpty);
112 
113  void fillTable();
114 
118  bool isRowActive(sal_Int32 nRow, sal_Int32* pLastRow = nullptr) const;
119 
122  void filterByPageDimension(const std::vector<Criterion>& rCriteria,
123  const std::unordered_set<sal_Int32>& rRepeatIfEmptyDims);
124 
128  const ScDPItemData* getCell(SCCOL nCol, SCROW nRow, bool bRepeatIfEmpty) const;
129  void getValue(ScDPValue& rVal, SCCOL nCol, SCROW nRow) const;
130  OUString getFieldName(SCCOL nIndex) const;
131 
135  const ::std::vector<SCROW>& getFieldEntries(sal_Int32 nColumn) const;
136 
140  void filterTable(const std::vector<Criterion>& rCriteria,
141  css::uno::Sequence<css::uno::Sequence<css::uno::Any>>& rTabData,
142  const std::unordered_set<sal_Int32>& rRepeatIfEmptyDims);
143 
144  void clear();
145  bool empty() const;
146 
147 #if DUMP_PIVOT_TABLE
148  static void dumpRowFlag(const RowFlagType& rFlag);
149  void dump() const;
150 #endif
151 
152 private:
153  ScDPFilteredCache(const ScDPFilteredCache&) = delete;
154 
161  bool isRowQualified(sal_Int32 nRow, const ::std::vector<Criterion>& rCriteria,
162  const std::unordered_set<sal_Int32>& rRepeatIfEmptyDims) const;
163 
164 private:
166  ::std::vector<::std::vector<SCROW>> maFieldEntries;
167 
169  RowFlagType maShowByFilter;
171  RowFlagType maShowByPage;
172 
174 };
175 #endif
176 
177 /* 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:48
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:29
ScDPFilteredCache(const ScDPCache &rCache)
sal_Int16 SCCOL
Definition: types.hxx:22
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:18
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