[Libreoffice-commits] core.git: sc/inc sc/qa sc/source

Tünde Tóth (via logerrit) logerrit at kemper.freedesktop.org
Sat May 22 10:29:43 UTC 2021


 sc/inc/strings.hrc                   |    1 
 sc/qa/uitest/autofilter/tdf141559.py |   93 +++++++++++++++++++++++++++++++++++
 sc/source/ui/inc/gridwin.hxx         |    1 
 sc/source/ui/view/gridwin.cxx        |    6 +-
 4 files changed, 100 insertions(+), 1 deletion(-)

New commits:
commit 451b9802dd708e646273839829845800e13db47e
Author:     Tünde Tóth <toth.tunde at nisz.hu>
AuthorDate: Fri May 14 14:44:48 2021 +0200
Commit:     László Németh <nemeth at numbertext.org>
CommitDate: Sat May 22 12:29:04 2021 +0200

    tdf#141559 sc UI: add Clear Filter to Autofilter widget
    
    Implement Clear Filter menu item in the Autofilter
    dropdown that can remove standard filter conditions
    and autofilter conditions too.
    
    Change-Id: I7521379955d3f38076c3129273629222412d9ed4
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115609
    Tested-by: Jenkins
    Reviewed-by: László Németh <nemeth at numbertext.org>

diff --git a/sc/inc/strings.hrc b/sc/inc/strings.hrc
index d2463ad39306..2da196f51776 100644
--- a/sc/inc/strings.hrc
+++ b/sc/inc/strings.hrc
@@ -31,6 +31,7 @@
 #define SCSTR_ALL                                   NC_("SCSTR_ALL", "- all -")
 #define SCSTR_MULTIPLE                              NC_("SCSTR_MULTIPLE", "- multiple -")
 #define SCSTR_STDFILTER                             NC_("SCSTR_STDFILTER", "Standard Filter...")
+#define SCSTR_CLEAR_FILTER                          NC_("SCSTR_CLEAR_FILTER", "Clear Filter")
 #define SCSTR_TOP10FILTER                           NC_("SCSTR_TOP10FILTER", "Top 10")
 #define SCSTR_FILTER_EMPTY                          NC_("SCSTR_FILTER_EMPTY", "Empty")
 #define SCSTR_FILTER_NOTEMPTY                       NC_("SCSTR_FILTER_NOTEMPTY", "Not Empty")
