sc/qa/uitest/calc_tests9/tdf124632.py |   78 ++++++++++++++++++++++++++++++++++
 sc/qa/uitest/data/tdf124632.ods       |binary
 sc/source/ui/undo/undodat.cxx         |    7 ---
 sc/source/ui/view/gridwin2.cxx        |    7 +--
 4 files changed, 83 insertions(+), 9 deletions(-)

New commits:
commit 203922ed789bb87f3cca8ea90c81de72e8919c83
Author:     Bojidar Marinov <[email protected]>
AuthorDate: Thu Jul 10 18:11:26 2025 +0300
Commit:     Tomaž Vajngerl <[email protected]>
CommitDate: Wed Nov 5 04:11:53 2025 +0100

    tdf#124632: fix undo when applying a filter to the pivot table
    
    Correctly save DataPivot object for the undo when applying a filter
    of one of the fields of the pivot table, so undoing resets the
    pivot table to the correct state which is preserved even when we reset
    the pivot table.
    
    Change-Id: I1027faa512e0f82a3af2655b32f6979bd87424fd
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/187655
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <[email protected]>

diff --git a/sc/qa/uitest/calc_tests9/tdf124632.py 
b/sc/qa/uitest/calc_tests9/tdf124632.py
new file mode 100644
index 000000000000..39ab4c7a0f16
--- /dev/null
+++ b/sc/qa/uitest/calc_tests9/tdf124632.py
@@ -0,0 +1,78 @@
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+from uitest.framework import UITestCase
+from libreoffice.uno.propertyvalue import mkPropertyValues
+from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file
+from libreoffice.calc.document import get_cell_by_position
+
+class tdf124632(UITestCase):
+    def test_undo(self):
+
+        with self.ui_test.load_file(get_url_for_data_file("tdf124632.ods")) as 
calc_doc:
+
+            xCalcDoc = self.xUITest.getTopFocusWindow()
+            gridwin = xCalcDoc.getChild("grid_window")
+
+            # 1) Cause all elements to be filtered out of the pivot table:
+
+            gridwin.executeAction("LAUNCH", mkPropertyValues({"PIVOTTABLE": 
"", "COL": "6", "ROW": "0"}))
+            xFloatWindow = self.xUITest.getFloatWindow()
+
+            xCheckListMenu = xFloatWindow.getChild("FilterDropDown")
+            xTreeList = xCheckListMenu.getChild("check_list_box")
+            xFirstEntry = xTreeList.getChild("1")
+            xFirstEntry.executeAction("CLICK", tuple())
+
+            xOkBtn = xFloatWindow.getChild("ok")
+            xOkBtn.executeAction("CLICK", tuple())
+
+            gridwin.executeAction("LAUNCH", mkPropertyValues({"PIVOTTABLE": 
"", "COL": "5", "ROW": "0"}))
+            xFloatWindow = self.xUITest.getFloatWindow()
+
+            xCheckListMenu = xFloatWindow.getChild("FilterDropDown")
+            xTreeList = xCheckListMenu.getChild("check_list_box")
+            xFirstEntry = xTreeList.getChild("0")
+            xFirstEntry.executeAction("CLICK", tuple())
+
+            xOkBtn = xFloatWindow.getChild("ok")
+            xOkBtn.executeAction("CLICK", tuple())
+
+            # 2) Confirm the pivot table is empty:
+
+            self.assertEqual("Total Result", get_cell_by_position(calc_doc, 0, 
5, 1).getString())
+
+            # 3) Undo
+
+            self.xUITest.executeCommand(".uno:Undo")
+
+            # 4) Reopen the pivot table filter and observe that it's still in 
its pre-undo state
+
+            # Before, this would have failed as we wouldn't have restored the 
DataPilot correctly
+            gridwin.executeAction("LAUNCH", mkPropertyValues({"PIVOTTABLE": 
"", "COL": "5", "ROW": "0"}))
+            xFloatWindow = self.xUITest.getFloatWindow()
+
+            xCheckListMenu = xFloatWindow.getChild("FilterDropDown")
+            xTreeList = xCheckListMenu.getChild("check_list_box")
+
+            # Before, this would have failed as we wouldn't have restored the 
DataPilot correctly
+            self.assertEqual('true', 
get_state_as_dict(xTreeList.getChild('0'))['IsChecked'])
+            self.assertEqual('true', 
get_state_as_dict(xTreeList.getChild('1'))['IsChecked'])
+
+            xCancelBtn = xFloatWindow.getChild("cancel")
+            xCancelBtn.executeAction("CLICK", tuple())
+
+            # Before, this would have failed as we wouldn't have restored the 
DataPilot correctly
+            gridwin.executeAction("LAUNCH", mkPropertyValues({"PIVOTTABLE": 
"", "COL": "6", "ROW": "0"}))
+            xFloatWindow = self.xUITest.getFloatWindow()
+            self.assertIsNotNone(xFloatWindow)
+
+
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sc/qa/uitest/data/tdf124632.ods b/sc/qa/uitest/data/tdf124632.ods
new file mode 100644
index 000000000000..696eade84cc2
Binary files /dev/null and b/sc/qa/uitest/data/tdf124632.ods differ
diff --git a/sc/source/ui/undo/undodat.cxx b/sc/source/ui/undo/undodat.cxx
index 6bdeeae2c9f6..1fdd7e64e765 100644
--- a/sc/source/ui/undo/undodat.cxx
+++ b/sc/source/ui/undo/undodat.cxx
@@ -1518,12 +1518,7 @@ void ScUndoDataPilot::Undo()
             if (xOldDPObject)
             {
                 //  restore old settings
-                xOldDPObject->WriteSourceDataTo( *pDocObj );
-                ScDPSaveData* pData = xOldDPObject->GetSaveData();
-                if (pData)
-                    pDocObj->SetSaveData(*pData);
-                pDocObj->SetOutRange(xOldDPObject->GetOutRange());
-                xOldDPObject->WriteTempDataTo( *pDocObj );
+                *pDocObj = *xOldDPObject;
             }
             else
             {
diff --git a/sc/source/ui/view/gridwin2.cxx b/sc/source/ui/view/gridwin2.cxx
index 5c07253e1de8..0a191875dd12 100644
--- a/sc/source/ui/view/gridwin2.cxx
+++ b/sc/source/ui/view/gridwin2.cxx
@@ -792,10 +792,11 @@ void ScGridWindow::UpdateDPFromFieldPopupMenu()
         return;
 
     ScDPObject* pDPObj = pDPData->mpDPObj;
-    ScDPSaveData* pSaveData = pDPObj->GetSaveData();
+    ScDPObject aNewObj(*pDPObj);
+    ScDPSaveData* pSaveData = aNewObj.GetSaveData();
 
     bool bIsDataLayout;
-    OUString aDimName = pDPObj->GetDimName(pDPData->mnDim, bIsDataLayout);
+    OUString aDimName = aNewObj.GetDimName(pDPData->mnDim, bIsDataLayout);
     ScDPSaveDimension* pDim = pSaveData->GetDimensionByName(aDimName);
     if (!pDim)
         return;
@@ -833,7 +834,7 @@ void ScGridWindow::UpdateDPFromFieldPopupMenu()
     pDim->UpdateMemberVisibility(aResult);
 
     ScDBDocFunc aFunc(mrViewData.GetDocShell());
-    aFunc.UpdatePivotTable(*pDPObj, true, false);
+    aFunc.DataPilotUpdate(pDPObj, &aNewObj, true, false);
 }
 
 namespace {

Reply via email to