diff --git a/chart2/qa/extras/chart2import2.cxx b/chart2/qa/extras/chart2import2.cxx index 04e0770dd143..27758c956449 100644 --- a/chart2/qa/extras/chart2import2.cxx +++ b/chart2/qa/extras/chart2import2.cxx @@ -14,6 +14,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -2038,6 +2041,66 @@ CPPUNIT_TEST_FIXTURE(Chart2ImportTest2, TestParetoDefaultColor) CPPUNIT_ASSERT_EQUAL(nCorrectColor, nFillColor); } +CPPUNIT_TEST_FIXTURE(Chart2ImportTest2, testTdf164516BarOfPieDiagram) +{ + loadFromFile(u"ods/chart.ods"); + + uno::Reference xChartComp = getChartCompFromSheet(0, 0); + uno::Reference xChartDoc(xChartComp, uno::UNO_QUERY_THROW); + uno::Reference xFactory(xChartDoc, uno::UNO_QUERY_THROW); + + // tdf#164516 - switch the chart type to bar-of-pie using the chart API + uno::Reference xDiagram( + xFactory->createInstance(u"com.sun.star.chart.BarOfPieDiagram"_ustr), uno::UNO_QUERY); + xChartDoc->setDiagram(xDiagram); + + // Without the fix in place, this test would have failed with + // - Expected: com.sun.star.chart.BarOfPieDiagram + // - Actual : com.sun.star.chart.BarDiagram + // i.e. the service name was unknown and the chart stays a bar chart + CPPUNIT_ASSERT_EQUAL(u"com.sun.star.chart.BarOfPieDiagram"_ustr, + xChartDoc->getDiagram()->getDiagramType()); + + uno::Reference xChart2Doc(xChartComp, uno::UNO_QUERY_THROW); + uno::Reference xChartType = getChartTypeFromDoc(xChart2Doc, 0); + CPPUNIT_ASSERT_EQUAL(u"com.sun.star.chart2.PieChartType"_ustr, xChartType->getChartType()); + + uno::Reference xPropSet(xChartType, uno::UNO_QUERY_THROW); + chart2::PieChartSubType eSubType; + CPPUNIT_ASSERT(xPropSet->getPropertyValue(u"SubPieType"_ustr) >>= eSubType); + CPPUNIT_ASSERT_EQUAL(chart2::PieChartSubType_BAR, eSubType); +} + +CPPUNIT_TEST_FIXTURE(Chart2ImportTest2, testTdf164516PieOfPieDiagram) +{ + loadFromFile(u"ods/chart.ods"); + + uno::Reference xChartComp = getChartCompFromSheet(0, 0); + uno::Reference xChartDoc(xChartComp, uno::UNO_QUERY_THROW); + uno::Reference xFactory(xChartDoc, uno::UNO_QUERY_THROW); + + // tdf#164516 - switch the chart type to pie-of-pie using the chart API + uno::Reference xDiagram( + xFactory->createInstance(u"com.sun.star.chart.PieOfPieDiagram"_ustr), uno::UNO_QUERY); + xChartDoc->setDiagram(xDiagram); + + // Without the fix in place, this test would have failed with + // - Expected: com.sun.star.chart.PieOfPieDiagram + // - Actual : com.sun.star.chart.BarDiagram + // i.e. the service name was unknown and the chart stays a bar chart + CPPUNIT_ASSERT_EQUAL(u"com.sun.star.chart.PieOfPieDiagram"_ustr, + xChartDoc->getDiagram()->getDiagramType()); + + uno::Reference xChart2Doc(xChartComp, uno::UNO_QUERY_THROW); + uno::Reference xChartType = getChartTypeFromDoc(xChart2Doc, 0); + CPPUNIT_ASSERT_EQUAL(u"com.sun.star.chart2.PieChartType"_ustr, xChartType->getChartType()); + + uno::Reference xPropSet(xChartType, uno::UNO_QUERY_THROW); + chart2::PieChartSubType eSubType; + CPPUNIT_ASSERT(xPropSet->getPropertyValue(u"SubPieType"_ustr) >>= eSubType); + CPPUNIT_ASSERT_EQUAL(chart2::PieChartSubType_PIE, eSubType); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/controller/chartapiwrapper/ChartDocumentWrapper.cxx b/chart2/source/controller/chartapiwrapper/ChartDocumentWrapper.cxx index 2888ee9b0672..59fddcc390e2 100644 --- a/chart2/source/controller/chartapiwrapper/ChartDocumentWrapper.cxx +++ b/chart2/source/controller/chartapiwrapper/ChartDocumentWrapper.cxx @@ -84,6 +84,8 @@ enum eServiceType SERVICE_NAME_NET_DIAGRAM, SERVICE_NAME_FILLED_NET_DIAGRAM, SERVICE_NAME_PIE_DIAGRAM, + SERVICE_NAME_BAR_OF_PIE_DIAGRAM, + SERVICE_NAME_PIE_OF_PIE_DIAGRAM, SERVICE_NAME_STOCK_DIAGRAM, SERVICE_NAME_XY_DIAGRAM, SERVICE_NAME_BUBBLE_DIAGRAM, @@ -114,6 +116,8 @@ tServiceNameMap & lcl_getStaticServiceNameMap() {"com.sun.star.chart.NetDiagram", SERVICE_NAME_NET_DIAGRAM}, {"com.sun.star.chart.FilledNetDiagram", SERVICE_NAME_FILLED_NET_DIAGRAM}, {"com.sun.star.chart.PieDiagram", SERVICE_NAME_PIE_DIAGRAM}, + {"com.sun.star.chart.BarOfPieDiagram", SERVICE_NAME_BAR_OF_PIE_DIAGRAM}, + {"com.sun.star.chart.PieOfPieDiagram", SERVICE_NAME_PIE_OF_PIE_DIAGRAM}, {"com.sun.star.chart.StockDiagram", SERVICE_NAME_STOCK_DIAGRAM}, {"com.sun.star.chart.XYDiagram", SERVICE_NAME_XY_DIAGRAM}, {"com.sun.star.chart.BubbleDiagram", SERVICE_NAME_BUBBLE_DIAGRAM}, @@ -1207,6 +1211,22 @@ uno::Reference< uno::XInterface > SAL_CALL ChartDocumentWrapper::createInstance( bCreateDiagram = true; } break; + case SERVICE_NAME_BAR_OF_PIE_DIAGRAM: + if (xChartTypeManager.is()) + { + xTemplate = xChartTypeManager->createTemplate( + u"com.sun.star.chart2.template.BarOfPie"_ustr); + bCreateDiagram = true; + } + break; + case SERVICE_NAME_PIE_OF_PIE_DIAGRAM: + if (xChartTypeManager.is()) + { + xTemplate = xChartTypeManager->createTemplate( + u"com.sun.star.chart2.template.PieOfPie"_ustr); + bCreateDiagram = true; + } + break; case SERVICE_NAME_STOCK_DIAGRAM: if( xChartTypeManager.is()) {