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 "scdllapi.h"
27 #include "types.hxx"
28 
29 #include <unordered_set>
30 #include <vector>
31 
32 #include <mdds/flat_segment_tree.hpp>
33 
34 namespace com::sun::star::uno { class Any; }
35 namespace com::sun::star::uno { template <typename > class Sequence; }
36 
37 class ScDPCache;
38 struct ScDPValue;
39 struct ScQueryParam;
40 
46 {
47  typedef mdds::flat_segment_tree<SCROW, bool> RowFlagType;
48 
49 public:
51  class FilterBase
52  {
53  public:
54  virtual ~FilterBase() {}
57  virtual bool match( const ScDPItemData& rCellData ) const = 0;
58 
59  virtual std::vector<ScDPItemData> getMatchValues() const = 0;
60  };
61 
63  class SingleFilter final : public FilterBase
64  {
65  public:
66  explicit SingleFilter(const ScDPItemData &rItem);
67 
68  virtual bool match(const ScDPItemData& rCellData) const override;
69  virtual std::vector<ScDPItemData> getMatchValues() const override;
70 
71  private:
73  };
74 
76  class GroupFilter final : public FilterBase
77  {
78  public:
79  GroupFilter();
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;
84 
85  private:
86  ::std::vector<ScDPItemData> maItems;
87  };
88 
90  struct Criterion
91  {
92  sal_Int32 mnFieldIndex;
93  std::shared_ptr<FilterBase> mpFilter;
94 
95  Criterion();
96  };
97 
98  ScDPFilteredCache(const ScDPCache& rCache);
100 
101  sal_Int32 getRowSize() const;
102  sal_Int32 getColSize() const;
103 
104  const ScDPCache& getCache() const { return mrCache;}
105 
106  void fillTable(const ScQueryParam& rQuery, bool bIgnoreEmptyRows, bool bRepeatIfEmpty);
107 
108  void fillTable();
109 
113  bool isRowActive(sal_Int32 nRow, sal_Int32* pLastRow = nullptr) const;
114 
117  void filterByPageDimension(const std::vector<Criterion>& rCriteria, const std::unordered_set<sal_Int32>& rRepeatIfEmptyDims);
118 
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;
125 
129  const ::std::vector<SCROW>& getFieldEntries( sal_Int32 nColumn ) const;
130 
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);
137 
138  void clear();
139  bool empty() const;
140 
141 #if DUMP_PIVOT_TABLE
142  static void dumpRowFlag( const RowFlagType& rFlag );
143  void dump() const;
144 #endif
145 
146 private:
147  ScDPFilteredCache(const ScDPFilteredCache&) = delete;
148 
155  bool isRowQualified(sal_Int32 nRow, const ::std::vector<Criterion>& rCriteria, const std::unordered_set<sal_Int32>& rRepeatIfEmptyDims) const;
156 
157 private:
158 
160  ::std::vector< ::std::vector<SCROW> > maFieldEntries;
161 
163  RowFlagType maShowByFilter;
165  RowFlagType maShowByPage;
166 
168 };
169 #endif
170 
171 /* 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
This class represents the cached data part of the datapilot cache table implementation.
Definition: dpcache.hxx:47
::std::vector< ::std::vector< SCROW > > maFieldEntries
unique field entries for each field (column).
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.
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.
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 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