[Libreoffice-commits] core.git: sc/source

Samuel Mehrbrodt (via logerrit) logerrit at kemper.freedesktop.org
Mon Sep 6 07:39:53 UTC 2021


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

New commits:
commit 817ef891cf2bef8fdc82852f73acb422afb89bd2
Author:     Samuel Mehrbrodt <samuel.mehrbrodt at allotropia.de>
AuthorDate: Thu Aug 26 10:54:23 2021 +0200
Commit:     Samuel Mehrbrodt <samuel.mehrbrodt at allotropia.de>
CommitDate: Mon Sep 6 09:39:19 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.mehrbrodt at allotropia.de>

diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index d6f5c6e749f6..0b9970e9b6c3 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
         Color textColor = pColor->GetValue();
         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();
+        }
         mrFilterEntries.addBackgroundColor(backgroundColor);
 
         if (rCell.hasString())
diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index b3470fc7d286..55df23457c77 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -68,6 +68,8 @@
 #include <bcaslot.hxx>
 #include <reordermap.hxx>
 #include <drwlayer.hxx>
+#include <conditio.hxx>
+#include <colorscale.hxx>
 
 #include <svl/sharedstringpool.hxx>
 
@@ -2715,8 +2717,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);
     }


More information about the Libreoffice-commits mailing list