Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / xmloff / source / chart / SchXMLPropertyMappingContext.cxx
blob7c92cbda67e878f4e53c6b0df261b06958fba0c4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include "SchXMLPropertyMappingContext.hxx"
11 #include "PropertyMap.hxx"
12 #include "SchXMLTools.hxx"
13 #include <xmloff/xmlnmspe.hxx>
14 #include <xmloff/xmlimp.hxx>
15 #include <xmloff/nmspmap.hxx>
16 #include <xmloff/SchXMLSeriesHelper.hxx>
17 #include "SchXMLImport.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>
23 using namespace com::sun::star;
24 using namespace com::sun::star::uno;
26 namespace {
28 Reference< chart2::data::XLabeledDataSequence2 > createAndAddSequenceToSeries( const OUString& rRole
29 , const OUString& rRange
30 , const Reference< chart2::XChartDocument >& xChartDoc
31 , const Reference< chart2::XDataSeries >& xSeries )
33 Reference< chart2::data::XLabeledDataSequence2 > xLabeledSeq;
35 Reference< chart2::data::XDataSource > xSeriesSource( xSeries,uno::UNO_QUERY );
37 if( !(!rRange.isEmpty() && xChartDoc.is() && xSeriesSource.is()) )
38 return xLabeledSeq;
40 // create a new sequence
41 xLabeledSeq = SchXMLTools::GetNewLabeledDataSequence();
43 // set values at the new sequence
44 Reference< chart2::data::XDataSequence > xSeq = SchXMLTools::CreateDataSequence( rRange, xChartDoc );
45 Reference< beans::XPropertySet > xSeqProp( xSeq, uno::UNO_QUERY );
46 if( xSeqProp.is())
47 xSeqProp->setPropertyValue("Role", uno::makeAny( rRole));
48 xLabeledSeq->setValues( xSeq );
50 Reference< chart2::data::XDataSink > xSink( xSeriesSource, uno::UNO_QUERY );
51 if( xSink.is())
53 Sequence< Reference< chart2::data::XLabeledDataSequence > > aData( xSeriesSource->getDataSequences());
54 aData.realloc( aData.getLength() + 1 );
55 aData[ aData.getLength() - 1 ] = xLabeledSeq;
56 xSink->setData( aData );
59 return xLabeledSeq;
64 SchXMLPropertyMappingContext::SchXMLPropertyMappingContext( SchXMLImportHelper& rImpHelper,
65 SvXMLImport& rImport, const OUString& rLocalName,
66 tSchXMLLSequencesPerIndex & rLSequencesPerIndex,
67 uno::Reference<
68 chart2::XDataSeries > xSeries ):
69 SvXMLImportContext( rImport, XML_NAMESPACE_LO_EXT, rLocalName ),
70 mrImportHelper( rImpHelper ),
71 mxDataSeries(xSeries),
72 mrLSequencesPerIndex(rLSequencesPerIndex)
77 SchXMLPropertyMappingContext::~SchXMLPropertyMappingContext()
81 void SchXMLPropertyMappingContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList )
83 OUString aRange;
84 OUString aRole;
85 // parse attributes
86 sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
87 const SvXMLTokenMap& rAttrTokenMap = mrImportHelper.GetPropMappingAttrTokenMap();
89 for( sal_Int16 i = 0; i < nAttrCount; i++ )
91 OUString sAttrName = xAttrList->getNameByIndex( i );
92 OUString aLocalName;
93 OUString aValue = xAttrList->getValueByIndex( i );
94 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
96 switch( rAttrTokenMap.Get( nPrefix, aLocalName ))
98 case XML_TOK_PROPERTY_MAPPING_PROPERTY:
99 aRole = aValue;
100 break;
101 case XML_TOK_PROPERTY_MAPPING_RANGE:
102 aRange = aValue;
103 break;
107 if( !aRange.isEmpty() && !aRole.isEmpty() )
109 Reference< chart2::XChartDocument > xChartDoc( GetImport().GetModel(), uno::UNO_QUERY );
110 Reference< chart2::data::XLabeledDataSequence2 > xSeq =
111 createAndAddSequenceToSeries(aRole, aRange, xChartDoc, mxDataSeries);
112 mrLSequencesPerIndex.insert(
113 tSchXMLLSequencesPerIndex::value_type(
114 tSchXMLIndexWithPart( 0, SCH_XML_PART_VALUES),
115 Reference< chart2::data::XLabeledDataSequence >( xSeq, UNO_QUERY )));
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */