sc/source/core/data/column3.cxx |   29 +++++++++++++++++++++++++++--
 sc/source/core/data/table3.cxx  |   29 +++++++++++++++++++++++++++--
 2 files changed, 54 insertions(+), 4 deletions(-)

New commits:
commit 63b004d4cab295c708686989869c9033ec91e449
Author:     Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de>
AuthorDate: Thu Aug 26 10:54:23 2021 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Fri Sep 24 14:20:28 2021 +0200

    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.mehrbr...@allotropia.de>
    Signed-off-by: Xisco Fauli <xiscofa...@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 49c646073e27..905fa65a0f08 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 5caea5500fda..d41c53a08532 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);
     }

Reply via email to