tdf#62032 use style list level when changing style
[LibreOffice.git] / sc / inc / dpresfilter.hxx
blob379989788559cbd65d638fb3defaa1b4704883d9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #pragma once
12 #include <rtl/ustring.hxx>
13 #include "calcmacros.hxx"
15 #include <memory>
16 #include <map>
17 #include <vector>
18 #include <unordered_map>
20 namespace com::sun::star::uno
22 template <typename> class Sequence;
24 namespace com::sun::star::sheet
26 struct DataPilotFieldFilter;
29 struct ScDPResultFilter
31 OUString maDimName;
32 OUString maValueName;
33 OUString maValue;
35 bool mbHasValue : 1;
36 bool mbDataLayout : 1;
38 ScDPResultFilter(const OUString& rDimName, bool bDataLayout);
41 /**
42 * This class maintains pivot table calculation result in a tree structure
43 * which represents the logical structure of pivot table result layout as
44 * presented in the sheet.
46 * <p>The root node has two child nodes if the pivot table consists of both
47 * column and row dimensions. The first child stores the result tree that is
48 * first filtered by row dimensions then by column dimensions. The second
49 * child stores the result tree that is filtered by column dimensions only
50 * (for column grand totals).</p>
52 * <p>If the pivot table layout only consists of either column or row
53 * dimensions, the root node only has one child node.</p>
55 class ScDPResultTree
57 public:
58 typedef std::vector<double> ValuesType;
60 private:
61 struct MemberNode;
62 typedef std::map<OUString, std::shared_ptr<MemberNode>> MembersType;
64 struct DimensionNode
66 MembersType maChildMembersValueNames;
67 MembersType maChildMembersValues;
69 #if DEBUG_PIVOT_TABLE
70 void dump(int nLevel) const;
71 #endif
74 struct MemberNode
76 ValuesType maValues;
77 std::map<OUString, DimensionNode> maChildDimensions;
79 MemberNode();
80 MemberNode(const MemberNode&) = delete;
81 const MemberNode& operator=(const MemberNode&) = delete;
82 ~MemberNode();
84 #if DEBUG_PIVOT_TABLE
85 void dump(int nLevel) const;
86 #endif
89 typedef std::pair<OUString, OUString> NamePairType;
91 struct NamePairHash
93 size_t operator()(const NamePairType& rPair) const;
95 typedef std::unordered_map<NamePairType, double, NamePairHash> LeafValuesType;
96 LeafValuesType maLeafValues;
98 OUString maPrimaryDimName;
99 std::unique_ptr<MemberNode> mpRoot;
101 public:
102 ScDPResultTree();
103 ScDPResultTree(const ScDPResultTree&) = delete;
104 const ScDPResultTree& operator=(const ScDPResultTree&) = delete;
105 ~ScDPResultTree();
107 * Add a single value filter path. The filters are expected to be sorted
108 * by row dimension order then by column dimension order.
110 * @param rFilter set of filters.
111 * @param fVal result value, as displayed in the table output.
113 void add(const std::vector<ScDPResultFilter>& rFilter, double fVal);
115 void swap(ScDPResultTree& rOther);
117 bool empty() const;
118 void clear();
120 const ValuesType*
121 getResults(const css::uno::Sequence<css::sheet::DataPilotFieldFilter>& rFilters) const;
123 double getLeafResult(const css::sheet::DataPilotFieldFilter& rFilter) const;
125 #if DEBUG_PIVOT_TABLE
126 void dump() const;
127 #endif
130 struct ScDPResultFilterContext
132 ScDPResultTree maFilterSet;
133 std::vector<ScDPResultFilter> maFilters;
134 sal_Int32 mnCol;
135 sal_Int32 mnRow;
137 ScDPResultFilterContext();
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */