[Libreoffice-commits] core.git: Branch 'distro/lhm/libreoffice-6-4+backports' - sc/source

Samuel Mehrbrodt (via logerrit) logerrit at kemper.freedesktop.org
Thu Sep 9 08:59:43 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 1007a026ccbee1e5788e463bb0a69cbae051dbf1
Author:     Samuel Mehrbrodt <samuel.mehrbrodt at allotropia.de>
AuthorDate: Thu Aug 26 10:54:23 2021 +0200
Commit:     Thorsten Behrens <thorsten.behrens at allotropia.de>
CommitDate: Thu Sep 9 10:59:11 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>
    (cherry picked from commit 817ef891cf2bef8fdc82852f73acb422afb89bd2)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121709
    Tested-by: Samuel Mehrbrodt <samuel.mehrbrodt at allotropia.de>
    Reviewed-by: Thorsten Behrens <thorsten.behrens at allotropia.de>

diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index 9923e657f247..6acb7a80263a 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>
 
@@ -2417,8 +2419,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 481d74e83f6e..0a50f790d8b6 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -66,6 +66,8 @@
 #include <bcaslot.hxx>
 #include <reordermap.hxx>
 #include <drwlayer.hxx>
+#include <conditio.hxx>
+#include <colorscale.hxx>
 
 #include <svl/sharedstringpool.hxx>
 
@@ -2703,8 +2705,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