sc/qa/unit/ucalc_pivottable.cxx      |  368 ++++++++++++++++++++++++++++-------
 sc/source/filter/xml/pivotsource.cxx |   61 +----
 2 files changed, 322 insertions(+), 107 deletions(-)

New commits:
commit 4bcab70b744a6666c3b1cef36c87f030c41dfae3
Author:     Tomaž Vajngerl <[email protected]>
AuthorDate: Mon Nov 10 21:55:04 2025 +0900
Commit:     Tomaž Vajngerl <[email protected]>
CommitDate: Wed Nov 12 11:16:38 2025 +0100

    sc: change test struct to use u16string_view for dimension name
    
    Change-Id: Ia07b4d15030e2bfd1bb7fc80008d8c62d0593902
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193748
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <[email protected]>

diff --git a/sc/qa/unit/ucalc_pivottable.cxx b/sc/qa/unit/ucalc_pivottable.cxx
index 7e4d583836d0..acf538a4392e 100644
--- a/sc/qa/unit/ucalc_pivottable.cxx
+++ b/sc/qa/unit/ucalc_pivottable.cxx
@@ -34,7 +34,7 @@ namespace {
 
 struct DPFieldDef
 {
-    const char* pName;
+    std::u16string_view aName;
     sheet::DataPilotFieldOrientation eOrient;
 
     /**
@@ -78,16 +78,17 @@ ScDPObject* createDPFromSourceDesc(
     // Set the dimension information.
     for (size_t i = 0; i < nFieldCount; ++i)
     {
-        OUString aDimName = OUString::createFromAscii(aFields[i].pName);
-        ScDPSaveDimension* pDim = aSaveData.GetNewDimensionByName(aDimName);
-        pDim->SetOrientation(aFields[i].eOrient);
+        auto& rField = aFields[i];
+        OUString aName(rField.aName);
+        ScDPSaveDimension* pDim = aSaveData.GetNewDimensionByName(aName);
+        pDim->SetOrientation(rField.eOrient);
         pDim->SetUsedHierarchy(0);
 
-        if (aFields[i].eOrient == sheet::DataPilotFieldOrientation_DATA)
+        if (rField.eOrient == sheet::DataPilotFieldOrientation_DATA)
         {
             ScGeneralFunction eFunc = ScGeneralFunction::SUM;
-            if (aFields[i].eFunc != ScGeneralFunction::NONE)
-                eFunc = aFields[i].eFunc;
+            if (rField.eFunc != ScGeneralFunction::NONE)
+                eFunc = rField.eFunc;
 
             pDim->SetFunction(eFunc);
             pDim->SetReferenceValue(nullptr);
@@ -108,7 +109,7 @@ ScDPObject* createDPFromSourceDesc(
             aShowInfo.ShowItemsMode = 0;
             aShowInfo.ItemCount = 0;
             pDim->SetAutoShowInfo(&aShowInfo);
-            pDim->SetRepeatItemLabels(aFields[i].bRepeatItemLabels);
+            pDim->SetRepeatItemLabels(rField.bRepeatItemLabels);
         }
     }
 
@@ -193,7 +194,7 @@ ScRange TestPivottable::insertDPSourceData(ScDocument* 
pDoc, DPFieldDef const aF
 {
     // Insert field names in row 0.
     for (size_t i = 0; i < nFieldCount; ++i)
-        pDoc->SetString(static_cast<SCCOL>(i), 0, 0, 
OUString(aFields[i].pName, strlen(aFields[i].pName), RTL_TEXTENCODING_UTF8));
+        pDoc->SetString(static_cast<SCCOL>(i), 0, 0, 
OUString(aFields[i].aName));
 
     // Insert data into row 1 and downward.
     for (size_t i = 0; i < nDataCount; ++i)
@@ -233,9 +234,9 @@ CPPUNIT_TEST_FIXTURE(TestPivottable, testPivotTable)
 
     // Dimension definition
     static const DPFieldDef aFields[] = {
-        { "Name",  sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
-        { "Group", sheet::DataPilotFieldOrientation_COLUMN, 
ScGeneralFunction::NONE, false },
-        { "Score", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::NONE, false }
+        { u"Name",  sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
+        { u"Group", sheet::DataPilotFieldOrientation_COLUMN, 
ScGeneralFunction::NONE, false },
+        { u"Score", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::NONE, false }
     };
 
     // Raw data
@@ -421,9 +422,9 @@ CPPUNIT_TEST_FIXTURE(TestPivottable, testPivotTableLabels)
 
     // Dimension definition
     static const DPFieldDef aFields[] = {
-        { "Software", sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
-        { "Version",  sheet::DataPilotFieldOrientation_COLUMN, 
ScGeneralFunction::NONE, false },
-        { "1.2.3",    sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::NONE, false }
+        { u"Software", sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
+        { u"Version",  sheet::DataPilotFieldOrientation_COLUMN, 
ScGeneralFunction::NONE, false },
+        { u"1.2.3",    sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::NONE, false }
     };
 
     // Raw data
@@ -481,9 +482,9 @@ CPPUNIT_TEST_FIXTURE(TestPivottable, 
testPivotTableDateLabels)
 
     // Dimension definition
     static const DPFieldDef aFields[] = {
-        { "Name",  sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
-        { "Date",  sheet::DataPilotFieldOrientation_COLUMN, 
ScGeneralFunction::NONE, false },
-        { "Value", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::NONE, false }
+        { u"Name",  sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
+        { u"Date",  sheet::DataPilotFieldOrientation_COLUMN, 
ScGeneralFunction::NONE, false },
+        { u"Value", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::NONE, false }
     };
 
     // Raw data
@@ -559,11 +560,11 @@ CPPUNIT_TEST_FIXTURE(TestPivottable, 
testPivotTableFilters)
 
     // Dimension definition
     static const DPFieldDef aFields[] = {
-        { "Name",   sheet::DataPilotFieldOrientation_HIDDEN, 
ScGeneralFunction::NONE, false },
-        { "Group1", sheet::DataPilotFieldOrientation_HIDDEN, 
ScGeneralFunction::NONE, false },
-        { "Group2", sheet::DataPilotFieldOrientation_PAGE, 
ScGeneralFunction::NONE, false },
-        { "Val1",   sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::NONE, false },
-        { "Val2",   sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::NONE, false }
+        { u"Name",   sheet::DataPilotFieldOrientation_HIDDEN, 
ScGeneralFunction::NONE, false },
+        { u"Group1", sheet::DataPilotFieldOrientation_HIDDEN, 
ScGeneralFunction::NONE, false },
+        { u"Group2", sheet::DataPilotFieldOrientation_PAGE, 
ScGeneralFunction::NONE, false },
+        { u"Val1",   sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::NONE, false },
+        { u"Val2",   sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::NONE, false }
     };
 
     // Raw data
@@ -714,9 +715,9 @@ CPPUNIT_TEST_FIXTURE(TestPivottable, 
testPivotTableNamedSource)
 
     // Dimension definition
     static const DPFieldDef aFields[] = {
-        { "Name",  sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
-        { "Group", sheet::DataPilotFieldOrientation_COLUMN, 
ScGeneralFunction::NONE, false },
-        { "Score", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::NONE, false }
+        { u"Name",  sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
+        { u"Group", sheet::DataPilotFieldOrientation_COLUMN, 
ScGeneralFunction::NONE, false },
+        { u"Score", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::NONE, false }
     };
 
     // Raw data
@@ -1045,9 +1046,9 @@ CPPUNIT_TEST_FIXTURE(TestPivottable, 
testPivotTableDuplicateDataFields)
 
     // Dimension definition
     static const DPFieldDef aFields[] = {
-        { "Name",  sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
-        { "Value", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::SUM, false },
-        { "Value", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::COUNT, false }
+        { u"Name",  sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
+        { u"Value", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::SUM, false },
+        { u"Value", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::COUNT, false }
     };
 
     ScAddress aPos(2,2,0);
@@ -1137,8 +1138,8 @@ CPPUNIT_TEST_FIXTURE(TestPivottable, 
testPivotTableNormalGrouping)
 
     // Dimension definition
     static const DPFieldDef aFields[] = {
-        { "Name",  sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
-        { "Value", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::SUM, false },
+        { u"Name",  sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
+        { u"Value", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::SUM, false },
     };
 
     ScAddress aPos(1,1,0);
@@ -1297,8 +1298,8 @@ CPPUNIT_TEST_FIXTURE(TestPivottable, 
testPivotTableNumberGrouping)
 
     // Dimension definition
     static const DPFieldDef aFields[] = {
-        { "Order", sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
-        { "Score", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::SUM, false },
+        { u"Order", sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
+        { u"Score", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::SUM, false },
     };
 
     ScAddress aPos(1,1,0);
@@ -1380,8 +1381,8 @@ CPPUNIT_TEST_FIXTURE(TestPivottable, 
testPivotTableDateGrouping)
 
     // Dimension definition
     static const DPFieldDef aFields[] = {
-        { "Date", sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
-        { "Value", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::SUM, false },
+        { u"Date", sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
+        { u"Value", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::SUM, false },
     };
 
     ScAddress aPos(1,1,0);
@@ -1548,8 +1549,8 @@ CPPUNIT_TEST_FIXTURE(TestPivottable, 
testPivotTableEmptyRows)
 
     // Dimension definition
     static const DPFieldDef aFields[] = {
-        { "Name", sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
-        { "Value", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::SUM, false },
+        { u"Name", sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
+        { u"Value", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::SUM, false },
     };
 
     ScAddress aPos(1,1,0);
@@ -1661,8 +1662,8 @@ CPPUNIT_TEST_FIXTURE(TestPivottable, 
testPivotTableTextNumber)
 
     // Dimension definition
     static const DPFieldDef aFields[] = {
-        { "Name", sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
-        { "Value", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::SUM, false },
+        { u"Name", sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
+        { u"Value", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::SUM, false },
     };
 
     // Insert raw data such that the first column values are entered as text.
@@ -1764,8 +1765,8 @@ CPPUNIT_TEST_FIXTURE(TestPivottable, 
testPivotTableCaseInsensitiveStrings)
 
     // Dimension definition
     static const DPFieldDef aFields[] = {
-        { "Name", sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
-        { "Value", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::SUM, false },
+        { u"Name", sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
+        { u"Value", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::SUM, false },
     };
 
     ScAddress aPos(1,1,0);
@@ -1842,8 +1843,8 @@ CPPUNIT_TEST_FIXTURE(TestPivottable, 
testPivotTableNumStability)
 
     // Dimension definition
     static const DPFieldDef aFields[] = {
-        { "Name",  sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
-        { "Total", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::SUM, false },
+        { u"Name",  sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
+        { u"Total", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::SUM, false },
     };
 
     m_pDoc->InsertTab(0, u"Data"_ustr);
@@ -1930,8 +1931,8 @@ CPPUNIT_TEST_FIXTURE(TestPivottable, 
testPivotTableFieldReference)
 
     // Dimension definition
     static const DPFieldDef aFields[] = {
-        { "Name", sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
-        { "Value", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::SUM, false },
+        { u"Name", sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
+        { u"Value", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::SUM, false },
     };
 
     ScAddress aPos(1,1,0);
@@ -2101,8 +2102,8 @@ CPPUNIT_TEST_FIXTURE(TestPivottable, 
testPivotTableDocFunc)
 
     // Dimension definition
     static const DPFieldDef aFields[] = {
-        { "Name", sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
-        { "Value", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::SUM, false },
+        { u"Name", sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
+        { u"Value", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::SUM, false },
     };
 
     ScAddress aPos(1,1,0);
@@ -2202,8 +2203,8 @@ CPPUNIT_TEST_FIXTURE(TestPivottable, testFuncGETPIVOTDATA)
     {
         // Dimension definition
         static const DPFieldDef aFields[] = {
-            { "Name", sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
-            { "Value", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::SUM, false },
+            { u"Name", sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
+            { u"Value", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::SUM, false },
         };
 
         pDPObj = createDPFromRange(m_pDoc, aDataRange, aFields, 
SAL_N_ELEMENTS(aFields), false);
@@ -2261,9 +2262,9 @@ CPPUNIT_TEST_FIXTURE(TestPivottable, testFuncGETPIVOTDATA)
     {
         // Dimension definition
         static const DPFieldDef aFields[] = {
-            { "Name", sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
-            { "Value", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::SUM, false },
-            { "Value", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::COUNT, false },
+            { u"Name", sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
+            { u"Value", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::SUM, false },
+            { u"Value", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::COUNT, false },
         };
 
         pDPObj = createDPFromRange(m_pDoc, aDataRange, aFields, 
SAL_N_ELEMENTS(aFields), false);
@@ -2355,9 +2356,9 @@ CPPUNIT_TEST_FIXTURE(TestPivottable, 
testFuncGETPIVOTDATALeafAccess)
 
     // Dimension definition
     static const DPFieldDef aFields[] = {
-        { "Type", sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
-        { "Member", sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
-        { "Value", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::SUM, false },
+        { u"Type", sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
+        { u"Member", sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
+        { u"Value", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::SUM, false },
     };
 
     // Create pivot table at A1 on 2nd sheet.
@@ -2433,10 +2434,10 @@ CPPUNIT_TEST_FIXTURE(TestPivottable, 
testPivotTableRepeatItemLabels)
 
     // Dimension definition
     static const DPFieldDef aFields[] = {
-        { "Name",  sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, true },
-        { "Country", sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
-        { "Year", sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
-        { "Score", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::NONE, false }
+        { u"Name",  sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, true },
+        { u"Country", sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
+        { u"Year", sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
+        { u"Score", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::NONE, false }
     };
 
     // Raw data
@@ -2513,9 +2514,9 @@ CPPUNIT_TEST_FIXTURE(TestPivottable, 
testPivotTableDPCollection)
 
     // Dimension definition
     static const DPFieldDef aFields[] = {
-        { "Software", sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
-        { "Version",  sheet::DataPilotFieldOrientation_COLUMN, 
ScGeneralFunction::NONE, false },
-        { "1.2.3",    sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::NONE, false }
+        { u"Software", sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
+        { u"Version",  sheet::DataPilotFieldOrientation_COLUMN, 
ScGeneralFunction::NONE, false },
+        { u"1.2.3",    sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::NONE, false }
     };
 
     // Raw data
@@ -2625,10 +2626,10 @@ CPPUNIT_TEST_FIXTURE(TestPivottable, 
testPivotTableMedianFunc)
 
     // Dimension definition
     static const DPFieldDef aFields[] = {
-        { "Condition", sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
-        { "Day1Hit", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::MEDIAN, false },
-        { "Day1Miss", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::MEDIAN, false },
-        { "Day1FalseAlarm", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::MEDIAN, false },
+        { u"Condition", sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
+        { u"Day1Hit", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::MEDIAN, false },
+        { u"Day1Miss", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::MEDIAN, false },
+        { u"Day1FalseAlarm", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::MEDIAN, false },
     };
 
     ScAddress aPos(1, 1, 0);
@@ -2701,8 +2702,8 @@ CPPUNIT_TEST_FIXTURE(TestPivottable, 
testPivotTableUndoCreate)
     {
         // Dimension definition
         static constexpr auto aFields = std::to_array<DPFieldDef>({
-            { "Name", sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
-            { "Value", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::COUNT, false },
+            { u"Name", sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
+            { u"Value", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::COUNT, false },
         });
 
         std::unique_ptr<ScDPObject> pDPObject(createDPFromRange(m_pDoc, 
aDataRange, aFields.data(), aFields.size(), false));
@@ -2788,8 +2789,8 @@ CPPUNIT_TEST_FIXTURE(TestPivottable, 
testPivotTableFilterValueUndoRedo)
     {
         // Dimension definition
         static constexpr auto aFields = std::to_array<DPFieldDef>({
-            { "Name", sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
-            { "Value", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::COUNT, false },
+            { u"Name", sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
+            { u"Value", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::COUNT, false },
         });
 
         std::unique_ptr<ScDPObject> pDPObject(createDPFromRange(m_pDoc, 
aDataRange, aFields.data(), aFields.size(), false));
commit 0343c36b4683df0960503f34d715d8f82bcab876
Author:     Tomaž Vajngerl <[email protected]>
AuthorDate: Fri Nov 7 18:39:42 2025 +0900
Commit:     Tomaž Vajngerl <[email protected]>
CommitDate: Wed Nov 12 11:16:30 2025 +0100

    sc: simplify PivotTableSources: use ranged for instead of for_each
    
    No need for for_each if the functors are so simple and not reused,
    we can just use ranged for instead.
    
    If this turns out to be too complex - create functions / methods.
    
    Change-Id: I97d93d65a8f7062fdfae1e336c711ff20d5bb62d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193747
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <[email protected]>

diff --git a/sc/source/filter/xml/pivotsource.cxx 
b/sc/source/filter/xml/pivotsource.cxx
index 15e868c646ee..6c488b194050 100644
--- a/sc/source/filter/xml/pivotsource.cxx
+++ b/sc/source/filter/xml/pivotsource.cxx
@@ -52,11 +52,27 @@ void PivotTableSources::appendSelectedPages( ScDPObject* 
pObj, SelectedPagesType
     maSelectedPagesList.emplace_back(pObj, std::move(rSelected));
 }
 
-namespace {
-
-struct SelectedPageProcessor
+void PivotTableSources::process()
 {
-    void operator() ( PivotTableSources::SelectedPages& rItem )
+    for (SheetSource const& rSource : maSheetSources)
+    {
+        ScDPObject* pObj = rSource.mpDP;
+        pObj->SetSheetDesc(rSource.maDesc);
+    }
+
+    for (DBSource const& rSource: maDBSources)
+    {
+        ScDPObject* pObj = rSource.mpDP;
+        pObj->SetImportDesc(rSource.maDesc);
+    }
+
+    for (ServiceSource const& rSource: maServiceSources)
+    {
+        ScDPObject* pObj = rSource.mpDP;
+        pObj->SetServiceData(rSource.maDesc);
+    }
+
+    for (SelectedPages const& rItem: maSelectedPagesList)
     {
         // Set selected pages after building all dimension members.
         if (!rItem.mpDP)
@@ -76,43 +92,6 @@ struct SelectedPageProcessor
             pDim->SetCurrentPage(&rSelected);
         }
     }
-};
-
-struct PivotSheetDescSetter
-{
-    void operator() ( sc::PivotTableSources::SheetSource& rSrc )
-    {
-        ScDPObject* pObj = rSrc.mpDP;
-        pObj->SetSheetDesc(rSrc.maDesc);
-    }
-};
-
-struct PivotDBDescSetter
-{
-    void operator() ( sc::PivotTableSources::DBSource& rSrc )
-    {
-        ScDPObject* pObj = rSrc.mpDP;
-        pObj->SetImportDesc(rSrc.maDesc);
-    }
-};
-
-struct PivotServiceDataSetter
-{
-    void operator() ( sc::PivotTableSources::ServiceSource& rSrc )
-    {
-        ScDPObject* pObj = rSrc.mpDP;
-        pObj->SetServiceData(rSrc.maDesc);
-    }
-};
-
-}
-
-void PivotTableSources::process()
-{
-    std::for_each(maSheetSources.begin(), maSheetSources.end(), 
PivotSheetDescSetter());
-    std::for_each(maDBSources.begin(), maDBSources.end(), PivotDBDescSetter());
-    std::for_each(maServiceSources.begin(), maServiceSources.end(), 
PivotServiceDataSetter());
-    std::for_each(maSelectedPagesList.begin(), maSelectedPagesList.end(), 
SelectedPageProcessor());
 }
 
 }
commit 783a9229263bc29bd9c5a6d70c920a39ac8846c9
Author:     Tomaž Vajngerl <[email protected]>
AuthorDate: Thu Nov 6 15:50:22 2025 +0900
Commit:     Tomaž Vajngerl <[email protected]>
CommitDate: Wed Nov 12 11:16:23 2025 +0100

    sc: test pivot table undo/redo creation and filter of field
    
    This adds a unit test for undo/redo of pivot table creation and
    filtering (filtering fixed in [1]).
    
    [1] 203922ed789bb87f3cca8ea90c81de72e8919c83
    
    Change-Id: Ied5f9c813c0c2b62c1cf7433b3bc47a3adcb9994
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193513
    Reviewed-by: Tomaž Vajngerl <[email protected]>
    Tested-by: Jenkins

diff --git a/sc/qa/unit/ucalc_pivottable.cxx b/sc/qa/unit/ucalc_pivottable.cxx
index 9517826423bf..7e4d583836d0 100644
--- a/sc/qa/unit/ucalc_pivottable.cxx
+++ b/sc/qa/unit/ucalc_pivottable.cxx
@@ -18,6 +18,7 @@
 #include <dbdocfun.hxx>
 #include <generalfunction.hxx>
 #include <tabprotection.hxx>
+#include <undomanager.hxx>
 
 #include <formula/errorcodes.hxx>
 #include <com/sun/star/sheet/DataPilotFieldGroupBy.hpp>
@@ -155,8 +156,31 @@ ScRange refreshGroups(ScDPCollection* pDPs, ScDPObject* 
pDPObj)
     return refresh(pDPObj);
 }
 
+ScDPObject* getDPObject(ScDocument* pDoc, size_t index)
+{
+    ScDPCollection* pDPCollection = pDoc->GetDPCollection();
+    CPPUNIT_ASSERT_MESSAGE("Failed to get pivot table collection.", 
pDPCollection);
+    return &(*pDPCollection)[index];
+}
+
+sal_Int32 getNumberOfPivotTables(ScDocument* pDoc)
+{
+    ScDPCollection* pDPCollection = pDoc->GetDPCollection();
+    if (!pDPCollection)
+        return -1;
+    return pDPCollection->GetCount();
+}
+
+void updatePivotTable(ScDocShellRef const& xDocShell, size_t index)
+{
+    ScDBDocFunc aFunc(*xDocShell);
+    ScDPObject* pDPObject = getDPObject(&xDocShell->GetDocument(), index);
+    CPPUNIT_ASSERT_MESSAGE("Failed to get pivot table object.", pDPObject);
+    aFunc.RefreshPivotTables(pDPObject, true);
 }
 
+} // end anonymous
+
 class TestPivottable : public ScUcalcTestBase
 {
 protected:
@@ -2649,6 +2673,217 @@ CPPUNIT_TEST_FIXTURE(TestPivottable, 
testPivotTableMedianFunc)
     m_pDoc->DeleteTab(0);
 }
 
+CPPUNIT_TEST_FIXTURE(TestPivottable, testPivotTableUndoCreate)
+{
+    // Test Undo and Redo creating a pivot table
+
+    m_pDoc->InsertTab(0, u"Data"_ustr);
+    m_pDoc->InsertTab(1, u"Table"_ustr);
+
+    bool bSuccess{};
+    ScDBDocFunc aFunc(*m_xDocShell);
+    ScRange aDataRange;
+
+    // Insert data
+    {
+        const std::vector<std::vector<const char*>> aData = {
+            { "Name", "Value" },
+            { "A", "1" },
+            { "B", "2" },
+        };
+
+        static constexpr ScAddress aPosition(1, 1, 0);
+        aDataRange = insertRangeData(m_pDoc, aPosition, aData);
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("failed to insert range data at correct 
position", aPosition, aDataRange.aStart);
+    }
+
+    // Create pivot table
+    {
+        // Dimension definition
+        static constexpr auto aFields = std::to_array<DPFieldDef>({
+            { "Name", sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
+            { "Value", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::COUNT, false },
+        });
+
+        std::unique_ptr<ScDPObject> pDPObject(createDPFromRange(m_pDoc, 
aDataRange, aFields.data(), aFields.size(), false));
+        CPPUNIT_ASSERT_MESSAGE("Failed to create pivot table object.", 
pDPObject);
+
+        // Create a new pivot table output.
+        bSuccess = aFunc.CreatePivotTable(*pDPObject, true, true);
+        CPPUNIT_ASSERT_MESSAGE("Failed to create pivot table output via 
ScDBDocFunc.", bSuccess);
+    }
+
+    // Check output
+    std::function functionCheckNotFiltered = [this, &bSuccess](int nLine)
+    {
+        ScDPObject* pDPObject = getDPObject(m_pDoc, 0);
+
+        ScRange aOutRange = pDPObject->GetOutRange();
+        {
+            std::vector<std::vector<const char*>> aOutputCheck = {
+                { "Name", "Count - Value" },
+                { "A", "1" },
+                { "B", "1" },
+                { "Total Result", "2" },
+            };
+
+            bSuccess = checkDPTableOutput(m_pDoc, aOutRange, aOutputCheck, 
"Unfiltered data not as expected");
+            CPPUNIT_ASSERT_MESSAGE(OString::number(nLine).getStr(), bSuccess);
+        }
+    };
+    functionCheckNotFiltered(__LINE__);
+
+    // Undo
+    m_pDoc->GetUndoManager()->Undo();
+    {
+        ScDPCollection* pDPCollection = m_pDoc->GetDPCollection();
+        CPPUNIT_ASSERT_EQUAL(size_t(0), pDPCollection->GetCount());
+    }
+
+    // Redo
+    m_pDoc->GetUndoManager()->Redo();
+    {
+        ScDPCollection* pDPCollection = m_pDoc->GetDPCollection();
+        CPPUNIT_ASSERT_EQUAL(size_t(1), pDPCollection->GetCount());
+    }
+
+    functionCheckNotFiltered(__LINE__);
+
+    // Remove Pivot Table
+    {
+        ScDPObject* pDPObject = getDPObject(m_pDoc, 0);
+        bSuccess = aFunc.RemovePivotTable(*pDPObject, true, true);
+        CPPUNIT_ASSERT_MESSAGE("Failed to remove pivot table object.", 
bSuccess);
+    }
+
+    m_pDoc->DeleteTab(1);
+    m_pDoc->DeleteTab(0);
+}
+
+CPPUNIT_TEST_FIXTURE(TestPivottable, testPivotTableFilterValueUndoRedo)
+{
+    // Test Undo and Redo when a value is filtered out
+
+    m_pDoc->InsertTab(0, u"Data"_ustr);
+    m_pDoc->InsertTab(1, u"Table"_ustr);
+
+    bool bSuccess{};
+    ScDBDocFunc aFunc(*m_xDocShell);
+    ScRange aDataRange;
+
+    // Insert data
+    {
+        const std::vector<std::vector<const char*>> aData = {
+            { "Name", "Value" },
+            { "A", "1" },
+            { "B", "2" },
+        };
+
+        static constexpr ScAddress aPosition(1, 1, 0);
+        aDataRange = insertRangeData(m_pDoc, aPosition, aData);
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("failed to insert range data at correct 
position", aPosition, aDataRange.aStart);
+    }
+
+    // Create pivot table
+    {
+        // Dimension definition
+        static constexpr auto aFields = std::to_array<DPFieldDef>({
+            { "Name", sheet::DataPilotFieldOrientation_ROW, 
ScGeneralFunction::NONE, false },
+            { "Value", sheet::DataPilotFieldOrientation_DATA, 
ScGeneralFunction::COUNT, false },
+        });
+
+        std::unique_ptr<ScDPObject> pDPObject(createDPFromRange(m_pDoc, 
aDataRange, aFields.data(), aFields.size(), false));
+        CPPUNIT_ASSERT_MESSAGE("Failed to create pivot table object.", 
pDPObject);
+
+        // Create a new pivot table output.
+        bSuccess = aFunc.CreatePivotTable(*pDPObject, true, true);
+        CPPUNIT_ASSERT_MESSAGE("Failed to create pivot table output via 
ScDBDocFunc.", bSuccess);
+    }
+
+    // Check output
+    std::function functionCheckNotFiltered = [this, &bSuccess](int nLine)
+    {
+        ScDPObject* pDPObject = getDPObject(m_pDoc, 0);
+
+        ScRange aOutRange = pDPObject->GetOutRange();
+        {
+            std::vector<std::vector<const char*>> aOutputCheck = {
+                { "Name", "Count - Value" },
+                { "A", "1" },
+                { "B", "1" },
+                { "Total Result", "2" },
+            };
+
+            bSuccess = checkDPTableOutput(m_pDoc, aOutRange, aOutputCheck, 
"Unfiltered data not as expected");
+            OString sMessage("Vales don't match. Called at line " + 
OString::number(nLine));
+            CPPUNIT_ASSERT_MESSAGE(sMessage.getStr(), bSuccess);
+        }
+    };
+    functionCheckNotFiltered(__LINE__);
+
+    // Filter value "A" in "Name" Dimension
+    {
+        ScDPObject* pDPObject = getDPObject(m_pDoc, 0);
+        ScDPObject aNewObject(*pDPObject);
+
+        ScDPSaveData* pSaveData = aNewObject.GetSaveData();
+        CPPUNIT_ASSERT_MESSAGE("Save data doesn't exist.", pSaveData);
+        ScDPSaveDimension* pDim = pSaveData->GetDimensionByName(u"Name"_ustr);
+        CPPUNIT_ASSERT_MESSAGE("Name dimension should exist.", pDim);
+        ScDPSaveMember* pMember = pDim->GetMemberByName(u"A"_ustr);
+        CPPUNIT_ASSERT_MESSAGE("Member should exist.", pMember);
+        pMember->SetIsVisible(false);
+
+        aNewObject.SetSaveData(*pSaveData);
+        aNewObject.ReloadGroupTableData();
+        aNewObject.InvalidateData();
+
+        bSuccess = aFunc.DataPilotUpdate(pDPObject, &aNewObject, true, true);
+        //TODO - We need to fix UpdatePivotTable too
+        // bSuccess = aFunc.UpdatePivotTable(aNewObject, true, true);
+        CPPUNIT_ASSERT_MESSAGE("Pivot table should update.", bSuccess);
+    }
+
+    std::function functionCheckFiltered = [this, &bSuccess](int nLine)
+    {
+        ScDPObject* pDPObject = getDPObject(m_pDoc, 0);
+        ScRange aOutRange = pDPObject->GetOutRange();
+        {
+            std::vector<std::vector<const char*>> aOutputCheck = {
+                { "Name", "Count - Value" },
+                { "B", "1" },
+                { "Total Result", "1" },
+            };
+
+            bSuccess = checkDPTableOutput(m_pDoc, aOutRange, aOutputCheck, 
"Filtered data not as expected");
+            OString sMessage("Vales don't match. Called at line " + 
OString::number(nLine));
+            CPPUNIT_ASSERT_MESSAGE(sMessage.getStr(), bSuccess);
+        }
+    };
+    functionCheckFiltered(__LINE__);
+    updatePivotTable(m_xDocShell, 0);
+    functionCheckFiltered(__LINE__);
+
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getNumberOfPivotTables(m_pDoc));
+
+    // Undo
+    m_pDoc->GetUndoManager()->Undo();
+
+    functionCheckNotFiltered(__LINE__);
+    updatePivotTable(m_xDocShell, 0);
+    functionCheckNotFiltered(__LINE__);
+
+    // Remove Pivot Table
+    {
+        ScDPObject* pDPObject = getDPObject(m_pDoc, 0);
+        bSuccess = aFunc.RemovePivotTable(*pDPObject, true, true);
+        CPPUNIT_ASSERT_MESSAGE("Failed to remove pivot table object.", 
bSuccess);
+    }
+
+    m_pDoc->DeleteTab(1);
+    m_pDoc->DeleteTab(0);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to