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 #ifndef INCLUDED_SC_INC_DPGROUP_HXX
21 #define INCLUDED_SC_INC_DPGROUP_HXX
22 
23 #include <memory>
24 #include <unordered_set>
25 #include <vector>
26 
27 #include "dptabdat.hxx"
28 #include "scdllapi.h"
29 #include "dpitemdata.hxx"
30 #include "dpnumgroupinfo.hxx"
31 
32 class ScDocument;
33 
34 typedef ::std::vector<ScDPItemData> ScDPItemDataVec;
35 
37 {
38  ScDPItemData aGroupName; // name of group item
39  ScDPItemDataVec aElements; // names of items in original dimension
40 
41 public:
42  ScDPGroupItem( const ScDPItemData& rName );
43 
44  void AddElement( const ScDPItemData& rName );
45 
46  const ScDPItemData& GetName() const { return aGroupName; }
47  bool HasElement( const ScDPItemData& rData ) const;
48  bool HasCommonElement( const ScDPGroupItem& rOther ) const;
49 
50  void FillGroupFilter( ScDPFilteredCache::GroupFilter& rFilter ) const;
51 };
52 
54 {
55  long nSourceDim;
56  long nGroupDim;
57  OUString aGroupName;
58  std::vector<ScDPGroupItem> aItems;
59  mutable std::vector<SCROW> maMemberEntries;
61 public:
62  ScDPGroupDimension( long nSource, const OUString& rNewName );
63  ScDPGroupDimension( const ScDPGroupDimension& rOther );
65 
67 
68  void AddItem( const ScDPGroupItem& rItem );
69  void SetGroupDim( long nDim ); // called from AddGroupDimension
70 
71  long GetSourceDim() const { return nSourceDim; }
72  long GetGroupDim() const { return nGroupDim; }
73  const OUString& GetName() const { return aGroupName; }
74 
75  const std::vector< SCROW >& GetColumnEntries( const ScDPFilteredCache& rCacheTable ) const;
76  const ScDPGroupItem* GetGroupForData( const ScDPItemData& rData ) const; // rData = entry in original dim.
77  const ScDPGroupItem* GetGroupForName( const ScDPItemData& rName ) const; // rName = entry in group dim.
78  const ScDPGroupItem* GetGroupByIndex( size_t nIndex ) const;
79 
80  void DisposeData();
81 
82  size_t GetItemCount() const { return aItems.size(); }
83 
84  void SetDateDimension();
85  bool IsDateDimension() const { return mbDateDimension;}
86 };
87 
89 {
90  mutable ScDPNumGroupInfo aGroupInfo; // settings
91  mutable std::vector<SCROW> maMemberEntries;
93 
94 public:
99 
100  ScDPNumGroupDimension& operator=( const ScDPNumGroupDimension& rOther );
101 
102  const ScDPNumGroupInfo& GetInfo() const { return aGroupInfo; }
103 
104  const std::vector<SCROW>& GetNumEntries(SCCOL nSourceDim, const ScDPCache* pCache) const;
105 
106  void SetDateDimension();
107 
108  void DisposeData();
109 
110  bool IsDateDimension() const { return mbDateDimension;}
111 };
112 
113 // proxy implementation of ScDPTableData to add grouped items
114 
115 class ScDPGroupTableData final : public ScDPTableData
116 {
117  std::shared_ptr<ScDPTableData> pSourceData;
119  std::vector<ScDPGroupDimension>
121  std::unique_ptr<ScDPNumGroupDimension[]>
122  pNumGroups; // array[nSourceCount]
124 
125  void FillGroupValues(std::vector<SCROW>& rItems, const std::vector<long>& rDims);
126  virtual long GetSourceDim( long nDim ) override;
127 
128  bool IsNumGroupDimension( long nDimension ) const;
129  void GetNumGroupInfo(long nDimension, ScDPNumGroupInfo& rInfo);
130 
131  void ModifyFilterCriteria(::std::vector<ScDPFilteredCache::Criterion>& rCriteria);
132 
133 public:
134  // takes ownership of pSource
135  ScDPGroupTableData( const std::shared_ptr<ScDPTableData>& pSource, ScDocument* pDocument );
136  virtual ~ScDPGroupTableData() override;
137 
138  const std::shared_ptr<ScDPTableData>& GetSourceTableData() const { return pSourceData;}
139 
140  void AddGroupDimension( const ScDPGroupDimension& rGroup );
141  void SetNumGroupDimension( long nIndex, const ScDPNumGroupDimension& rGroup );
142  long GetDimensionIndex( const OUString& rName );
143 
144  virtual long GetColumnCount() override;
145  virtual long GetMembersCount( long nDim ) override;
146  virtual const std::vector< SCROW >& GetColumnEntries( long nColumn ) override ;
147  virtual const ScDPItemData* GetMemberById( long nDim, long nId) override;
148  virtual long Compare( long nDim, long nDataId1, long nDataId2) override;
149 
150  virtual OUString getDimensionName(long nColumn) override;
151  virtual bool getIsDataLayoutDimension(long nColumn) override;
152  virtual bool IsDateDimension(long nDim) override;
153  virtual sal_uInt32 GetNumberFormat(long nDim) override;
154  virtual void DisposeData() override;
155  virtual void SetEmptyFlags( bool bIgnoreEmptyRows, bool bRepeatIfEmpty ) override;
156 
157  virtual bool IsRepeatIfEmpty() override;
158 
159  virtual void CreateCacheTable() override;
160  virtual void FilterCacheTable(const std::vector<ScDPFilteredCache::Criterion>& rCriteria, const std::unordered_set<sal_Int32>& rDataDims) override;
161  virtual void GetDrillDownData(const std::vector<ScDPFilteredCache::Criterion>& rCriteria,
162  const std::unordered_set<sal_Int32>& rCatDims,
163  css::uno::Sequence< css::uno::Sequence< css::uno::Any > >& rData) override;
164  virtual void CalcResults(CalcInfo& rInfo, bool bAutoShow) override;
165  virtual const ScDPFilteredCache& GetCacheTable() const override;
166  virtual void ReloadCacheTable() override;
167 
168  virtual bool IsBaseForGroup(long nDim) const override;
169  virtual long GetGroupBase(long nGroupDim) const override;
170  virtual bool IsNumOrDateGroup(long nDim) const override;
171  virtual bool IsInGroup( const ScDPItemData& rGroupData, long nGroupIndex,
172  const ScDPItemData& rBaseData, long nBaseIndex ) const override;
173  virtual bool HasCommonElement( const ScDPItemData& rFirstData, long nFirstIndex,
174  const ScDPItemData& rSecondData, long nSecondIndex ) const override;
175 
176 #if DUMP_PIVOT_TABLE
177  virtual void Dump() const override;
178 #endif
179 };
180 
181 #endif
182 
183 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void FilterCacheTable(const std::vector< ScDPFilteredCache::Criterion > &rCriteria, const std::unordered_set< sal_Int32 > &rDataDims) override
Definition: dpgroup.cxx:749
virtual bool IsBaseForGroup(long nDim) const override
Definition: dpgroup.cxx:874
void FillGroupValues(std::vector< SCROW > &rItems, const std::vector< long > &rDims)
Definition: dpgroup.cxx:804
virtual void CalcResults(CalcInfo &rInfo, bool bAutoShow) override
Definition: dpgroup.cxx:763
OUString aGroupName
Definition: dpgroup.hxx:57
const ScDPNumGroupInfo & GetInfo() const
Definition: dpgroup.hxx:102
void AddGroupDimension(const ScDPGroupDimension &rGroup)
Definition: dpgroup.cxx:479
const std::vector< SCROW > & GetColumnEntries(const ScDPFilteredCache &rCacheTable) const
Definition: dpgroup.cxx:374
long GetGroupDim() const
Definition: dpgroup.hxx:72
void SetNumGroupDimension(long nIndex, const ScDPNumGroupDimension &rGroup)
Definition: dpgroup.cxx:486
ScDPItemData aGroupName
Definition: dpgroup.hxx:38
ScDPGroupTableData(const std::shared_ptr< ScDPTableData > &pSource, ScDocument *pDocument)
Definition: dpgroup.cxx:463
bool HasElement(const ScDPItemData &rData) const
Definition: dpgroup.cxx:314
std::vector< ScDPGroupDimension > aGroups
Definition: dpgroup.hxx:120
std::vector< ScDPGroupItem > aItems
Definition: dpgroup.hxx:58
virtual ~ScDPGroupTableData() override
Definition: dpgroup.cxx:475
This class represents the cached data part of the datapilot cache table implementation.
Definition: dpcache.hxx:47
virtual bool IsNumOrDateGroup(long nDim) const override
Definition: dpgroup.cxx:890
std::unique_ptr< ScDPNumGroupDimension[]> pNumGroups
Definition: dpgroup.hxx:122
virtual void Dump() const override
virtual bool IsDateDimension(long nDim) override
Definition: dpgroup.cxx:571
virtual long Compare(long nDim, long nDataId1, long nDataId2) override
Definition: dpgroup.cxx:1005
virtual void GetDrillDownData(const std::vector< ScDPFilteredCache::Criterion > &rCriteria, const std::unordered_set< sal_Int32 > &rCatDims, css::uno::Sequence< css::uno::Sequence< css::uno::Any > > &rData) override
Definition: dpgroup.cxx:756
virtual long GetColumnCount() override
use (new) typed collection instead of ScStrCollection or separate Str and ValueCollection ...
Definition: dpgroup.cxx:504
multi-item (group) filter.
ScDocument * pDoc
Definition: dpgroup.hxx:123
::std::vector< ScDPItemData > ScDPItemDataVec
Definition: dpgroup.hxx:32
virtual long GetGroupBase(long nGroupDim) const override
Definition: dpgroup.cxx:880
virtual bool getIsDataLayoutDimension(long nColumn) override
Definition: dpgroup.cxx:565
void SetDateDimension()
Definition: dpgroup.cxx:417
bool IsDateDimension() const
Definition: dpgroup.hxx:85
virtual OUString getDimensionName(long nColumn) override
Definition: dpgroup.cxx:552
When assigning a string value, you can also assign an interned string whose life-cycle is managed by ...
Definition: dpitemdata.hxx:29
void AddElement(const ScDPItemData &rName)
Definition: dpgroup.cxx:309
virtual const std::vector< SCROW > & GetColumnEntries(long nColumn) override
Definition: dpgroup.cxx:524
const ScDPGroupItem * GetGroupByIndex(size_t nIndex) const
Definition: dpgroup.cxx:404
ScDPGroupItem(const ScDPItemData &rName)
Definition: dpgroup.cxx:304
long GetSourceDim() const
Definition: dpgroup.hxx:71
sal_Int16 SCCOL
Definition: types.hxx:22
virtual void CreateCacheTable() override
Definition: dpgroup.cxx:618
virtual bool IsInGroup(const ScDPItemData &rGroupData, long nGroupIndex, const ScDPItemData &rBaseData, long nBaseIndex) const override
Definition: dpgroup.cxx:908
std::vector< SCROW > maMemberEntries
Definition: dpgroup.hxx:59
virtual const ScDPItemData * GetMemberById(long nDim, long nId) override
Definition: dpgroup.cxx:547
void FillGroupFilter(ScDPFilteredCache::GroupFilter &rFilter) const
Definition: dpgroup.cxx:326
virtual void ReloadCacheTable() override
Definition: dpgroup.cxx:799
virtual void DisposeData() override
Definition: dpgroup.cxx:597
const std::shared_ptr< ScDPTableData > & GetSourceTableData() const
Definition: dpgroup.hxx:138
std::vector< SCROW > maMemberEntries
Definition: dpgroup.hxx:91
void AddItem(const ScDPGroupItem &rItem)
Definition: dpgroup.cxx:364
const OUString & GetName() const
Definition: dpgroup.hxx:73
std::shared_ptr< ScDPTableData > pSourceData
Definition: dpgroup.hxx:117
Base class that abstracts different data source types of a datapilot table.
Definition: dptabdat.hxx:56
virtual void SetEmptyFlags(bool bIgnoreEmptyRows, bool bRepeatIfEmpty) override
Definition: dpgroup.cxx:608
virtual long GetSourceDim(long nDim) override
Definition: dpgroup.cxx:993
virtual long GetMembersCount(long nDim) override
Definition: dpgroup.cxx:519
bool HasCommonElement(const ScDPGroupItem &rOther) const
Definition: dpgroup.cxx:320
ScDPGroupDimension & operator=(const ScDPGroupDimension &rOther)
Definition: dpgroup.cxx:354
ScDPItemDataVec aElements
Definition: dpgroup.hxx:39
void GetNumGroupInfo(long nDimension, ScDPNumGroupInfo &rInfo)
Definition: dpgroup.cxx:514
void ModifyFilterCriteria(::std::vector< ScDPFilteredCache::Criterion > &rCriteria)
Definition: dpgroup.cxx:639
ScDPGroupDimension(long nSource, const OUString &rNewName)
Definition: dpgroup.cxx:332
virtual bool HasCommonElement(const ScDPItemData &rFirstData, long nFirstIndex, const ScDPItemData &rSecondData, long nSecondIndex) const override
Definition: dpgroup.cxx:936
ScDPNumGroupInfo aGroupInfo
Definition: dpgroup.hxx:90
virtual sal_uInt32 GetNumberFormat(long nDim) override
Definition: dpgroup.cxx:584
const ScDPGroupItem * GetGroupForData(const ScDPItemData &rData) const
Definition: dpgroup.cxx:384
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:794
const ScDPGroupItem * GetGroupForName(const ScDPItemData &rName) const
Definition: dpgroup.cxx:394
size_t GetItemCount() const
Definition: dpgroup.hxx:82
#define SC_DLLPUBLIC
Definition: scdllapi.h:28
long GetDimensionIndex(const OUString &rName)
Definition: dpgroup.cxx:496
void SetGroupDim(long nDim)
Definition: dpgroup.cxx:369
bool IsNumGroupDimension(long nDimension) const
Definition: dpgroup.cxx:509
const ScDPItemData & GetName() const
Definition: dpgroup.hxx:46
bool IsDateDimension() const
Definition: dpgroup.hxx:110
virtual bool IsRepeatIfEmpty() override
Definition: dpgroup.cxx:613