sc/inc/dbdata.hxx                   |    3 +
 sc/qa/uitest/autofilter/tdf48025.py |   72 ++++++++++++++++++++++++++++++++++++
 sc/source/core/tool/dbdata.cxx      |   24 +++++++++++-
 3 files changed, 96 insertions(+), 3 deletions(-)

New commits:
commit a703f2d7b0647e264220efc4a042086396e27238
Author:     Tünde Tóth <toth.tu...@nisz.hu>
AuthorDate: Thu Apr 22 14:19:41 2021 +0200
Commit:     Gabor Kelemen <kelemen.gab...@nisz.hu>
CommitDate: Thu Jul 1 17:22:18 2021 +0200

    tdf#48025 sc: fix broken filter criteria when deleting columns
    
    The autofilter criteria weren't remain with the filtered column
    when we deleted a column left of the filtered column or
    the filtered column itself.
    
    Change-Id: I0eb103ea5569d82eac4d81bce1b31b0c3bbcbf41
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114483
    Tested-by: László Németh <nem...@numbertext.org>
    Reviewed-by: László Németh <nem...@numbertext.org>
    (cherry picked from commit edb64cc363e782470870089041c48993d7c34de5)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118186
    Tested-by: Gabor Kelemen <kelemen.gab...@nisz.hu>
    Reviewed-by: Gabor Kelemen <kelemen.gab...@nisz.hu>

diff --git a/sc/inc/dbdata.hxx b/sc/inc/dbdata.hxx
index c39d8676ffb6..a406e3fb4c5b 100644
--- a/sc/inc/dbdata.hxx
+++ b/sc/inc/dbdata.hxx
@@ -125,7 +125,8 @@ public:
     void        GetArea(SCTAB& rTab, SCCOL& rCol1, SCROW& rRow1, SCCOL& rCol2, 
SCROW& rRow2) const;
     SC_DLLPUBLIC void GetArea(ScRange& rRange) const;
     void        SetArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, 
SCROW nRow2);
-    void        MoveTo(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, 
SCROW nRow2);
+    void        MoveTo(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, 
SCROW nRow2,
+                       SCCOL nUpdateCol = -1);
     void        SetByRow(bool bByR)             { bByRow = bByR; }
     bool        HasHeader() const               { return bHasHeader; }
     void        SetHeader(bool bHasH)           { bHasHeader = bHasH; }
diff --git a/sc/qa/uitest/autofilter/tdf48025.py 
b/sc/qa/uitest/autofilter/tdf48025.py
new file mode 100644
index 000000000000..c5d5c711da5f
--- /dev/null
+++ b/sc/qa/uitest/autofilter/tdf48025.py
@@ -0,0 +1,72 @@
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
+#
+# 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 libreoffice.uno.propertyvalue import mkPropertyValues
+
+#Bug 48025 - EDITING AUTOFILTER: Autofilter settings stay with the column 
number when deleting columns
+
+class tdf48025(UITestCase):
+    def test_tdf48025_deleted_columns(self):
+        self.ui_test.create_doc_in_start_center("calc")
+        document = self.ui_test.get_component()
+        calcDoc = self.xUITest.getTopFocusWindow()
+        gridwin = calcDoc.getChild("grid_window")
+        document = self.ui_test.get_component()
+
+        enter_text_to_cell(gridwin, "A1", "A")
+        enter_text_to_cell(gridwin, "A2", "1")
+        enter_text_to_cell(gridwin, "A3", "2")
+        enter_text_to_cell(gridwin, "A4", "3")
+
+        enter_text_to_cell(gridwin, "B1", "B")
+        enter_text_to_cell(gridwin, "B2", "4")
+        enter_text_to_cell(gridwin, "B3", "5")
+        enter_text_to_cell(gridwin, "B4", "6")
+
+        enter_text_to_cell(gridwin, "C1", "C")
+        enter_text_to_cell(gridwin, "C2", "7")
+        enter_text_to_cell(gridwin, "C3", "8")
+        enter_text_to_cell(gridwin, "C4", "9")
+
+        gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:C4"}))
+
+        self.xUITest.executeCommand(".uno:DataFilterAutoFilter")
+
+        gridwin.executeAction("LAUNCH", mkPropertyValues({"AUTOFILTER": "", 
"COL": "1", "ROW": "0"}))
+        xFloatWindow = self.xUITest.getFloatWindow()
+        xCheckListMenu = xFloatWindow.getChild("check_list_menu")
+        xList = xCheckListMenu.getChild("check_list_box")
+        xEntry = xList.getChild("1")
+        xEntry.executeAction("CLICK", tuple())
+
+        xOkButton = xFloatWindow.getChild("ok")
+        xOkButton.executeAction("CLICK", tuple())
+
+        gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
+
+        self.xUITest.executeCommand(".uno:DeleteColumns")
+
+        gridwin.executeAction("LAUNCH", mkPropertyValues({"AUTOFILTER": "", 
"COL": "0", "ROW": "0"}))
+        xFloatWindow = self.xUITest.getFloatWindow()
+        xCheckListMenu = xFloatWindow.getChild("check_list_menu")
+        xList = xCheckListMenu.getChild("check_list_box")
+        self.assertEqual(3, len(xList.getChildren()))
+        xCloseBtn = xFloatWindow.getChild("cancel")
+        xCloseBtn.executeAction("CLICK", tuple())
+
+        gridwin.executeAction("LAUNCH", mkPropertyValues({"AUTOFILTER": "", 
"COL": "1", "ROW": "0"}))
+        xFloatWindow = self.xUITest.getFloatWindow()
+        xCheckListMenu = xFloatWindow.getChild("check_list_menu")
+        xList = xCheckListMenu.getChild("check_list_box")
+        self.assertEqual(2, len(xList.getChildren()))
+        xCloseBtn = xFloatWindow.getChild("cancel")
+        xCloseBtn.executeAction("CLICK", tuple())
+
+        self.ui_test.close_doc()
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sc/source/core/tool/dbdata.cxx b/sc/source/core/tool/dbdata.cxx
index 1af154bc79f2..d0d7f87339ba 100644
--- a/sc/source/core/tool/dbdata.cxx
+++ b/sc/source/core/tool/dbdata.cxx
@@ -342,7 +342,8 @@ void ScDBData::SetArea(SCTAB nTab, SCCOL nCol1, SCROW 
nRow1, SCCOL nCol2, SCROW
     }
 }
 
