diff options
-rw-r--r-- | chart2/qa/extras/chart2export.cxx | 16 | ||||
-rw-r--r-- | chart2/qa/extras/data/docx/piechart_deleted_legend_entry.docx | bin | 0 -> 27165 bytes | |||
-rw-r--r-- | xmloff/source/chart/SchXMLExport.cxx | 25 | ||||
-rw-r--r-- | xmloff/source/chart/SchXMLPlotAreaContext.cxx | 19 |
4 files changed, 59 insertions, 1 deletions
diff --git a/chart2/qa/extras/chart2export.cxx b/chart2/qa/extras/chart2export.cxx index 5ee135f5920b..1ff1064046e1 100644 --- a/chart2/qa/extras/chart2export.cxx +++ b/chart2/qa/extras/chart2export.cxx @@ -153,6 +153,7 @@ public: void testTdf115012(); void testTdf123206_customLabelText(); void testDeletedLegendEntries(); + void testTdf130225(); CPPUNIT_TEST_SUITE(Chart2ExportTest); CPPUNIT_TEST(testErrorBarXLSX); @@ -269,6 +270,7 @@ public: CPPUNIT_TEST(testTdf115012); CPPUNIT_TEST(testTdf123206_customLabelText); CPPUNIT_TEST(testDeletedLegendEntries); + CPPUNIT_TEST(testTdf130225); CPPUNIT_TEST_SUITE_END(); @@ -2469,6 +2471,20 @@ void Chart2ExportTest::testDeletedLegendEntries() } } +void Chart2ExportTest::testTdf130225() +{ + load("/chart2/qa/extras/data/docx/", "piechart_deleted_legend_entry.docx"); + reload("Office Open XML Text"); + Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY); + CPPUNIT_ASSERT(xChartDoc.is()); + Reference<chart2::XDataSeries> xDataSeries(getDataSeriesFromDoc(xChartDoc, 0)); + CPPUNIT_ASSERT(xDataSeries.is()); + Reference<beans::XPropertySet> xPropertySet(xDataSeries, uno::UNO_QUERY_THROW); + Sequence<sal_Int32> deletedLegendEntriesSeq; + CPPUNIT_ASSERT(xPropertySet->getPropertyValue("DeletedLegendEntries") >>= deletedLegendEntriesSeq); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), deletedLegendEntriesSeq[0]); +} + CPPUNIT_TEST_SUITE_REGISTRATION(Chart2ExportTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/chart2/qa/extras/data/docx/piechart_deleted_legend_entry.docx b/chart2/qa/extras/data/docx/piechart_deleted_legend_entry.docx Binary files differnew file mode 100644 index 000000000000..da6b2fa19a63 --- /dev/null +++ b/chart2/qa/extras/data/docx/piechart_deleted_legend_entry.docx 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))); + } + } } } |