summaryrefslogtreecommitdiff
path: root/sc/source/core
diff options
context:
space:
mode:
authorBalazs Varga <balazs.varga991@gmail.com>2021-04-22 10:23:41 +0200
committerLászló Németh <nemeth@numbertext.org>2021-05-04 10:13:27 +0200
commitd5c2584bf36d21580db677b231c57f99f49aa2cb (patch)
tree1405add4e3e8df04b85f717939631d85ddc18fa1 /sc/source/core
parentd78f9b5cca2415c0d3bc4d081dec19a0ce976cb7 (diff)
Related: tdf#140968 avoid duplicated filter values
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). Followed up of 4fd1333ba4bb4f2311e9098291154772bd310429 (tdf#140968 tdf#140978 XLSX import: fix lost rounded filters) tdf#141916: odf export: Indicating the formatted filter values, by export the XML_DATA_TYPE with XML_TEXT, to avoid bad filtering of formatted filter values. tdf#141775: fix regression of 4fd1333ba4bb4f2311e9098291154772bd310429 (tdf#140968 tdf#140978 XLSX import: fix lost rounded filters) tdf#141915: fix OOXML import of 0.0 filter values of filter conditions by setting it byValue filtering in datauno.cxx. Change-Id: I1c840249ee1ef95aff33a4740b8bf2ebc47f2325 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113314 Tested-by: Jenkins Tested-by: László Németh <nemeth@numbertext.org> Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'sc/source/core')
-rw-r--r--sc/source/core/data/column3.cxx6
-rw-r--r--sc/source/core/tool/typedstrdata.cxx34
2 files changed, 30 insertions, 10 deletions
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index 712595aab369..5fd4a5965586 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -2495,8 +2495,10 @@ class FilterEntriesHandler
sal_uInt32 nIndex = pFormatter->GetFormatIndex(NF_DATETIME_ISO_YYYYMMDD_HHMMSS);
pFormatter->GetInputLineString(fVal, nIndex, aStr);
}
- // maybe extend ScTypedStrData enum is also an option here
- mrFilterEntries.push_back(ScTypedStrData(aStr, fVal, ScTypedStrData::Value,bDate));
+ /* use string compare later for formatted and filtered cell values
+ to avoid duplicates in the filter lists with setting the mbIsFormatted */
+ bool bFormFiltVal = mrColumn.HasFiltering() && nFormat;
+ mrFilterEntries.push_back(ScTypedStrData(aStr, fVal, ScTypedStrData::Value, bDate, bFormFiltVal));
mrFilterEntries.addTextColor(textColor);
mrFilterEntries.addBackgroundColor(backgroundColor);
}
diff --git a/sc/source/core/tool/typedstrdata.cxx b/sc/source/core/tool/typedstrdata.cxx
index a114b280293c..0420b359ab76 100644
--- a/sc/source/core/tool/typedstrdata.cxx
+++ b/sc/source/core/tool/typedstrdata.cxx
@@ -47,14 +47,22 @@ bool ScTypedStrData::EqualCaseSensitive::operator() (const ScTypedStrData& left,
if (left.meStrType != right.meStrType)
return false;
- if (left.meStrType == Value && left.mfValue != right.mfValue)
+ if (left.meStrType == Value && left.mfValue != right.mfValue &&
+ !left.mbIsFormatted)
return false;
if (left.mbIsDate != right.mbIsDate )
return false;
- return ScGlobal::GetCaseCollator()->compareString(
- left.maStrValue, right.maStrValue) == 0;
+ if (ScGlobal::GetCaseCollator()->compareString(
+ left.maStrValue, right.maStrValue) == 0)
+ {
+ // hack: it's possible, because we only compare values of the same filter range
+ const_cast<bool&>(left.mbIsDuplicated) = true;
+ return true;
+ }
+ else
+ return false;
}
bool ScTypedStrData::EqualCaseInsensitive::operator() (const ScTypedStrData& left, const ScTypedStrData& right) const
@@ -62,14 +70,22 @@ bool ScTypedStrData::EqualCaseInsensitive::operator() (const ScTypedStrData& lef
if (left.meStrType != right.meStrType)
return false;
- if (left.meStrType == Value && left.mfValue != right.mfValue)
+ if (left.meStrType == Value && left.mfValue != right.mfValue &&
+ !left.mbIsFormatted)
return false;
if (left.mbIsDate != right.mbIsDate )
return false;
- return ScGlobal::GetCollator()->compareString(
- left.maStrValue, right.maStrValue) == 0;
+ if (ScGlobal::GetCollator()->compareString(
+ left.maStrValue, right.maStrValue) == 0)
+ {
+ // hack: it's possible, because we only compare values of the same filter range
+ const_cast<bool&>(left.mbIsDuplicated) = true;
+ return true;
+ }
+ else
+ return false;
}
bool ScTypedStrData::operator< (const ScTypedStrData& r) const
@@ -79,11 +95,13 @@ bool ScTypedStrData::operator< (const ScTypedStrData& r) const
}
ScTypedStrData::ScTypedStrData(
- const OUString& rStr, double nVal, StringType nType, bool bDate ) :
+ const OUString& rStr, double nVal, StringType nType, bool bDate, bool bFormatted, bool bDuplicated ) :
maStrValue(rStr),
mfValue(nVal),
meStrType(nType),
- mbIsDate( bDate ) {}
+ mbIsDate( bDate ),
+ mbIsFormatted( bFormatted ),
+ mbIsDuplicated( bDuplicated ) {}
FindTypedStrData::FindTypedStrData(const ScTypedStrData& rVal, bool bCaseSens) :
maVal(rVal), mbCaseSens(bCaseSens) {}