diff options
author | Tamas Bunth <tamas.bunth@collabora.co.uk> | 2019-12-18 13:08:11 +0100 |
---|---|---|
committer | Tamás Bunth <btomi96@gmail.com> | 2020-01-01 17:35:50 +0100 |
commit | 7d2c7e7af04d9604d86d2d605ef95b9abb10966c (patch) | |
tree | 7ca4e6ae75368c275bcdd92bc11522e81977e597 /xmloff/source/chart/SchXMLPlotAreaContext.cxx | |
parent | 75778a50f730568fee2466b6e794401f1e2a8f67 (diff) |
tdf#123206 Store custom label as chart:data-label
Use the chart:data-label element instead of using the
loext:custom-label-field attribute.
chart:data-label stores can be a child of chart:data-point and it may
contain a text:o element for holding one or more paragraphs of custom
label text.
This commit aims to export and import chart:data-label with paragraphs
put into different text:span elements. These span elements may hold a
text:style-name attribute in order to achieve formatted text.
This structure is already in the ODF format.
Change-Id: I0bea7ce1a16af9c47b33555e18545bdaae7e95ca
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/85659
Tested-by: Jenkins
Reviewed-by: Tamás Bunth <btomi96@gmail.com>
Diffstat (limited to 'xmloff/source/chart/SchXMLPlotAreaContext.cxx')
-rw-r--r-- | xmloff/source/chart/SchXMLPlotAreaContext.cxx | 100 |
1 files changed, 88 insertions, 12 deletions
diff --git a/xmloff/source/chart/SchXMLPlotAreaContext.cxx b/xmloff/source/chart/SchXMLPlotAreaContext.cxx index 33bb1e043893..9767efd933dc 100644 --- a/xmloff/source/chart/SchXMLPlotAreaContext.cxx +++ b/xmloff/source/chart/SchXMLPlotAreaContext.cxx @@ -587,17 +587,87 @@ void SchXMLPlotAreaContext::EndElement() SchXMLAxisContext::CorrectAxisPositions( uno::Reference< chart2::XChartDocument >( mrImportHelper.GetChartDocument(), uno::UNO_QUERY ), maChartTypeServiceName, GetImport().GetODFVersion(), m_bAxisPositionAttributeImported ); } -SchXMLDataPointContext::SchXMLDataPointContext( SvXMLImport& rImport, const OUString& rLocalName, +SchXMLDataLabelSpanContext::SchXMLDataLabelSpanContext( SvXMLImport& rImport, const OUString& rLocalName, ::std::vector<OUString>& rLabels): + SvXMLImportContext( rImport, XML_NAMESPACE_TEXT, rLocalName), + mrLabels(rLabels) +{ +} + +void SchXMLDataLabelSpanContext::Characters(const OUString& sChars) +{ + mrLabels.push_back(sChars); +} + +SchXMLDataLabelParaContext::SchXMLDataLabelParaContext( SvXMLImport& rImport, const OUString& rLocalName, ::std::vector<OUString>& rLabels): + SvXMLImportContext( rImport, XML_NAMESPACE_TEXT, rLocalName), + mrLabels(rLabels) +{ +} + +SvXMLImportContextRef SchXMLDataLabelParaContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const uno::Reference< xml::sax::XAttributeList >& /*xAttrList*/ ) +{ + SvXMLImportContextRef xContext; + if ( IsXMLToken( rLocalName, XML_SPAN ) && nPrefix == XML_NAMESPACE_TEXT ) + xContext = new SchXMLDataLabelSpanContext(GetImport(), rLocalName, mrLabels); + return xContext; +} + +SchXMLDataLabelContext::SchXMLDataLabelContext( SvXMLImport& rImport, const OUString& rLocalName, ::std::vector<OUString>& rLabels): + SvXMLImportContext( rImport, XML_NAMESPACE_CHART, rLocalName), + mrLabels(rLabels) +{ +} + +SvXMLImportContextRef SchXMLDataLabelContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const uno::Reference< xml::sax::XAttributeList >& xAttrList ) +{ + SvXMLImportContextRef xContext; + if ( IsXMLToken( rLocalName, XML_P ) && nPrefix == XML_NAMESPACE_TEXT ) + xContext = new SchXMLDataLabelParaContext(GetImport(), rLocalName, mrLabels); + + if (!xContext) + xContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList ); + + return xContext; +} + + +SchXMLDataPointContext::SchXMLDataPointContext( SchXMLImportHelper& rImportHelper, + SvXMLImport& rImport, const OUString& rLocalName, ::std::vector< DataRowPointStyle >& rStyleVector, const css::uno::Reference< css::chart2::XDataSeries >& xSeries, sal_Int32& rIndex, bool bSymbolSizeForSeriesIsMissingInFile ) : SvXMLImportContext( rImport, XML_NAMESPACE_CHART, rLocalName ), + mrImportHelper( rImportHelper ), mrStyleVector( rStyleVector ), - m_xSeries( xSeries ), mrIndex( rIndex ), - mbSymbolSizeForSeriesIsMissingInFile( bSymbolSizeForSeriesIsMissingInFile ) + mDataPoint(DataRowPointStyle::DATA_POINT, xSeries, rIndex, 1, OUString{}) +{ + mDataPoint.mbSymbolSizeForSeriesIsMissingInFile = bSymbolSizeForSeriesIsMissingInFile; +} + +SvXMLImportContextRef SchXMLDataPointContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const uno::Reference< xml::sax::XAttributeList >& /*xAttrList*/ ) { + SvXMLImportContext* pContext = nullptr; + const SvXMLTokenMap& rTokenMap = mrImportHelper.GetSeriesElemTokenMap(); + + switch( rTokenMap.Get( nPrefix, rLocalName )) + { + case XML_TOK_SERIES_DATA_LABEL: + mbHasLabelParagraph = true; + pContext = new SchXMLDataLabelContext( GetImport(), rLocalName, mDataPoint.mCustomLabels); + break; + } + return pContext; } SchXMLDataPointContext::~SchXMLDataPointContext() @@ -620,29 +690,35 @@ void SchXMLDataPointContext::StartElement( const uno::Reference< xml::sax::XAttr if( nPrefix == XML_NAMESPACE_CHART ) { if( IsXMLToken( aLocalName, XML_STYLE_NAME ) ) + { sAutoStyleName = xAttrList->getValueByIndex( i ); + mDataPoint.msStyleName = sAutoStyleName; + } else if( IsXMLToken( aLocalName, XML_REPEATED ) ) + { nRepeat = xAttrList->getValueByIndex( i ).toInt32(); + mDataPoint.m_nPointRepeat = nRepeat; + } } else if( nPrefix == XML_NAMESPACE_LO_EXT) { - if( IsXMLToken( aLocalName, XML_CUSTOM_LABEL_FIELD)) + if( IsXMLToken( aLocalName, XML_CUSTOM_LABEL_FIELD) && !mbHasLabelParagraph) { sCustomLabelField = xAttrList->getValueByIndex( i ); + mDataPoint.mCustomLabels.push_back(sCustomLabelField); } } } - if( !sAutoStyleName.isEmpty()) + mrIndex += nRepeat; +} + +void SchXMLDataPointContext::EndElement() +{ + if( !mDataPoint.msStyleName.isEmpty() || mDataPoint.mCustomLabels.size() > 0) { - DataRowPointStyle aStyle( - DataRowPointStyle::DATA_POINT, - m_xSeries, mrIndex, nRepeat, sAutoStyleName ); - aStyle.mbSymbolSizeForSeriesIsMissingInFile = mbSymbolSizeForSeriesIsMissingInFile; - aStyle.msCustomLabelField = sCustomLabelField; - mrStyleVector.push_back( aStyle ); + mrStyleVector.push_back( mDataPoint ); } - mrIndex += nRepeat; } SchXMLPositionAttributesHelper::SchXMLPositionAttributesHelper( SvXMLImport& rImporter ) |