tdf#164516 - Allow changing the chart type to of-pie by macro

Register BarOfPieDiagram and PieOfPieDiagram and map them to the
existing chart2 BarOfPie/PieOfPie templates used by the chart type
dialog.

Change-Id: Id5ba30d7547d290826bb360b2ccb3713fdb95a42
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/211460
Reviewed-by: Andreas Heinisch <andreas.heinisch@yahoo.de>
Tested-by: Jenkins
This commit is contained in:
DrRobotto
2026-09-25 23:00:20 +02:00
committed by Andreas Heinisch
parent 24ccaeea23
commit 2a6ccbc40b
2 changed files with 83 additions and 0 deletions
+63
View File
@@ -14,6 +14,9 @@
#include <com/sun/star/chart2/RelativePosition.hpp>
#include <com/sun/star/chart2/XChartDocument.hpp>
#include <com/sun/star/chart/XChartDocument.hpp>
#include <com/sun/star/chart/XDiagram.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/chart2/PieChartSubType.hpp>
#include <com/sun/star/chart2/XInternalDataProvider.hpp>
#include <com/sun/star/chart2/data/XTextualDataSequence.hpp>
#include <com/sun/star/chart/XAxisXSupplier.hpp>
@@ -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<lang::XComponent> xChartComp = getChartCompFromSheet(0, 0);
uno::Reference<chart::XChartDocument> xChartDoc(xChartComp, uno::UNO_QUERY_THROW);
uno::Reference<lang::XMultiServiceFactory> xFactory(xChartDoc, uno::UNO_QUERY_THROW);
// tdf#164516 - switch the chart type to bar-of-pie using the chart API
uno::Reference<chart::XDiagram> 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<chart2::XChartDocument> xChart2Doc(xChartComp, uno::UNO_QUERY_THROW);
uno::Reference<chart2::XChartType> xChartType = getChartTypeFromDoc(xChart2Doc, 0);
CPPUNIT_ASSERT_EQUAL(u"com.sun.star.chart2.PieChartType"_ustr, xChartType->getChartType());
uno::Reference<beans::XPropertySet> 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<lang::XComponent> xChartComp = getChartCompFromSheet(0, 0);
uno::Reference<chart::XChartDocument> xChartDoc(xChartComp, uno::UNO_QUERY_THROW);
uno::Reference<lang::XMultiServiceFactory> xFactory(xChartDoc, uno::UNO_QUERY_THROW);
// tdf#164516 - switch the chart type to pie-of-pie using the chart API
uno::Reference<chart::XDiagram> 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<chart2::XChartDocument> xChart2Doc(xChartComp, uno::UNO_QUERY_THROW);
uno::Reference<chart2::XChartType> xChartType = getChartTypeFromDoc(xChart2Doc, 0);
CPPUNIT_ASSERT_EQUAL(u"com.sun.star.chart2.PieChartType"_ustr, xChartType->getChartType());
uno::Reference<beans::XPropertySet> 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: */
@@ -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())
{