sc/qa/uitest/autofilter2/tdf158314_EmptyError.py | 94 +++++++++++++++++++++++ sc/source/core/data/column3.cxx | 4 sc/source/ui/view/gridwin.cxx | 7 - 3 files changed, 100 insertions(+), 5 deletions(-)
New commits: commit f14e942e84942b42956a058e737742f5d19daa96 Author: Kevin Suo <suokunl...@126.com> AuthorDate: Tue Jan 16 10:13:59 2024 +0800 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Thu Jan 18 17:21:23 2024 +0100 tdf#158314: show Empty and Error entries as non-selected and inactive... ...when hidden by autofilter. The "show hidden filter elements as inactive" feature was added and improved by: commit 2d1df9f3dccc10f13b8585ad18afce1542ebc4d1 (tdf#117276 sc: Show hidden filter elements as inactive elements) commit 2085e90fe8ac129bc4dbac4612d1ea7544335dae (FilteredRow is not a property of the column, tdf#117276 follow-up) commit 7321db3cadc8c0e4437ca04e5dcb652734ea9c26 (Related tdf#117276 sc: Show hidden filter elements as inactive elements) commit 19533948370dc1ccd7334dbe1a8b7fc8330b10c0 (Name FilteredRow what it is, not hidden; tdf#117276 follow-up) Those changes correctly made normal hidden filter elements as inactive, but failed to do so for Empty and Error entries. This patch shows the hidden Empty and Error entries as inactive and unselected. Also, do not show the Empty entry at the top of the list in case it is inactive. Change-Id: Ibcd758cebc0692b04b162cdfc3e06eceb86b17da Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162166 Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> Reviewed-by: Kevin Suo <suokunl...@126.com> Tested-by: Kevin Suo <suokunl...@126.com> (cherry picked from commit 2e844921083ee45a36454ea3f03c1796439e4d16) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162224 Tested-by: Jenkins diff --git a/sc/qa/uitest/autofilter2/tdf158314_EmptyError.py b/sc/qa/uitest/autofilter2/tdf158314_EmptyError.py new file mode 100644 index 000000000000..2ced88c80db3 --- /dev/null +++ b/sc/qa/uitest/autofilter2/tdf158314_EmptyError.py @@ -0,0 +1,94 @@ +# -*- 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 +from libreoffice.calc.document import is_row_hidden + +# Bug 158314 - Autofilter dropdown list always shows "Empty" entry as active + +class tdf158314_EmptyEntries(UITestCase): + def testTdf158314(self): + with self.ui_test.create_doc_in_start_center("calc") as calcDoc: + xCalcDoc = self.xUITest.getTopFocusWindow() + xGridWin = xCalcDoc.getChild("grid_window") + + # Fill the sheet with test data + enter_text_to_cell(xGridWin, "A1", "a") + enter_text_to_cell(xGridWin, "A2", "1") + enter_text_to_cell(xGridWin, "A3", "2") + enter_text_to_cell(xGridWin, "A4", "3") + enter_text_to_cell(xGridWin, "A5", "4") + + enter_text_to_cell(xGridWin, "B1", "b") + enter_text_to_cell(xGridWin, "B2", "5") + enter_text_to_cell(xGridWin, "B3", "") + enter_text_to_cell(xGridWin, "B4", "=1/0") + enter_text_to_cell(xGridWin, "B5", "8") + + # Select the data range and set autofilter + xGridWin.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:B5"})) + self.xUITest.executeCommand(".uno:DataFilterAutoFilter") + + # Click the autofilter dropdown in column A + xGridWin.executeAction("LAUNCH", mkPropertyValues({"AUTOFILTER": "", "COL": "0", "ROW": "0"})) + xFloatWindow = self.xUITest.getFloatWindow() + xCheckListMenu = xFloatWindow.getChild("FilterDropDown") + xTreeList = xCheckListMenu.getChild("check_list_box") + + # Select the first entry only. Uncheck all other entries. + for i in xTreeList.getChildren(): + if i != "0": + xEntry = xTreeList.getChild(i) + xEntry.executeAction("CLICK", tuple()) + + xOkButton = xFloatWindow.getChild("ok") + xOkButton.executeAction("CLICK", tuple()) + + # Check that only row#2 is visible + self.assertFalse(is_row_hidden(calcDoc, 1)) + self.assertTrue(is_row_hidden(calcDoc, 2)) + self.assertTrue(is_row_hidden(calcDoc, 3)) + self.assertTrue(is_row_hidden(calcDoc, 4)) + + # Click the autofilter dropdown in column B + xGridWin.executeAction("LAUNCH", mkPropertyValues({"AUTOFILTER": "", "COL": "1", "ROW": "0"})) + xFloatWindow = self.xUITest.getFloatWindow() + xCheckListMenu = xFloatWindow.getChild("FilterDropDown") + xTreeList = xCheckListMenu.getChild("check_list_box") + + # There should be at least one entry in the dropdown + # (i.e., the feature of showing inactive autofilter entries may be disabled) + self.assertEqual(True, len(xTreeList.getChildren()) >= 1) + + for i in xTreeList.getChildren(): + state = get_state_as_dict(xTreeList.getChild(i)) + # The Text of the first element should be '5' and it should be checked and active + if i == "0": + self.assertEqual("5", state["Text"]) + self.assertEqual("true", state["IsChecked"]) + self.assertEqual("true", state["IsSelected"]) + self.assertEqual("false", state["IsSemiTransparent"]) + # All other elements (including the Empty and #DIV/0!) should be unchecked and inactive + else: + self.assertEqual("false", state["IsChecked"]) + self.assertEqual("false", state["IsSelected"]) + self.assertEqual("true", state["IsSemiTransparent"]) + + # Close the popup window + xOkButton = xFloatWindow.getChild("ok") + xOkButton.executeAction("CLICK", tuple()) + + # Check again that only row#2 is visible + self.assertFalse(is_row_hidden(calcDoc, 1)) + self.assertTrue(is_row_hidden(calcDoc, 2)) + self.assertTrue(is_row_hidden(calcDoc, 3)) + self.assertTrue(is_row_hidden(calcDoc, 4)) +# vim: set shiftwidth=4 softtabstop=4 expandtab: diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx index a0b0c639a003..79027226387e 100644 --- a/sc/source/core/data/column3.cxx +++ b/sc/source/core/data/column3.cxx @@ -2584,7 +2584,7 @@ class FilterEntriesHandler { if (!mrFilterEntries.mbHasEmpties) { - mrFilterEntries.push_back(ScTypedStrData(OUString())); + mrFilterEntries.push_back(ScTypedStrData(OUString(), 0.0, 0.0, ScTypedStrData::Standard, false, mbFilteredRow)); mrFilterEntries.mbHasEmpties = true; } return; @@ -2614,7 +2614,7 @@ class FilterEntriesHandler OUString aErr = ScGlobal::GetErrorString(nErr); if (!aErr.isEmpty()) { - mrFilterEntries.push_back(ScTypedStrData(std::move(aErr))); + mrFilterEntries.push_back(ScTypedStrData(std::move(aErr), 0.0, 0.0, ScTypedStrData::Standard, false, mbFilteredRow)); return; } } diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx index 3f4f6b219c67..9848cc522036 100644 --- a/sc/source/ui/view/gridwin.cxx +++ b/sc/source/ui/view/gridwin.cxx @@ -1041,8 +1041,8 @@ void ScGridWindow::LaunchAutoFilterMenu(SCCOL nCol, SCROW nRow) mpAutoFilterPopup->setMemberSize(aFilterEntries.size()); for (auto it = aFilterEntries.begin(); it != aFilterEntries.end(); ++it) { - // tdf#140745 show (empty) entry on top of the checkbox list - if (it->GetString().isEmpty()) + // tdf#140745 show (empty) entry on top of the checkbox list if not hidden by filter + if (it->GetString().isEmpty() && !it->IsHiddenByFilter()) { const OUString& aStringVal = it->GetString(); const double aDoubleVal = it->GetValue(); @@ -1051,7 +1051,8 @@ void ScGridWindow::LaunchAutoFilterMenu(SCCOL nCol, SCROW nRow) bSelected = aSelectedString.count(aStringVal) > 0; else if (bQueryByNonEmpty) bSelected = false; - mpAutoFilterPopup->addMember(aStringVal, aDoubleVal, bSelected, it->IsHiddenByFilter()); + // it->IsHiddenByFilter() is always false here so no need to evaluate it + mpAutoFilterPopup->addMember(aStringVal, aDoubleVal, bSelected, false); aFilterEntries.maStrData.erase(it); break; }