1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SC_INC_DPGROUP_HXX
21 #define INCLUDED_SC_INC_DPGROUP_HXX
24 #include <unordered_set>
27 #include "dptabdat.hxx"
29 #include "dpitemdata.hxx"
30 #include "dpnumgroupinfo.hxx"
34 typedef ::std::vector
<ScDPItemData
> ScDPItemDataVec
;
38 ScDPItemData aGroupName
; // name of group item
39 ScDPItemDataVec aElements
; // names of items in original dimension
42 ScDPGroupItem( const ScDPItemData
& rName
);
45 void AddElement( const ScDPItemData
& rName
);
47 const ScDPItemData
& GetName() const { return aGroupName
; }
48 bool HasElement( const ScDPItemData
& rData
) const;
49 bool HasCommonElement( const ScDPGroupItem
& rOther
) const;
51 void FillGroupFilter( ScDPFilteredCache::GroupFilter
& rFilter
) const;
54 typedef ::std::vector
<ScDPGroupItem
> ScDPGroupItemVec
;
56 class ScDPGroupDimension
61 ScDPGroupItemVec aItems
;
62 mutable std::vector
<SCROW
> maMemberEntries
;
65 ScDPGroupDimension( long nSource
, const OUString
& rNewName
);
66 ScDPGroupDimension( const ScDPGroupDimension
& rOther
);
67 ~ScDPGroupDimension();
69 ScDPGroupDimension
& operator=( const ScDPGroupDimension
& rOther
);
71 void AddItem( const ScDPGroupItem
& rItem
);
72 void SetGroupDim( long nDim
); // called from AddGroupDimension
74 long GetSourceDim() const { return nSourceDim
; }
75 long GetGroupDim() const { return nGroupDim
; }
76 const OUString
& GetName() const { return aGroupName
; }
78 const std::vector
< SCROW
>& GetColumnEntries( const ScDPFilteredCache
& rCacheTable
) const;
79 const ScDPGroupItem
* GetGroupForData( const ScDPItemData
& rData
) const; // rData = entry in original dim.
80 const ScDPGroupItem
* GetGroupForName( const ScDPItemData
& rName
) const; // rName = entry in group dim.
81 const ScDPGroupItem
* GetGroupByIndex( size_t nIndex
) const;
85 size_t GetItemCount() const { return aItems
.size(); }
87 void SetDateDimension();
88 bool IsDateDimension() const { return mbDateDimension
;}
91 typedef ::std::vector
<ScDPGroupDimension
> ScDPGroupDimensionVec
;
93 class SC_DLLPUBLIC ScDPNumGroupDimension
95 mutable ScDPNumGroupInfo aGroupInfo
; // settings
96 mutable std::vector
<SCROW
> maMemberEntries
;
100 ScDPNumGroupDimension();
101 ScDPNumGroupDimension( const ScDPNumGroupInfo
& rInfo
);
102 ScDPNumGroupDimension( const ScDPNumGroupDimension
& rOther
);
103 ~ScDPNumGroupDimension();
105 ScDPNumGroupDimension
& operator=( const ScDPNumGroupDimension
& rOther
);
107 const ScDPNumGroupInfo
& GetInfo() const { return aGroupInfo
; }
109 const std::vector
<SCROW
>& GetNumEntries(SCCOL nSourceDim
, const ScDPCache
* pCache
) const;
111 void SetDateDimension();
115 bool IsDateDimension() const { return mbDateDimension
;}
118 // proxy implementation of ScDPTableData to add grouped items
120 class ScDPGroupTableData
: public ScDPTableData
122 std::shared_ptr
<ScDPTableData
> pSourceData
;
124 ScDPGroupDimensionVec aGroups
;
125 std::unique_ptr
<ScDPNumGroupDimension
[]>
126 pNumGroups
; // array[nSourceCount]
128 std::unordered_set
< OUString
>
131 void FillGroupValues(std::vector
<SCROW
>& rItems
, const std::vector
<long>& rDims
);
132 virtual long GetSourceDim( long nDim
) override
;
134 bool IsNumGroupDimension( long nDimension
) const;
135 void GetNumGroupInfo(long nDimension
, ScDPNumGroupInfo
& rInfo
);
137 void ModifyFilterCriteria(::std::vector
<ScDPFilteredCache::Criterion
>& rCriteria
);
140 // takes ownership of pSource
141 ScDPGroupTableData( const std::shared_ptr
<ScDPTableData
>& pSource
, ScDocument
* pDocument
);
142 virtual ~ScDPGroupTableData() override
;
144 const std::shared_ptr
<ScDPTableData
>& GetSourceTableData() const { return pSourceData
;}
146 void AddGroupDimension( const ScDPGroupDimension
& rGroup
);
147 void SetNumGroupDimension( long nIndex
, const ScDPNumGroupDimension
& rGroup
);
148 long GetDimensionIndex( const OUString
& rName
);
150 virtual long GetColumnCount() override
;
151 virtual long GetMembersCount( long nDim
) override
;
152 virtual const std::vector
< SCROW
>& GetColumnEntries( long nColumn
) override
;
153 virtual const ScDPItemData
* GetMemberById( long nDim
, long nId
) override
;
154 virtual long Compare( long nDim
, long nDataId1
, long nDataId2
) override
;
156 virtual OUString
getDimensionName(long nColumn
) override
;
157 virtual bool getIsDataLayoutDimension(long nColumn
) override
;
158 virtual bool IsDateDimension(long nDim
) override
;
159 virtual sal_uInt32
GetNumberFormat(long nDim
) override
;
160 virtual void DisposeData() override
;
161 virtual void SetEmptyFlags( bool bIgnoreEmptyRows
, bool bRepeatIfEmpty
) override
;
163 virtual bool IsRepeatIfEmpty() override
;
165 virtual void CreateCacheTable() override
;
166 virtual void FilterCacheTable(const std::vector
<ScDPFilteredCache::Criterion
>& rCriteria
, const std::unordered_set
<sal_Int32
>& rDataDims
) override
;
167 virtual void GetDrillDownData(const std::vector
<ScDPFilteredCache::Criterion
>& rCriteria
,
168 const std::unordered_set
<sal_Int32
>& rCatDims
,
169 css::uno::Sequence
< css::uno::Sequence
< css::uno::Any
> >& rData
) override
;
170 virtual void CalcResults(CalcInfo
& rInfo
, bool bAutoShow
) override
;
171 virtual const ScDPFilteredCache
& GetCacheTable() const override
;
172 virtual void ReloadCacheTable() override
;
174 virtual bool IsBaseForGroup(long nDim
) const override
;
175 virtual long GetGroupBase(long nGroupDim
) const override
;
176 virtual bool IsNumOrDateGroup(long nDim
) const override
;
177 virtual bool IsInGroup( const ScDPItemData
& rGroupData
, long nGroupIndex
,
178 const ScDPItemData
& rBaseData
, long nBaseIndex
) const override
;
179 virtual bool HasCommonElement( const ScDPItemData
& rFirstData
, long nFirstIndex
,
180 const ScDPItemData
& rSecondData
, long nSecondIndex
) const override
;
183 virtual void Dump() const override
;
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */