LibreOffice Module sc (master)  1
dpgroup.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 <memory>
23 #include <unordered_set>
24 #include <vector>
25 
26 #include "dptabdat.hxx"
27 #include "scdllapi.h"
28 #include "dpitemdata.hxx"
29 #include "dpnumgroupinfo.hxx"
30 
31 class ScDocument;
32 
33 typedef ::std::vector<ScDPItemData> ScDPItemDataVec;
34 
36 {
37  ScDPItemData aGroupName; // name of group item
38  ScDPItemDataVec aElements; // names of items in original dimension
39 
40 public:
41  ScDPGroupItem( const ScDPItemData& rName );
42 
43  void AddElement( const ScDPItemData& rName );
44 
45  const ScDPItemData& GetName() const { return aGroupName; }
46  bool HasElement( const ScDPItemData& rData ) const;
47  bool HasCommonElement( const ScDPGroupItem& rOther ) const;
48 
49  void FillGroupFilter( ScDPFilteredCache::GroupFilter& rFilter ) const;
50 };
51 
53 {
56  OUString aGroupName;
57  std::vector<ScDPGroupItem> aItems;
58  mutable std::vector<SCROW> maMemberEntries;
60 public:
61  ScDPGroupDimension( tools::Long nSource, const OUString& rNewName );
62  ScDPGroupDimension( const ScDPGroupDimension& rOther );
64 
66 
67  void AddItem( const ScDPGroupItem& rItem );
68  void SetGroupDim( tools::Long nDim ); // called from AddGroupDimension
69 
70  tools::Long GetSourceDim() const { return nSourceDim; }
71  tools::Long GetGroupDim() const { return nGroupDim; }
72  const OUString& GetName() const { return aGroupName; }
73 
74  const std::vector< SCROW >& GetColumnEntries( const ScDPFilteredCache& rCacheTable ) const;
75  const ScDPGroupItem* GetGroupForData( const ScDPItemData& rData ) const; // rData = entry in original dim.
76  const ScDPGroupItem* GetGroupForName( const ScDPItemData& rName ) const; // rName = entry in group dim.
77  const ScDPGroupItem* GetGroupByIndex( size_t nIndex ) const;
78 
79  void DisposeData();
80 
81  size_t GetItemCount() const { return aItems.size(); }
82 
83  void SetDateDimension();
84  bool IsDateDimension() const { return mbDateDimension;}
85 };
86 
88 {
89  mutable ScDPNumGroupInfo aGroupInfo; // settings
90  mutable std::vector<SCROW> maMemberEntries;
92 
93 public:
98 
99  ScDPNumGroupDimension& operator=( const ScDPNumGroupDimension& rOther );
100 
101  const ScDPNumGroupInfo& GetInfo() const { return aGroupInfo; }
102 
103  const std::vector<SCROW>& GetNumEntries(SCCOL nSourceDim, const ScDPCache* pCache) const;
104 
105  void SetDateDimension();
106 
107  void DisposeData();
108 
109  bool IsDateDimension() const { return mbDateDimension;}
110 };
111 
112 // proxy implementation of ScDPTableData to add grouped items
113 
114 class ScDPGroupTableData final : public ScDPTableData
115 {
116  std::shared_ptr<ScDPTableData> pSourceData;
117  sal_Int32 nSourceCount;
118  std::vector<ScDPGroupDimension>
120  std::unique_ptr<ScDPNumGroupDimension[]>
121  pNumGroups; // array[nSourceCount]
123 
124  void FillGroupValues(std::vector<SCROW>& rItems, const std::vector<sal_Int32>& rDims);
125  virtual sal_Int32 GetSourceDim( sal_Int32 nDim ) override;
126 
127  bool IsNumGroupDimension( tools::Long nDimension ) const;
128  void GetNumGroupInfo(tools::Long nDimension, ScDPNumGroupInfo& rInfo);
129 
130  void ModifyFilterCriteria(::std::vector<ScDPFilteredCache::Criterion>& rCriteria);
131 
132 public:
133  // takes ownership of pSource
134  ScDPGroupTableData( const std::shared_ptr<ScDPTableData>& pSource, ScDocument* pDocument );
135  virtual ~ScDPGroupTableData() override;
136 
137  const std::shared_ptr<ScDPTableData>& GetSourceTableData() const { return pSourceData;}
138 
139  void AddGroupDimension( const ScDPGroupDimension& rGroup );
140  void SetNumGroupDimension( sal_Int32 nIndex, const ScDPNumGroupDimension& rGroup );
141  sal_Int32 GetDimensionIndex( std::u16string_view rName );
142 
143  virtual sal_Int32 GetColumnCount() override;
144  virtual sal_Int32 GetMembersCount( sal_Int32 nDim ) override;
145  virtual const std::vector< SCROW >& GetColumnEntries( sal_Int32 nColumn ) override ;
146  virtual const ScDPItemData* GetMemberById( sal_Int32 nDim, sal_Int32 nId) override;
147  virtual sal_Int32 Compare( sal_Int32 nDim, sal_Int32 nDataId1, sal_Int32 nDataId2) override;
148 
149  virtual OUString getDimensionName(sal_Int32 nColumn) override;
150  virtual bool getIsDataLayoutDimension(sal_Int32 nColumn) override;
151  virtual bool IsDateDimension(sal_Int32 nDim) override;
152  virtual sal_uInt32 GetNumberFormat(sal_Int32 nDim) override;
153  virtual void DisposeData() override;
154  virtual void SetEmptyFlags( bool bIgnoreEmptyRows, bool bRepeatIfEmpty ) override;
155 
156  virtual bool IsRepeatIfEmpty() override;
157 
158  virtual void CreateCacheTable() override;
159  virtual void FilterCacheTable(std::vector<ScDPFilteredCache::Criterion>&& rCriteria, std::unordered_set<sal_Int32>&& rDataDims) override;
160  virtual void GetDrillDownData(std::vector<ScDPFilteredCache::Criterion>&& rCriteria,
161  std::unordered_set<sal_Int32>&& rCatDims,
162  css::uno::Sequence< css::uno::Sequence< css::uno::Any > >& rData) override;
163  virtual void CalcResults(CalcInfo& rInfo, bool bAutoShow) override;
164  virtual const ScDPFilteredCache& GetCacheTable() const override;
165  virtual void ReloadCacheTable() override;
166 
167  virtual bool IsBaseForGroup(sal_Int32 nDim) const override;
168  virtual sal_Int32 GetGroupBase(sal_Int32 nGroupDim) const override;
169  virtual bool IsNumOrDateGroup(sal_Int32 nDim) const override;
170  virtual bool IsInGroup( const ScDPItemData& rGroupData, sal_Int32 nGroupIndex,
171  const ScDPItemData& rBaseData, sal_Int32 nBaseIndex ) const override;
172  virtual bool HasCommonElement( const ScDPItemData& rFirstData, sal_Int32 nFirstIndex,
173  const ScDPItemData& rSecondData, sal_Int32 nSecondIndex ) const override;
174 
175 #if DUMP_PIVOT_TABLE
176  virtual void Dump() const override;
177 #endif
178 };
179 
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void GetNumGroupInfo(tools::Long nDimension, ScDPNumGroupInfo &rInfo)
Definition: dpgroup.cxx:515
void FillGroupValues(std::vector< SCROW > &rItems, const std::vector< sal_Int32 > &rDims)
Definition: dpgroup.cxx:803
virtual void CalcResults(CalcInfo &rInfo, bool bAutoShow) override
Definition: dpgroup.cxx:762
OUString aGroupName
Definition: dpgroup.hxx:56
const ScDPNumGroupInfo & GetInfo() const
Definition: dpgroup.hxx:101
void AddGroupDimension(const ScDPGroupDimension &rGroup)
Definition: dpgroup.cxx:480
const std::vector< SCROW > & GetColumnEntries(const ScDPFilteredCache &rCacheTable) const
Definition: dpgroup.cxx:375
virtual bool IsNumOrDateGroup(sal_Int32 nDim) const override
Definition: dpgroup.cxx:889
ScDPItemData aGroupName
Definition: dpgroup.hxx:37
ScDPGroupTableData(const std::shared_ptr< ScDPTableData > &pSource, ScDocument *pDocument)
Definition: dpgroup.cxx:464
long Long
bool HasElement(const ScDPItemData &rData) const
Definition: dpgroup.cxx:315
std::vector< ScDPGroupDimension > aGroups
Definition: dpgroup.hxx:119
std::vector< ScDPGroupItem > aItems
Definition: dpgroup.hxx:57
virtual ~ScDPGroupTableData() override
Definition: dpgroup.cxx:476
This class represents the cached data part of the datapilot cache table implementation.
Definition: dpcache.hxx:47
std::unique_ptr< ScDPNumGroupDimension[]> pNumGroups
Definition: dpgroup.hxx:121
virtual void FilterCacheTable(std::vector< ScDPFilteredCache::Criterion > &&rCriteria, std::unordered_set< sal_Int32 > &&rDataDims) override
Definition: dpgroup.cxx:750
virtual void Dump() const override
bool IsNumGroupDimension(tools::Long nDimension) const
Definition: dpgroup.cxx:510
tools::Long GetGroupDim() const
Definition: dpgroup.hxx:71
void SetNumGroupDimension(sal_Int32 nIndex, const ScDPNumGroupDimension &rGroup)
Definition: dpgroup.cxx:487
virtual sal_Int32 GetSourceDim(sal_Int32 nDim) override
Definition: dpgroup.cxx:992
tools::Long nSourceDim
Definition: dpgroup.hxx:54
multi-item (group) filter.
ScDocument * pDoc
Definition: dpgroup.hxx:122
::std::vector< ScDPItemData > ScDPItemDataVec
Definition: dpgroup.hxx:31
virtual bool IsBaseForGroup(sal_Int32 nDim) const override
Definition: dpgroup.cxx:873
void SetDateDimension()
Definition: dpgroup.cxx:418
bool IsDateDimension() const
Definition: dpgroup.hxx:84
virtual bool HasCommonElement(const ScDPItemData &rFirstData, sal_Int32 nFirstIndex, const ScDPItemData &rSecondData, sal_Int32 nSecondIndex) const override
Definition: dpgroup.cxx:935
virtual const std::vector< SCROW > & GetColumnEntries(sal_Int32 nColumn) override
Definition: dpgroup.cxx:525
When assigning a string value, you can also assign an interned string whose life-cycle is managed by ...
Definition: dpitemdata.hxx:28
void AddElement(const ScDPItemData &rName)
Definition: dpgroup.cxx:310
const ScDPGroupItem * GetGroupByIndex(size_t nIndex) const
Definition: dpgroup.cxx:405
ScDPGroupItem(const ScDPItemData &rName)
Definition: dpgroup.cxx:305
virtual sal_Int32 Compare(sal_Int32 nDim, sal_Int32 nDataId1, sal_Int32 nDataId2) override
Definition: dpgroup.cxx:1004
virtual bool IsDateDimension(sal_Int32 nDim) override
Definition: dpgroup.cxx:572
sal_Int16 SCCOL
Definition: types.hxx:21
virtual sal_Int32 GetGroupBase(sal_Int32 nGroupDim) const override
Definition: dpgroup.cxx:879
tools::Long GetSourceDim() const
Definition: dpgroup.hxx:70
virtual void CreateCacheTable() override
Definition: dpgroup.cxx:619
virtual bool IsInGroup(const ScDPItemData &rGroupData, sal_Int32 nGroupIndex, const ScDPItemData &rBaseData, sal_Int32 nBaseIndex) const override
Definition: dpgroup.cxx:907
virtual void GetDrillDownData(std::vector< ScDPFilteredCache::Criterion > &&rCriteria, std::unordered_set< sal_Int32 > &&rCatDims, css::uno::Sequence< css::uno::Sequence< css::uno::Any > > &rData) override
Definition: dpgroup.cxx:756
std::vector< SCROW > maMemberEntries
Definition: dpgroup.hxx:58
void FillGroupFilter(ScDPFilteredCache::GroupFilter &rFilter) const
Definition: dpgroup.cxx:327
sal_Int32 GetDimensionIndex(std::u16string_view rName)
Definition: dpgroup.cxx:497
virtual void ReloadCacheTable() override
Definition: dpgroup.cxx:798
virtual sal_Int32 GetMembersCount(sal_Int32 nDim) override
Definition: dpgroup.cxx:520
ScDPGroupDimension(tools::Long nSource, const OUString &rNewName)
Definition: dpgroup.cxx:333
virtual void DisposeData() override
Definition: dpgroup.cxx:598
virtual sal_Int32 GetColumnCount() override
use (new) typed collection instead of ScStrCollection or separate Str and ValueCollection ...
Definition: dpgroup.cxx:505
virtual sal_uInt32 GetNumberFormat(sal_Int32 nDim) override
Definition: dpgroup.cxx:585
const std::shared_ptr< ScDPTableData > & GetSourceTableData() const
Definition: dpgroup.hxx:137
std::vector< SCROW > maMemberEntries
Definition: dpgroup.hxx:90
void AddItem(const ScDPGroupItem &rItem)
Definition: dpgroup.cxx:365
const OUString & GetName() const
Definition: dpgroup.hxx:72
std::shared_ptr< ScDPTableData > pSourceData
Definition: dpgroup.hxx:116
virtual const ScDPItemData * GetMemberById(sal_Int32 nDim, sal_Int32 nId) override
Definition: dpgroup.cxx:548
Base class that abstracts different data source types of a datapilot table.
Definition: dptabdat.hxx:56
tools::Long nGroupDim
Definition: dpgroup.hxx:55
virtual void SetEmptyFlags(bool bIgnoreEmptyRows, bool bRepeatIfEmpty) override
Definition: dpgroup.cxx:609
bool HasCommonElement(const ScDPGroupItem &rOther) const
Definition: dpgroup.cxx:321
ScDPGroupDimension & operator=(const ScDPGroupDimension &rOther)
Definition: dpgroup.cxx:355
ScDPItemDataVec aElements
Definition: dpgroup.hxx:38
void ModifyFilterCriteria(::std::vector< ScDPFilteredCache::Criterion > &rCriteria)
Definition: dpgroup.cxx:640
ScDPNumGroupInfo aGroupInfo
Definition: dpgroup.hxx:89
const ScDPGroupItem * GetGroupForData(const ScDPItemData &rData) const
Definition: dpgroup.cxx:385
void SetGroupDim(tools::Long nDim)
Definition: dpgroup.cxx:370
virtual bool getIsDataLayoutDimension(sal_Int32 nColumn) override
Definition: dpgroup.cxx:566
This class is only a wrapper to the actual cache, to provide filtering on the raw data based on the q...
virtual const ScDPFilteredCache & GetCacheTable() const override
Definition: dpgroup.cxx:793
const ScDPGroupItem * GetGroupForName(const ScDPItemData &rName) const
Definition: dpgroup.cxx:395
virtual OUString getDimensionName(sal_Int32 nColumn) override
Definition: dpgroup.cxx:553
size_t GetItemCount() const
Definition: dpgroup.hxx:81
#define SC_DLLPUBLIC
Definition: scdllapi.h:27
sal_Int32 nSourceCount
Definition: dpgroup.hxx:117
const ScDPItemData & GetName() const
Definition: dpgroup.hxx:45
bool IsDateDimension() const
Definition: dpgroup.hxx:109
virtual bool IsRepeatIfEmpty() override
Definition: dpgroup.cxx:614