pivotcharts: ignore subtotals, grand totals in pivot table data
Change-Id: I08cdd28aaae536fa8306446168dcdb977897dfcd
Reviewed-on: https://gerrit.libreoffice.org/36308
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
diff --git a/chart2/qa/extras/PivotChartTest.cxx b/chart2/qa/extras/PivotChartTest.cxx
index 7f7b095..ff1dd58 100644
--- a/chart2/qa/extras/PivotChartTest.cxx
+++ b/chart2/qa/extras/PivotChartTest.cxx
@@ -126,7 +126,6 @@ void PivotChartTest::testRoundtrip()
{
uno::Reference<sheet::XDataPilotTable> xDataPilotTable = lclGetPivotTableByName(1, "DataPilot1", mxComponent);
uno::Reference<sheet::XDataPilotDescriptor> xDataPilotDescriptor(xDataPilotTable, UNO_QUERY_THROW);
lclModifyOrientation(xDataPilotDescriptor, "Exp.", sheet::DataPilotFieldOrientation_HIDDEN);
}
@@ -161,13 +160,18 @@ void PivotChartTest::testChangePivotTable()
load("/chart2/qa/extras/data/ods/", "PivotTableExample.ods");
// Check we have the Pivot Table
OUString sPivotTableName("DataPilot1");
uno::Reference<sheet::XDataPilotTable> xDataPilotTable = lclGetPivotTableByName(1, sPivotTableName, mxComponent);
CPPUNIT_ASSERT(xDataPilotTable.is());
// Check that we don't have any pivot chart in the document
uno::Reference<table::XTablePivotCharts> xTablePivotCharts = getTablePivotChartsFromSheet(1, mxComponent);
uno::Reference<container::XIndexAccess> xIndexAccess(xTablePivotCharts, UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount());
// Create a new pivot chart
xTablePivotCharts->addNewByName("Chart", awt::Rectangle{0, 0, 9000, 9000}, "DataPilot1");
xTablePivotCharts->addNewByName("Chart", awt::Rectangle{0, 0, 9000, 9000}, sPivotTableName);
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
// Get the pivot chart document so we ca access its data
@@ -175,6 +179,8 @@ void PivotChartTest::testChangePivotTable()
CPPUNIT_ASSERT(xChartDoc.is());
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), getNumberOfDataSeries(xChartDoc));
// Check first data series
{
std::vector<double> aReference { 10162.033139, 16614.523063, 27944.146101 };
@@ -197,9 +203,9 @@ void PivotChartTest::testChangePivotTable()
CPPUNIT_ASSERT_EQUAL(aExpectedLabel, lclGetLabel(xChartDoc, 1));
}
// Modify the pivot table
// Modify the pivot table, move "Group Segment" to Column fields,
// add "Servie Month" to Row fields, remove "Rev." Data field
{
uno::Reference<sheet::XDataPilotTable> xDataPilotTable = lclGetPivotTableByName(1, "DataPilot1", mxComponent);
uno::Reference<sheet::XDataPilotDescriptor> xDataPilotDescriptor(xDataPilotTable, UNO_QUERY_THROW);
lclModifyOrientation(xDataPilotDescriptor, "Service Month", sheet::DataPilotFieldOrientation_ROW);
@@ -209,7 +215,7 @@ void PivotChartTest::testChangePivotTable()
// Check the pivot chart again as we expect it has been updated when we updated the pivot table
CPPUNIT_ASSERT(xChartDoc.is());
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), getNumberOfDataSeries(xChartDoc));
// Check the first data series
{
@@ -244,17 +250,46 @@ void PivotChartTest::testChangePivotTable()
CPPUNIT_ASSERT_EQUAL(aExpectedLabel, lclGetLabel(xChartDoc, 2));
}
// Modify the pivot table
// Remove "Service Month" so row fields are empty - check we handle empty rows
{
uno::Reference<sheet::XDataPilotTable> xDataPilotTable = lclGetPivotTableByName(1, "DataPilot1", mxComponent);
uno::Reference<sheet::XDataPilotDescriptor> xDataPilotDescriptor(xDataPilotTable, UNO_QUERY_THROW);
uno::Reference<sheet::XDataPilotDescriptor> xDataPilotDescriptor(xDataPilotTable, uno::UNO_QUERY_THROW);
lclModifyOrientation(xDataPilotDescriptor, "Service Month", sheet::DataPilotFieldOrientation_HIDDEN);
}
// Check the pivot chart again as we expect it has been updated when we updated the pivot table
CPPUNIT_ASSERT(xChartDoc.is());
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), getNumberOfDataSeries(xChartDoc));
// Check the first data series
{
std::vector<double> aReference { 10162.033139 };
xSequence = getDataSequenceFromDocByRole(xChartDoc, "values-y", 0)->getData();
lclCheckSequence(aReference, xSequence, 1E-3);
CPPUNIT_ASSERT_EQUAL(OUString("Big"), lclGetLabel(xChartDoc, 0));
}
// Check the second data series
{
std::vector<double> aReference { 16614.523063 };
xSequence = getDataSequenceFromDocByRole(xChartDoc, "values-y", 1)->getData();
lclCheckSequence(aReference, xSequence, 1E-3);
CPPUNIT_ASSERT_EQUAL(OUString("Medium"), lclGetLabel(xChartDoc, 1));
}
// Check the third data series
{
std::vector<double> aReference { 27944.146101 };
xSequence = getDataSequenceFromDocByRole(xChartDoc, "values-y", 2)->getData();
lclCheckSequence(aReference, xSequence, 1E-3);
CPPUNIT_ASSERT_EQUAL(OUString("Small"), lclGetLabel(xChartDoc, 2));
}
// Enable column totals and check the data is still unchanged
{
uno::Reference<sheet::XDataPilotDescriptor> xDataPilotDescriptor(xDataPilotTable, uno::UNO_QUERY_THROW);
uno::Reference<beans::XPropertySet> xProperties(xDataPilotTable, uno::UNO_QUERY_THROW);
xProperties->setPropertyValue("ColumnGrand", uno::makeAny(true));
}
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), getNumberOfDataSeries(xChartDoc));
// Check the first data series
{
diff --git a/sc/source/ui/unoobj/PivotTableDataProvider.cxx b/sc/source/ui/unoobj/PivotTableDataProvider.cxx
index 5eb66c6..df7b180c 100644
--- a/sc/source/ui/unoobj/PivotTableDataProvider.cxx
+++ b/sc/source/ui/unoobj/PivotTableDataProvider.cxx
@@ -265,9 +265,8 @@ void PivotTableDataProvider::collectPivotTableData()
{
ScDPCollection* pDPCollection = m_pDocument->GetDPCollection();
ScDPObject* pDPObject = pDPCollection->GetByName(m_sPivotTableName);
uno::Reference<sheet::XDataPilotResults> xDPResults(pDPObject->GetSource(), uno::UNO_QUERY);
uno::Sequence<uno::Sequence<sheet::DataResult>> xDataResultsSequence = xDPResults->getResults();
if (!pDPObject)
return;
m_aCategoriesColumnOrientation.clear();
m_aCategoriesRowOrientation.clear();
@@ -278,6 +277,9 @@ void PivotTableDataProvider::collectPivotTableData()
m_aPageFields.clear();
m_aDataFields.clear();
uno::Reference<sheet::XDataPilotResults> xDPResults(pDPObject->GetSource(), uno::UNO_QUERY);
uno::Sequence<uno::Sequence<sheet::DataResult>> xDataResultsSequence = xDPResults->getResults();
double fNan;
rtl::math::setNan(&fNan);
@@ -286,6 +288,8 @@ void PivotTableDataProvider::collectPivotTableData()
size_t nIndex = 0;
for (sheet::DataResult const & rDataResult : xDataResults)
{
if (rDataResult.Flags & css::sheet::DataResultFlags::SUBTOTAL)
continue;
if (rDataResult.Flags == 0 || rDataResult.Flags & css::sheet::DataResultFlags::HASDATA)
{
if (nIndex >= m_aDataRowVector.size())