diff options
author | Tünde Tóth <tundeth@gmail.com> | 2019-12-18 16:46:36 +0100 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2020-01-10 14:22:57 +0100 |
commit | 86be3422cd55fa9e44104f1628648061bb6a3495 (patch) | |
tree | 99e0a154d9e88cba9d121e9ace83419357805530 /oox/source/export/chartexport.cxx | |
parent | 6e847aa817999ab18acd534f9e6a86685bb268fc (diff) |
tdf#129857 Chart OOXML export: fix deleted legend entries
The legend showed deleted legend entries too after export.
Change-Id: I872654d6e4d3f385c468b7fde03d39e233692fa1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86161
Reviewed-by: László Németh <nemeth@numbertext.org>
Tested-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'oox/source/export/chartexport.cxx')
-rw-r--r-- | oox/source/export/chartexport.cxx | 82 |
1 files changed, 80 insertions, 2 deletions
diff --git a/oox/source/export/chartexport.cxx b/oox/source/export/chartexport.cxx index 60172be93a38..8dfb053a1f7d 100644 --- a/oox/source/export/chartexport.cxx +++ b/oox/source/export/chartexport.cxx @@ -18,6 +18,7 @@ */ #include <oox/token/namespaces.hxx> +#include <oox/token/properties.hxx> #include <oox/token/tokens.hxx> #include <oox/core/xmlfilterbase.hxx> #include <oox/export/chartexport.hxx> @@ -1092,6 +1093,85 @@ void ChartExport::exportLegend( const Reference< css::chart::XChartDocument >& x pFS->singleElement(FSNS(XML_c, XML_legendPos), XML_val, strPos); } + // legendEntry + Reference<chart2::XCoordinateSystemContainer> xCooSysContainer(mxNewDiagram, UNO_QUERY_THROW); + const Sequence<Reference<chart2::XCoordinateSystem>> xCooSysSequence(xCooSysContainer->getCoordinateSystems()); + if (!xCooSysSequence.hasElements()) + return; + + sal_Int32 nIndex = 0; + bool bShowLegendEntry; + for (const auto& rCooSys : xCooSysSequence) + { + PropertySet aCooSysProp(rCooSys); + bool bSwapXAndY = false; + aCooSysProp.getProperty(bSwapXAndY, PROP_SwapXAndYAxis); + + Reference<chart2::XChartTypeContainer> xChartTypeContainer(rCooSys, UNO_QUERY_THROW); + const Sequence<Reference<chart2::XChartType>> xChartTypeSequence(xChartTypeContainer->getChartTypes()); + if (!xChartTypeSequence.hasElements()) + continue; + + for (const auto& rCT : xChartTypeSequence) + { + Reference<chart2::XDataSeriesContainer> xDSCont(rCT, UNO_QUERY); + if (!xDSCont.is()) + continue; + + const Sequence<Reference<chart2::XDataSeries>> aDataSeriesSeq = xDSCont->getDataSeries(); + if (bSwapXAndY) + nIndex += aDataSeriesSeq.getLength() - 1; + for (const auto& rDataSeries : aDataSeriesSeq) + { + PropertySet aSeriesProp(rDataSeries); + bool bVaryColorsByPoint = false; + aSeriesProp.getProperty(bVaryColorsByPoint, PROP_VaryColorsByPoint); + if (bVaryColorsByPoint) + { + Sequence<sal_Int32> deletedLegendEntriesSeq; + aSeriesProp.getProperty(deletedLegendEntriesSeq, PROP_DeletedLegendEntries); + for (auto& deletedLegendEntry : deletedLegendEntriesSeq) + { + pFS->startElement(FSNS(XML_c, XML_legendEntry)); + pFS->singleElement(FSNS(XML_c, XML_idx), XML_val, + OString::number(nIndex + deletedLegendEntry)); + pFS->singleElement(FSNS(XML_c, XML_delete), XML_val, "1"); + pFS->endElement(FSNS(XML_c, XML_legendEntry)); + } + Reference<chart2::data::XDataSource> xDSrc(rDataSeries, UNO_QUERY); + if (!xDSrc.is()) + continue; + + const Sequence<Reference<chart2::data::XLabeledDataSequence>> aDataSeqs = xDSrc->getDataSequences(); + for (const auto& rDataSeq : aDataSeqs) + { + Reference<chart2::data::XDataSequence> xValues = rDataSeq->getValues(); + if (!xValues.is()) + continue; + + sal_Int32 nDataSeqSize = xValues->getData().getLength(); + nIndex += nDataSeqSize; + } + } + else + { + aSeriesProp.getProperty(bShowLegendEntry, PROP_ShowLegendEntry); + if (!bShowLegendEntry) + { + pFS->startElement(FSNS(XML_c, XML_legendEntry)); + pFS->singleElement(FSNS(XML_c, XML_idx), XML_val, + OString::number(nIndex)); + pFS->singleElement(FSNS(XML_c, XML_delete), XML_val, "1"); + pFS->endElement(FSNS(XML_c, XML_legendEntry)); + } + bSwapXAndY ? nIndex-- : nIndex++; + } + } + if (bSwapXAndY) + nIndex += aDataSeriesSeq.getLength() + 1; + } + } + uno::Any aRelativePos = xProp->getPropertyValue("RelativePosition"); if (aRelativePos.hasValue()) { @@ -1139,8 +1219,6 @@ void ChartExport::exportLegend( const Reference< css::chart::XChartDocument >& x exportTextProps( xProp ); } - // legendEntry - pFS->endElement( FSNS( XML_c, XML_legend ) ); } |