summaryrefslogtreecommitdiff
path: root/sc/source/core/data/table3.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'sc/source/core/data/table3.cxx')
-rw-r--r--sc/source/core/data/table3.cxx103
1 files changed, 102 insertions, 1 deletions
diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index c27c73fb88e1..3372b8aac247 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -19,6 +19,8 @@
#include <comphelper/processfactory.hxx>
#include <comphelper/random.hxx>
+#include <editeng/brushitem.hxx>
+#include <editeng/colritem.hxx>
#include <unotools/textsearch.hxx>
#include <svl/zforlist.hxx>
#include <svl/zformat.hxx>
@@ -64,6 +66,8 @@
#include <bcaslot.hxx>
#include <reordermap.hxx>
#include <drwlayer.hxx>
+#include <conditio.hxx>
+#include <colorscale.hxx>
#include <svl/sharedstringpool.hxx>
@@ -2687,6 +2691,83 @@ public:
return std::pair<bool,bool>(bOk, bTestEqual);
}
+ std::pair<bool, bool> compareByTextColor(SCCOL nCol, SCROW nRow, SCTAB nTab,
+ const ScQueryEntry::Item& rItem)
+ {
+ ScAddress aPos(nCol, nRow, nTab);
+ Color color;
+ bool bHasConditionalColor = false;
+ // Text color can be set via conditional formatting - check that first
+ const ScPatternAttr* pPattern = mrDoc.GetPattern(nCol, nRow, nTab);
+ if (pPattern)
+ {
+ if (!pPattern->GetItem(ATTR_CONDITIONAL).GetCondFormatData().empty())
+ {
+ const SfxItemSet* pCondSet
+ = mrDoc.GetCondResult(nCol, nRow, nTab);
+ const SvxColorItem* pColor = &pPattern->GetItem(ATTR_FONT_COLOR, pCondSet);
+ color = pColor->GetValue();
+ bHasConditionalColor = true;
+ }
+ }
+
+ if (!bHasConditionalColor)
+ {
+ const SvxColorItem* pColor = mrDoc.GetAttr(aPos, ATTR_FONT_COLOR);
+ color = pColor->GetValue();
+ }
+
+ bool bMatch = rItem.maColor == color;
+ return std::pair<bool, bool>(bMatch, false);
+ }
+
+ std::pair<bool, bool> compareByBackgroundColor(SCCOL nCol, SCROW nRow, SCTAB nTab,
+ const ScQueryEntry::Item& rItem)
+ {
+ ScAddress aPos(nCol, nRow, nTab);
+ Color color;
+
+ // Background color can be set via conditional formatting - check that first
+ bool bHasConditionalColor = false;
+ const ScPatternAttr* pPattern = mrDoc.GetPattern(nCol, nRow, nTab);
+ if (pPattern)
+ {
+ if (!pPattern->GetItem(ATTR_CONDITIONAL).GetCondFormatData().empty())
+ {
+ const SfxItemSet* pCondSet
+ = mrDoc.GetCondResult(nCol, nRow, nTab);
+ const SvxBrushItem* pBackgroundColor = &pPattern->GetItem(ATTR_BACKGROUND, pCondSet);
+ color = pBackgroundColor->GetColor();
+ bHasConditionalColor = true;
+ }
+ }
+
+ ScConditionalFormat* pCondFormat = mrDoc.GetCondFormat(nCol, nRow, nTab);
+ if (pCondFormat)
+ {
+ for (size_t i = 0; i < pCondFormat->size(); i++)
+ {
+ auto aEntry = pCondFormat->GetEntry(i);
+ if (aEntry->GetType() == ScFormatEntry::Type::Colorscale)
+ {
+ const ScColorScaleFormat* pColFormat
+ = static_cast<const ScColorScaleFormat*>(aEntry);
+ color = *(pColFormat->GetColor(aPos));
+ bHasConditionalColor = true;
+ }
+ }
+ }
+
+ if (!bHasConditionalColor)
+ {
+ const SvxBrushItem* pBrush = mrDoc.GetAttr(aPos, ATTR_BACKGROUND);
+ color = pBrush->GetColor();
+ }
+
+ bool bMatch = rItem.maColor == color;
+ return std::pair<bool, bool>(bMatch, false);
+ }
+
// To be called only if both isQueryByValue() and isQueryByString()
// returned false and range lookup is wanted! In range lookup comparison
// numbers are less than strings. Nothing else is compared.
@@ -2787,7 +2868,21 @@ bool ScTable::ValidQuery(
{
for (const auto& rItem : rItems)
{
- if (aEval.isQueryByValue(rItem, nCol, nRow, aCell))
+ if (rItem.meType == ScQueryEntry::ByTextColor)
+ {
+ std::pair<bool, bool> aThisRes
+ = aEval.compareByTextColor(nCol, nRow, nTab, rItem);
+ aRes.first |= aThisRes.first;
+ aRes.second |= aThisRes.second;
+ }
+ else if (rItem.meType == ScQueryEntry::ByBackgroundColor)
+ {
+ std::pair<bool,bool> aThisRes =
+ aEval.compareByBackgroundColor(nCol, nRow, nTab, rItem);
+ aRes.first |= aThisRes.first;
+ aRes.second |= aThisRes.second;
+ }
+ else if (aEval.isQueryByValue(rItem, nCol, nRow, aCell))
{
std::pair<bool,bool> aThisRes =
aEval.compareByValue(aCell, nCol, nRow, rEntry, rItem, pContext);
@@ -3452,6 +3547,9 @@ bool ScTable::HasRowHeader( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCR
void ScTable::GetFilterEntries( SCCOL nCol, SCROW nRow1, SCROW nRow2, ScFilterEntries& rFilterEntries )
{
+ if (nCol >= aCol.size())
+ return;
+
sc::ColumnBlockConstPosition aBlockPos;
aCol[nCol].InitBlockPosition(aBlockPos);
aCol[nCol].GetFilterEntries(aBlockPos, nRow1, nRow2, rFilterEntries);
@@ -3460,6 +3558,9 @@ void ScTable::GetFilterEntries( SCCOL nCol, SCROW nRow1, SCROW nRow2, ScFilterEn
void ScTable::GetFilteredFilterEntries(
SCCOL nCol, SCROW nRow1, SCROW nRow2, const ScQueryParam& rParam, ScFilterEntries& rFilterEntries )
{
+ if (nCol >= aCol.size())
+ return;
+
sc::ColumnBlockConstPosition aBlockPos;
aCol[nCol].InitBlockPosition(aBlockPos);