/src/libreoffice/sc/inc/pivot/PivotTableFormatOutput.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 | | |
10 | | #pragma once |
11 | | |
12 | | #include <com/sun/star/uno/Sequence.hxx> |
13 | | #include <tools/long.hxx> |
14 | | #include <address.hxx> |
15 | | #include <dptypes.hxx> |
16 | | #include "PivotTableFormats.hxx" |
17 | | |
18 | | #include <memory> |
19 | | #include <vector> |
20 | | |
21 | | namespace com::sun::star::sheet |
22 | | { |
23 | | struct MemberResult; |
24 | | } |
25 | | |
26 | | class ScDPObject; |
27 | | struct ScDPOutLevelData; |
28 | | |
29 | | namespace sc |
30 | | { |
31 | | /// Direction or orientation of the results |
32 | | enum class FormatResultDirection |
33 | | { |
34 | | ROW, |
35 | | COLUMN |
36 | | }; |
37 | | |
38 | | /// Data dimension constant |
39 | | constexpr tools::Long constDataDimension = -2; |
40 | | |
41 | | /// A field data for a format output, |
42 | | struct FormatOutputField |
43 | | { |
44 | | tools::Long nDimension = constDataDimension; |
45 | | OUString aName; |
46 | | sal_Int32 nIndex = -1; |
47 | | bool bMatchesAll = false; |
48 | | bool bSelected = true; |
49 | | bool bHasSubtotal = false; |
50 | | bool bSet = false; |
51 | | }; |
52 | | |
53 | | /// Data for a entry of a format output, which matches a one format entry |
54 | | struct FormatOutputEntry |
55 | | { |
56 | | FormatType eType = FormatType::None; |
57 | | std::optional<SCTAB> onTab = std::nullopt; |
58 | | std::shared_ptr<ScPatternAttr> pPattern; |
59 | | bool bGrandRow = false; |
60 | | bool bGrandColumn = false; |
61 | | std::optional<ScRange> oOffset = std::nullopt; |
62 | | |
63 | | std::vector<FormatOutputField> aRowOutputFields; |
64 | | std::vector<FormatOutputField> aColumnOutputFields; |
65 | | }; |
66 | | |
67 | | /// data of one "field" that is part of a line |
68 | | struct FieldData |
69 | | { |
70 | | tools::Long mnDimension = constDataDimension; |
71 | | OUString aName; |
72 | | tools::Long nIndex = -1; |
73 | | |
74 | | bool bIsSet = false; |
75 | | bool bIsMember = false; |
76 | | bool bSubtotal = false; |
77 | | bool bContinue = false; |
78 | | }; |
79 | | |
80 | | /// data for a "line" of one row/column axis |
81 | | struct LineData |
82 | | { |
83 | | /// primary axis depending if we are row or column oriented (when selecting a column or row we get a "line") |
84 | | std::optional<SCCOLROW> oLine = std::nullopt; |
85 | | /// secondary axis depending if we are row or column oriented (position in a line) |
86 | | std::optional<SCCOLROW> oPosition = std::nullopt; |
87 | | /// fields of a line |
88 | | std::vector<FieldData> maFields; |
89 | | }; |
90 | | |
91 | | /** Format output class, which is responsible to check if any of the formats and matches the |
92 | | * pivot table output, and applies the cell attributes when the match is found. */ |
93 | | class FormatOutput |
94 | | { |
95 | | private: |
96 | | ScDPObject& mrObject; |
97 | | |
98 | | bool tryHandleGrandTotals(ScDocument& rDocument, sc::FormatOutputEntry const& rEntry); |
99 | | |
100 | | public: |
101 | | FormatOutput(ScDPObject& rObject) |
102 | 309 | : mrObject(rObject) |
103 | 309 | { |
104 | 309 | } |
105 | | |
106 | | std::unique_ptr<sc::PivotTableFormats> mpFormats; |
107 | | std::vector<sc::FormatOutputEntry> maFormatOutputEntries; |
108 | | |
109 | | std::vector<LineData> maRowLines; |
110 | | std::vector<LineData> maColumnLines; |
111 | | |
112 | | SCROW mnGrandTotalRow = -1; |
113 | | SCCOL mnGrandTotalColumn = -1; |
114 | | SCCOL mnTabStartColumn = -1; |
115 | | SCROW mnTabStartRow = -1; |
116 | | SCCOL mnDataStartColumn = -1; |
117 | | SCROW mnDataStartRow = -1; |
118 | | SCCOL mnTabEndColumn = -1; |
119 | | SCROW mnTabEndRow = -1; |
120 | | |
121 | | void setFormats(sc::PivotTableFormats const& rPivotTableFormats) |
122 | 15 | { |
123 | 15 | mpFormats.reset(new sc::PivotTableFormats(rPivotTableFormats)); |
124 | 15 | } |
125 | | |
126 | | void insertFieldMember(size_t nFieldIndex, const ScDPOutLevelData& rField, |
127 | | tools::Long nMemberIndex, css::sheet::MemberResult const& rMember, |
128 | | SCCOL nColPos, SCROW nRowPos, FormatResultDirection eResultDirection); |
129 | | |
130 | | void insertEmptyDataColumn(SCCOL nColPos, SCROW nRowPos); |
131 | | |
132 | | void setGrandTotalPositions(SCROW nGrandTotalRow, SCCOL nGrandTotalColumn) |
133 | 309 | { |
134 | 309 | mnGrandTotalRow = nGrandTotalRow; |
135 | 309 | mnGrandTotalColumn = nGrandTotalColumn; |
136 | 309 | } |
137 | | |
138 | | void setDataArea(SCCOL nTabStartColumn, SCROW nTabStartRow, SCCOL nDataStartColumn, |
139 | | SCROW nDataStartRow, SCCOL nTabEndColumn, SCROW nTabEndRow) |
140 | 309 | { |
141 | 309 | mnTabStartColumn = nTabStartColumn; |
142 | 309 | mnTabStartRow = nTabStartRow; |
143 | 309 | mnDataStartColumn = nDataStartColumn; |
144 | 309 | mnDataStartRow = nDataStartRow; |
145 | 309 | mnTabEndColumn = nTabEndColumn; |
146 | 309 | mnTabEndRow = nTabEndRow; |
147 | 309 | } |
148 | | |
149 | | void apply(ScDocument& rDocument); |
150 | | void prepare(SCTAB nTab, std::vector<ScDPOutLevelData> const& rColumnFields, |
151 | | std::vector<ScDPOutLevelData> const& rRowFields, bool bColumnFieldIsDataOnly); |
152 | | }; |
153 | | |
154 | | } // end sc |
155 | | |
156 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |