diff options
Diffstat (limited to 'xmloff/source/chart/SchXMLExport.cxx')
-rw-r--r-- | xmloff/source/chart/SchXMLExport.cxx | 55 |
1 files changed, 32 insertions, 23 deletions
diff --git a/xmloff/source/chart/SchXMLExport.cxx b/xmloff/source/chart/SchXMLExport.cxx index d13f58e19a62..2fe73a3ed7cc 100644 --- a/xmloff/source/chart/SchXMLExport.cxx +++ b/xmloff/source/chart/SchXMLExport.cxx @@ -121,11 +121,13 @@ using ::std::vector; namespace { + using CustomLabelSeq = Sequence<Reference<chart2::XDataPointCustomLabelField>>; + struct SchXMLDataPointStruct { OUString maStyleName; sal_Int32 mnRepeat; - OUString msCustomLabelText; + CustomLabelSeq mCustomLabelText; SchXMLDataPointStruct() : mnRepeat( 1 ) {} }; @@ -239,6 +241,8 @@ public: const css::uno::Reference< css::chart2::XDiagram > & xDiagram, bool bExportContent ); + void exportCustomLabel(const CustomLabelSeq & xCustomLabel); + void exportRegressionCurve( const css::uno::Reference<css::chart2::XDataSeries>& xSeries, const css::awt::Size& rPageSize, @@ -292,31 +296,26 @@ constexpr OUStringLiteral SchXMLExportHelper_Impl::gsTableName; namespace { -OUString lcl_getCustomLabelField(sal_Int32 nDataPointIndex, +CustomLabelSeq lcl_getCustomLabelField(sal_Int32 nDataPointIndex, const uno::Reference< chart2::XDataSeries >& rSeries) { if( !rSeries.is() ) - return OUString{}; + return CustomLabelSeq(); const SvtSaveOptions::ODFDefaultVersion nCurrentODFVersion( SvtSaveOptions().GetODFDefaultVersion() ); if( nCurrentODFVersion <= SvtSaveOptions::ODFVER_012 )//do not export to ODF 1.2 or older - return OUString{}; + return CustomLabelSeq(); - // export custom label text if(Reference<beans::XPropertySet> xLabels = rSeries->getDataPointByIndex(nDataPointIndex); xLabels.is()) { if(Any aAny = xLabels->getPropertyValue("CustomLabelFields"); aAny.hasValue()) { Sequence<uno::Reference<chart2::XDataPointCustomLabelField>> aCustomLabels; aAny >>= aCustomLabels; - OUString sLabel; - // TODO export formatted string instead of simple characters - for(auto& aLabel : aCustomLabels) - sLabel += aLabel->getString(); - return sLabel; + return aCustomLabels; } } - return OUString{}; + return CustomLabelSeq(); } class lcl_MatchesRole @@ -3323,7 +3322,7 @@ void SchXMLExportHelper_Impl::exportDataPoints( SchXMLDataPointStruct aPoint; aPoint.maStyleName = maAutoStyleNameQueue.front(); if(bExportNumFmt) - aPoint.msCustomLabelText = lcl_getCustomLabelField(nElement, xSeries); + aPoint.mCustomLabelText = lcl_getCustomLabelField(nElement, xSeries); maAutoStyleNameQueue.pop(); aDataPointVector.push_back( aPoint ); } @@ -3352,7 +3351,7 @@ void SchXMLExportHelper_Impl::exportDataPoints( { SchXMLDataPointStruct aPoint; aPoint.mnRepeat = nCurrIndex - nLastIndex - 1; - aPoint.msCustomLabelText = lcl_getCustomLabelField(nCurrIndex, xSeries); + aPoint.mCustomLabelText = lcl_getCustomLabelField(nCurrIndex, xSeries); aDataPointVector.push_back( aPoint ); } @@ -3385,7 +3384,7 @@ void SchXMLExportHelper_Impl::exportDataPoints( SAL_WARN_IF( maAutoStyleNameQueue.empty(), "xmloff.chart", "Autostyle queue empty!" ); SchXMLDataPointStruct aPoint; aPoint.maStyleName = maAutoStyleNameQueue.front(); - aPoint.msCustomLabelText = lcl_getCustomLabelField(nCurrIndex, xSeries); + aPoint.mCustomLabelText = lcl_getCustomLabelField(nCurrIndex, xSeries); maAutoStyleNameQueue.pop(); aDataPointVector.push_back( aPoint ); @@ -3401,7 +3400,7 @@ void SchXMLExportHelper_Impl::exportDataPoints( // if we get here the property states are empty SchXMLDataPointStruct aPoint; - aPoint.msCustomLabelText = lcl_getCustomLabelField(nCurrIndex, xSeries); + aPoint.mCustomLabelText = lcl_getCustomLabelField(nCurrIndex, xSeries); aDataPointVector.push_back( aPoint ); nLastIndex = nCurrIndex; @@ -3431,13 +3430,10 @@ void SchXMLExportHelper_Impl::exportDataPoints( { aPoint = rPoint; - if( aPoint.maStyleName == aLastPoint.maStyleName && aPoint.msCustomLabelText.isEmpty() ) + if( aPoint.maStyleName == aLastPoint.maStyleName && aLastPoint.mCustomLabelText.getLength() < 1 ) aPoint.mnRepeat += aLastPoint.mnRepeat; else if( aLastPoint.mnRepeat > 0 ) { - // export custom label text - if(!aLastPoint.msCustomLabelText.isEmpty()) - mrExport.AddAttribute( XML_NAMESPACE_LO_EXT, XML_CUSTOM_LABEL_FIELD, aLastPoint.msCustomLabelText); // write last element if( !aLastPoint.maStyleName.isEmpty() ) mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_STYLE_NAME, aLastPoint.maStyleName ); @@ -3447,16 +3443,13 @@ void SchXMLExportHelper_Impl::exportDataPoints( OUString::number( ( aLastPoint.mnRepeat ) )); SvXMLElementExport aPointElem( mrExport, XML_NAMESPACE_CHART, XML_DATA_POINT, true, true ); + exportCustomLabel(aLastPoint.mCustomLabelText); } aLastPoint = aPoint; } // write last element if it hasn't been written in last iteration if( aPoint.maStyleName == aLastPoint.maStyleName ) { - // export custom label text - if(!aLastPoint.msCustomLabelText.isEmpty()) - mrExport.AddAttribute( XML_NAMESPACE_LO_EXT, XML_CUSTOM_LABEL_FIELD, aLastPoint.msCustomLabelText); - if( !aLastPoint.maStyleName.isEmpty() ) mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_STYLE_NAME, aLastPoint.maStyleName ); @@ -3465,6 +3458,22 @@ void SchXMLExportHelper_Impl::exportDataPoints( OUString::number( ( aLastPoint.mnRepeat ) )); SvXMLElementExport aPointElem( mrExport, XML_NAMESPACE_CHART, XML_DATA_POINT, true, true ); + exportCustomLabel(aLastPoint.mCustomLabelText); + } +} + +void SchXMLExportHelper_Impl::exportCustomLabel( const CustomLabelSeq & xCustomLabel ) +{ + if( xCustomLabel.getLength() < 1 ) + return; // nothing to export + + SvXMLElementExport aLabelElem( mrExport, XML_NAMESPACE_CHART, XML_DATA_LABEL, true, true); + SvXMLElementExport aPara( mrExport, XML_NAMESPACE_TEXT, XML_P, true, false ); + for( const Reference<chart2::XDataPointCustomLabelField>& label : xCustomLabel ) + { + // TODO add style + SvXMLElementExport aSpan( mrExport, XML_NAMESPACE_TEXT, XML_SPAN, true, false); + mrExport.GetDocHandler()->characters(label->getString()); } } |