summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBalazs Varga <balazs.varga991@gmail.com>2021-02-17 15:20:34 +0100
committerLászló Németh <nemeth@numbertext.org>2021-03-01 16:39:10 +0100
commitf37f159f2e0c7abe45ac7a3eec447f1234ad1662 (patch)
tree5fae50ec3efa6e25783cff95cce12257e102c0a4
parent493a916a3113e877835c9bc7c93faef0d29f9a33 (diff)
tdf#140462 sc ODF import: fix empty autofilter columns
(followed a date type autofilter column) by setting QueryType to ByDate at ODF import. Change-Id: Ie78cb15885dfb1e40c9e8ac993ff79b19fe17993 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111070 Tested-by: László Németh <nemeth@numbertext.org> Reviewed-by: László Németh <nemeth@numbertext.org>
-rw-r--r--sc/inc/document.hxx1
-rw-r--r--sc/inc/table.hxx1
-rw-r--r--sc/qa/uitest/autofilter/autofilter.py31
-rw-r--r--sc/qa/uitest/data/autofilter/tdf140462.odsbin0 -> 12203 bytes
-rw-r--r--sc/source/core/data/documen3.cxx11
-rw-r--r--sc/source/core/data/table3.cxx24
-rw-r--r--sc/source/filter/xml/xmldrani.cxx2
7 files changed, 65 insertions, 5 deletions
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index ae66e0a0fb8e..111956304334 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -2063,6 +2063,7 @@ public:
void Reorder( const sc::ReorderParam& rParam );
+ void PrepareQuery( SCTAB nTab, ScQueryParam& rQueryParam );
SCSIZE Query( SCTAB nTab, const ScQueryParam& rQueryParam, bool bKeepSub );
SC_DLLPUBLIC bool CreateQueryParam( const ScRange& rRange, ScQueryParam& rQueryParam );
void GetUpperCellString(SCCOL nCol, SCROW nRow, SCTAB nTab, OUString& rStr);
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index fed4d4b12388..9e8e6233295a 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -949,6 +949,7 @@ public:
bool* pbTestEqualCondition = nullptr, const ScInterpreterContext* pContext = nullptr,
sc::TableColumnBlockPositionSet* pBlockPos = nullptr );
void TopTenQuery( ScQueryParam& );
+ void PrepareQuery( ScQueryParam& rQueryParam );
SCSIZE Query(const ScQueryParam& rQueryParam, bool bKeepSub);
bool CreateQueryParam(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, ScQueryParam& rQueryParam);
diff --git a/sc/qa/uitest/autofilter/autofilter.py b/sc/qa/uitest/autofilter/autofilter.py
index 1eedfe4b22a7..ca1871ee933c 100644
--- a/sc/qa/uitest/autofilter/autofilter.py
+++ b/sc/qa/uitest/autofilter/autofilter.py
@@ -278,4 +278,35 @@ class AutofilterTest(UITestCase):
xOkBtn.executeAction("CLICK", tuple())
self.ui_test.close_doc()
+
+ def test_tdf140462(self):
+ doc = self.ui_test.load_file(get_url_for_data_file("tdf140462.ods"))
+
+ xGridWin = self.xUITest.getTopFocusWindow().getChild("grid_window")
+
+ xGridWin.executeAction("LAUNCH", mkPropertyValues({"AUTOFILTER": "", "COL": "0", "ROW": "0"}))
+ xFloatWindow = self.xUITest.getFloatWindow()
+ xCheckListMenu = xFloatWindow.getChild("check_list_menu")
+ xTreeList = xCheckListMenu.getChild("check_tree_box")
+ self.assertEqual(3, len(xTreeList.getChildren()))
+ xOkBtn = xFloatWindow.getChild("cancel")
+ xOkBtn.executeAction("CLICK", tuple())
+
+ 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(3, len(xTreeList.getChildren()))
+ xOkBtn = xFloatWindow.getChild("cancel")
+ xOkBtn.executeAction("CLICK", tuple())
+
+ xGridWin.executeAction("LAUNCH", mkPropertyValues({"AUTOFILTER": "", "COL": "2", "ROW": "0"}))
+ xFloatWindow = self.xUITest.getFloatWindow()
+ xCheckListMenu = xFloatWindow.getChild("check_list_menu")
+ xTreeList = xCheckListMenu.getChild("check_list_box")
+ self.assertEqual(4, 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/tdf140462.ods b/sc/qa/uitest/data/autofilter/tdf140462.ods
new file mode 100644
index 000000000000..8fe7ed8a9705
--- /dev/null
+++ b/sc/qa/uitest/data/autofilter/tdf140462.ods
Binary files differ
diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx
index b7ece0dfbc0a..f7dfad201bd2 100644
--- a/sc/source/core/data/documen3.cxx
+++ b/sc/source/core/data/documen3.cxx
@@ -1442,6 +1442,17 @@ void ScDocument::Reorder( const sc::ReorderParam& rParam )
EnableIdle(bOldEnableIdle);
}
+void ScDocument::PrepareQuery( SCTAB nTab, ScQueryParam& rQueryParam )
+{
+ if( ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] )
+ maTabs[nTab]->PrepareQuery(rQueryParam);
+ else
+ {
+ OSL_FAIL("missing tab");
+ return;
+ }
+}
+
SCSIZE ScDocument::Query(SCTAB nTab, const ScQueryParam& rQueryParam, bool bKeepSub)
{
if ( ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] )
diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index b4967a9a31dd..fe2c2785d8f4 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -2978,7 +2978,7 @@ void ScTable::TopTenQuery( ScQueryParam& rParam )
namespace {
-bool CanOptimizeQueryStringToNumber( SvNumberFormatter* pFormatter, sal_uInt32 nFormatIndex )
+bool CanOptimizeQueryStringToNumber( SvNumberFormatter* pFormatter, sal_uInt32 nFormatIndex, bool& bDateFormat )
{
// tdf#105629: ScQueryEntry::ByValue queries are faster than ScQueryEntry::ByString.
// The problem with this optimization is that the autofilter dialog apparently converts
@@ -2994,6 +2994,10 @@ bool CanOptimizeQueryStringToNumber( SvNumberFormatter* pFormatter, sal_uInt32 n
case SvNumFormatType::FRACTION:
case SvNumFormatType::SCIENTIFIC:
return true;
+ case SvNumFormatType::DATE:
+ case SvNumFormatType::DATETIME:
+ bDateFormat = true;
+ break;
default:
break;
}
@@ -3022,9 +3026,11 @@ public:
if (rItem.meType == ScQueryEntry::ByString)
{
- if (bNumber && CanOptimizeQueryStringToNumber( mrDoc.GetFormatTable(), nIndex ))
+ bool bDateFormat = false;
+ if (bNumber && CanOptimizeQueryStringToNumber( mrDoc.GetFormatTable(), nIndex, bDateFormat ))
rItem.meType = ScQueryEntry::ByValue;
- return;
+ if (!bDateFormat)
+ return;
}
// Double-check if the query by date is really appropriate.
@@ -3037,6 +3043,8 @@ public:
SvNumFormatType nNumFmtType = pEntry->GetType();
if (!(nNumFmtType & SvNumFormatType::DATE) || (nNumFmtType & SvNumFormatType::TIME))
rItem.meType = ScQueryEntry::ByValue; // not a date only
+ else
+ rItem.meType = ScQueryEntry::ByDate; // date only
}
else
rItem.meType = ScQueryEntry::ByValue; // what the ... not a date
@@ -3087,6 +3095,11 @@ void lcl_PrepareQuery( const ScDocument* pDoc, ScTable* pTab, ScQueryParam& rPar
}
+void ScTable::PrepareQuery( ScQueryParam& rQueryParam )
+{
+ lcl_PrepareQuery(&rDocument, this, rQueryParam);
+}
+
SCSIZE ScTable::Query(const ScQueryParam& rParamOrg, bool bKeepSub)
{
ScQueryParam aParam( rParamOrg );
@@ -3403,8 +3416,9 @@ bool ScTable::CreateQueryParam(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow
sal_uInt32 nIndex = 0;
bool bNumber = pFormatter->IsNumberFormat(
rItem.maString.getString(), nIndex, rItem.mfVal);
- rItem.meType = bNumber && CanOptimizeQueryStringToNumber( pFormatter, nIndex )
- ? ScQueryEntry::ByValue : ScQueryEntry::ByString;
+ bool bDateFormat = false;
+ rItem.meType = bNumber && CanOptimizeQueryStringToNumber( pFormatter, nIndex, bDateFormat )
+ ? ScQueryEntry::ByValue : (bDateFormat ? ScQueryEntry::ByDate : ScQueryEntry::ByString);
}
}
else
diff --git a/sc/source/filter/xml/xmldrani.cxx b/sc/source/filter/xml/xmldrani.cxx
index 422ea7f30421..756e874f91c7 100644
--- a/sc/source/filter/xml/xmldrani.cxx
+++ b/sc/source/filter/xml/xmldrani.cxx
@@ -254,6 +254,8 @@ std::unique_ptr<ScDBData> ScXMLDatabaseRangeContext::ConvertToDBData(const OUStr
pData->SetDoSize(bMoveCells);
pData->SetStripData(bStripData);
+ pDoc->PrepareQuery(mpQueryParam->nTab, *mpQueryParam);
+
pData->SetQueryParam(*mpQueryParam);
if (bFilterConditionSourceRange)