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: commit86be3422cd
(tdf#129857 Chart OOXML export: fix deleted legend entries) commit6e847aa817
(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>
This commit is contained in:
committed by
László Németh
parent
8daffb60dd
commit
a96ec04a07
@@ -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();
|
||||
|
BIN
chart2/qa/extras/data/docx/piechart_deleted_legend_entry.docx
Normal file
BIN
chart2/qa/extras/data/docx/piechart_deleted_legend_entry.docx
Normal file
Binary file not shown.
@@ -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);
|
||||
}
|
||||
|
@@ -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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user