diff options
author | Tünde Tóth <toth.tunde@nisz.hu> | 2021-04-22 14:19:41 +0200 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2021-04-29 12:58:52 +0200 |
commit | edb64cc363e782470870089041c48993d7c34de5 (patch) | |
tree | b3d41b505f58b0ae192029c4909b58487c1c545c | |
parent | b49eca55210d3f7e731f32f2f20bd12bfd729ec6 (diff) |
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 <nemeth@numbertext.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
-rw-r--r-- | sc/inc/dbdata.hxx | 3 | ||||
-rw-r--r-- | sc/qa/uitest/autofilter/tdf48025.py | 72 | ||||
-rw-r--r-- | sc/source/core/tool/dbdata.cxx | 24 |
3 files changed, 96 insertions, 3 deletions
diff --git a/sc/inc/dbdata.hxx b/sc/inc/dbdata.hxx index 39ae2835e0f8..c1e714fc3e9f 100644 --- a/sc/inc/dbdata.hxx +++ b/sc/inc/dbdata.hxx @@ -124,7 +124,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 f5ffea0984be..d7a8f4dd5297 100644 --- a/sc/source/core/tool/dbdata.cxx +++ b/sc/source/core/tool/dbdata.cxx @@ -341,7 +341,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); @@ -364,6 +365,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; @@ -595,7 +610,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; |