LibreOffice Module sc (master) 1
SparklineGroupsExport.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 */
10
12#include "xmlexprt.hxx"
13#include <rangeutl.hxx>
14#include <SparklineList.hxx>
15#include <document.hxx>
16
17#include <xmloff/xmluconv.hxx>
18#include <xmloff/xmltoken.hxx>
21#include <rtl/ustrbuf.hxx>
24
25using namespace css;
26using namespace xmloff::token;
27
28namespace sc
29{
31 : m_rExport(rExport)
32 , m_nTable(nTable)
33{
34}
35
37{
38 OUStringBuffer aStringBuffer;
39 if (aColor != COL_TRANSPARENT)
40 {
41 sax::Converter::convertColor(aStringBuffer, aColor);
42 m_rExport.AddAttribute(XML_NAMESPACE_CALC_EXT, eToken, aStringBuffer.makeStringAndClear());
43 }
44}
45
47{
48 if (bValue)
50}
51
53{
54 auto const* pDocument = m_rExport.GetDocument();
55
56 {
57 OUString sAddressString;
58 ScAddress aAddress(rSparkline.getColumn(), rSparkline.getRow(), m_nTable);
59 ScRangeStringConverter::GetStringFromAddress(sAddressString, aAddress, pDocument,
62 }
63
64 {
65 OUString sDataRangeString;
66 ScRangeList const& rRangeList = rSparkline.getInputRange();
67 ScRangeStringConverter::GetStringFromRangeList(sDataRangeString, &rRangeList, pDocument,
70 }
71}
72
73namespace
74{
75OUString convertSparklineType(sc::SparklineType eType)
76{
77 switch (eType)
78 {
80 return u"line";
82 return u"column";
84 return u"stacked";
85 }
86 return u"";
87}
88
89OUString convertDisplayEmptyCellsAs(sc::DisplayEmptyCellsAs eType)
90{
91 switch (eType)
92 {
94 return u"zero";
96 return u"gap";
98 return u"span";
99 }
100 return u"";
101}
102
103OUString convertAxisType(sc::AxisType eType)
104{
105 switch (eType)
106 {
108 return u"individual";
110 return u"group";
112 return u"custom";
113 }
114 return u"";
115}
116
117} // end anonymous ns
118
120{
121 OUString sType = convertSparklineType(rAttributes.getType());
123
124 // Line Weight = Line Width in ODF
125
127 OUString::number(rAttributes.getLineWeight()) + "pt");
128
129 insertBool(rAttributes.isDateAxis(), XML_DATE_AXIS);
130
131 OUString sDisplayEmptyCellsAs
132 = convertDisplayEmptyCellsAs(rAttributes.getDisplayEmptyCellsAs());
134 sDisplayEmptyCellsAs);
135
136 insertBool(rAttributes.isMarkers(), XML_MARKERS);
137 insertBool(rAttributes.isHigh(), XML_HIGH);
138 insertBool(rAttributes.isLow(), XML_LOW);
139 insertBool(rAttributes.isFirst(), XML_FIRST);
140 insertBool(rAttributes.isLast(), XML_LAST);
141 insertBool(rAttributes.isNegative(), XML_NEGATIVE);
144
145 OUString sMinAxisType = convertAxisType(rAttributes.getMinAxisType());
147
148 OUString sMaxAxisType = convertAxisType(rAttributes.getMaxAxisType());
150
152
153 if (rAttributes.getManualMax() && rAttributes.getMaxAxisType() == sc::AxisType::Custom)
155 OUString::number(*rAttributes.getManualMax()));
156
157 if (rAttributes.getManualMin() && rAttributes.getMinAxisType() == sc::AxisType::Custom)
159 OUString::number(*rAttributes.getManualMin()));
160
168 insertColor(rAttributes.getColorLow(), XML_COLOR_LOW);
169}
170
172 std::shared_ptr<SparklineGroup> const& pSparklineGroup,
173 std::vector<std::shared_ptr<Sparkline>> const& rSparklines)
174{
175 auto const& rAttributes = pSparklineGroup->getAttributes();
176
177 OUString sID = pSparklineGroup->getID().getOUString();
179
180 addSparklineGroupAttributes(rAttributes);
181
183 XML_SPARKLINE_GROUP, true, true);
184
186 true);
187
188 for (auto const& rSparkline : rSparklines)
189 {
190 addSparklineAttributes(*rSparkline);
192 true);
193 }
194}
195
197{
198 auto* pDocument = m_rExport.GetDocument();
199 if (sc::SparklineList* pSparklineList = pDocument->GetSparklineList(m_nTable))
200 {
201 auto const& aSparklineGroups = pSparklineList->getSparklineGroups();
202 if (!aSparklineGroups.empty())
203 {
205 true, true);
206
207 for (auto const& pSparklineGroup : aSparklineGroups)
208 {
209 auto const& aSparklines = pSparklineList->getSparklinesFor(pSparklineGroup);
210 addSparklineGroup(pSparklineGroup, aSparklines);
211 }
212 }
213 }
214}
215
216} // end sc
217
218/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OptionalString sType
static void GetStringFromRangeList(OUString &rString, const ScRangeList *pRangeList, const ScDocument *pDocument, formula::FormulaGrammar::AddressConvention eConv, sal_Unicode cSeparator=' ')
static void GetStringFromAddress(OUString &rString, const ScAddress &rAddress, const ScDocument *pDocument, formula::FormulaGrammar::AddressConvention eConv, sal_Unicode cSeparator=' ', bool bAppendStr=false, ScRefFlags nFormatFlags=ScRefFlags::VALID|ScRefFlags::TAB_3D)
Range to String core.
ScDocument * GetDocument()
Definition: xmlexprt.hxx:240
void AddAttribute(sal_uInt16 nPrefix, const OUString &rName, const OUString &rValue)
static bool convertColor(sal_Int32 &rColor, std::u16string_view rValue)
Common properties for a group of sparklines.
DisplayEmptyCellsAs getDisplayEmptyCellsAs() const
std::optional< double > getManualMax() const
SparklineType getType() const
std::optional< double > getManualMin() const
double getLineWeight() const
Line weight or width in points.
void addSparklineGroupAttributes(sc::SparklineAttributes const &rAttributes)
SparklineGroupsExport(ScXMLExport &rExport, SCTAB nTable)
void addSparklineAttributes(Sparkline const &rSparkline)
void insertBool(bool bValue, xmloff::token::XMLTokenEnum eToken)
void insertColor(Color aColor, xmloff::token::XMLTokenEnum eToken)
void addSparklineGroup(std::shared_ptr< SparklineGroup > const &pSparklineGroup, std::vector< std::shared_ptr< Sparkline > > const &rSparklines)
Tracks and gathers all created sparklines and sparkline groups.
Sparkline data, used for rendering the content of a cell.
Definition: Sparkline.hxx:29
SCROW getRow() const
Definition: Sparkline.hxx:55
ScRangeList const & getInputRange() const
Definition: Sparkline.hxx:49
SCCOL getColumn() const
Definition: Sparkline.hxx:53
constexpr ::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
float u
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.
XMLTokenEnum
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_SPARKLINE_GROUPS
XML_RIGHT_TO_LEFT
XML_CELL_ADDRESS
XML_TYPE
sal_Int16 SCTAB
Definition: types.hxx:22
constexpr sal_uInt16 XML_NAMESPACE_CALC_EXT
XMLTokenEnum eToken