From e9c04fdc6d91a152c9197bda3b07316bed1dc4f3 Mon Sep 17 00:00:00 2001 From: scito Date: Fri, 3 Apr 2020 16:13:42 +0200 Subject: tdf#130770 apply autofilter to data regardless of autofilter changes Add a unit test Apply autofilter to data if there are no changes from the user for AutoFilterMode::Normal mode The condition eMode == AutoFilterMode::Normal at that position is equivalent to eMode != AutoFilterMode::Top10 && eMode != AutoFilterMode::Empty && eMode != AutoFilterMode::NonEmpty because - Top10: Excluded in if() - Custom: Already handled before - Empty: Excluded in if() - NonEmpty: Excluded in if() - SortAscending: Already handled before - SortDescending: Already handled before - Normal: The remaining condition Delete dead code: The condition if (mpAutoFilterPopup->isAllSelected()) will never be true since eMode == AutoFilterMode::Normal && mpAutoFilterPopup->isAllSelected() is excluded in the "outer if condition" !(eMode == AutoFilterMode::Normal && mpAutoFilterPopup->isAllSelected()) Moreover aParam.RemoveAllEntriesByField(rPos.Col()); has already been called before. Change-Id: I1a5362f6edf6d28b3e049977d761cef83897e63e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91645 Tested-by: Jenkins Tested-by: Serge Krot (CIB) Reviewed-by: Serge Krot (CIB) --- sc/source/ui/view/gridwin.cxx | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) (limited to 'sc/source/ui/view') diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx index c7fdb08adbdf..4fcda857a4ca 100644 --- a/sc/source/ui/view/gridwin.cxx +++ b/sc/source/ui/view/gridwin.cxx @@ -800,25 +800,31 @@ void ScGridWindow::UpdateAutoFilterFromMenu(AutoFilterMode eMode) pViewData->GetDispatcher().Execute(SID_FILTER, SfxCallMode::SLOT|SfxCallMode::RECORD); return; } - if (eMode != AutoFilterMode::Top10 - && eMode != AutoFilterMode::Empty - && eMode != AutoFilterMode::NonEmpty) + + ScQueryParam aParam; + pDBData->GetQueryParam(aParam); + + if (eMode == AutoFilterMode::Normal) { - // do not recreate auto-filter rules if there is no any changes from the user + // Do not recreate autofilter rules if there are no changes from the user ScCheckListMenuWindow::ResultType aResult; mpAutoFilterPopup->getResult(aResult); if (aResult == aSaveAutoFilterResult) { - SAL_INFO("sc.ui", "nothing to do when autofilter entries are the same"); + SAL_INFO("sc.ui", "Apply autofilter to data when entries are the same"); + // Apply autofilter to data + ScQueryEntry* pEntry = aParam.FindEntryByField(rPos.Col(), true); + pEntry->bDoQuery = true; + pEntry->nField = rPos.Col(); + pEntry->eConnect = SC_AND; + pEntry->eOp = SC_EQUAL; + pViewData->GetView()->Query(aParam, nullptr, true); return; } } - ScQueryParam aParam; - pDBData->GetQueryParam(aParam); - - // Remove old entries. + // Remove old entries in auto-filter rules aParam.RemoveAllEntriesByField(rPos.Col()); if( !(eMode == AutoFilterMode::Normal && mpAutoFilterPopup->isAllSelected() ) ) @@ -849,19 +855,6 @@ void ScGridWindow::UpdateAutoFilterFromMenu(AutoFilterMode eMode) ScQueryEntry::QueryItemsType& rItems = pEntry->GetQueryItems(); rItems.clear(); std::for_each(aResult.begin(), aResult.end(), AddItemToEntry(rItems, rPool)); - - if (mpAutoFilterPopup->isAllSelected()) - { - // get all strings from the column - std::vector aAllStrings; // case sensitive - pDoc->GetDataEntries(rPos.Col(), rPos.Row(), rPos.Tab(), aAllStrings, true); - - if (rItems.size() == aAllStrings.size() || aAllStrings.empty()) - { - // all selected => Remove filter entries - aParam.RemoveAllEntriesByField(rPos.Col()); - } - } } break; case AutoFilterMode::Top10: -- cgit