diff --git a/dbaccess/qa/uitest/edit_field/tdf173673.py b/dbaccess/qa/uitest/edit_field/tdf173673.py new file mode 100644 index 000000000000..3edeb65ae170 --- /dev/null +++ b/dbaccess/qa/uitest/edit_field/tdf173673.py @@ -0,0 +1,63 @@ +# -*- 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.common import get_url_for_data_file, select_pos + +from libreoffice.uno.propertyvalue import mkPropertyValues + +# Bug 173673 - Tablefilter: Resetting impossible when "Apply Filter" is unchecked +class tdf173673(UITestCase): + def test_tdf173673(self): + with self.ui_test.load_file(get_url_for_data_file("tdf75509.odb")) as document: + xConnection = document.DataSource.getConnection("", "") + xStatement = xConnection.createStatement() + xStatement.executeUpdate('INSERT INTO "Table1" ("FrenchField", "EnglishField") VALUES (1, 1)') + xStatement.executeUpdate('INSERT INTO "Table1" ("FrenchField", "EnglishField") VALUES (2, 2)') + xConnection.close() + + self.xUITest.executeCommand(".uno:DBViewTables") + xToolkit = self.xContext.ServiceManager.createInstance('com.sun.star.awt.Toolkit') + xToolkit.waitUntilAllIdlesDispatched() + self.xUITest.executeCommand(".uno:SelectAll") + + with self.ui_test.open_subcomponent_through_command(".uno:DBTableOpen") as xTableFrame: + xTableWindow = self.xUITest.getWindow(xTableFrame.getContainerWindow()) + xGrid = xTableWindow.getChild("DBGrid") + xForm = xTableFrame.getController().CurrentControl.getModel().getParent() + + self.assertEqual(2, xForm.RowCount) + + # AutoFilter on the first row's FrenchField cell (value 1) + xGrid.executeAction("FOCUS", tuple()) + xGrid.executeAction("TYPE", mkPropertyValues({"KEYCODE": "TAB"})) + self.xUITest.executeCommandForProvider(".uno:AutoFilter", xTableFrame) + xToolkit.waitUntilAllIdlesDispatched() + self.assertNotEqual("", xForm.Filter) + self.assertTrue(xForm.ApplyFilter) + self.assertEqual(1, xForm.RowCount) + + # Uncheck "Apply Filter": the filter is kept, but no longer applied + self.xUITest.executeCommandForProvider(".uno:FormFiltered", xTableFrame) + xToolkit.waitUntilAllIdlesDispatched() + self.assertNotEqual("", xForm.Filter) + self.assertFalse(xForm.ApplyFilter) + self.assertEqual(2, xForm.RowCount) + + # Clear the condition in the Standard Filter dialog + with self.ui_test.execute_blocking_action( + self.xUITest.executeCommandForProvider, + args=(".uno:FilterCrit", xTableFrame)) as xDialog: + xDialog.getChild("field1").executeAction("SELECT", mkPropertyValues({"TEXT": "- none -"})) + xToolkit.waitUntilAllIdlesDispatched() + + # Check that the old filter is removed + self.assertEqual("", xForm.Filter) + self.assertEqual(2, xForm.RowCount) + +# vim: set shiftwidth=4 softtabstop=4 expandtab: diff --git a/dbaccess/source/ui/browser/brwctrlr.cxx b/dbaccess/source/ui/browser/brwctrlr.cxx index fcc775f5f008..5876483e35ca 100644 --- a/dbaccess/source/ui/browser/brwctrlr.cxx +++ b/dbaccess/source/ui/browser/brwctrlr.cxx @@ -1361,8 +1361,14 @@ FeatureState SbaXDataBrowserController::GetState(sal_uInt16 nId) const aReturn.bEnabled = false; return aReturn; } - // any filter or sort order set ? - aReturn.bEnabled = m_xParser->getFilter().getLength() || m_xParser->getHavingClause().getLength() || m_xParser->getOrder().getLength(); + { + Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY); + OUString sFilter, sHaving; + xFormSet->getPropertyValue(PROPERTY_FILTER) >>= sFilter; + xFormSet->getPropertyValue(PROPERTY_HAVING_CLAUSE) >>= sHaving; + // any filter or sort order set ? + aReturn.bEnabled = !sFilter.isEmpty() || !sHaving.isEmpty() || m_xParser->getOrder().getLength(); + } return aReturn; } // no chance without valid models @@ -1705,8 +1711,16 @@ void SbaXDataBrowserController::ExecuteFilterSortCrit(bool bFilter) Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY); - const OUString sOldVal = bFilter ? m_xParser->getFilter() : m_xParser->getOrder(); - const OUString sOldHaving = m_xParser->getHavingClause(); + OUString sOldVal, sOldHaving; + if (bFilter) + { + xFormSet->getPropertyValue(PROPERTY_FILTER) >>= sOldVal; + xFormSet->getPropertyValue(PROPERTY_HAVING_CLAUSE) >>= sOldHaving; + } + else + { + sOldVal = m_xParser->getOrder(); + } Reference< XSingleSelectQueryComposer > xParser = createParser_nothrow(); try {