include/svl/zforlist.hxx | 7 ++++-- sc/inc/cellform.hxx | 2 - sc/inc/column.hxx | 5 +++- sc/inc/queryentry.hxx | 3 +- sc/inc/table.hxx | 2 - sc/qa/uitest/autofilter/autofilter.py | 15 ++++++++++++++ sc/qa/uitest/data/autofilter/time_value.xlsx |binary sc/source/core/data/column.cxx | 3 +- sc/source/core/data/column3.cxx | 5 ++-- sc/source/core/data/documen3.cxx | 2 - sc/source/core/data/table3.cxx | 13 +++++++----- sc/source/core/tool/cellform.cxx | 4 +-- sc/source/core/tool/queryentry.cxx | 2 - sc/source/ui/unoobj/datauno.cxx | 14 ++++++++++++- sc/source/ui/view/gridwin.cxx | 28 ++++++++++++++++----------- svl/source/numbers/zforlist.cxx | 6 +++-- 16 files changed, 79 insertions(+), 32 deletions(-)
New commits: commit 0e962f0594ec113e9737d82b4d8ff46e7066b1e1 Author: Balazs Varga <balazs.varga...@gmail.com> AuthorDate: Thu Mar 11 14:44:49 2021 +0100 Commit: Gabor Kelemen <kelemen.gab...@nisz.hu> CommitDate: Tue Jun 29 11:39:05 2021 +0200 tdf#140968 tdf#140978 XLSX import: fix lost rounded filters if the stored filter values are in the visible cell format (e.g. rounded values) instead of the original (editing) values. Now AutoFilter popup window shows the items according to the visible cell format (e.g. 1.0 instead of 1.01 or 0.99), but still grouping them based on the "editing format" (e.g. not rounded values which visible during editing), i.e. there could be repeated values in the filtering conditions (e.g. two options "1.0" and "1.0" for 1.01 and 0.99). Note: Next step will be to group and filter based on the actual cell format, like MSO does, to simplify filtering of values rounded by the cell format (e.g. selecting the single AutoFilter condition "1.0" to filter both 1.01 and 0.99). Change-Id: I430da5e09794fc4ed8acf79b6485926f46b70277 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112343 Tested-by: Jenkins Reviewed-by: László Németh <nem...@numbertext.org> (cherry picked from commit 4fd1333ba4bb4f2311e9098291154772bd310429) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118066 Tested-by: Gabor Kelemen <kelemen.gab...@nisz.hu> Reviewed-by: Gabor Kelemen <kelemen.gab...@nisz.hu> diff --git a/include/svl/zforlist.hxx b/include/svl/zforlist.hxx index 2639ac138998..1bca0ceb785b 100644 --- a/include/svl/zforlist.hxx +++ b/include/svl/zforlist.hxx @@ -560,9 +560,12 @@ public: OUString& sOutString, const Color** ppColor, bool bUseStarFormat = false ); /** Format a number according to the standard default format matching - the given format index */ + the given format index. rOutString will be the real cell string (e.g. + a number rounded by the cell format, which rounded value is used + in the filtering condition now), instead of the EditFormat string + (e.g a not rounded value, which is visible during editing).*/ void GetInputLineString( const double& fOutNumber, - sal_uInt32 nFIndex, OUString& rOutString ); + sal_uInt32 nFIndex, OUString& rOutString, bool bFiltering = false ); /** Format a number according to a format code string to be scanned. @return diff --git a/sc/inc/cellform.hxx b/sc/inc/cellform.hxx index a19b61695624..1ee38b669c2a 100644 --- a/sc/inc/cellform.hxx +++ b/sc/inc/cellform.hxx @@ -45,7 +45,7 @@ public: static void GetInputString( const ScRefCellValue& rCell, sal_uInt32 nFormat, OUString& rString, SvNumberFormatter& rFormatter, - const ScDocument& rDoc ); + const ScDocument& rDoc, bool bFiltering = false ); static OUString GetOutputString( ScDocument& rDoc, const ScAddress& rPos, const ScRefCellValue& rCell ); diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx index 3adca3745ec0..ab1605c5365f 100644 --- a/sc/inc/column.hxx +++ b/sc/inc/column.hxx @@ -135,6 +135,8 @@ class ScColumn SCCOL nCol; SCTAB nTab; + bool mbFiltering; // it is true if there is a filtering in the column + friend class ScDocument; // for FillInfo friend class ScTable; friend class ScValueIterator; @@ -182,6 +184,7 @@ public: ScDocument& GetDoc() const { return pAttrArray->GetDoc(); } SCTAB GetTab() const { return nTab; } SCCOL GetCol() const { return nCol; } + bool HasFiltering() const { return mbFiltering; } sc::CellStoreType& GetCellStore() { return maCells; } const sc::CellStoreType& GetCellStore() const { return maCells; } sc::CellTextAttrStoreType& GetCellAttrStore() { return maCellTextAttrs; } @@ -535,7 +538,7 @@ public: void GetFilterEntries( sc::ColumnBlockConstPosition& rBlockPos, SCROW nStartRow, SCROW nEndRow, - ScFilterEntries& rFilterEntries ); + ScFilterEntries& rFilterEntries, bool bFiltering ); bool GetDataEntries( SCROW nRow, std::set<ScTypedStrData>& rStrings, bool bLimit ) const; diff --git a/sc/inc/queryentry.hxx b/sc/inc/queryentry.hxx index f1282e21a5a0..f21b7e94a839 100644 --- a/sc/inc/queryentry.hxx +++ b/sc/inc/queryentry.hxx @@ -40,8 +40,9 @@ struct SC_DLLPUBLIC ScQueryEntry double mfVal; svl::SharedString maString; bool mbMatchEmpty; + bool mbFormattedValue; - Item() : meType(ByValue), mfVal(0.0), mbMatchEmpty(false) {} + Item() : meType(ByValue), mfVal(0.0), mbMatchEmpty(false), mbFormattedValue(false) {} bool operator== (const Item& r) const; }; diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index 4a02a53f8b88..519fb6c860ef 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -954,7 +954,7 @@ public: bool CreateQueryParam(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, ScQueryParam& rQueryParam); void GetFilterEntries(SCCOL nCol, SCROW nRow1, SCROW nRow2, ScFilterEntries& rFilterEntries ); - void GetFilteredFilterEntries(SCCOL nCol, SCROW nRow1, SCROW nRow2, const ScQueryParam& rParam, ScFilterEntries& rFilterEntries ); + void GetFilteredFilterEntries(SCCOL nCol, SCROW nRow1, SCROW nRow2, const ScQueryParam& rParam, ScFilterEntries& rFilterEntries, bool bFiltering ); [[nodiscard]] bool GetDataEntries(SCCOL nCol, SCROW nRow, std::set<ScTypedStrData>& rStrings, bool bLimit); diff --git a/sc/qa/uitest/autofilter/autofilter.py b/sc/qa/uitest/autofilter/autofilter.py index 18bb9105bb87..c3664f57cafc 100644 --- a/sc/qa/uitest/autofilter/autofilter.py +++ b/sc/qa/uitest/autofilter/autofilter.py @@ -297,5 +297,20 @@ class AutofilterTest(UITestCase): xOkBtn = xFloatWindow.getChild("cancel") xOkBtn.executeAction("CLICK", tuple()) + self.ui_test.close_doc() + + def test_time_value(self): + doc = self.ui_test.load_file(get_url_for_data_file("time_value.xlsx")) + + xGridWin = self.xUITest.getTopFocusWindow().getChild("grid_window") + + xGridWin.executeAction("LAUNCH", mkPropertyValues({"AUTOFILTER": "", "COL": "1", "ROW": "0"})) + xFloatWindow = self.xUITest.getFloatWindow() + xCheckListMenu = xFloatWindow.getChild("check_list_menu") + xTreeList = xCheckListMenu.getChild("check_list_box") + self.assertEqual(2, len(xTreeList.getChildren())) + xOkBtn = xFloatWindow.getChild("cancel") + xOkBtn.executeAction("CLICK", tuple()) + self.ui_test.close_doc() # vim: set shiftwidth=4 softtabstop=4 expandtab: diff --git a/sc/qa/uitest/data/autofilter/time_value.xlsx b/sc/qa/uitest/data/autofilter/time_value.xlsx new file mode 100644 index 000000000000..4dc6cf85eb2e Binary files /dev/null and b/sc/qa/uitest/data/autofilter/time_value.xlsx differ diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx index 791352304533..cf8231d4eca7 100644 --- a/sc/source/core/data/column.cxx +++ b/sc/source/core/data/column.cxx @@ -85,7 +85,8 @@ ScColumn::ScColumn(ScSheetLimits const & rSheetLimits) : maCells(maCellsEvent), mnBlkCountFormula(0), nCol( 0 ), - nTab( 0 ) + nTab( 0 ), + mbFiltering( false ) { maCells.resize(rSheetLimits.GetMaxRowCount()); } diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx index 8a457be7ea00..651425dbe048 100644 --- a/sc/source/core/data/column3.cxx +++ b/sc/source/core/data/column3.cxx @@ -2421,7 +2421,7 @@ class FilterEntriesHandler SvNumberFormatter* pFormatter = mrColumn.GetDoc().GetFormatTable(); OUString aStr; sal_uLong nFormat = mrColumn.GetNumberFormat(mrColumn.GetDoc().GetNonThreadedContext(), nRow); - ScCellFormat::GetInputString(rCell, nFormat, aStr, *pFormatter, mrColumn.GetDoc()); + ScCellFormat::GetInputString(rCell, nFormat, aStr, *pFormatter, mrColumn.GetDoc(), mrColumn.HasFiltering()); if (rCell.hasString()) { @@ -2533,8 +2533,9 @@ public: void ScColumn::GetFilterEntries( sc::ColumnBlockConstPosition& rBlockPos, SCROW nStartRow, SCROW nEndRow, - ScFilterEntries& rFilterEntries ) + ScFilterEntries& rFilterEntries, bool bFiltering ) { + mbFiltering = bFiltering; FilterEntriesHandler aFunc(*this, rFilterEntries); rBlockPos.miCellPos = sc::ParseAll(rBlockPos.miCellPos, maCells, nStartRow, nEndRow, aFunc, aFunc); diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx index 4291a2b6e03c..9d9fcc110ed8 100644 --- a/sc/source/core/data/documen3.cxx +++ b/sc/source/core/data/documen3.cxx @@ -1582,7 +1582,7 @@ void ScDocument::GetFilterEntries( if ( bFilter ) { - maTabs[nTab]->GetFilteredFilterEntries( nCol, nStartRow, nEndRow, aParam, rFilterEntries ); + maTabs[nTab]->GetFilteredFilterEntries( nCol, nStartRow, nEndRow, aParam, rFilterEntries, bFilter ); } else { diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx index fe2c2785d8f4..58a0594f63b8 100644 --- a/sc/source/core/data/table3.cxx +++ b/sc/source/core/data/table3.cxx @@ -2418,7 +2418,7 @@ public: } std::pair<bool,bool> compareByString( - ScRefCellValue& rCell, SCROW nRow, const ScQueryEntry& rEntry, const ScQueryEntry::Item& rItem, + const ScRefCellValue& rCell, SCROW nRow, const ScQueryEntry& rEntry, const ScQueryEntry::Item& rItem, const ScInterpreterContext* pContext) { if (!rCell.isEmpty()) @@ -2439,7 +2439,7 @@ public: mrTab.GetNumberFormat( static_cast<SCCOL>(rEntry.nField), nRow ); OUString aStr; SvNumberFormatter* pFormatter = pContext ? pContext->GetFormatTable() : mrDoc.GetFormatTable(); - ScCellFormat::GetInputString(rCell, nFormat, aStr, *pFormatter, mrDoc); + ScCellFormat::GetInputString(rCell, nFormat, aStr, *pFormatter, mrDoc, rEntry.bDoQuery); return compareByStringComparator(rEntry, rItem, nullptr, &aStr); } } @@ -3016,6 +3016,9 @@ public: if (rItem.meType != ScQueryEntry::ByString && rItem.meType != ScQueryEntry::ByDate) return; + if (rItem.mbFormattedValue) + return; + sal_uInt32 nIndex = 0; bool bNumber = mrDoc.GetFormatTable()-> IsNumberFormat(rItem.maString.getString(), nIndex, rItem.mfVal); @@ -3507,11 +3510,11 @@ void ScTable::GetFilterEntries( SCCOL nCol, SCROW nRow1, SCROW nRow2, ScFilterEn { sc::ColumnBlockConstPosition aBlockPos; aCol[nCol].InitBlockPosition(aBlockPos); - aCol[nCol].GetFilterEntries(aBlockPos, nRow1, nRow2, rFilterEntries); + aCol[nCol].GetFilterEntries(aBlockPos, nRow1, nRow2, rFilterEntries, false); } void ScTable::GetFilteredFilterEntries( - SCCOL nCol, SCROW nRow1, SCROW nRow2, const ScQueryParam& rParam, ScFilterEntries& rFilterEntries ) + SCCOL nCol, SCROW nRow1, SCROW nRow2, const ScQueryParam& rParam, ScFilterEntries& rFilterEntries, bool bFiltering ) { sc::ColumnBlockConstPosition aBlockPos; aCol[nCol].InitBlockPosition(aBlockPos); @@ -3525,7 +3528,7 @@ void ScTable::GetFilteredFilterEntries( { if (ValidQuery(j, aParam)) { - aCol[nCol].GetFilterEntries(aBlockPos, j, j, rFilterEntries); + aCol[nCol].GetFilterEntries(aBlockPos, j, j, rFilterEntries, bFiltering); } } } diff --git a/sc/source/core/tool/cellform.cxx b/sc/source/core/tool/cellform.cxx index 315bc9ca2a2a..abc13f254677 100644 --- a/sc/source/core/tool/cellform.cxx +++ b/sc/source/core/tool/cellform.cxx @@ -118,7 +118,7 @@ OUString ScCellFormat::GetString( } void ScCellFormat::GetInputString( - const ScRefCellValue& rCell, sal_uInt32 nFormat, OUString& rString, SvNumberFormatter& rFormatter, const ScDocument& rDoc ) + const ScRefCellValue& rCell, sal_uInt32 nFormat, OUString& rString, SvNumberFormatter& rFormatter, const ScDocument& rDoc, bool bFiltering ) { switch (rCell.meType) { @@ -127,7 +127,7 @@ void ScCellFormat::GetInputString( rString = rCell.getString(&rDoc); break; case CELLTYPE_VALUE: - rFormatter.GetInputLineString(rCell.mfValue, nFormat, rString ); + rFormatter.GetInputLineString(rCell.mfValue, nFormat, rString, bFiltering); break; case CELLTYPE_FORMULA: { diff --git a/sc/source/core/tool/queryentry.cxx b/sc/source/core/tool/queryentry.cxx index 1c4326c47b29..a295759e0c3c 100644 --- a/sc/source/core/tool/queryentry.cxx +++ b/sc/source/core/tool/queryentry.cxx @@ -32,7 +32,7 @@ bool ScQueryEntry::Item::operator== (const Item& r) const { - return meType == r.meType && mfVal == r.mfVal && maString == r.maString && mbMatchEmpty == r.mbMatchEmpty; + return meType == r.meType && mfVal == r.mfVal && maString == r.maString && mbMatchEmpty == r.mbMatchEmpty && mbFormattedValue == r.mbFormattedValue; } ScQueryEntry::ScQueryEntry() : diff --git a/sc/source/ui/unoobj/datauno.cxx b/sc/source/ui/unoobj/datauno.cxx index 531cc27eaa0f..2f22b09d857c 100644 --- a/sc/source/ui/unoobj/datauno.cxx +++ b/sc/source/ui/unoobj/datauno.cxx @@ -1128,7 +1128,19 @@ void fillQueryParam( aItem.mfVal = rVal.NumericValue; aItem.maString = rPool.intern(rVal.StringValue); - if (aItem.meType == ScQueryEntry::ByValue) + if (aItem.meType == ScQueryEntry::ByString) + { + sal_uInt32 nIndex = 0; + aItem.mbFormattedValue = true; + bool bNumber = pDoc->GetFormatTable()->IsNumberFormat(rVal.StringValue, nIndex, aItem.mfVal); + if (bNumber) + { + OUString aStr; + pDoc->GetFormatTable()->GetInputLineString(aItem.mfVal, nIndex, aStr); + aItem.maString = rPool.intern(aStr); + } + } + else if (aItem.meType == ScQueryEntry::ByValue) { OUString aStr; pDoc->GetFormatTable()->GetInputLineString(aItem.mfVal, 0, aStr); diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx index d794e1c9bcdb..e15a89ca6e9c 100644 --- a/sc/source/ui/view/gridwin.cxx +++ b/sc/source/ui/view/gridwin.cxx @@ -569,14 +569,18 @@ public: class AddSelectedItemString { - std::unordered_set<OUString>& mrSet; + std::unordered_set<OUString>& mrSetString; + std::unordered_set<double>& mrSetValue; public: - explicit AddSelectedItemString(std::unordered_set<OUString>& r) : - mrSet(r) {} + explicit AddSelectedItemString(std::unordered_set<OUString>& rString, std::unordered_set<double>& rValue) : + mrSetString(rString), mrSetValue(rValue) {} void operator() (const ScQueryEntry::Item& rItem) { - mrSet.insert(rItem.maString.getString()); + if( rItem.meType == ScQueryEntry::QueryType::ByValue ) + mrSetValue.insert(rItem.mfVal); + else + mrSetString.insert(rItem.maString.getString()); } }; @@ -681,13 +685,14 @@ void ScGridWindow::LaunchAutoFilterMenu(SCCOL nCol, SCROW nRow) ScQueryParam aParam; pDBData->GetQueryParam(aParam); std::vector<ScQueryEntry*> aEntries = aParam.FindAllEntriesByField(nCol); - std::unordered_set<OUString> aSelected; + std::unordered_set<OUString> aSelectedString; + std::unordered_set<double> aSelectedValue; for (ScQueryEntry* pEntry : aEntries) { if (pEntry && pEntry->bDoQuery && pEntry->eOp == SC_EQUAL) { ScQueryEntry::QueryItemsType& rItems = pEntry->GetQueryItems(); - std::for_each(rItems.begin(), rItems.end(), AddSelectedItemString(aSelected)); + std::for_each(rItems.begin(), rItems.end(), AddSelectedItemString(aSelectedString, aSelectedValue)); } } @@ -695,14 +700,15 @@ void ScGridWindow::LaunchAutoFilterMenu(SCCOL nCol, SCROW nRow) rControl.setMemberSize(aFilterEntries.size()); for (const auto& rEntry : aFilterEntries) { - const OUString& aVal = rEntry.GetString(); + const OUString& aStringVal = rEntry.GetString(); + const double aDoubleVal = rEntry.GetValue(); bool bSelected = true; - if (!aSelected.empty()) - bSelected = aSelected.count(aVal) > 0; + if (!aSelectedValue.empty() || !aSelectedString.empty()) + bSelected = aSelectedValue.count(aDoubleVal) > 0 || aSelectedString.count(aStringVal) > 0; if ( rEntry.IsDate() ) - rControl.addDateMember( aVal, rEntry.GetValue(), bSelected ); + rControl.addDateMember( aStringVal, rEntry.GetValue(), bSelected ); else - rControl.addMember(aVal, bSelected); + rControl.addMember(aStringVal, bSelected); } // Populate the menu. diff --git a/svl/source/numbers/zforlist.cxx b/svl/source/numbers/zforlist.cxx index cced64f86d8c..e288453fd270 100644 --- a/svl/source/numbers/zforlist.cxx +++ b/svl/source/numbers/zforlist.cxx @@ -1589,7 +1589,8 @@ sal_uInt32 SvNumberFormatter::GetEditFormat( double fNumber, sal_uInt32 nFIndex, void SvNumberFormatter::GetInputLineString(const double& fOutNumber, sal_uInt32 nFIndex, - OUString& sOutString) + OUString& sOutString, + bool bFiltering) { ::osl::MutexGuard aGuard( GetInstanceMutex() ); const Color* pColor; @@ -1630,7 +1631,8 @@ void SvNumberFormatter::GetInputLineString(const double& fOutNumber, } sal_uInt32 nKey = GetEditFormat( fOutNumber, nRealKey, eType, eLang, pFormat); - if ( nKey != nRealKey ) + // if bFiltering true keep the nRealKey format + if ( nKey != nRealKey && !bFiltering ) { pFormat = GetFormatEntry( nKey ); } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits