tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / chart2 / qa / extras / PivotChartTest.cxx
blob30cd8c65652629e38b131d079750131d23678afd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include "charttest.hxx"
12 #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
13 #include <com/sun/star/sheet/DataPilotFieldLayoutMode.hpp>
14 #include <com/sun/star/sheet/DataPilotFieldLayoutInfo.hpp>
15 #include <com/sun/star/sheet/XDataPilotTable.hpp>
16 #include <com/sun/star/sheet/XDataPilotDescriptor.hpp>
17 #include <com/sun/star/sheet/XDataPilotTables.hpp>
18 #include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp>
19 #include <com/sun/star/sheet/XSpreadsheet.hpp>
20 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
21 #include <com/sun/star/sheet/XSpreadsheets.hpp>
22 #include <com/sun/star/table/XTablePivotCharts.hpp>
23 #include <com/sun/star/sheet/GeneralFunction.hpp>
24 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
25 #include <com/sun/star/util/XNumberFormatTypes.hpp>
26 #include <com/sun/star/util/NumberFormat.hpp>
28 #include <com/sun/star/chart2/data/XPivotTableDataProvider.hpp>
29 #include <com/sun/star/chart2/data/XTextualDataSequence.hpp>
31 namespace com::sun::star::table { class XCellRange; }
32 namespace com::sun::star::util { class XNumberFormats; }
34 class PivotChartTest : public ChartTest
36 public:
37 PivotChartTest()
38 : ChartTest(u"/chart2/qa/extras/data/"_ustr)
41 void testRoundtrip();
42 void testChangePivotTable();
43 void testPivotChartWithOneColumnField();
44 void testPivotChartWithOneRowField();
45 void testPivotTableDataProvider_PivotTableFields();
46 void testPivotChartRowFieldInOutlineMode();
47 void testPivotChartWithDateRowField();
49 CPPUNIT_TEST_SUITE(PivotChartTest);
50 CPPUNIT_TEST(testRoundtrip);
51 CPPUNIT_TEST(testChangePivotTable);
52 CPPUNIT_TEST(testPivotChartWithOneColumnField);
53 CPPUNIT_TEST(testPivotChartWithOneRowField);
54 CPPUNIT_TEST(testPivotTableDataProvider_PivotTableFields);
55 CPPUNIT_TEST(testPivotChartRowFieldInOutlineMode);
56 CPPUNIT_TEST(testPivotChartWithDateRowField);
57 CPPUNIT_TEST_SUITE_END();
59 private:
60 uno::Reference<sheet::XDataPilotTable> getPivotTableByName(sal_Int32 nIndex, OUString const & sPivotTableName);
63 namespace
66 void lclModifyOrientation(uno::Reference<sheet::XDataPilotDescriptor> const & xDescriptor,
67 std::u16string_view sFieldName,
68 sheet::DataPilotFieldOrientation eOrientation)
70 uno::Reference<container::XIndexAccess> xIndexAccess(xDescriptor->getDataPilotFields(), UNO_SET_THROW);
71 sal_Int32 nCount = xIndexAccess->getCount();
72 for (sal_Int32 i = 0; i < nCount; ++i)
74 uno::Reference<container::XNamed> xNamed(xIndexAccess->getByIndex(i), UNO_QUERY_THROW);
75 OUString aName = xNamed->getName();
76 uno::Reference<beans::XPropertySet> xPropSet(xNamed, UNO_QUERY_THROW);
77 if (aName == sFieldName)
78 xPropSet->setPropertyValue(u"Orientation"_ustr, uno::Any(eOrientation));
82 void lclModifyFunction(uno::Reference<sheet::XDataPilotDescriptor> const & xDescriptor,
83 std::u16string_view sFieldName,
84 sheet::GeneralFunction eFunction)
86 uno::Reference<container::XIndexAccess> xPilotIndexAccess(xDescriptor->getDataPilotFields(), UNO_SET_THROW);
87 sal_Int32 nCount = xPilotIndexAccess->getCount();
88 for (sal_Int32 i = 0; i < nCount; ++i)
90 uno::Reference<container::XNamed> xNamed(xPilotIndexAccess->getByIndex(i), UNO_QUERY_THROW);
91 OUString aName = xNamed->getName();
92 uno::Reference<beans::XPropertySet> xPropSet(xNamed, UNO_QUERY_THROW);
93 if (aName == sFieldName)
94 xPropSet->setPropertyValue(u"Function"_ustr, uno::Any(eFunction));
98 void lclModifyLayoutInfo(uno::Reference<sheet::XDataPilotDescriptor> const & xDescriptor,
99 std::u16string_view sFieldName,
100 sheet::DataPilotFieldLayoutInfo aLayoutInfo)
102 uno::Reference<container::XIndexAccess> xIndexAccess(xDescriptor->getDataPilotFields(), UNO_SET_THROW);
103 sal_Int32 nCount = xIndexAccess->getCount();
104 for (sal_Int32 i = 0; i < nCount; ++i)
106 uno::Reference<container::XNamed> xNamed(xIndexAccess->getByIndex(i), UNO_QUERY_THROW);
107 OUString aName = xNamed->getName();
108 uno::Reference<beans::XPropertySet> xPropSet(xNamed, UNO_QUERY_THROW);
109 if (aName == sFieldName)
111 uno::Any aValue;
112 aValue <<= aLayoutInfo;
113 xPropSet->setPropertyValue(u"LayoutInfo"_ustr, aValue);
118 void lclModifySubtotals(uno::Reference<sheet::XDataPilotDescriptor> const & xDescriptor,
119 std::u16string_view sFieldName,
120 uno::Sequence<sheet::GeneralFunction> const & rSubtotalFunctions)
122 uno::Reference<container::XIndexAccess> xIndexAccess(xDescriptor->getDataPilotFields(), UNO_SET_THROW);
123 sal_Int32 nCount = xIndexAccess->getCount();
124 for (sal_Int32 i = 0; i < nCount; ++i)
126 uno::Reference<container::XNamed> xNamed(xIndexAccess->getByIndex(i), UNO_QUERY_THROW);
127 OUString aName = xNamed->getName();
128 uno::Reference<beans::XPropertySet> xPropSet(xNamed, UNO_QUERY_THROW);
129 if (aName == sFieldName)
131 uno::Any aValue;
132 aValue <<= rSubtotalFunctions;
133 xPropSet->setPropertyValue(u"Subtotals"_ustr, aValue);
138 void lclModifyColumnGrandTotal(uno::Reference<sheet::XDataPilotDescriptor> const & xDataPilotDescriptor, bool bTotal)
140 uno::Reference<beans::XPropertySet> xProperties(xDataPilotDescriptor, uno::UNO_QUERY_THROW);
141 xProperties->setPropertyValue(u"ColumnGrand"_ustr, uno::Any(bTotal));
144 void lclModifyRowGrandTotal(uno::Reference<sheet::XDataPilotDescriptor> const & xDataPilotDescriptor, bool bTotal)
146 uno::Reference<beans::XPropertySet> xProperties(xDataPilotDescriptor, uno::UNO_QUERY_THROW);
147 xProperties->setPropertyValue(u"RowGrand"_ustr, uno::Any(bTotal));
150 void lclCheckSequence(std::vector<double> const & reference,
151 uno::Sequence<uno::Any> const & values,
152 double delta)
154 CPPUNIT_ASSERT_EQUAL(reference.size(), size_t(values.getLength()));
155 for (size_t i = 0; i < reference.size(); ++i)
157 CPPUNIT_ASSERT_DOUBLES_EQUAL(
158 reference[i], values[i].get<double>(), delta);
162 void lclCheckCategories(std::vector<OUString> const & reference,
163 uno::Reference<chart2::data::XDataSequence> const & xSequence)
165 uno::Reference<chart2::data::XTextualDataSequence> xTextualDataSequence(xSequence, uno::UNO_QUERY_THROW);
166 uno::Sequence<OUString> aText = xTextualDataSequence->getTextualData();
168 CPPUNIT_ASSERT_EQUAL(reference.size(), size_t(aText.getLength()));
169 for (size_t i = 0; i < reference.size(); ++i)
171 CPPUNIT_ASSERT_EQUAL(reference[i], aText[i]);
175 uno::Sequence<uno::Reference<chart2::data::XLabeledDataSequence>>
176 lclGetCategories(Reference<chart2::XChartDocument> const & xChartDoc)
178 uno::Sequence<beans::PropertyValue> aArguments( comphelper::InitPropertySequence(
179 {{"CellRangeRepresentation", uno::Any(u"PT@categories"_ustr)}} ));
181 uno::Reference<chart2::data::XDataProvider> xDataProvider(xChartDoc->getDataProvider(), uno::UNO_SET_THROW);
182 return xDataProvider->createDataSource(aArguments)->getDataSequences();
185 struct Value
187 OUString maString;
188 double mfValue;
189 bool mbIsValue;
191 Value(OUString const & rString)
192 : maString(rString)
193 , mfValue(0.0)
194 , mbIsValue(false)
197 Value(double fValue)
198 : mfValue(fValue)
199 , mbIsValue(true)
203 uno::Reference< sheet::XDataPilotTables>
204 lclGetDataPilotTables(sal_Int32 nIndex, uno::Reference<sheet::XSpreadsheetDocument> const & xSheetDoc)
206 uno::Reference<sheet::XSpreadsheets> xSpreadsheets = xSheetDoc->getSheets();
207 uno::Reference<container::XIndexAccess> oIndexAccess(xSpreadsheets, uno::UNO_QUERY_THROW);
208 uno::Reference<sheet::XSpreadsheet> xSheet;
209 CPPUNIT_ASSERT(oIndexAccess->getByIndex(nIndex) >>= xSheet);
211 // create the test objects
212 uno::Reference< sheet::XDataPilotTablesSupplier> xDataPilotTablesSupplier(xSheet, uno::UNO_QUERY_THROW);
213 return xDataPilotTablesSupplier->getDataPilotTables();
216 table::CellRangeAddress lclCreateTestData(uno::Reference<sheet::XSpreadsheetDocument> const & xSheetDoc)
218 CPPUNIT_ASSERT_MESSAGE("no calc document!", xSheetDoc.is());
220 std::vector<OUString> aHeaders {
221 u"Country"_ustr, u"City"_ustr, u"Type"_ustr, u"Sales T1"_ustr, u"Sales T2"_ustr, u"Sales T3"_ustr, u"Sales T4"_ustr, u"Date"_ustr
224 std::vector<std::vector<Value>> aData {
225 { {u"FR"_ustr}, {u"Paris"_ustr}, {u"A"_ustr}, {123.0}, {223.0}, {323.0}, {423.0}, {u"12/14/15"_ustr} },
226 { {u"EN"_ustr}, {u"London"_ustr}, {u"A"_ustr}, {456.0}, {556.0}, {656.0}, {756.0}, {u"12/11/15"_ustr} },
227 { {u"DE"_ustr}, {u"Berlin"_ustr}, {u"A"_ustr}, {468.0}, {568.0}, {668.0}, {768.0}, {u"12/11/15"_ustr} },
228 { {u"FR"_ustr}, {u"Nantes"_ustr}, {u"A"_ustr}, {694.0}, {794.0}, {894.0}, {994.0}, {u"12/11/15"_ustr} },
229 { {u"EN"_ustr}, {u"Glasgow"_ustr}, {u"A"_ustr}, {298.0}, {398.0}, {498.0}, {598.0}, {u"12/11/15"_ustr} },
230 { {u"DE"_ustr}, {u"Munich"_ustr}, {u"A"_ustr}, {369.0}, {469.0}, {569.0}, {669.0}, {u"12/11/15"_ustr} },
231 { {u"FR"_ustr}, {u"Paris"_ustr}, {u"B"_ustr}, {645.0}, {745.0}, {845.0}, {945.0}, {u"12/11/15"_ustr} },
232 { {u"EN"_ustr}, {u"London"_ustr}, {u"B"_ustr}, {687.0}, {787.0}, {887.0}, {987.0}, {u"03/21/17"_ustr} },
233 { {u"DE"_ustr}, {u"Munich"_ustr}, {u"B"_ustr}, {253.0}, {353.0}, {453.0}, {553.0}, {u"12/17/15"_ustr} },
234 { {u"FR"_ustr}, {u"Nantes"_ustr}, {u"B"_ustr}, {474.0}, {574.0}, {674.0}, {774.0}, {u"01/20/16"_ustr} },
235 { {u"EN"_ustr}, {u"Liverpool"_ustr}, {u"B"_ustr}, {562.0}, {662.0}, {762.0}, {862.0}, {u"01/20/16"_ustr} },
236 { {u"DE"_ustr}, {u"Berlin"_ustr}, {u"B"_ustr}, {648.0}, {748.0}, {848.0}, {948.0}, {u"01/20/16"_ustr} }
239 // Getting spreadsheet
240 uno::Reference<sheet::XSpreadsheets> xSpreadsheets = xSheetDoc->getSheets();
241 uno::Reference<container::XIndexAccess> oIndexAccess(xSpreadsheets, uno::UNO_QUERY_THROW);
242 uno::Reference<sheet::XSpreadsheet> xSheet;
243 CPPUNIT_ASSERT(oIndexAccess->getByIndex(0) >>= xSheet);
245 uno::Reference<sheet::XSpreadsheet> oPivotTableSheet;
246 xSpreadsheets->insertNewByName(u"Pivot Table"_ustr, 1);
247 CPPUNIT_ASSERT(oIndexAccess->getByIndex(1) >>= oPivotTableSheet);
249 sal_Int32 currentRow = 0;
250 for (size_t column = 0; column < aHeaders.size(); ++column)
252 xSheet->getCellByPosition(column, currentRow)->setFormula(aHeaders[column]);
254 currentRow++;
256 for (std::vector<Value> const & rRowOfData : aData)
258 for (size_t column = 0; column < rRowOfData.size(); ++column)
260 Value const & rValue = rRowOfData[column];
261 uno::Reference<table::XCell> xCell(xSheet->getCellByPosition(column, currentRow));
262 if (rValue.mbIsValue)
263 xCell->setValue(rValue.mfValue);
264 else
265 xCell->setFormula(rValue.maString);
267 currentRow++;
270 sal_Int32 nEndCol = sal_Int32(aHeaders.size() - 1);
271 sal_Int32 nEndRow = sal_Int32(1/*HEADER*/ + aData.size() - 1);
273 // Apply date format to the last column
274 uno::Reference<util::XNumberFormatsSupplier> xNumberFormatsSupplier(xSheetDoc, UNO_QUERY_THROW);
275 uno::Reference<util::XNumberFormats> xNumberFormats = xNumberFormatsSupplier->getNumberFormats();
276 uno::Reference<util::XNumberFormatTypes> xNumberFormatTypes(xNumberFormats, UNO_QUERY_THROW);
277 lang::Locale aLocale;
278 sal_Int32 nDateKey = xNumberFormatTypes->getStandardFormat(util::NumberFormat::DATE, aLocale);
279 uno::Reference<table::XCellRange> xCellRange = xSheet->getCellRangeByPosition(nEndCol, 1, nEndCol, nEndRow);
280 uno::Reference<beans::XPropertySet> xCellProp(xCellRange, UNO_QUERY_THROW);
281 xCellProp->setPropertyValue(u"NumberFormat"_ustr, uno::Any(nDateKey));
283 table::CellRangeAddress sCellRangeAddress;
284 sCellRangeAddress.Sheet = 0;
285 sCellRangeAddress.StartColumn = 0;
286 sCellRangeAddress.StartRow = 0;
287 sCellRangeAddress.EndColumn = nEndCol;
288 sCellRangeAddress.EndRow = nEndRow;
290 return sCellRangeAddress;
293 } // end anonymous namespace
295 uno::Reference<sheet::XDataPilotTable> PivotChartTest::getPivotTableByName(sal_Int32 nIndex, OUString const & sPivotTableName)
297 uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW);
298 uno::Reference<container::XIndexAccess> xSheetIndexAccess(xDoc->getSheets(), UNO_QUERY_THROW);
299 uno::Any aAny = xSheetIndexAccess->getByIndex(nIndex);
300 uno::Reference<sheet::XSpreadsheet> xSheet;
301 CPPUNIT_ASSERT(aAny >>= xSheet);
302 uno::Reference<sheet::XDataPilotTablesSupplier> xDataPilotTablesSupplier(xSheet, uno::UNO_QUERY_THROW);
303 uno::Reference<sheet::XDataPilotTables> xDataPilotTables = xDataPilotTablesSupplier->getDataPilotTables();
304 return uno::Reference<sheet::XDataPilotTable>(xDataPilotTables->getByName(sPivotTableName), UNO_QUERY_THROW);
307 void PivotChartTest::testRoundtrip()
309 uno::Sequence<uno::Any> xSequence;
310 Reference<chart2::XChartDocument> xChartDoc;
312 std::vector<double> aReference1 { 10162.033139, 16614.523063, 27944.146101 };
314 std::vector<double> aReference2 { 101879.458079, 178636.929704, 314626.484864 };
316 loadFromFile(u"ods/PivotChartRoundTrip.ods");
318 xChartDoc = getPivotChartDocFromSheet(1);
319 CPPUNIT_ASSERT(xChartDoc.is());
321 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), getNumberOfDataSeries(xChartDoc));
323 // Check the data series
325 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 0)->getData();
326 lclCheckSequence(aReference1, xSequence, 1E-4);
327 Reference<chart2::data::XDataSequence> xLabelDataSequence = getLabelDataSequenceFromDoc(xChartDoc, 0);
328 CPPUNIT_ASSERT_EQUAL(u"Exp."_ustr, xLabelDataSequence->getData()[0].get<OUString>());
331 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 1)->getData();
332 lclCheckSequence(aReference2, xSequence, 1E-4);
333 Reference<chart2::data::XDataSequence> xLabelDataSequence = getLabelDataSequenceFromDoc(xChartDoc, 1);
334 CPPUNIT_ASSERT_EQUAL(u"Rev."_ustr, xLabelDataSequence->getData()[0].get<OUString>());
337 // Modify the pivot table
339 uno::Reference<sheet::XDataPilotTable> xDataPilotTable = getPivotTableByName(1, u"DataPilot1"_ustr );
340 uno::Reference<sheet::XDataPilotDescriptor> xDataPilotDescriptor(xDataPilotTable, UNO_QUERY_THROW);
341 lclModifyOrientation(xDataPilotDescriptor, u"Exp.", sheet::DataPilotFieldOrientation_HIDDEN);
344 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getNumberOfDataSeries(xChartDoc));
346 // Check again the data series
348 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 0)->getData();
349 lclCheckSequence(aReference2, xSequence, 1E-4);
350 Reference<chart2::data::XDataSequence> xLabelDataSequence = getLabelDataSequenceFromDoc(xChartDoc, 0);
351 CPPUNIT_ASSERT_EQUAL(u"Total"_ustr, xLabelDataSequence->getData()[0].get<OUString>());
354 saveAndReload(u"calc8"_ustr);
356 xChartDoc = getPivotChartDocFromSheet(1 );
357 CPPUNIT_ASSERT(xChartDoc.is());
359 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getNumberOfDataSeries(xChartDoc));
361 // Check again the data series
363 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 0)->getData();
364 lclCheckSequence(aReference2, xSequence, 1E-4);
365 Reference<chart2::data::XDataSequence> xLabelDataSequence = getLabelDataSequenceFromDoc(xChartDoc, 0);
366 CPPUNIT_ASSERT_EQUAL(u"Total"_ustr, xLabelDataSequence->getData()[0].get<OUString>());
370 void PivotChartTest::testChangePivotTable()
372 uno::Sequence<uno::Any> xSequence;
373 Reference<chart2::XChartDocument> xChartDoc;
375 loadFromFile(u"ods/PivotTableExample.ods");
377 // Check we have the Pivot Table
378 OUString sPivotTableName(u"DataPilot1"_ustr);
379 uno::Reference<sheet::XDataPilotTable> xDataPilotTable = getPivotTableByName(1, sPivotTableName );
380 CPPUNIT_ASSERT(xDataPilotTable.is());
382 // Check that we don't have any pivot chart in the document
383 uno::Reference<table::XTablePivotCharts> xTablePivotCharts = getTablePivotChartsFromSheet(1 );
384 uno::Reference<container::XIndexAccess> xIndexAccess(xTablePivotCharts, UNO_QUERY_THROW);
385 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount());
387 // Create a new pivot chart
388 xTablePivotCharts->addNewByName(u"Chart"_ustr, awt::Rectangle{0, 0, 9000, 9000}, sPivotTableName);
389 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
391 // Get the pivot chart document so we can access its data
392 xChartDoc.set(getPivotChartDocFromSheet(xTablePivotCharts, 0));
394 CPPUNIT_ASSERT(xChartDoc.is());
396 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), getNumberOfDataSeries(xChartDoc));
398 // Check first data series
400 std::vector<double> aReference { 10162.033139, 16614.523063, 27944.146101 };
402 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 0)->getData();
403 lclCheckSequence(aReference, xSequence, 1E-4);
405 Reference<chart2::data::XDataSequence> xLabelDataSequence = getLabelDataSequenceFromDoc(xChartDoc, 0);
406 CPPUNIT_ASSERT_EQUAL(u"Exp."_ustr, xLabelDataSequence->getData()[0].get<OUString>());
409 // Check second data series
411 std::vector<double> aReference { 101879.458079, 178636.929704, 314626.484864 };
413 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 1)->getData();
414 lclCheckSequence(aReference, xSequence, 1E-4);
416 Reference<chart2::data::XDataSequence> xLabelDataSequence = getLabelDataSequenceFromDoc(xChartDoc, 1);
417 CPPUNIT_ASSERT_EQUAL(u"Rev."_ustr, xLabelDataSequence->getData()[0].get<OUString>());
420 // Modify the pivot table, move "Group Segment" to Column fields,
421 // add "Service Month" to Row fields, remove "Rev." Data field
423 uno::Reference<sheet::XDataPilotDescriptor> xDataPilotDescriptor(xDataPilotTable, UNO_QUERY_THROW);
425 lclModifyOrientation(xDataPilotDescriptor, u"Service Month", sheet::DataPilotFieldOrientation_ROW);
426 lclModifyOrientation(xDataPilotDescriptor, u"Group Segment", sheet::DataPilotFieldOrientation_COLUMN);
427 lclModifyOrientation(xDataPilotDescriptor, u"Rev.", sheet::DataPilotFieldOrientation_HIDDEN);
430 // Check the pivot chart again as we expect it has been updated when we updated the pivot table
432 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), getNumberOfDataSeries(xChartDoc));
434 // Check the first data series
436 std::vector<double> aReference { 2855.559, 1780.326, 2208.713, 2130.064, 1187.371 };
438 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 0)->getData();
439 lclCheckSequence(aReference, xSequence, 1E-3);
441 Reference<chart2::data::XDataSequence> xLabelDataSequence = getLabelDataSequenceFromDoc(xChartDoc, 0);
442 CPPUNIT_ASSERT_EQUAL(u"Big"_ustr, xLabelDataSequence->getData()[0].get<OUString>());
445 // Check the second data series
447 std::vector<double> aReference { 4098.908, 2527.286, 4299.716, 2362.225, 3326.389 };
449 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 1)->getData();
450 lclCheckSequence(aReference, xSequence, 1E-3);
452 Reference<chart2::data::XDataSequence> xLabelDataSequence = getLabelDataSequenceFromDoc(xChartDoc, 1);
453 CPPUNIT_ASSERT_EQUAL(u"Medium"_ustr, xLabelDataSequence->getData()[0].get<OUString>());
456 // Check the third data series
458 std::vector<double> aReference { 4926.303, 5684.060, 4201.398, 7290.795, 5841.591 };
460 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 2)->getData();
461 lclCheckSequence(aReference, xSequence, 1E-3);
463 Reference<chart2::data::XDataSequence> xLabelDataSequence = getLabelDataSequenceFromDoc(xChartDoc, 2);
464 CPPUNIT_ASSERT_EQUAL(u"Small"_ustr, xLabelDataSequence->getData()[0].get<OUString>());
467 // Remove "Service Month" so row fields are empty - check we handle empty rows
469 uno::Reference<sheet::XDataPilotDescriptor> xDataPilotDescriptor(xDataPilotTable, uno::UNO_QUERY_THROW);
470 lclModifyOrientation(xDataPilotDescriptor, u"Service Month", sheet::DataPilotFieldOrientation_HIDDEN);
473 // Check the pivot chart again as we expect it has been updated when we updated the pivot table
475 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), getNumberOfDataSeries(xChartDoc));
477 // Check the first data series
479 std::vector<double> aReference { 10162.033139 };
480 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 0)->getData();
481 lclCheckSequence(aReference, xSequence, 1E-3);
482 Reference<chart2::data::XDataSequence> xLabelDataSequence = getLabelDataSequenceFromDoc(xChartDoc, 0);
483 CPPUNIT_ASSERT_EQUAL(u"Big"_ustr, xLabelDataSequence->getData()[0].get<OUString>());
485 // Check the second data series
487 std::vector<double> aReference { 16614.523063 };
488 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 1)->getData();
489 lclCheckSequence(aReference, xSequence, 1E-3);
490 Reference<chart2::data::XDataSequence> xLabelDataSequence = getLabelDataSequenceFromDoc(xChartDoc, 1);
491 CPPUNIT_ASSERT_EQUAL(u"Medium"_ustr, xLabelDataSequence->getData()[0].get<OUString>());
493 // Check the third data series
495 std::vector<double> aReference { 27944.146101 };
496 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 2)->getData();
497 lclCheckSequence(aReference, xSequence, 1E-3);
498 Reference<chart2::data::XDataSequence> xLabelDataSequence = getLabelDataSequenceFromDoc(xChartDoc, 2);
499 CPPUNIT_ASSERT_EQUAL(u"Small"_ustr, xLabelDataSequence->getData()[0].get<OUString>());
502 // Enable column totals and check the data is still unchanged
504 uno::Reference<beans::XPropertySet> xProperties(xDataPilotTable, uno::UNO_QUERY_THROW);
505 xProperties->setPropertyValue(u"ColumnGrand"_ustr, uno::Any(true));
508 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), getNumberOfDataSeries(xChartDoc));
510 // Check the first data series
512 std::vector<double> aReference { 10162.033139 };
513 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 0)->getData();
514 lclCheckSequence(aReference, xSequence, 1E-3);
515 Reference<chart2::data::XDataSequence> xLabelDataSequence = getLabelDataSequenceFromDoc(xChartDoc, 0);
516 CPPUNIT_ASSERT_EQUAL(u"Big"_ustr, xLabelDataSequence->getData()[0].get<OUString>());
518 // Check the second data series
520 std::vector<double> aReference { 16614.523063 };
521 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 1)->getData();
522 lclCheckSequence(aReference, xSequence, 1E-3);
523 Reference<chart2::data::XDataSequence> xLabelDataSequence = getLabelDataSequenceFromDoc(xChartDoc, 1);
524 CPPUNIT_ASSERT_EQUAL(u"Medium"_ustr, xLabelDataSequence->getData()[0].get<OUString>());
526 // Check the third data series
528 std::vector<double> aReference { 27944.146101 };
529 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 2)->getData();
530 lclCheckSequence(aReference, xSequence, 1E-3);
531 Reference<chart2::data::XDataSequence> xLabelDataSequence = getLabelDataSequenceFromDoc(xChartDoc, 2);
532 CPPUNIT_ASSERT_EQUAL(u"Small"_ustr, xLabelDataSequence->getData()[0].get<OUString>());
536 void PivotChartTest::testPivotChartWithOneColumnField()
538 // We put one field as COLUMN field only and one DATA field. We expect we will get as many data series
539 // in the pivot table as many distinct column values we have (with this example data 3: DE, EN, FR).
541 // SETUP DATA and PIVOT TABLE
543 loadFromURL(u"private:factory/scalc"_ustr);
545 uno::Reference<sheet::XSpreadsheetDocument> xSheetDoc(mxComponent, uno::UNO_QUERY_THROW);
547 OUString sPivotTableName(u"DataPilotTable"_ustr);
549 table::CellRangeAddress sCellRangeAddress = lclCreateTestData(xSheetDoc);
551 uno::Reference<sheet::XDataPilotTables> xDataPilotTables = lclGetDataPilotTables(0, xSheetDoc);
553 uno::Reference<sheet::XDataPilotDescriptor> xDataPilotDescriptor = xDataPilotTables->createDataPilotDescriptor();
554 xDataPilotDescriptor->setSourceRange(sCellRangeAddress);
556 lclModifyOrientation(xDataPilotDescriptor, u"Country", sheet::DataPilotFieldOrientation_COLUMN);
557 lclModifyOrientation(xDataPilotDescriptor, u"Sales T1", sheet::DataPilotFieldOrientation_DATA);
558 lclModifyFunction(xDataPilotDescriptor, u"Sales T1", sheet::GeneralFunction_SUM);
560 xDataPilotTables->insertNewByName(sPivotTableName, table::CellAddress{1, 0, 0}, xDataPilotDescriptor);
562 // TEST
564 uno::Sequence<uno::Any> xSequence;
565 Reference<chart2::XChartDocument> xChartDoc;
567 // Check we have the Pivot Table
569 uno::Reference<sheet::XDataPilotTable> xDataPilotTable = getPivotTableByName(1, sPivotTableName );
570 CPPUNIT_ASSERT(xDataPilotTable.is());
572 // Check that we don't have any pivot chart in the document
573 uno::Reference<table::XTablePivotCharts> xTablePivotCharts = getTablePivotChartsFromSheet(1 );
574 uno::Reference<container::XIndexAccess> xIndexAccess(xTablePivotCharts, UNO_QUERY_THROW);
575 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount());
577 // Create a new pivot chart
578 xTablePivotCharts->addNewByName(u"PivotChart"_ustr, awt::Rectangle{ 9000, 9000, 21000, 18000 }, sPivotTableName);
579 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
581 // Get the pivot chart document so we can access its data
582 xChartDoc.set(getPivotChartDocFromSheet(xTablePivotCharts, 0));
584 CPPUNIT_ASSERT(xChartDoc.is());
586 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), getNumberOfDataSeries(xChartDoc));
587 // Check data series 1
589 std::vector<double> aReference { 1738.0 };
591 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 0)->getData();
592 lclCheckSequence(aReference, xSequence, 1E-4);
594 Reference<chart2::data::XDataSequence> xLabelDataSequence = getLabelDataSequenceFromDoc(xChartDoc, 0);
595 CPPUNIT_ASSERT_EQUAL(u"DE"_ustr, xLabelDataSequence->getData()[0].get<OUString>());
598 // Check data series 2
600 std::vector<double> aReference { 2003.0 };
602 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 1)->getData();
603 lclCheckSequence(aReference, xSequence, 1E-4);
605 Reference<chart2::data::XDataSequence> xLabelDataSequence = getLabelDataSequenceFromDoc(xChartDoc, 1);
606 CPPUNIT_ASSERT_EQUAL(u"EN"_ustr, xLabelDataSequence->getData()[0].get<OUString>());
608 // Check data series 3
610 std::vector<double> aReference { 1936.0 };
612 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 2)->getData();
613 lclCheckSequence(aReference, xSequence, 1E-4);
615 Reference<chart2::data::XDataSequence> xLabelDataSequence = getLabelDataSequenceFromDoc(xChartDoc, 2);
616 CPPUNIT_ASSERT_EQUAL(u"FR"_ustr, xLabelDataSequence->getData()[0].get<OUString>());
620 void PivotChartTest::testPivotChartWithOneRowField()
622 // We put one field as ROW field only and one DATA field. We expect we will get one data series
623 // in the pivot table.
625 // SETUP DATA and PIVOT TABLE
627 loadFromURL(u"private:factory/scalc"_ustr);
629 uno::Reference<sheet::XSpreadsheetDocument> xSheetDoc(mxComponent, uno::UNO_QUERY_THROW);
631 OUString sPivotTableName(u"DataPilotTable"_ustr);
633 table::CellRangeAddress sCellRangeAddress = lclCreateTestData(xSheetDoc);
635 uno::Reference<sheet::XDataPilotTables> xDataPilotTables = lclGetDataPilotTables(0, xSheetDoc);
637 uno::Reference<sheet::XDataPilotDescriptor> xDataPilotDescriptor = xDataPilotTables->createDataPilotDescriptor();
638 xDataPilotDescriptor->setSourceRange(sCellRangeAddress);
640 lclModifyOrientation(xDataPilotDescriptor, u"Country", sheet::DataPilotFieldOrientation_ROW);
641 lclModifyOrientation(xDataPilotDescriptor, u"Sales T1", sheet::DataPilotFieldOrientation_DATA);
642 lclModifyFunction(xDataPilotDescriptor, u"Sales T1", sheet::GeneralFunction_SUM);
644 xDataPilotTables->insertNewByName(sPivotTableName, table::CellAddress{1, 0, 0}, xDataPilotDescriptor);
646 // TEST
648 uno::Sequence<uno::Any> xSequence;
649 Reference<chart2::XChartDocument> xChartDoc;
651 // Check we have the Pivot Table
653 uno::Reference<sheet::XDataPilotTable> xDataPilotTable = getPivotTableByName(1, sPivotTableName );
654 CPPUNIT_ASSERT(xDataPilotTable.is());
656 // Check that we don't have any pivot chart in the document
657 uno::Reference<table::XTablePivotCharts> xTablePivotCharts = getTablePivotChartsFromSheet(1 );
658 uno::Reference<container::XIndexAccess> xIndexAccess(xTablePivotCharts, UNO_QUERY_THROW);
659 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount());
661 // Create a new pivot chart
662 xTablePivotCharts->addNewByName(u"PivotChart"_ustr, awt::Rectangle{ 9000, 9000, 21000, 18000 }, sPivotTableName);
663 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
665 // Get the pivot chart document so we can access its data
666 xChartDoc.set(getPivotChartDocFromSheet(xTablePivotCharts, 0));
668 CPPUNIT_ASSERT(xChartDoc.is());
670 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getNumberOfDataSeries(xChartDoc));
671 // Check data series 1
673 std::vector<double> aReference { 1738.0, 2003.0, 1936.0 };
675 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 0)->getData();
676 lclCheckSequence(aReference, xSequence, 1E-4);
678 Reference<chart2::data::XDataSequence> xLabelDataSequence = getLabelDataSequenceFromDoc(xChartDoc, 0);
679 CPPUNIT_ASSERT_EQUAL(u"Total"_ustr, xLabelDataSequence->getData()[0].get<OUString>());
683 void PivotChartTest::testPivotTableDataProvider_PivotTableFields()
685 // SETUP DATA and PIVOT TABLE
687 loadFromURL(u"private:factory/scalc"_ustr);
689 uno::Reference<sheet::XSpreadsheetDocument> xSheetDoc(mxComponent, uno::UNO_QUERY_THROW);
691 OUString sPivotTableName(u"DataPilotTable"_ustr);
693 table::CellRangeAddress sCellRangeAddress = lclCreateTestData(xSheetDoc);
695 uno::Reference<sheet::XDataPilotTables> xDataPilotTables = lclGetDataPilotTables(0, xSheetDoc);
697 uno::Reference<sheet::XDataPilotDescriptor> xDataPilotDescriptor = xDataPilotTables->createDataPilotDescriptor();
698 xDataPilotDescriptor->setSourceRange(sCellRangeAddress);
700 lclModifyOrientation(xDataPilotDescriptor, u"City", sheet::DataPilotFieldOrientation_ROW);
701 lclModifyOrientation(xDataPilotDescriptor, u"Country", sheet::DataPilotFieldOrientation_COLUMN);
702 lclModifyOrientation(xDataPilotDescriptor, u"Type", sheet::DataPilotFieldOrientation_COLUMN);
703 lclModifyOrientation(xDataPilotDescriptor, u"Sales T1", sheet::DataPilotFieldOrientation_DATA);
704 lclModifyFunction(xDataPilotDescriptor, u"Sales T1", sheet::GeneralFunction_SUM);
705 lclModifyOrientation(xDataPilotDescriptor, u"Sales T2", sheet::DataPilotFieldOrientation_DATA);
706 lclModifyFunction(xDataPilotDescriptor, u"Sales T2", sheet::GeneralFunction_SUM);
708 lclModifyColumnGrandTotal(xDataPilotDescriptor, true);
709 lclModifyRowGrandTotal(xDataPilotDescriptor, true);
711 xDataPilotTables->insertNewByName(sPivotTableName, table::CellAddress{1, 0, 0}, xDataPilotDescriptor);
713 // TEST
714 Reference<chart2::XChartDocument> xChartDoc;
716 // Check we have the Pivot Table
717 uno::Reference<sheet::XDataPilotTable> xDataPilotTable = getPivotTableByName(1, sPivotTableName );
718 CPPUNIT_ASSERT(xDataPilotTable.is());
720 // refetch the XDataPilotDescriptor
721 xDataPilotDescriptor.set(xDataPilotTable, uno::UNO_QUERY_THROW);
723 // Check that we don't have any pivot chart in the document
724 uno::Reference<table::XTablePivotCharts> xTablePivotCharts = getTablePivotChartsFromSheet(1 );
725 uno::Reference<container::XIndexAccess> xIndexAccess(xTablePivotCharts, UNO_QUERY_THROW);
726 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount());
728 // Create a new pivot chart
729 xTablePivotCharts->addNewByName(u"PivotChart"_ustr, awt::Rectangle{ 9000, 9000, 21000, 18000 }, sPivotTableName);
730 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
732 // Get the pivot chart document so we can access its data
733 xChartDoc.set(getPivotChartDocFromSheet(xTablePivotCharts, 0));
735 CPPUNIT_ASSERT(xChartDoc.is());
737 uno::Reference<chart2::data::XPivotTableDataProvider> xPivotTableDataProvider(xChartDoc->getDataProvider(), UNO_QUERY_THROW);
738 uno::Sequence<chart2::data::PivotTableFieldEntry> aFieldEntries;
740 aFieldEntries = xPivotTableDataProvider->getColumnFields();
742 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aFieldEntries.getLength());
743 CPPUNIT_ASSERT_EQUAL(u"Country"_ustr, aFieldEntries[0].Name);
744 CPPUNIT_ASSERT_EQUAL(u"Type"_ustr, aFieldEntries[1].Name);
746 aFieldEntries = xPivotTableDataProvider->getRowFields();
748 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aFieldEntries.getLength());
749 CPPUNIT_ASSERT_EQUAL(u"City"_ustr, aFieldEntries[0].Name);
750 CPPUNIT_ASSERT_EQUAL(u"Data"_ustr, aFieldEntries[1].Name);
752 aFieldEntries = xPivotTableDataProvider->getDataFields();
754 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aFieldEntries.getLength());
755 CPPUNIT_ASSERT_EQUAL(u"Sum - Sales T1"_ustr, aFieldEntries[0].Name);
756 CPPUNIT_ASSERT_EQUAL(u"Sum - Sales T2"_ustr, aFieldEntries[1].Name);
758 // Data to column fields
759 lclModifyOrientation(xDataPilotDescriptor, u"Data", sheet::DataPilotFieldOrientation_COLUMN);
761 // Change the order of column fields: expected data, type, country
762 lclModifyOrientation(xDataPilotDescriptor, u"Country", sheet::DataPilotFieldOrientation_HIDDEN);
763 lclModifyOrientation(xDataPilotDescriptor, u"Type", sheet::DataPilotFieldOrientation_HIDDEN);
765 lclModifyOrientation(xDataPilotDescriptor, u"Type", sheet::DataPilotFieldOrientation_COLUMN);
766 lclModifyOrientation(xDataPilotDescriptor, u"Country", sheet::DataPilotFieldOrientation_COLUMN);
768 // set the XPivotTableDataProvider again as the old one was exchanged
769 xPivotTableDataProvider.set(xChartDoc->getDataProvider(), uno::UNO_QUERY_THROW);
771 aFieldEntries = xPivotTableDataProvider->getColumnFields();
773 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aFieldEntries.getLength());
774 CPPUNIT_ASSERT_EQUAL(u"Data"_ustr, aFieldEntries[0].Name);
775 CPPUNIT_ASSERT_EQUAL(u"Type"_ustr, aFieldEntries[1].Name);
776 CPPUNIT_ASSERT_EQUAL(u"Country"_ustr, aFieldEntries[2].Name);
778 aFieldEntries = xPivotTableDataProvider->getRowFields();
780 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aFieldEntries.getLength());
781 CPPUNIT_ASSERT_EQUAL(u"City"_ustr, aFieldEntries[0].Name);
783 aFieldEntries = xPivotTableDataProvider->getDataFields();
785 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aFieldEntries.getLength());
786 CPPUNIT_ASSERT_EQUAL(u"Sum - Sales T1"_ustr, aFieldEntries[0].Name);
787 CPPUNIT_ASSERT_EQUAL(u"Sum - Sales T2"_ustr, aFieldEntries[1].Name);
790 void PivotChartTest::testPivotChartRowFieldInOutlineMode()
792 // SETUP DATA and PIVOT TABLE
794 loadFromURL(u"private:factory/scalc"_ustr);
796 uno::Reference<sheet::XSpreadsheetDocument> xSheetDoc(mxComponent, uno::UNO_QUERY_THROW);
798 OUString sPivotTableName(u"DataPilotTable"_ustr);
800 table::CellRangeAddress sCellRangeAddress = lclCreateTestData(xSheetDoc);
802 uno::Reference<sheet::XDataPilotTables> xDataPilotTables = lclGetDataPilotTables(0, xSheetDoc);
804 uno::Reference<sheet::XDataPilotDescriptor> xDataPilotDescriptor = xDataPilotTables->createDataPilotDescriptor();
805 xDataPilotDescriptor->setSourceRange(sCellRangeAddress);
807 lclModifyOrientation(xDataPilotDescriptor, u"Country", sheet::DataPilotFieldOrientation_ROW);
808 lclModifyOrientation(xDataPilotDescriptor, u"City", sheet::DataPilotFieldOrientation_ROW);
809 lclModifyOrientation(xDataPilotDescriptor, u"Sales T1", sheet::DataPilotFieldOrientation_DATA);
810 lclModifyFunction(xDataPilotDescriptor, u"Sales T1", sheet::GeneralFunction_SUM);
811 xDataPilotTables->insertNewByName(sPivotTableName, table::CellAddress{1, 0, 0}, xDataPilotDescriptor);
813 // TEST
814 uno::Sequence<uno::Any> xSequence;
815 Reference<chart2::XChartDocument> xChartDoc;
817 // Check we have the Pivot Table
818 uno::Reference<sheet::XDataPilotTable> xDataPilotTable = getPivotTableByName(1, sPivotTableName );
819 CPPUNIT_ASSERT(xDataPilotTable.is());
821 // refetch the XDataPilotDescriptor
822 xDataPilotDescriptor.set(xDataPilotTable, uno::UNO_QUERY_THROW);
824 // Check that we don't have any pivot chart in the document
825 uno::Reference<table::XTablePivotCharts> xTablePivotCharts = getTablePivotChartsFromSheet(1 );
826 uno::Reference<container::XIndexAccess> xIndexAccess(xTablePivotCharts, UNO_QUERY_THROW);
827 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount());
829 // Create a new pivot chart
830 xTablePivotCharts->addNewByName(u"PivotChart"_ustr, awt::Rectangle{ 9000, 9000, 21000, 18000 }, sPivotTableName);
831 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
833 // Get the pivot chart document so we can access its data
834 xChartDoc.set(getPivotChartDocFromSheet(xTablePivotCharts, 0));
836 CPPUNIT_ASSERT(xChartDoc.is());
838 // Test case with defaults
840 // Check when using defaults the data is as expected
841 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getNumberOfDataSeries(xChartDoc));
843 std::vector<double> aReference { 1116.0, 622.0, 298.0, 562.0, 1143.0, 1168.0, 768.0 };
845 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 0)->getData();
846 lclCheckSequence(aReference, xSequence, 1E-4);
848 Reference<chart2::data::XDataSequence> xLabelDataSequence = getLabelDataSequenceFromDoc(xChartDoc, 0);
849 CPPUNIT_ASSERT_EQUAL(u"Total"_ustr, xLabelDataSequence->getData()[0].get<OUString>());
851 // Check the categories
853 lclCheckCategories({ u"DE"_ustr, u""_ustr, u"EN"_ustr, u""_ustr, u""_ustr, u"FR"_ustr, u""_ustr},
854 lclGetCategories(xChartDoc)[0]->getValues());
855 lclCheckCategories({ u"Berlin"_ustr, u"Munich"_ustr, u"Glasgow"_ustr, u"Liverpool"_ustr, u"London"_ustr, u"Nantes"_ustr, u"Paris"_ustr},
856 lclGetCategories(xChartDoc)[1]->getValues());
859 sheet::DataPilotFieldLayoutInfo aLayoutInfoValue;
861 // Test case where we enable subtotals (auto) and set the outline subtotals at the bottom
862 // We don't expect any change in data as every extra subtotal row should be ignored
864 // Enable subtotals - set to auto
865 uno::Sequence<sheet::GeneralFunction> aGeneralFunctionSequence{ sheet::GeneralFunction_AUTO };
866 lclModifySubtotals(xDataPilotDescriptor, u"Country", aGeneralFunctionSequence);
867 // Set Subtotals layout to bottom + add empty lines
868 aLayoutInfoValue.AddEmptyLines = true;
869 aLayoutInfoValue.LayoutMode = sheet::DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_BOTTOM;
870 lclModifyLayoutInfo(xDataPilotDescriptor, u"Country", aLayoutInfoValue);
872 // Check data is unchanged
873 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getNumberOfDataSeries(xChartDoc));
875 std::vector<double> aReference { 1116.0, 622.0, 298.0, 562.0, 1143.0, 1168.0, 768.0 };
877 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 0)->getData();
878 lclCheckSequence(aReference, xSequence, 1E-4);
880 Reference<chart2::data::XDataSequence> xLabelDataSequence = getLabelDataSequenceFromDoc(xChartDoc, 0);
881 CPPUNIT_ASSERT_EQUAL(u"Total"_ustr, xLabelDataSequence->getData()[0].get<OUString>());
883 // Check categories
885 lclCheckCategories({ u"DE"_ustr, u""_ustr, u"EN"_ustr, u""_ustr, u""_ustr, u"FR"_ustr, u""_ustr},
886 lclGetCategories(xChartDoc)[0]->getValues());
887 lclCheckCategories({ u"Berlin"_ustr, u"Munich"_ustr, u"Glasgow"_ustr, u"Liverpool"_ustr, u"London"_ustr, u"Nantes"_ustr, u"Paris"_ustr},
888 lclGetCategories(xChartDoc)[1]->getValues());
891 // Test case where we enable subtotals (auto) and set the outline subtotals at the top
892 // We don't expect any change in data as every extra subtotal row should be ignored
894 // Enable subtotals - set to auto
895 aGeneralFunctionSequence.getArray()[0] = sheet::GeneralFunction_AUTO;
896 lclModifySubtotals(xDataPilotDescriptor, u"Country", aGeneralFunctionSequence);
897 // Set Subtotals layout to top + add empty lines
898 aLayoutInfoValue.AddEmptyLines = true;
899 aLayoutInfoValue.LayoutMode = sheet::DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_TOP;
900 lclModifyLayoutInfo(xDataPilotDescriptor, u"Country", aLayoutInfoValue);
902 // Check data is unchanged
903 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getNumberOfDataSeries(xChartDoc));
905 std::vector<double> aReference { 1116.0, 622.0, 298.0, 562.0, 1143.0, 1168.0, 768.0 };
907 xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 0)->getData();
908 lclCheckSequence(aReference, xSequence, 1E-4);
910 Reference<chart2::data::XDataSequence> xLabelDataSequence = getLabelDataSequenceFromDoc(xChartDoc, 0);
911 CPPUNIT_ASSERT_EQUAL(u"Total"_ustr, xLabelDataSequence->getData()[0].get<OUString>());
913 // Check categories
915 lclCheckCategories({ u"DE"_ustr, u""_ustr, u"EN"_ustr, u""_ustr, u""_ustr, u"FR"_ustr, u""_ustr},
916 lclGetCategories(xChartDoc)[0]->getValues());
917 lclCheckCategories({ u"Berlin"_ustr, u"Munich"_ustr, u"Glasgow"_ustr, u"Liverpool"_ustr, u"London"_ustr, u"Nantes"_ustr, u"Paris"_ustr},
918 lclGetCategories(xChartDoc)[1]->getValues());
922 void PivotChartTest::testPivotChartWithDateRowField()
924 // SETUP DATA and PIVOT TABLE
926 loadFromURL(u"private:factory/scalc"_ustr);
928 uno::Reference<sheet::XSpreadsheetDocument> xSheetDoc(mxComponent, uno::UNO_QUERY_THROW);
930 OUString sPivotTableName(u"DataPilotTable"_ustr);
932 table::CellRangeAddress sCellRangeAddress = lclCreateTestData(xSheetDoc);
934 uno::Reference<sheet::XDataPilotTables> xDataPilotTables = lclGetDataPilotTables(0, xSheetDoc);
936 uno::Reference<sheet::XDataPilotDescriptor> xDataPilotDescriptor = xDataPilotTables->createDataPilotDescriptor();
937 xDataPilotDescriptor->setSourceRange(sCellRangeAddress);
939 lclModifyOrientation(xDataPilotDescriptor, u"Date", sheet::DataPilotFieldOrientation_ROW);
940 lclModifyOrientation(xDataPilotDescriptor, u"City", sheet::DataPilotFieldOrientation_ROW);
941 lclModifyOrientation(xDataPilotDescriptor, u"Country", sheet::DataPilotFieldOrientation_ROW);
942 lclModifyOrientation(xDataPilotDescriptor, u"Type", sheet::DataPilotFieldOrientation_COLUMN);
943 lclModifyOrientation(xDataPilotDescriptor, u"Sales T1", sheet::DataPilotFieldOrientation_DATA);
944 lclModifyFunction(xDataPilotDescriptor, u"Sales T1", sheet::GeneralFunction_SUM);
946 lclModifyColumnGrandTotal(xDataPilotDescriptor, true);
947 lclModifyRowGrandTotal(xDataPilotDescriptor, true);
949 xDataPilotTables->insertNewByName(sPivotTableName, table::CellAddress{1, 0, 0}, xDataPilotDescriptor);
951 // TEST
952 Reference<chart2::XChartDocument> xChartDoc;
954 // Check we have the Pivot Table
955 uno::Reference<sheet::XDataPilotTable> xDataPilotTable = getPivotTableByName(1, sPivotTableName );
956 CPPUNIT_ASSERT(xDataPilotTable.is());
958 // refetch the XDataPilotDescriptor
959 xDataPilotDescriptor.set(xDataPilotTable, uno::UNO_QUERY_THROW);
961 // Check that we don't have any pivot chart in the document
962 uno::Reference<table::XTablePivotCharts> xTablePivotCharts = getTablePivotChartsFromSheet(1 );
963 uno::Reference<container::XIndexAccess> xIndexAccess(xTablePivotCharts, UNO_QUERY_THROW);
964 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount());
966 // Create a new pivot chart
967 xTablePivotCharts->addNewByName(u"PivotChart"_ustr, awt::Rectangle{ 9000, 9000, 21000, 18000 }, sPivotTableName);
968 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
970 // Get the pivot chart document so we can access its data
971 xChartDoc.set(getPivotChartDocFromSheet(xTablePivotCharts, 0));
973 CPPUNIT_ASSERT(xChartDoc.is());
975 // Check if Date category is date formatted.
976 lclCheckCategories( { u"12/11/15"_ustr, u""_ustr, u""_ustr, u""_ustr, u""_ustr, u""_ustr, u"12/14/15"_ustr, u"12/17/15"_ustr, u"01/20/16"_ustr, u""_ustr, u""_ustr, u"03/21/17"_ustr },
977 lclGetCategories( xChartDoc )[0]->getValues() );
981 CPPUNIT_TEST_SUITE_REGISTRATION(PivotChartTest);
983 CPPUNIT_PLUGIN_IMPLEMENT();
985 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */