diff options
author | Markus Mohrhard <markus.mohrhard@collabora.co.uk> | 2014-03-11 12:38:06 +0100 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@collabora.co.uk> | 2014-03-17 08:13:49 +0100 |
commit | cd99c5c0dda08470f165c9a25bca2cb6ab6887c3 (patch) | |
tree | 9b002965c763279803e0d4ea7806630477d96678 /xmloff | |
parent | 0e894caf47a7969b1ec65665340e1b5522ef7b93 (diff) |
property mapping import
Change-Id: I0859699b3639b6f7d5d15865e6ec1591b3d36f06
Diffstat (limited to 'xmloff')
-rw-r--r-- | xmloff/Library_xo.mk | 1 | ||||
-rw-r--r-- | xmloff/inc/SchXMLImport.hxx | 9 | ||||
-rw-r--r-- | xmloff/source/chart/SchXMLImport.cxx | 20 | ||||
-rw-r--r-- | xmloff/source/chart/SchXMLPropertyMappingContext.cxx | 111 | ||||
-rw-r--r-- | xmloff/source/chart/SchXMLPropertyMappingContext.hxx | 50 | ||||
-rw-r--r-- | xmloff/source/chart/SchXMLSeries2Context.cxx | 6 |
6 files changed, 196 insertions, 1 deletions
diff --git a/xmloff/Library_xo.mk b/xmloff/Library_xo.mk index 46ae11fbe24a..553fcc148d36 100644 --- a/xmloff/Library_xo.mk +++ b/xmloff/Library_xo.mk @@ -69,6 +69,7 @@ $(eval $(call gb_Library_add_exception_objects,xo,\ xmloff/source/chart/SchXMLLegendContext \ xmloff/source/chart/SchXMLParagraphContext \ xmloff/source/chart/SchXMLPlotAreaContext \ + xmloff/source/chart/SchXMLPropertyMappingContext \ xmloff/source/chart/SchXMLRegressionCurveObjectContext \ xmloff/source/chart/SchXMLSeries2Context \ xmloff/source/chart/SchXMLSeriesHelper \ diff --git a/xmloff/inc/SchXMLImport.hxx b/xmloff/inc/SchXMLImport.hxx index 3d96d52dae2d..16fa7f394000 100644 --- a/xmloff/inc/SchXMLImport.hxx +++ b/xmloff/inc/SchXMLImport.hxx @@ -79,7 +79,14 @@ enum SchXMLSeriesElemTokenMap XML_TOK_SERIES_DOMAIN, XML_TOK_SERIES_MEAN_VALUE_LINE, XML_TOK_SERIES_REGRESSION_CURVE, - XML_TOK_SERIES_ERROR_INDICATOR + XML_TOK_SERIES_ERROR_INDICATOR, + XML_TOK_SERIES_PROPERTY_MAPPING +}; + +enum SchXMLPropertyMappingAttrTokenMap +{ + XML_TOK_PROPERTY_MAPPING_PROPERTY, + XML_TOK_PROPERTY_MAPPING_RANGE }; enum SchXMLChartAttrMap diff --git a/xmloff/source/chart/SchXMLImport.cxx b/xmloff/source/chart/SchXMLImport.cxx index 5ca496f68d68..3a3dc51e9370 100644 --- a/xmloff/source/chart/SchXMLImport.cxx +++ b/xmloff/source/chart/SchXMLImport.cxx @@ -96,6 +96,7 @@ SchXMLImportHelper::SchXMLImportHelper() : mpAutoStyleAttrTokenMap( 0 ), mpCellAttrTokenMap( 0 ), mpSeriesAttrTokenMap( 0 ), + mpPropMappingAttrTokenMap( 0 ), mpRegEquationAttrTokenMap( 0 ) { } @@ -124,6 +125,7 @@ SchXMLImportHelper::~SchXMLImportHelper() delete mpCellAttrTokenMap; if( mpSeriesAttrTokenMap ) delete mpSeriesAttrTokenMap; + delete mpPropMappingAttrTokenMap; } SvXMLImportContext* SchXMLImportHelper::CreateChartContext( @@ -247,6 +249,7 @@ const SvXMLTokenMap& SchXMLImportHelper::GetSeriesElemTokenMap() { XML_NAMESPACE_CHART, XML_MEAN_VALUE, XML_TOK_SERIES_MEAN_VALUE_LINE }, { XML_NAMESPACE_CHART, XML_REGRESSION_CURVE, XML_TOK_SERIES_REGRESSION_CURVE }, { XML_NAMESPACE_CHART, XML_ERROR_INDICATOR, XML_TOK_SERIES_ERROR_INDICATOR }, + { XML_NAMESPACE_LO_EXT, XML_PROPERTY_MAPPING, XML_TOK_SERIES_PROPERTY_MAPPING }, XML_TOKEN_MAP_END }; @@ -348,6 +351,23 @@ const SvXMLTokenMap& SchXMLImportHelper::GetSeriesAttrTokenMap() return *mpSeriesAttrTokenMap; } +const SvXMLTokenMap& SchXMLImportHelper::GetPropMappingAttrTokenMap() +{ + if( !mpPropMappingAttrTokenMap ) + { + static const SvXMLTokenMapEntry aPropMappingAttrTokenMap[] = + { + { XML_NAMESPACE_LO_EXT, XML_PROPERTY, XML_TOK_PROPERTY_MAPPING_PROPERTY }, + { XML_NAMESPACE_LO_EXT, XML_CELL_RANGE_ADDRESS, XML_TOK_PROPERTY_MAPPING_RANGE }, + XML_TOKEN_MAP_END + }; + + mpPropMappingAttrTokenMap = new SvXMLTokenMap( aPropMappingAttrTokenMap ); + } + + return *mpPropMappingAttrTokenMap; +} + const SvXMLTokenMap& SchXMLImportHelper::GetRegEquationAttrTokenMap() { if( ! mpRegEquationAttrTokenMap ) diff --git a/xmloff/source/chart/SchXMLPropertyMappingContext.cxx b/xmloff/source/chart/SchXMLPropertyMappingContext.cxx new file mode 100644 index 000000000000..affe3aabb4ff --- /dev/null +++ b/xmloff/source/chart/SchXMLPropertyMappingContext.cxx @@ -0,0 +1,111 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "SchXMLPropertyMappingContext.hxx" +#include "PropertyMap.hxx" +#include "SchXMLTools.hxx" +#include <xmloff/xmlnmspe.hxx> +#include <xmloff/xmlimp.hxx> +#include <xmloff/nmspmap.hxx> +#include <xmloff/SchXMLSeriesHelper.hxx> +#include "SchXMLImport.hxx" + +#include <com/sun/star/chart2/data/XLabeledDataSequence2.hpp> +#include <com/sun/star/chart2/data/XDataSource.hpp> +#include <com/sun/star/chart2/data/XDataSink.hpp> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace { + +Reference< chart2::data::XLabeledDataSequence2 > createAndAddSequenceToSeries( const OUString& rRole + , const OUString& rRange + , const Reference< chart2::XChartDocument >& xChartDoc + , const Reference< chart2::XDataSeries >& xSeries ) +{ + Reference< chart2::data::XLabeledDataSequence2 > xLabeledSeq; + + Reference< chart2::data::XDataSource > xSeriesSource( xSeries,uno::UNO_QUERY ); + + if( !(!rRange.isEmpty() && xChartDoc.is() && xSeriesSource.is()) ) + return xLabeledSeq; + + // create a new sequence + xLabeledSeq = SchXMLTools::GetNewLabeledDataSequence(); + + // set values at the new sequence + Reference< chart2::data::XDataSequence > xSeq = SchXMLTools::CreateDataSequence( rRange, xChartDoc ); + Reference< beans::XPropertySet > xSeqProp( xSeq, uno::UNO_QUERY ); + if( xSeqProp.is()) + xSeqProp->setPropertyValue("Role", uno::makeAny( rRole)); + xLabeledSeq->setValues( xSeq ); + + return xLabeledSeq; +} + +} + +SchXMLPropertyMappingContext::SchXMLPropertyMappingContext( SchXMLImportHelper& rImpHelper, + SvXMLImport& rImport, const OUString& rLocalName, + tSchXMLLSequencesPerIndex & rLSequencesPerIndex, + uno::Reference< + chart2::XDataSeries > xSeries ): + SvXMLImportContext( rImport, XML_NAMESPACE_LO_EXT, rLocalName ), + mrImportHelper( rImpHelper ), + mxDataSeries(xSeries), + mrLSequencesPerIndex(rLSequencesPerIndex) +{ + +} + +SchXMLPropertyMappingContext::~SchXMLPropertyMappingContext() +{ +} + +void SchXMLPropertyMappingContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList ) +{ + OUString aRange; + OUString aRole; + // parse attributes + sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0; + const SvXMLTokenMap& rAttrTokenMap = mrImportHelper.GetPropMappingAttrTokenMap(); + + for( sal_Int16 i = 0; i < nAttrCount; i++ ) + { + OUString sAttrName = xAttrList->getNameByIndex( i ); + OUString aLocalName; + OUString aValue = xAttrList->getValueByIndex( i ); + sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ); + + switch( rAttrTokenMap.Get( nPrefix, aLocalName )) + { + case XML_TOK_PROPERTY_MAPPING_PROPERTY: + aRole = aValue; + break; + case XML_TOK_PROPERTY_MAPPING_RANGE: + aRange = aValue; + break; + } + } + + if( !aRange.isEmpty() && !aRole.isEmpty() ) + { + Reference< chart2::XChartDocument > xChartDoc( GetImport().GetModel(), uno::UNO_QUERY ); + Reference< chart2::data::XLabeledDataSequence2 > xSeq = + createAndAddSequenceToSeries(aRole, aRange, xChartDoc, mxDataSeries); + mrLSequencesPerIndex.insert( + tSchXMLLSequencesPerIndex::value_type( + tSchXMLIndexWithPart( 0, SCH_XML_PART_VALUES), + Reference< chart2::data::XLabeledDataSequence >( xSeq, UNO_QUERY ))); + } +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/chart/SchXMLPropertyMappingContext.hxx b/xmloff/source/chart/SchXMLPropertyMappingContext.hxx new file mode 100644 index 000000000000..b42bba2bc097 --- /dev/null +++ b/xmloff/source/chart/SchXMLPropertyMappingContext.hxx @@ -0,0 +1,50 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_XMLOFF_SOURCE_CHART_SCHXMLPROPERTYMAPPINGCONTEXt_HXX +#define INCLUDED_XMLOFF_SOURCE_CHART_SCHXMLPROPERTYMAPPINGCONTEXt_HXX + +#include "transporttypes.hxx" +#include "SchXMLChartContext.hxx" +#include <xmloff/xmlictxt.hxx> +#include <xmloff/SchXMLImportHelper.hxx> + +namespace com { namespace sun { namespace star { + namespace chart2 { + class XChartDocument; + class XDataSeries; + } +}}} + +class SchXMLPropertyMappingContext : public SvXMLImportContext +{ +public: + + SchXMLPropertyMappingContext( SchXMLImportHelper& rImpHelper, + SvXMLImport& rImport, const OUString& rLocalName, + tSchXMLLSequencesPerIndex& rLSequencesPerIndex, + com::sun::star::uno::Reference< + com::sun::star::chart2::XDataSeries > xSeries ); + + virtual ~SchXMLPropertyMappingContext(); + + virtual void StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList ); +private: + + com::sun::star::uno::Reference< com::sun::star::chart2::XChartDocument > mxChartDocument; + SchXMLImportHelper& mrImportHelper; + com::sun::star::uno::Reference< com::sun::star::chart2::XDataSeries > mxDataSeries; + + tSchXMLLSequencesPerIndex& mrLSequencesPerIndex; + +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/chart/SchXMLSeries2Context.cxx b/xmloff/source/chart/SchXMLSeries2Context.cxx index 0ac51597c052..a243744a800f 100644 --- a/xmloff/source/chart/SchXMLSeries2Context.cxx +++ b/xmloff/source/chart/SchXMLSeries2Context.cxx @@ -20,6 +20,7 @@ #include "SchXMLSeries2Context.hxx" #include "SchXMLPlotAreaContext.hxx" #include "SchXMLRegressionCurveObjectContext.hxx" +#include "SchXMLPropertyMappingContext.hxx" #include "SchXMLTools.hxx" #include "PropertyMap.hxx" @@ -674,6 +675,11 @@ SvXMLImportContext* SchXMLSeries2Context::CreateChildContext( pContext = new SchXMLDataPointContext( GetImport(), rLocalName, mrStyleList, m_xSeries, mnDataPointIndex, mbSymbolSizeIsMissingInFile ); break; + case XML_TOK_SERIES_PROPERTY_MAPPING: + pContext = new SchXMLPropertyMappingContext( mrImportHelper, + GetImport(), rLocalName, + mrLSequencesPerIndex, m_xSeries ); + break; default: pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); |