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 70845c616706601a3fe3fe35e1b16e2b0ac3df38
Author:     Balazs Varga <balazs.varga...@gmail.com>
AuthorDate: Thu Mar 11 14:44:49 2021 +0100
Commit:     Gabor Kelemen <kelemen.gab...@nisz.hu>
CommitDate: Fri Apr 30 11:42:44 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/+/114864
    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 2cc857b5e6cb..f6e07a420552 100644
--- a/include/svl/zforlist.hxx
+++ b/include/svl/zforlist.hxx
@@ -560,9 +560,12 @@ public:
                           OUString& sOutString, 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 5d7de17f8344..92d1f25c527f 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* pDoc );
+        const ScDocument* pDoc, 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 0eb2ad5f1c85..34625a40e64a 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; }
@@ -534,7 +537,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 46a65b957658..abdd0a0c1ea3 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 218c768ec241..cff9a25bc249 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -950,7 +950,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 b968a06a8f74..7aaec48b29db 100644
--- a/sc/qa/uitest/autofilter/autofilter.py
+++ b/sc/qa/uitest/autofilter/autofilter.py
@@ -188,5 +188,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 61011da9aeae..29e8b4f89e60 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -85,7 +85,8 @@ ScColumn::ScColumn() :
     maCells(maCellsEvent),
     mnBlkCountFormula(0),
     nCol( 0 ),
-    nTab( 0 )
+    nTab( 0 ),
+    mbFiltering( false )
 {
     maCells.resize(MAXROWCOUNT);
 }
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index d8f5c0a4224f..80dba7080e55 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -2418,7 +2418,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())
         {
@@ -2530,8 +2530,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 125bbf82d7f2..fba3774a4a93 100644
--- a/sc/source/core/data/documen3.cxx
+++ b/sc/source/core/data/documen3.cxx
@@ -1581,7 +1581,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 72c1b4bbd8eb..ca0a69f7ff76 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 1fe9b0e69ec7..584495f98f1b 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* pDoc )
+    const ScRefCellValue& rCell, sal_uInt32 nFormat, OUString& rString, 
SvNumberFormatter& rFormatter, const ScDocument* pDoc, bool bFiltering )
 {
     switch (rCell.meType)
     {
@@ -127,7 +127,7 @@ void ScCellFormat::GetInputString(
             rString = rCell.getString(pDoc);
         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 6ebcf0003e9b..465bbd805e03 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 d502f2f65a63..79a55f27843e 100644
--- a/sc/source/ui/unoobj/datauno.cxx
+++ b/sc/source/ui/unoobj/datauno.cxx
@@ -1127,7 +1127,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 6390343c42fe..b7977281400c 100644
--- a/sc/source/ui/view/gridwin.cxx
+++ b/sc/source/ui/view/gridwin.cxx
@@ -606,14 +606,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());
     }
 };
 
@@ -670,13 +674,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));
         }
     }
 
@@ -688,14 +693,15 @@ void ScGridWindow::LaunchAutoFilterMenu(SCCOL nCol, SCROW 
nRow)
     mpAutoFilterPopup->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() )
-            mpAutoFilterPopup->addDateMember( aVal, rEntry.GetValue(), 
bSelected );
+            mpAutoFilterPopup->addDateMember( aStringVal, rEntry.GetValue(), 
bSelected );
         else
-            mpAutoFilterPopup->addMember(aVal, bSelected);
+            mpAutoFilterPopup->addMember(aStringVal, bSelected);
     }
     mpAutoFilterPopup->initMembers();
 
diff --git a/svl/source/numbers/zforlist.cxx b/svl/source/numbers/zforlist.cxx
index 304b36285827..de331a25c813 100644
--- a/svl/source/numbers/zforlist.cxx
+++ b/svl/source/numbers/zforlist.cxx
@@ -1591,7 +1591,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() );
     Color* pColor;
@@ -1632,7 +1633,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

Reply via email to