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 SC_DPGROUP_HXX
21 #define SC_DPGROUP_HXX
24 #include <boost/unordered_set.hpp>
25 #include <boost/shared_ptr.hpp>
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;
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;
119 // proxy implementation of ScDPTableData to add grouped items
122 class ScDPGroupTableData
: public ScDPTableData
124 typedef ::boost::unordered_set
< OUString
, OUStringHash
, ::std::equal_to
< OUString
> > StringHashSet
;
126 ::boost::shared_ptr
<ScDPTableData
> pSourceData
;
128 ScDPGroupDimensionVec aGroups
;
129 ScDPNumGroupDimension
* pNumGroups
; // array[nSourceCount]
131 StringHashSet aGroupNames
;
133 void FillGroupValues(std::vector
<SCROW
>& rItems
, const std::vector
<long>& rDims
);
134 virtual long GetSourceDim( long nDim
);
136 bool IsNumGroupDimension( long nDimension
) const;
137 void GetNumGroupInfo(long nDimension
, ScDPNumGroupInfo
& rInfo
);
139 void ModifyFilterCriteria(::std::vector
<ScDPFilteredCache::Criterion
>& rCriteria
);
142 // takes ownership of pSource
143 ScDPGroupTableData( const ::boost::shared_ptr
<ScDPTableData
>& pSource
, ScDocument
* pDocument
);
144 virtual ~ScDPGroupTableData();
146 boost::shared_ptr
<ScDPTableData
> GetSourceTableData();
148 void AddGroupDimension( const ScDPGroupDimension
& rGroup
);
149 void SetNumGroupDimension( long nIndex
, const ScDPNumGroupDimension
& rGroup
);
150 long GetDimensionIndex( const OUString
& rName
);
152 ScDocument
* GetDocument() { return pDoc
; }
154 virtual long GetColumnCount();
155 virtual long GetMembersCount( long nDim
);
156 virtual const std::vector
< SCROW
>& GetColumnEntries( long nColumn
) ;
157 virtual const ScDPItemData
* GetMemberById( long nDim
, long nId
);
158 virtual long Compare( long nDim
, long nDataId1
, long nDataId2
);
160 virtual OUString
getDimensionName(long nColumn
);
161 virtual sal_Bool
getIsDataLayoutDimension(long nColumn
);
162 virtual sal_Bool
IsDateDimension(long nDim
);
163 virtual sal_uLong
GetNumberFormat(long nDim
);
164 virtual void DisposeData();
165 virtual void SetEmptyFlags( sal_Bool bIgnoreEmptyRows
, sal_Bool bRepeatIfEmpty
);
167 virtual bool IsRepeatIfEmpty();
169 virtual void CreateCacheTable();
170 virtual void FilterCacheTable(const ::std::vector
<ScDPFilteredCache::Criterion
>& rCriteria
, const ::boost::unordered_set
<sal_Int32
>& rDataDims
);
171 virtual void GetDrillDownData(const ::std::vector
<ScDPFilteredCache::Criterion
>& rCriteria
,
172 const ::boost::unordered_set
<sal_Int32
>& rCatDims
,
173 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
> >& rData
);
174 virtual void CalcResults(CalcInfo
& rInfo
, bool bAutoShow
);
175 virtual const ScDPFilteredCache
& GetCacheTable() const;
176 virtual void ReloadCacheTable();
178 virtual sal_Bool
IsBaseForGroup(long nDim
) const;
179 virtual long GetGroupBase(long nGroupDim
) const;
180 virtual sal_Bool
IsNumOrDateGroup(long nDim
) const;
181 virtual sal_Bool
IsInGroup( const ScDPItemData
& rGroupData
, long nGroupIndex
,
182 const ScDPItemData
& rBaseData
, long nBaseIndex
) const;
183 virtual sal_Bool
HasCommonElement( const ScDPItemData
& rFirstData
, long nFirstIndex
,
184 const ScDPItemData
& rSecondData
, long nSecondIndex
) const;
186 #if DEBUG_PIVOT_TABLE
187 virtual void Dump() const;
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */