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 "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
;
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()) )
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
);
47 xSeqProp
->setPropertyValue("Role", uno::makeAny( rRole
));
48 xLabeledSeq
->setValues( xSeq
);
50 Reference
< chart2::data::XDataSink
> xSink( xSeriesSource
, uno::UNO_QUERY
);
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
);
64 SchXMLPropertyMappingContext::SchXMLPropertyMappingContext( SchXMLImportHelper
& rImpHelper
,
65 SvXMLImport
& rImport
, const OUString
& rLocalName
,
66 tSchXMLLSequencesPerIndex
& rLSequencesPerIndex
,
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
)
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
);
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
:
101 case XML_TOK_PROPERTY_MAPPING_RANGE
:
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: */