LibreOffice Module xmloff (master) 1
SchXMLPropertyMappingContext.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#include "SchXMLTools.hxx"
12#include <utility>
14#include <xmloff/xmlimp.hxx>
16#include <SchXMLImport.hxx>
17#include <sal/log.hxx>
18
19#include <com/sun/star/chart2/data/XLabeledDataSequence2.hpp>
20#include <com/sun/star/chart2/data/XDataSource.hpp>
21#include <com/sun/star/chart2/data/XDataSink.hpp>
22#include <com/sun/star/chart2/XChartDocument.hpp>
23
24using namespace com::sun::star;
25using namespace com::sun::star::uno;
26using namespace ::xmloff::token;
27
28namespace {
29
30Reference< chart2::data::XLabeledDataSequence2 > createAndAddSequenceToSeries( const OUString& rRole
31 , const OUString& rRange
33 , const Reference< chart2::XDataSeries >& xSeries )
34{
36
37 Reference< chart2::data::XDataSource > xSeriesSource( xSeries,uno::UNO_QUERY );
38
39 if( !(!rRange.isEmpty() && xChartDoc.is() && xSeriesSource.is()) )
40 return xLabeledSeq;
41
42 // create a new sequence
44
45 // set values at the new sequence
47 Reference< beans::XPropertySet > xSeqProp( xSeq, uno::UNO_QUERY );
48 if( xSeqProp.is())
49 xSeqProp->setPropertyValue("Role", uno::Any( rRole));
50 xLabeledSeq->setValues( xSeq );
51
52 Reference< chart2::data::XDataSink > xSink( xSeriesSource, uno::UNO_QUERY );
53 if( xSink.is())
54 {
55 Sequence< Reference< chart2::data::XLabeledDataSequence > > aData( xSeriesSource->getDataSequences());
56 aData.realloc( aData.getLength() + 1 );
57 aData.getArray()[ aData.getLength() - 1 ] = xLabeledSeq;
58 xSink->setData( aData );
59 }
60
61 return xLabeledSeq;
62}
63
64}
65
67 SvXMLImport& rImport,
68 tSchXMLLSequencesPerIndex & rLSequencesPerIndex,
69 uno::Reference<
70 chart2::XDataSeries > xSeries ):
71 SvXMLImportContext( rImport ),
72 mxDataSeries(std::move(xSeries)),
73 mrLSequencesPerIndex(rLSequencesPerIndex)
74{
75
76}
77
79{
80}
81
83 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList)
84{
85 OUString aRange;
86 OUString aRole;
87 // parse attributes
88 for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
89 {
90 OUString aValue = aIter.toString();
91 switch( aIter.getToken() )
92 {
93 case XML_ELEMENT(LO_EXT, XML_PROPERTY):
94 aRole = aValue;
95 break;
97 aRange = aValue;
98 break;
99 default:
100 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
101 }
102 }
103
104 if( !aRange.isEmpty() && !aRole.isEmpty() )
105 {
106 Reference< chart2::XChartDocument > xChartDoc( GetImport().GetModel(), uno::UNO_QUERY );
108 createAndAddSequenceToSeries(aRole, aRange, xChartDoc, mxDataSeries);
109 mrLSequencesPerIndex.emplace(
111 xSeq);
112 }
113}
114
115
116/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SchXMLPropertyMappingContext(SvXMLImport &rImport, tSchXMLLSequencesPerIndex &rLSequencesPerIndex, css::uno::Reference< css::chart2::XDataSeries > xSeries)
virtual void SAL_CALL startFastElement(sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
tSchXMLLSequencesPerIndex & mrLSequencesPerIndex
css::uno::Reference< css::chart2::XDataSeries > mxDataSeries
This class deliberately does not support XWeak, to improve performance when loading large documents.
Definition: xmlictxt.hxx:48
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:60
tools::SvRef< SvBaseLink > xSink
constexpr OUStringLiteral aData
Reference< chart2::data::XLabeledDataSequence2 > GetNewLabeledDataSequence()
Reference< chart2::data::XDataSequence > CreateDataSequence(const OUString &rRange, const Reference< chart2::XChartDocument > &xChartDoc)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
Handling of tokens in XML:
@ XML_CELL_RANGE_ADDRESS
Definition: xmltoken.hxx:412
@ SCH_XML_PART_VALUES
::std::multimap< tSchXMLIndexWithPart, css::uno::Reference< css::chart2::data::XLabeledDataSequence > > tSchXMLLSequencesPerIndex
::std::pair< tSchXMLIndex, SchXMLLabeledSequencePart > tSchXMLIndexWithPart
#define XMLOFF_WARN_UNKNOWN(area, rIter)
Definition: xmlictxt.hxx:114
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97