-void ScDBData::MoveTo(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW 
nRow2)
+void ScDBData::MoveTo(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW 
nRow2,
+                      SCCOL nUpdateCol)
 {
     tools::Long nDifX = static_cast<tools::Long>(nCol1) - 
static_cast<tools::Long>(nStartCol);
     tools::Long nDifY = static_cast<tools::Long>(nRow1) - 
static_cast<tools::Long>(nStartRow);
@@ -365,6 +366,20 @@ void ScDBData::MoveTo(SCTAB nTab, SCCOL nCol1, SCROW 
nRow1, SCCOL nCol2, SCROW n
     {
         ScQueryEntry& rEntry = mpQueryParam->GetEntry(i);
         rEntry.nField += nDifX;
+
+        // tdf#48025 update the column index of the filter criteria,
+        // when the deleted columns are inside the data range
+        if (nUpdateCol != -1)
+        {
+            nUpdateCol += nDifX;
+            tools::Long nDifX2
+                = static_cast<tools::Long>(nCol2) - 
static_cast<tools::Long>(nEndCol);
+            if (rEntry.nField >= nUpdateCol)
+                rEntry.nField += nDifX2;
+            else if (rEntry.nField >= nUpdateCol + nDifX2)
+                rEntry.Clear();
+        }
+
         if (rEntry.nField > nCol2)
         {
             rEntry.nField = 0;
@@ -596,7 +611,12 @@ void ScDBData::UpdateReference(const ScDocument* pDoc, 
UpdateRefMode eUpdateRefM
         AdjustTableColumnNames( eUpdateRefMode, nDx, nCol1, nOldCol1, 
nOldCol2, theCol1, theCol2);
         ::std::vector<OUString> aNames( maTableColumnNames);
         bool bTableColumnNamesDirty = mbTableColumnNamesDirty;
-        MoveTo( theTab1, theCol1, theRow1, theCol2, theRow2 );
+        // tdf#48025 update the column index of the filter criteria,
+        // when the deleted columns are inside the data range
+        if (HasAutoFilter() && theCol1 - nOldCol1 > theCol2 - nOldCol2)
+            MoveTo(theTab1, theCol1, theRow1, theCol2, theRow2, nCol1);
+        else
+            MoveTo( theTab1, theCol1, theRow1, theCol2, theRow2 );
         // Do not use SetTableColumnNames() because that resets 
mbTableColumnNamesDirty.
         maTableColumnNames = aNames;
         mbTableColumnNamesDirty = bTableColumnNamesDirty;
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to