diff --git a/sc/qa/uitest/autofilter/tdf141559.py b/sc/qa/uitest/autofilter/tdf141559.py
new file mode 100644
index 000000000000..6bce18852ff3
--- /dev/null
+++ b/sc/qa/uitest/autofilter/tdf141559.py
@@ -0,0 +1,93 @@
+# -*- 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 uitest.uihelper.common import select_by_text
+from libreoffice.uno.propertyvalue import mkPropertyValues
+from libreoffice.calc.document import get_row
+from uitest.uihelper.common import get_state_as_dict
+
+#Bug 141559 - Add Clear Standard Filter to Autofilter widget
+
+class tdf141559(UITestCase):
+    def test_tdf141559_clear_filter(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")
+
+        gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:A4"}))
+
+        self.xUITest.executeCommand(".uno:DataFilterAutoFilter")
+
+        gridwin.executeAction("LAUNCH", mkPropertyValues({"AUTOFILTER": "", "COL": "0", "ROW": "0"}))
+        xFloatWindow = self.xUITest.getFloatWindow()
+        #Choose Standard Filter... button
+        xMenu = xFloatWindow.getChild("menu")
+
+        # check last item: 'Standard Filter...' (new menu item 'Clear Filter' is optional)
+        nLastIdx = int(get_state_as_dict(xMenu)['Children']) - 1
+        self.assertEqual(10, nLastIdx)
+        self.assertEqual('Standard Filter...', get_state_as_dict(xMenu.getChild(str(nLastIdx)))['Text'])
+
+        xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"DOWN"}))
+        xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"DOWN"}))
+        xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"DOWN"}))
+        xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"DOWN"}))
+        xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"DOWN"}))
+        xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"DOWN"}))
+        xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"DOWN"}))
+        self.assertEqual("Standard Filter...", get_state_as_dict(xMenu)['SelectEntryText'])
+        xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"RETURN"}))
+
+        xDialog = self.xUITest.getTopFocusWindow()
+        xfield1 = xDialog.getChild("field1")
+        xcond1 = xDialog.getChild("cond1")
+        xval1 = xDialog.getChild("val1")
+
+        select_by_text(xfield1, "A")
+        select_by_text(xcond1, ">")
+        xval1.executeAction("TYPE", mkPropertyValues({"TEXT":"1"}))
+        xOKBtn = xDialog.getChild("ok")
+        self.ui_test.close_dialog_through_button(xOKBtn)
+
+        row = get_row(document, 1)
+        self.assertFalse(row.getPropertyValue("IsVisible"))
+
+        gridwin.executeAction("LAUNCH", mkPropertyValues({"AUTOFILTER": "", "COL": "0", "ROW": "0"}))
+        xFloatWindow = self.xUITest.getFloatWindow()
+        #Choose Clear Filter button
+        xMenu = xFloatWindow.getChild("menu")
+
+        # check last item: 'Clear Filter'
+        nLastIdx = int(get_state_as_dict(xMenu)['Children']) - 1
+        self.assertEqual(11, nLastIdx)
+        self.assertEqual('Clear Filter', get_state_as_dict(xMenu.getChild(str(nLastIdx)))['Text'])
+
+        xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"DOWN"}))
+        xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"DOWN"}))
+        xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"DOWN"}))
+        xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"DOWN"}))
+        xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"DOWN"}))
+        xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"DOWN"}))
+        xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"DOWN"}))
+        xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"DOWN"}))
+        # Use new menu item "Clear Filter" to remove the standard filter condition
+        self.assertEqual("Clear Filter", get_state_as_dict(xMenu)['SelectEntryText'])
+        xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"RETURN"}))
+
+        self.assertTrue(row.getPropertyValue("IsVisible"))
+
+        self.ui_test.close_doc()
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sc/source/ui/inc/gridwin.hxx b/sc/source/ui/inc/gridwin.hxx
index 023715a33c8a..09e46d7a4e21 100644
--- a/sc/source/ui/inc/gridwin.hxx
+++ b/sc/source/ui/inc/gridwin.hxx
@@ -333,6 +333,7 @@ public:
         BackgroundColor,
         SortAscending,
         SortDescending,
+        Clear
     };
 
     ScGridWindow( vcl::Window* pParent, ScViewData& rData, ScSplitPos eWhichPos );
diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx
index 644feab4b654..400a6a8184ce 100644
--- a/sc/source/ui/view/gridwin.cxx
+++ b/sc/source/ui/view/gridwin.cxx
@@ -720,6 +720,9 @@ void ScGridWindow::LaunchAutoFilterMenu(SCCOL nCol, SCROW nRow)
     rControl.addSeparator();
     rControl.addMenuItem(
         ScResId(SCSTR_STDFILTER), new AutoFilterAction(this, AutoFilterMode::Custom));
+    if (aEntries.size())
+        rControl.addMenuItem(
+            ScResId(SCSTR_CLEAR_FILTER), new AutoFilterAction(this, AutoFilterMode::Clear));
 
     rControl.initMembers(nMaxTextWidth + 20); // 20 pixel estimated for the checkbox
 
@@ -848,7 +851,8 @@ void ScGridWindow::UpdateAutoFilterFromMenu(AutoFilterMode eMode)
     if (!bColorMode)
         aParam.RemoveAllEntriesByField(rPos.Col());
 
-    if( !(eMode == AutoFilterMode::Normal && rControl.isAllSelected() ) )
+    if (eMode != AutoFilterMode::Clear
+        && !(eMode == AutoFilterMode::Normal && rControl.isAllSelected()))
     {
         // Try to use the existing entry for the column (if one exists).
         ScQueryEntry* pEntry = aParam.FindEntryByField(rPos.Col(), true);


More information about the Libreoffice-commits mailing list