sc/qa/unit/data/ods/pivottable_restore_query_filter.ods |binary sc/qa/unit/pivottable_filters_test.cxx | 41 ++++++++++++++++ sc/source/filter/xml/xmlfilti.cxx | 2 3 files changed, 42 insertions(+), 1 deletion(-)
New commits: commit 26e3bfa02c4d582fd430171d509fa570ca364d35 Author: Chenxiong Qi <qcxh...@gmail.com> AuthorDate: Sat Aug 27 16:00:19 2022 +0800 Commit: Hossein <hoss...@libreoffice.org> CommitDate: Mon Sep 5 11:42:29 2022 +0200 tdf#73845 restore Empty and NonEmpty query filter after FILEOPEN Signed-off-by: Chenxiong Qi <qcxh...@gmail.com> Change-Id: I659e0d97c44bf189f457ca04eb49248121278c10 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138919 Tested-by: Jenkins Reviewed-by: Hossein <hoss...@libreoffice.org> diff --git a/sc/qa/unit/data/ods/pivottable_restore_query_filter.ods b/sc/qa/unit/data/ods/pivottable_restore_query_filter.ods new file mode 100644 index 000000000000..7eb038646fa6 Binary files /dev/null and b/sc/qa/unit/data/ods/pivottable_restore_query_filter.ods differ diff --git a/sc/qa/unit/pivottable_filters_test.cxx b/sc/qa/unit/pivottable_filters_test.cxx index f0e5d5a8b830..69a1d4a3b7f0 100644 --- a/sc/qa/unit/pivottable_filters_test.cxx +++ b/sc/qa/unit/pivottable_filters_test.cxx @@ -25,6 +25,9 @@ #include <dpshttab.hxx> #include <globstr.hrc> #include <scresid.hxx> +#include <queryentry.hxx> +#include <queryparam.hxx> +#include <rtl/string.hxx> #include <test/xmltesttools.hxx> #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp> @@ -96,6 +99,7 @@ public: void testTdf125046(); void testTdf125055(); void testTdf125086(); + void testTdf73845(); CPPUNIT_TEST_SUITE(ScPivotTableFiltersTest); @@ -149,6 +153,7 @@ public: CPPUNIT_TEST(testTdf125046); CPPUNIT_TEST(testTdf125055); CPPUNIT_TEST(testTdf125086); + CPPUNIT_TEST(testTdf73845); CPPUNIT_TEST_SUITE_END(); @@ -2743,6 +2748,42 @@ void ScPivotTableFiltersTest::testTdf125086() assertXPath(pDoc, "/x:pivotTableDefinition/x:pivotFields/x:pivotField[2]", "dataField", "1"); } +void ScPivotTableFiltersTest::testTdf73845() +{ + // Query filter is set for individual pivot table in this ODS document. + // This test checks the query filter is restored for ByEmpty and ByNonEmpty query. + ScDocShellRef xDocSh = loadDoc(u"pivottable_restore_query_filter.", FORMAT_ODS); + ScDocument& rDoc = xDocSh->GetDocument(); + ScDPCollection* pDPs = rDoc.GetDPCollection(); + CPPUNIT_ASSERT_MESSAGE("Failed to get a live ScDPCollection instance.", pDPs); + + // Three pivot tables are created in the spreadsheet. Query filters are set as follow: + // pivot table 0: Confirmed Date = Not Empty + // pivot table 1: Confirmed Date = Empty + // pivot table 2: Category > C1 AND Confirmed Date = Not Empty + // + // Following assertions check the Confirmed Date is restored properly + // after file is opened again. + const SCCOLROW nConfirmedDateCol = SCCOLROW(2); + size_t nDPCount = pDPs->GetCount(); + for (size_t i = 0; i < nDPCount; i++) + { + ScDPObject& pDPObj = (*pDPs)[i]; + ScQueryParam aQueryParam(pDPObj.GetSheetDesc()->GetQueryParam()); + size_t nEntriesCount = aQueryParam.GetEntryCount(); + for (size_t j = 0; j < nEntriesCount; j++) + { + ScQueryEntry rEntry = aQueryParam.GetEntry(j); + if (rEntry.IsQueryByEmpty() || rEntry.IsQueryByNonEmpty()) + { + const OString msg = "Query entry " + OString::number(j) + " on pivot table " + + OString::number(i) + " is not restored."; + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.getStr(), nConfirmedDateCol, rEntry.nField); + } + } + } +} + CPPUNIT_TEST_SUITE_REGISTRATION(ScPivotTableFiltersTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sc/source/filter/xml/xmlfilti.cxx b/sc/source/filter/xml/xmlfilti.cxx index 20a89d5763ec..e549a3438d78 100644 --- a/sc/source/filter/xml/xmlfilti.cxx +++ b/sc/source/filter/xml/xmlfilti.cxx @@ -745,6 +745,7 @@ void ScXMLDPConditionContext::getOperatorXML( void SAL_CALL ScXMLDPConditionContext::endFastElement( sal_Int32 /*nElement*/ ) { ScQueryEntry aFilterField; + aFilterField.nField = nField; if (pFilterContext->GetConnection()) aFilterField.eConnect = SC_OR; else @@ -759,7 +760,6 @@ void SAL_CALL ScXMLDPConditionContext::endFastElement( sal_Int32 /*nElement*/ ) utl::SearchParam::SearchType eSearchType = utl::SearchParam::SearchType::Normal; getOperatorXML(sOperator, aFilterField.eOp, eSearchType); pFilterContext->SetSearchType(eSearchType); - aFilterField.nField = nField; ScQueryEntry::Item& rItem = aFilterField.GetQueryItem(); svl::SharedStringPool& rPool = GetScImport().GetDocument()->GetSharedStringPool();