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

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


 sc/source/core/data/column3.cxx |   34 +++++++++++++++++++++++++++-------
 sc/source/core/data/table3.cxx  |   24 ++++++++++++++++++++++--
 2 files changed, 49 insertions(+), 9 deletions(-)

New commits:
commit 0f5edf0899962bc696cd1c40646c8d4b5add2208
Author:     Samuel Mehrbrodt <samuel.mehrbrodt at allotropia.de>
AuthorDate: Mon Aug 30 16:01:02 2021 +0200
Commit:     Samuel Mehrbrodt <samuel.mehrbrodt at allotropia.de>
CommitDate: Mon Sep 6 09:39:42 2021 +0200

    tdf#142580 Consider cond. format text colors in color filter
    
    When using a conditional style to override the text color in conditional formatting,
    the color from the style overrides directly applied text color.
    Consider this in the color filter.
    
    Change-Id: Ieaa1c475d87866de1e2d497127be9d06d1f3d3f1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121311
    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 0b9970e9b6c3..240832316ec5 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -46,6 +46,7 @@
 #include <filterentries.hxx>
 #include <conditio.hxx>
 #include <colorscale.hxx>
+#include <stlpool.hxx>
 #include <editeng/brushitem.hxx>
 #include <editeng/colritem.hxx>
 
@@ -2434,13 +2435,33 @@ class FilterEntriesHandler
 
         // Colors
         ScAddress aPos(rColumn.GetCol(), nRow, rColumn.GetTab());
-        const SvxColorItem* pColor = rColumn.GetDoc().GetAttr(aPos, ATTR_FONT_COLOR);
-        Color textColor = pColor->GetValue();
+
+        // Text color
+        Color textColor;
+        bool bHasConditionalTextColor = false;
+        const ScPatternAttr* pPattern
+            = mrColumn.GetDoc().GetPattern(aPos.Col(), aPos.Row(), aPos.Tab());
+        if (pPattern)
+        {
+            if (!pPattern->GetItem(ATTR_CONDITIONAL).GetCondFormatData().empty())
+            {
+                const SfxItemSet* pCondSet
+                    = mrColumn.GetDoc().GetCondResult(aPos.Col(), aPos.Row(), aPos.Tab());
+                const SvxColorItem* pColor = &pPattern->GetItem(ATTR_FONT_COLOR, pCondSet);
+                textColor = pColor->GetValue();
+                bHasConditionalTextColor = true;
+            }
+        }
+        if (!bHasConditionalTextColor)
+        {
+            const SvxColorItem* pColor = rColumn.GetDoc().GetAttr(aPos, ATTR_FONT_COLOR);
+            textColor = pColor->GetValue();
+        }
         mrFilterEntries.addTextColor(textColor);
 
-        // Background color can be set via conditional formatting - check that first
+        // Background color
         Color backgroundColor;
-        bool bHasConditionalColor = false;
+        bool bHasConditionalBackgroundColor = false;
         ScConditionalFormat* pCondFormat
             = rColumn.GetDoc().GetCondFormat(aPos.Col(), aPos.Row(), aPos.Tab());
         if (pCondFormat)
@@ -2453,12 +2474,11 @@ class FilterEntriesHandler
                     const ScColorScaleFormat* pColFormat
                         = static_cast<const ScColorScaleFormat*>(aEntry);
                     backgroundColor = *(pColFormat->GetColor(aPos));
-                    bHasConditionalColor = true;
+                    bHasConditionalBackgroundColor = true;
                 }
             }
         }
-
-        if (!bHasConditionalColor)
+        if (!bHasConditionalBackgroundColor)
         {
             const SvxBrushItem* pBrush = rColumn.GetDoc().GetAttr(aPos, ATTR_BACKGROUND);
             backgroundColor = pBrush->GetColor();
diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index 55df23457c77..a0d62f6eaff6 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -2707,8 +2707,28 @@ public:
                                              const ScQueryEntry::Item& rItem)
     {
         ScAddress aPos(nCol, nRow, nTab);
-        const SvxColorItem* pColor = mrDoc.GetAttr(aPos, ATTR_FONT_COLOR);
-        Color color = pColor->GetValue();
+        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);
     }


More information about the Libreoffice-commits mailing list