tdf#142579 Consider color scale background colors in color filter

When using a color scale in conditional formatting, the color from the color
scale overrides the cell background color.
Consider this in the color filter.

Change-Id: Ifbefedbf1152165b65f8fbc3eeff29ffccf29898
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121074
Tested-by: Jenkins
Reviewed-by: Samuel Mehrbrodt <samuel.mehrbrodt@allotropia.de>
Signed-off-by: Xisco Fauli <xiscofauli@libreoffice.org>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122465
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index 49c6460..905fa65a 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -44,6 +44,8 @@
#include <sharedformula.hxx>
#include <listenercontext.hxx>
#include <filterentries.hxx>
#include <conditio.hxx>
#include <colorscale.hxx>
#include <editeng/brushitem.hxx>
#include <editeng/colritem.hxx>

@@ -2436,8 +2438,31 @@ class FilterEntriesHandler
        if (textColor != COL_AUTO)
            mrFilterEntries.addTextColor(textColor);

        const SvxBrushItem* pBrush = rColumn.GetDoc().GetAttr(aPos, ATTR_BACKGROUND);
        Color backgroundColor = pBrush->GetColor();
        // Background color can be set via conditional formatting - check that first
        Color backgroundColor;
        bool bHasConditionalColor = false;
        ScConditionalFormat* pCondFormat
            = rColumn.GetDoc().GetCondFormat(aPos.Col(), aPos.Row(), aPos.Tab());
        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);
                    backgroundColor = *(pColFormat->GetColor(aPos));
                    bHasConditionalColor = true;
                }
            }
        }

        if (!bHasConditionalColor)
        {
            const SvxBrushItem* pBrush = rColumn.GetDoc().GetAttr(aPos, ATTR_BACKGROUND);
            backgroundColor = pBrush->GetColor();
        }
        if (backgroundColor != COL_AUTO)
            mrFilterEntries.addBackgroundColor(backgroundColor);

diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index 5caea55..d41c53a 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -67,6 +67,8 @@
#include <bcaslot.hxx>
#include <reordermap.hxx>
#include <drwlayer.hxx>
#include <conditio.hxx>
#include <colorscale.hxx>

#include <svl/sharedstringpool.hxx>

@@ -2827,8 +2829,31 @@ public:
                                                   const ScQueryEntry::Item& rItem)
    {
        ScAddress aPos(nCol, nRow, nTab);
        const SvxBrushItem* pBrush = mrDoc.GetAttr(aPos, ATTR_BACKGROUND);
        Color color = pBrush->GetColor();
        Color color;
        // Background color can be set via conditional formatting - check that first
        ScConditionalFormat* pCondFormat = mrDoc.GetCondFormat(nCol, nRow, nTab);
        bool bHasConditionalColor = false;
        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);
    }