summaryrefslogtreecommitdiff
path: root/xmloff
diff options
context:
space:
mode:
authorTünde Tóth <tundeth@gmail.com>2020-02-05 13:37:00 +0100
committerLászló Németh <nemeth@numbertext.org>2020-02-13 11:15:56 +0100
commita96ec04a07c35338f5f9a0cb361b9322e5ca9cec (patch)
tree20b109bd965560010312b19d1dd3d8b01f05d76e /xmloff
parent8daffb60dd2863878bb04317ca2849d76df01f4b (diff)
tdf#130225 implement ODF export of deleted legend entries of pie charts
Follow-up of the following commits related to the new UNO property DeletedLegendEntries for pie charts: commit 86be3422cd55fa9e44104f1628648061bb6a3495 (tdf#129857 Chart OOXML export: fix deleted legend entries) commit 6e847aa817999ab18acd534f9e6a86685bb268fc (tdf#129859 XLSX import: don't show deleted legend entries) Change-Id: Id24cddefa83e50dde1ec6555d02891753483dd5f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88018 Tested-by: Jenkins Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'xmloff')
-rw-r--r--xmloff/source/chart/SchXMLExport.cxx25
-rw-r--r--xmloff/source/chart/SchXMLPlotAreaContext.cxx19
2 files changed, 43 insertions, 1 deletions
diff --git a/xmloff/source/chart/SchXMLExport.cxx b/xmloff/source/chart/SchXMLExport.cxx
index b3d18c7c758c..12f772b0d8b5 100644
--- a/xmloff/source/chart/SchXMLExport.cxx
+++ b/xmloff/source/chart/SchXMLExport.cxx
@@ -3188,10 +3188,15 @@ void SchXMLExportHelper_Impl::exportDataPoints(
bool bVaryColorsByPoint = false;
Sequence< sal_Int32 > aDataPointSeq;
+ Sequence<sal_Int32> deletedLegendEntriesSeq;
if( xSeriesProperties.is())
{
xSeriesProperties->getPropertyValue("AttributedDataPoints") >>= aDataPointSeq;
xSeriesProperties->getPropertyValue("VaryColorsByPoint") >>= bVaryColorsByPoint;
+
+ const SvtSaveOptions::ODFDefaultVersion nCurrentODFVersion( SvtSaveOptions().GetODFDefaultVersion() );
+ if( nCurrentODFVersion >= SvtSaveOptions::ODFVER_012 )
+ xSeriesProperties->getPropertyValue("DeletedLegendEntries") >>= deletedLegendEntriesSeq;
}
sal_Int32 nSize = aDataPointSeq.getLength();
@@ -3362,7 +3367,7 @@ void SchXMLExportHelper_Impl::exportDataPoints(
// initialize so that it doesn't matter if
// the element is counted in the first iteration
aLastPoint.mnRepeat = 0;
-
+ sal_Int32 nIndex = 0;
for( const auto& rPoint : aDataPointVector )
{
aPoint = rPoint;
@@ -3379,6 +3384,15 @@ void SchXMLExportHelper_Impl::exportDataPoints(
mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_REPEATED,
OUString::number( ( aLastPoint.mnRepeat ) ));
+ for (auto& deletedLegendEntry : deletedLegendEntriesSeq)
+ {
+ if (nIndex == deletedLegendEntry)
+ {
+ mrExport.AddAttribute(XML_NAMESPACE_LO_EXT, XML_HIDE_LEGEND, OUString::boolean(true));
+ break;
+ }
+ }
+ nIndex++;
SvXMLElementExport aPointElem( mrExport, XML_NAMESPACE_CHART, XML_DATA_POINT, true, true );
exportCustomLabel(aLastPoint.mCustomLabelText);
}
@@ -3394,6 +3408,15 @@ void SchXMLExportHelper_Impl::exportDataPoints(
mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_REPEATED,
OUString::number( ( aLastPoint.mnRepeat ) ));
+ for (auto& deletedLegendEntry : deletedLegendEntriesSeq)
+ {
+ if (nIndex == deletedLegendEntry)
+ {
+ mrExport.AddAttribute(XML_NAMESPACE_LO_EXT, XML_HIDE_LEGEND, OUString::boolean(true));
+ break;
+ }
+ }
+
SvXMLElementExport aPointElem( mrExport, XML_NAMESPACE_CHART, XML_DATA_POINT, true, true );
exportCustomLabel(aLastPoint.mCustomLabelText);
}
diff --git a/xmloff/source/chart/SchXMLPlotAreaContext.cxx b/xmloff/source/chart/SchXMLPlotAreaContext.cxx
index 5ea889aa7621..dc32a9e900a0 100644
--- a/xmloff/source/chart/SchXMLPlotAreaContext.cxx
+++ b/xmloff/source/chart/SchXMLPlotAreaContext.cxx
@@ -31,6 +31,7 @@
#include <xmloff/xmluconv.hxx>
#include <xmloff/prstylei.hxx>
#include <xmloff/xmlstyle.hxx>
+#include <oox/helper/containerhelper.hxx>
#include <com/sun/star/awt/Point.hpp>
#include <com/sun/star/awt/Size.hpp>
@@ -679,6 +680,7 @@ void SchXMLDataPointContext::StartElement( const uno::Reference< xml::sax::XAttr
{
OUString sAttrName = xAttrList->getNameByIndex( i );
OUString aLocalName;
+ bool bHideLegend = false;
sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
if( nPrefix == XML_NAMESPACE_CHART )
@@ -703,6 +705,23 @@ void SchXMLDataPointContext::StartElement( const uno::Reference< xml::sax::XAttr
sCustomLabelField = xAttrList->getValueByIndex( i );
mDataPoint.mCustomLabels.push_back(sCustomLabelField);
}
+ else if (IsXMLToken(aLocalName, XML_HIDE_LEGEND))
+ {
+ bHideLegend = xAttrList->getValueByIndex(i).toBoolean();
+ if (bHideLegend)
+ {
+ uno::Sequence<sal_Int32> deletedLegendEntriesSeq;
+ Reference<beans::XPropertySet> xSeriesProp(mDataPoint.m_xSeries, uno::UNO_QUERY);
+ xSeriesProp->getPropertyValue("DeletedLegendEntries") >>= deletedLegendEntriesSeq;
+ std::vector<sal_Int32> deletedLegendEntries;
+ for (auto& deletedLegendEntry : deletedLegendEntriesSeq)
+ {
+ deletedLegendEntries.push_back(deletedLegendEntry);
+ }
+ deletedLegendEntries.push_back(mDataPoint.m_nPointIndex);
+ xSeriesProp->setPropertyValue("DeletedLegendEntries", uno::makeAny(::oox::ContainerHelper::vectorToSequence(deletedLegendEntries)));
+ }
+ }
}
}