Coverage Report

Created: 2026-10-14 09:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sc/inc/dpgroup.hxx
Line
Count
Source
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
class ScTokenArray;
33
34
typedef ::std::vector<ScDPItemData> ScDPItemDataVec;
35
36
class ScDPGroupItem
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
47
    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
53
class ScDPGroupDimension
54
{
55
    tools::Long                        nSourceDim;
56
    tools::Long                        nGroupDim;
57
    OUString                    aGroupName;
58
    std::vector<ScDPGroupItem>  aItems;
59
    mutable std::vector<SCROW> maMemberEntries;
60
    bool mbDateDimension;
61
public:
62
                ScDPGroupDimension( tools::Long nSource, OUString aNewName );
63
                ScDPGroupDimension( const ScDPGroupDimension& rOther );
64
                ~ScDPGroupDimension();
65
66
    ScDPGroupDimension& operator=( const ScDPGroupDimension& rOther );
67
68
    void        AddItem( const ScDPGroupItem& rItem );
69
    void        SetGroupDim( tools::Long nDim );           // called from AddGroupDimension
70
71
8.21k
    tools::Long        GetSourceDim() const    { return nSourceDim; }
72
19
    tools::Long        GetGroupDim() const     { return nGroupDim; }
73
727
    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
0
    size_t      GetItemCount() const { return aItems.size(); }
83
84
    void SetDateDimension();
85
4.01k
    bool IsDateDimension() const { return mbDateDimension;}
86
};
87
88
class SC_DLLPUBLIC ScDPNumGroupDimension
89
{
90
    mutable ScDPNumGroupInfo    aGroupInfo;         // settings
91
    mutable std::vector<SCROW>  maMemberEntries;
92
    bool mbDateDimension;
93
94
public:
95
                ScDPNumGroupDimension();
96
                ScDPNumGroupDimension( const ScDPNumGroupInfo& rInfo );
97
                ScDPNumGroupDimension( const ScDPNumGroupDimension& rOther );
98
                ~ScDPNumGroupDimension();
99
100
    ScDPNumGroupDimension&  operator=( const ScDPNumGroupDimension& rOther );
101
102
139
    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
0
    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;
118
    sal_Int32                    nSourceCount;
119
    std::vector<ScDPGroupDimension>
120
                            aGroups;
121
    std::unique_ptr<ScDPNumGroupDimension[]>
122
                            pNumGroups;     // array[nSourceCount]
123
    ScDocument*             pDoc;
124
125
    void FillGroupValues(std::vector<SCROW>& rItems, const std::vector<sal_Int32>& rDims);
126
    virtual sal_Int32                GetSourceDim( sal_Int32 nDim ) override;
127
128
    /// Maps a proxy dimension index in the calc field zone [N+G, N+G+C) to the
129
    /// actual cache mnIndex (OOXML field index). Returns nDim unchanged for other zones.
130
    sal_Int32   CalcFieldToCacheIndex( sal_Int32 nDim ) const;
131
132
    bool        IsNumGroupDimension( tools::Long nDimension ) const;
133
    void GetNumGroupInfo(tools::Long nDimension, ScDPNumGroupInfo& rInfo);
134
135
    void        ModifyFilterCriteria(::std::vector<ScDPFilteredCache::Criterion>& rCriteria);
136
137
public:
138
                // takes ownership of pSource
139
                ScDPGroupTableData( const std::shared_ptr<ScDPTableData>& pSource, ScDocument* pDocument );
140
    virtual     ~ScDPGroupTableData() override;
141
142
7
    const std::shared_ptr<ScDPTableData>& GetSourceTableData() const { return pSourceData;}
143
144
    void        AddGroupDimension( const ScDPGroupDimension& rGroup );
145
    void        SetNumGroupDimension( sal_Int32 nIndex, const ScDPNumGroupDimension& rGroup );
146
    sal_Int32        GetDimensionIndex( std::u16string_view rName );
147
148
    virtual sal_Int32                    GetColumnCount() override;
149
    virtual sal_Int32                    GetCalculatedColumnCount() override;
150
    virtual sal_Int32                    GetMembersCount( sal_Int32 nDim ) override;
151
    virtual const std::vector< SCROW >& GetColumnEntries( sal_Int32 nColumn ) override ;
152
    virtual const ScDPItemData* GetMemberById( sal_Int32 nDim, sal_Int32 nId) override;
153
    virtual sal_Int32 Compare( sal_Int32 nDim, sal_Int32 nDataId1, sal_Int32 nDataId2) override;
154
155
    virtual OUString                getDimensionName(sal_Int32 nColumn) override;
156
    virtual bool                    getIsDataLayoutDimension(sal_Int32 nColumn) override;
157
    virtual bool                    IsDateDimension(sal_Int32 nDim) override;
158
    virtual bool                    IsCalculatedDimension(sal_Int32 nDim) override;
159
    virtual OUString                GetCalculation(sal_Int32 nDim) override;
160
    virtual const ScTokenArray*     GetCalculationToken(sal_Int32 nDim) override;
161
    virtual sal_uInt32              GetNumberFormat(sal_Int32 nDim) override;
162
    virtual void                    DisposeData() override;
163
    virtual void                    SetEmptyFlags( bool bIgnoreEmptyRows, bool bRepeatIfEmpty ) override;
164
165
    virtual bool                    IsRepeatIfEmpty() override;
166
167
    virtual void                    CreateCacheTable() override;
168
    virtual void                    FilterCacheTable(std::vector<ScDPFilteredCache::Criterion>&& rCriteria, std::unordered_set<sal_Int32>&& rDataDims) override;
169
    virtual void                    GetDrillDownData(std::vector<ScDPFilteredCache::Criterion>&& rCriteria,
170
                                                     std::unordered_set<sal_Int32>&& rCatDims,
171
                                                     css::uno::Sequence< css::uno::Sequence< css::uno::Any > >& rData) override;
172
    virtual void                    CalcResults(CalcInfo& rInfo, bool bAutoShow) override;
173
    virtual const ScDPFilteredCache&   GetCacheTable() const override;
174
    virtual void ReloadCacheTable() override;
175
176
    virtual bool                    IsBaseForGroup(sal_Int32 nDim) const override;
177
    virtual sal_Int32               GetGroupBase(sal_Int32 nGroupDim) const override;
178
    virtual bool                    IsNumOrDateGroup(sal_Int32 nDim) const override;
179
    virtual bool                    IsInGroup( const ScDPItemData& rGroupData, sal_Int32 nGroupIndex,
180
                                               const ScDPItemData& rBaseData, sal_Int32 nBaseIndex ) const override;
181
    virtual bool                    HasCommonElement( const ScDPItemData& rFirstData, sal_Int32 nFirstIndex,
182
                                                      const ScDPItemData& rSecondData, sal_Int32 nSecondIndex ) const override;
183
184
#if DUMP_PIVOT_TABLE
185
    virtual void Dump() const override;
186
#endif
187
};
188
189
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */