LibreOffice Module sc (master) 1
SparklineGroupsImportContext.cxx
Go to the documentation of this file.
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
11
14#include <xmloff/xmltoken.hxx>
15#include <xmloff/xmluconv.hxx>
16
17#include <document.hxx>
18#include <rangeutl.hxx>
19#include <Sparkline.hxx>
20#include <SparklineGroup.hxx>
22
23using namespace xmloff::token;
24using namespace css;
25
26namespace sc
27{
29 : ScXMLImportContext(rImport)
30{
31}
32
33namespace
34{
35sc::SparklineType parseSparklineType(std::string_view aString)
36{
37 if (aString == "column")
39 else if (aString == "stacked")
42}
43
44sc::DisplayEmptyCellsAs parseDisplayEmptyCellsAs(std::string_view aString)
45{
46 if (aString == "span")
48 else if (aString == "gap")
51}
52
53sc::AxisType parseAxisType(std::string_view aString)
54{
55 if (aString == "group")
57 else if (aString == "custom")
60}
61
62} // end anonymous namespace
63
65 uno::Reference<xml::sax::XFastAttributeList> const& xAttrList)
66{
67 for (auto& rIter : sax_fastparser::castToFastAttributeList(xAttrList))
68 {
69 switch (rIter.getToken())
70 {
71 case XML_ELEMENT(CALC_EXT, XML_ID):
72 {
73 tools::Guid aGuid(rIter.toView());
74 m_pCurrentSparklineGroup->setID(aGuid);
75 break;
76 }
77 }
78 }
79}
80
82 uno::Reference<xml::sax::XFastAttributeList> const& xAttrList)
83{
84 sc::SparklineAttributes& rAttributes = m_pCurrentSparklineGroup->getAttributes();
85
86 for (auto& rIter : sax_fastparser::castToFastAttributeList(xAttrList))
87 {
88 switch (rIter.getToken())
89 {
90 case XML_ELEMENT(CALC_EXT, XML_TYPE):
91 {
92 rAttributes.setType(parseSparklineType(rIter.toView()));
93 break;
94 }
95 case XML_ELEMENT(CALC_EXT, XML_LINE_WIDTH):
96 {
97 OUString sLineWidth = rIter.toString();
98 double fLineWidth;
99 sal_Int16 const eSrcUnit
100 = ::sax::Converter::GetUnitFromString(sLineWidth, util::MeasureUnit::POINT);
101 ::sax::Converter::convertDouble(fLineWidth, sLineWidth, eSrcUnit,
102 util::MeasureUnit::POINT);
103 rAttributes.setLineWeight(fLineWidth);
104 break;
105 }
106 case XML_ELEMENT(CALC_EXT, XML_DATE_AXIS):
107 {
108 rAttributes.setDateAxis(rIter.toBoolean());
109 break;
110 }
112 {
113 auto eDisplayEmptyCellsAs = parseDisplayEmptyCellsAs(rIter.toView());
114 rAttributes.setDisplayEmptyCellsAs(eDisplayEmptyCellsAs);
115 break;
116 }
117 case XML_ELEMENT(CALC_EXT, XML_MARKERS):
118 {
119 rAttributes.setMarkers(rIter.toBoolean());
120 break;
121 }
122 case XML_ELEMENT(CALC_EXT, XML_HIGH):
123 {
124 rAttributes.setHigh(rIter.toBoolean());
125 break;
126 }
127 case XML_ELEMENT(CALC_EXT, XML_LOW):
128 {
129 rAttributes.setLow(rIter.toBoolean());
130 break;
131 }
132 case XML_ELEMENT(CALC_EXT, XML_FIRST):
133 {
134 rAttributes.setFirst(rIter.toBoolean());
135 break;
136 }
137 case XML_ELEMENT(CALC_EXT, XML_LAST):
138 {
139 rAttributes.setLast(rIter.toBoolean());
140 break;
141 }
142 case XML_ELEMENT(CALC_EXT, XML_NEGATIVE):
143 {
144 rAttributes.setNegative(rIter.toBoolean());
145 break;
146 }
147 case XML_ELEMENT(CALC_EXT, XML_DISPLAY_X_AXIS):
148 {
149 rAttributes.setDisplayXAxis(rIter.toBoolean());
150 break;
151 }
152 case XML_ELEMENT(CALC_EXT, XML_DISPLAY_HIDDEN):
153 {
154 rAttributes.setDisplayHidden(rIter.toBoolean());
155 break;
156 }
157 case XML_ELEMENT(CALC_EXT, XML_MIN_AXIS_TYPE):
158 {
159 rAttributes.setMinAxisType(parseAxisType(rIter.toView()));
160 break;
161 }
162 case XML_ELEMENT(CALC_EXT, XML_MAX_AXIS_TYPE):
163 {
164 rAttributes.setMaxAxisType(parseAxisType(rIter.toView()));
165 break;
166 }
167 case XML_ELEMENT(CALC_EXT, XML_RIGHT_TO_LEFT):
168 {
169 rAttributes.setRightToLeft(rIter.toBoolean());
170 break;
171 }
172 case XML_ELEMENT(CALC_EXT, XML_MANUAL_MAX):
173 {
174 rAttributes.setManualMax(rIter.toDouble());
175 break;
176 }
177 case XML_ELEMENT(CALC_EXT, XML_MANUAL_MIN):
178 {
179 rAttributes.setManualMin(rIter.toDouble());
180 break;
181 }
182 case XML_ELEMENT(CALC_EXT, XML_COLOR_SERIES):
183 {
184 Color aColor;
185 sax::Converter::convertColor(aColor, rIter.toView());
186 rAttributes.setColorSeries(aColor);
187 break;
188 }
189 case XML_ELEMENT(CALC_EXT, XML_COLOR_NEGATIVE):
190 {
191 Color aColor;
192 sax::Converter::convertColor(aColor, rIter.toView());
193 rAttributes.setColorNegative(aColor);
194 break;
195 }
196 case XML_ELEMENT(CALC_EXT, XML_COLOR_AXIS):
197 {
198 Color aColor;
199 sax::Converter::convertColor(aColor, rIter.toView());
200 rAttributes.setColorAxis(aColor);
201 break;
202 }
203 case XML_ELEMENT(CALC_EXT, XML_COLOR_MARKERS):
204 {
205 Color aColor;
206 sax::Converter::convertColor(aColor, rIter.toView());
207 rAttributes.setColorMarkers(aColor);
208 break;
209 }
210 case XML_ELEMENT(CALC_EXT, XML_COLOR_FIRST):
211 {
212 Color aColor;
213 sax::Converter::convertColor(aColor, rIter.toView());
214 rAttributes.setColorFirst(aColor);
215 break;
216 }
217 case XML_ELEMENT(CALC_EXT, XML_COLOR_LAST):
218 {
219 Color aColor;
220 sax::Converter::convertColor(aColor, rIter.toView());
221 rAttributes.setColorLast(aColor);
222 break;
223 }
224 case XML_ELEMENT(CALC_EXT, XML_COLOR_HIGH):
225 {
226 Color aColor;
227 sax::Converter::convertColor(aColor, rIter.toView());
228 rAttributes.setColorHigh(aColor);
229 break;
230 }
231 case XML_ELEMENT(CALC_EXT, XML_COLOR_LOW):
232 {
233 Color aColor;
234 sax::Converter::convertColor(aColor, rIter.toView());
235 rAttributes.setColorLow(aColor);
236 break;
237 }
238 default:
239 break;
240 }
241 }
242}
243
245 SparklineImportData& rImportData, uno::Reference<xml::sax::XFastAttributeList> const& xAttrList)
246{
247 ScDocument* pDocument = GetScImport().GetDocument();
248
249 for (auto& rIter : sax_fastparser::castToFastAttributeList(xAttrList))
250 {
251 switch (rIter.getToken())
252 {
253 case XML_ELEMENT(CALC_EXT, XML_CELL_ADDRESS):
254 {
255 sal_Int32 nOffset = 0;
257 rImportData.m_aAddress, rIter.toString(), *pDocument,
259 break;
260 }
261 case XML_ELEMENT(CALC_EXT, XML_DATA_RANGE):
262 {
264 rIter.toString(), *pDocument,
266 break;
267 }
268 default:
269 break;
270 }
271 }
272}
273
274uno::Reference<xml::sax::XFastContextHandler>
276 sal_Int32 nElement, uno::Reference<xml::sax::XFastAttributeList> const& xAttrList)
277{
278 SvXMLImportContext* pContext = nullptr;
279 switch (nElement)
280 {
281 case XML_ELEMENT(CALC_EXT, XML_SPARKLINE_GROUP):
282 {
283 m_pCurrentSparklineGroup = std::make_shared<sc::SparklineGroup>();
284 fillSparklineGroupID(xAttrList);
286 pContext = this;
287 break;
288 }
289 case XML_ELEMENT(CALC_EXT, XML_SPARKLINES):
290 {
291 pContext = this;
292 break;
293 }
294 case XML_ELEMENT(CALC_EXT, XML_SPARKLINE):
295 {
296 SparklineImportData& rImportData = m_aCurrentSparklineDataList.emplace_back();
297 fillSparklineAttributes(rImportData, xAttrList);
298 pContext = this;
299 break;
300 }
301 }
302
303 return pContext;
304}
305
307{
308 ScDocument* pDocument = GetScImport().GetDocument();
309 for (auto const& rSparklineImportData : m_aCurrentSparklineDataList)
310 {
311 auto* pSparkline
312 = pDocument->CreateSparkline(rSparklineImportData.m_aAddress, m_pCurrentSparklineGroup);
313 pSparkline->setInputRange(rSparklineImportData.m_aDataRangeList);
314 }
315}
316
317void SAL_CALL SparklineGroupsImportContext::endFastElement(sal_Int32 nElement)
318{
319 switch (nElement)
320 {
321 case XML_ELEMENT(CALC_EXT, XML_SPARKLINE_GROUP):
322 {
326 break;
327 }
328 }
329}
330
331} // end sc
332
333/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SC_DLLPUBLIC sc::Sparkline * CreateSparkline(ScAddress const &rPosition, std::shared_ptr< sc::SparklineGroup > const &pSparklineGroup)
Definition: document.cxx:6508
static bool GetAddressFromString(ScAddress &rAddress, std::u16string_view rAddressStr, const ScDocument &rDocument, formula::FormulaGrammar::AddressConvention eConv, sal_Int32 &nOffset, sal_Unicode cSeparator=' ', sal_Unicode cQuote='\'')
String to Range core.
Definition: rangeutl.cxx:461
static bool GetRangeListFromString(ScRangeList &rRangeList, std::u16string_view rRangeListStr, const ScDocument &rDocument, formula::FormulaGrammar::AddressConvention eConv, sal_Unicode cSeparator=' ', sal_Unicode cQuote='\'')
Definition: rangeutl.cxx:552
This class exists only to provide GetScImport() to its derived classes.
ScXMLImport & GetScImport()
ScDocument * GetDocument()
Definition: xmlimprt.hxx:205
static void convertDouble(OUStringBuffer &rBuffer, double fNumber, bool bWriteUnits, sal_Int16 nSourceUnit, sal_Int16 nTargetUnit)
static bool convertColor(sal_Int32 &rColor, std::u16string_view rValue)
static sal_Int16 GetUnitFromString(std::u16string_view rString, sal_Int16 nDefaultUnit)
Common properties for a group of sparklines.
void setType(SparklineType eType)
void setDisplayHidden(bool bValue)
void setColorLast(Color aColorSeries)
void setManualMax(std::optional< double > aValue)
void setColorSeries(Color aColorSeries)
void setColorFirst(Color aColorSeries)
void setColorLow(Color aColorSeries)
void setMaxAxisType(AxisType eAxisType)
void setDisplayEmptyCellsAs(DisplayEmptyCellsAs eValue)
void setLineWeight(double nWeight)
void setRightToLeft(bool bValue)
void setMinAxisType(AxisType eAxisType)
void setManualMin(std::optional< double > aValue)
void setColorAxis(Color aColorSeries)
void setColorMarkers(Color aColorSeries)
void setDisplayXAxis(bool bValue)
void setColorNegative(Color aColorSeries)
void setColorHigh(Color aColorSeries)
std::vector< SparklineImportData > m_aCurrentSparklineDataList
css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, css::uno::Reference< css::xml::sax::XFastAttributeList > const &xAttrList) override
void fillSparklineAttributes(SparklineImportData &rImportData, css::uno::Reference< css::xml::sax::XFastAttributeList > const &xAttrList)
void SAL_CALL endFastElement(sal_Int32 nElement) override
std::shared_ptr< sc::SparklineGroup > m_pCurrentSparklineGroup
void fillSparklineGroupAttributes(css::uno::Reference< css::xml::sax::XFastAttributeList > const &xAttrList)
void fillSparklineGroupID(css::uno::Reference< css::xml::sax::XFastAttributeList > const &xAttrList)
void setInputRange(ScRangeList const &rInputRange)
Definition: Sparkline.hxx:47
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
CAUTION! The following defines must be in the same namespace as the respective type.
Definition: broadcast.cxx:15
SparklineType
Supported sparkline types.
DisplayEmptyCellsAs
Determines how to display the empty cells.
AxisType
The method of calculating the axis min or max value.
XML_SPARKLINE
XML_COLOR_SERIES
XML_MANUAL_MIN
XML_COLOR_NEGATIVE
XML_LOW
XML_DISPLAY_X_AXIS
XML_MANUAL_MAX
XML_SPARKLINE_GROUP
XML_COLOR_HIGH
XML_COLOR_MARKERS
XML_ID
XML_MIN_AXIS_TYPE
XML_MAX_AXIS_TYPE
XML_MARKERS
XML_COLOR_AXIS
XML_DATE_AXIS
XML_NEGATIVE
XML_FIRST
XML_DISPLAY_EMPTY_CELLS_AS
XML_COLOR_LOW
XML_DISPLAY_HIDDEN
XML_HIGH
XML_LAST
XML_COLOR_FIRST
XML_COLOR_LAST
XML_DATA_RANGE
XML_LINE_WIDTH
XML_SPARKLINES
XML_RIGHT_TO_LEFT
XML_CELL_ADDRESS
XML_TYPE
Transitional import data of a sparkline.
#define XML_ELEMENT(prefix, name)