1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include "SchXMLPropertyMappingContext.hxx"
11 #include "SchXMLTools.hxx"
13 #include <xmloff/xmlnamespace.hxx>
14 #include <xmloff/xmlimp.hxx>
15 #include <xmloff/namespacemap.hxx>
16 #include <SchXMLImport.hxx>
17 #include <sal/log.hxx>
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>
24 using namespace com::sun::star
;
25 using namespace com::sun::star::uno
;
26 using namespace ::xmloff::token
;
30 Reference
< chart2::data::XLabeledDataSequence2
> createAndAddSequenceToSeries( const OUString
& rRole
31 , const OUString
& rRange
32 , const Reference
< chart2::XChartDocument
>& xChartDoc
33 , const Reference
< chart2::XDataSeries
>& xSeries
)
35 Reference
< chart2::data::XLabeledDataSequence2
> xLabeledSeq
;
37 Reference
< chart2::data::XDataSource
> xSeriesSource( xSeries
,uno::UNO_QUERY
);
39 if( !(!rRange
.isEmpty() && xChartDoc
.is() && xSeriesSource
.is()) )
42 // create a new sequence
43 xLabeledSeq
= SchXMLTools::GetNewLabeledDataSequence();
45 // set values at the new sequence
46 Reference
< chart2::data::XDataSequence
> xSeq
= SchXMLTools::CreateDataSequence( rRange
, xChartDoc
);
47 Reference
< beans::XPropertySet
> xSeqProp( xSeq
, uno::UNO_QUERY
);
49 xSeqProp
->setPropertyValue("Role", uno::Any( rRole
));
50 xLabeledSeq
->setValues( xSeq
);
52 Reference
< chart2::data::XDataSink
> xSink( xSeriesSource
, uno::UNO_QUERY
);
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
);
66 SchXMLPropertyMappingContext::SchXMLPropertyMappingContext(
68 tSchXMLLSequencesPerIndex
& rLSequencesPerIndex
,
70 chart2::XDataSeries
> xSeries
):
71 SvXMLImportContext( rImport
),
72 mxDataSeries(std::move(xSeries
)),
73 mrLSequencesPerIndex(rLSequencesPerIndex
)
78 SchXMLPropertyMappingContext::~SchXMLPropertyMappingContext()
82 void SchXMLPropertyMappingContext::startFastElement (sal_Int32
/*nElement*/,
83 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
)
88 for( auto& aIter
: sax_fastparser::castToFastAttributeList(xAttrList
) )
90 OUString aValue
= aIter
.toString();
91 switch( aIter
.getToken() )
93 case XML_ELEMENT(LO_EXT
, XML_PROPERTY
):
96 case XML_ELEMENT(LO_EXT
, XML_CELL_RANGE_ADDRESS
):
100 XMLOFF_WARN_UNKNOWN("xmloff", aIter
);
104 if( !aRange
.isEmpty() && !aRole
.isEmpty() )
106 Reference
< chart2::XChartDocument
> xChartDoc( GetImport().GetModel(), uno::UNO_QUERY
);
107 Reference
< chart2::data::XLabeledDataSequence2
> xSeq
=
108 createAndAddSequenceToSeries(aRole
, aRange
, xChartDoc
, mxDataSeries
);
109 mrLSequencesPerIndex
.emplace(
110 tSchXMLIndexWithPart( 0, SCH_XML_PART_VALUES
),
116 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */