sc/qa/uitest/autofilter2/tdf169108_prevent_selection_change.py |   44 
++++++++++
 sc/source/ui/docshell/docsh5.cxx                               |    2 
 sc/source/ui/view/cellsh1.cxx                                  |    4 
 3 files changed, 47 insertions(+), 3 deletions(-)

New commits:
commit bbd19f18077882d5945063e77f3ae0db3085a934
Author:     Andreas Heinisch <[email protected]>
AuthorDate: Tue Oct 28 13:59:09 2025 +0100
Commit:     Xisco Fauli <[email protected]>
CommitDate: Tue Nov 4 18:11:25 2025 +0100

    tdf#169108 - Create anonymous database range or data
    
    Create anonymous database range or data during the creation of a pivot 
table. Otherwise, the selection changes to a old autofilter areas and the pivot 
table cannot be created.
    
    Change-Id: If55b9d1204ab2ce2c3ee9a227bf0dbe1e222dbcb
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193096
    Tested-by: Jenkins
    Reviewed-by: Andreas Heinisch <[email protected]>
    (cherry picked from commit 2a50c7fbb85941a2c50ac01257af36f132b07006)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193137
    Reviewed-by: Xisco Fauli <[email protected]>
    (cherry picked from commit 465e7fddb34fe06d9464ee534c79a02dd72707d4)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193143
    Reviewed-by: Michael Weghorn <[email protected]>
    Tested-by: Ilmari Lauhakangas <[email protected]>

diff --git a/sc/qa/uitest/autofilter2/tdf169108_prevent_selection_change.py 
b/sc/qa/uitest/autofilter2/tdf169108_prevent_selection_change.py
new file mode 100644
index 000000000000..e8021cff10cb
--- /dev/null
+++ b/sc/qa/uitest/autofilter2/tdf169108_prevent_selection_change.py
@@ -0,0 +1,44 @@
+# -*- 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 uitest.uihelper.calc import enter_text_to_cell
+from uitest.uihelper.common import get_state_as_dict
+from libreoffice.uno.propertyvalue import mkPropertyValues
+
+class tdf169108(UITestCase):
+
+    def test_tdf169108_prevent_selection_change(self):
+        with self.ui_test.create_doc_in_start_center("calc"):
+            xCalcDoc = self.xUITest.getTopFocusWindow()
+            xGridWindow = xCalcDoc.getChild("grid_window")
+
+            # Insert test data
+            enter_text_to_cell(xGridWindow, "A1", "Header")
+            enter_text_to_cell(xGridWindow, "A2", "1")
+            enter_text_to_cell(xGridWindow, "A3", "2")
+            enter_text_to_cell(xGridWindow, "A4", "1")
+            enter_text_to_cell(xGridWindow, "C1", "Header")
+            enter_text_to_cell(xGridWindow, "C2", "1")
+
+            # Apply auto filter on C1:C2
+            xGridWindow.executeAction("SELECT", mkPropertyValues({"RANGE": 
"C1:C2"}))
+            self.xUITest.executeCommand(".uno:DataFilterAutoFilter")
+
+            # Create a pivot table on different range
+            xGridWindow.executeAction("SELECT", mkPropertyValues({"RANGE": 
"A1:A4"}))
+            with 
self.ui_test.execute_dialog_through_command(".uno:DataDataPilotRun", 
close_button="cancel"):
+                pass
+
+            # Without the fix in place, this test would have failed with
+            # AssertionError: 'Sheet1.A1:Sheet1.A4' != 'Sheet1.C1:Sheet1.C2'
+            # i.e., the old auto filter range will be restored
+            gridWinState = get_state_as_dict(xGridWindow)
+            self.assertEqual("Sheet1.A1:Sheet1.A4", gridWinState["MarkedArea"])
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sc/source/ui/docshell/docsh5.cxx b/sc/source/ui/docshell/docsh5.cxx
index ea9e5ddd4123..e0ca5fec3145 100644
--- a/sc/source/ui/docshell/docsh5.cxx
+++ b/sc/source/ui/docshell/docsh5.cxx
@@ -195,7 +195,7 @@ ScDBData* ScDocShell::GetDBData( const ScRange& rMarked, 
ScGetDBMode eMode, ScGe
     {
         pData->GetArea( nStartTab, nStartCol,nStartRow, nEndCol,nEndRow );
     }
-    // tdf #168478 - use the previously found range rather than returning an 
empty one
+    // tdf#168478 - use the previously found range rather than returning an 
empty one
     else if ( eMode != SC_DB_OLD )
     {
         if ( !bSelected )
diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx
index b0a6c605714f..28789f58a683 100644
--- a/sc/source/ui/view/cellsh1.cxx
+++ b/sc/source/ui/view/cellsh1.cxx
@@ -3467,8 +3467,8 @@ void ScCellShell::ExecuteDataPilotDialog()
     }
     else            // create new table
     {
-        //  select database range or data
-        pTabViewShell->GetDBData( true, SC_DB_OLD );
+        // tdf#169108 - create anonymous database range or data
+        pTabViewShell->GetDBData( true, SC_DB_MAKE );
         ScMarkData& rMark = GetViewData().GetMarkData();
         if ( !rMark.IsMarked() && !rMark.IsMultiMarked() )
             pTabViewShell->MarkDataArea( false );

Reply via email to