[gnumeric] CondFormat: recognize equal-style regions with conditional formats.



commit 1651daafd0270423209865ac8ebf4860e601b0c4
Author: Morten Welinder <terra gnome org>
Date:   Thu Jan 19 20:32:19 2017 -0500

    CondFormat: recognize equal-style regions with conditional formats.
    
    We used to compare mstyle->conditions by pointer.  This implements proper
    equality.

 ChangeLog              |    7 ++++++
 NEWS                   |    1 +
 src/mstyle.c           |    6 +++-
 src/style-conditions.c |   51 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/style-conditions.h |    3 ++
 5 files changed, 66 insertions(+), 2 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 3a0cd6d..86f3998 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2017-01-19  Morten Welinder  <terra gnome org>
+
+       * src/mstyle.c (ELEM_IS_EQ): Don't compare conditions by pointer.
+
+       * src/style-conditions.c (gnm_style_conditions_equal): New
+       function.
+
 2016-12-08  Morten Welinder  <terra gnome org>
 
        * src/mathfunc.c (gnm_linear_solve): Use proper matrix type.  All
diff --git a/NEWS b/NEWS
index dfa6001..51d5939 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,7 @@ Morten:
        * Speed up sstest part of test suite.
        * Bring documentation build into the 21 century.
        * Non-linear solver improvements.
+       * Avoid atomizing style regions with conditional formats.
 
 --------------------------------------------------------------------------
 Gnumeric 1.12.32
diff --git a/src/mstyle.c b/src/mstyle.c
index 438dd2d..7a8a120 100644
--- a/src/mstyle.c
+++ b/src/mstyle.c
@@ -393,11 +393,13 @@ gnm_style_hash (gconstpointer style)
     : (elem == MSTYLE_INPUT_MSG                                                \
     ? a->input_msg == b->input_msg                                     \
     : (elem == MSTYLE_CONDITIONS                                       \
-    ? a->conditions == b->conditions                                   \
+    ? (a->conditions == b->conditions ||                               \
+       (a->conditions &&                                               \
+       gnm_style_conditions_equal (a->conditions, b->conditions)))     \
     : FALSE)))))))))))))))))))))))))
 
 /*
- * Note: the above is suboptimal from validation and down.
+ * Note: the above is suboptimal for validation, hlink, input_msg.
  *
  * We are comparing pointers (which at least safely matches what we do
  * with the hash), but I think we want proper equality.
diff --git a/src/style-conditions.c b/src/style-conditions.c
index c849fb6..26c7e9b 100644
--- a/src/style-conditions.c
+++ b/src/style-conditions.c
@@ -764,6 +764,57 @@ gnm_style_conditions_hash (GnmStyleConditions const *sc)
 
 #undef MIX
 
+/**
+ * gnm_style_conditions_equal:
+ * @sca: first #GnmStyleConditions to compare.
+ * @scb: second #GnmStyleConditions to compare.
+ *
+ * Returns: %TRUE if the conditions are equal.
+ **/
+gboolean
+gnm_style_conditions_equal (GnmStyleConditions const *sca,
+                           GnmStyleConditions const *scb)
+{
+       GPtrArray const *ga, *gb;
+       unsigned ui;
+
+       g_return_val_if_fail (sca != NULL, FALSE);
+       g_return_val_if_fail (scb != NULL, FALSE);
+
+       if (sca->sheet != scb->sheet)
+               return FALSE;
+
+       ga = gnm_style_conditions_details (sca);
+       gb = gnm_style_conditions_details (scb);
+       if (!ga || !gb)
+               return ga == gb;
+       if (ga->len != gb->len)
+               return FALSE;
+
+       for (ui = 0; ui < ga->len; ui++) {
+               GnmStyleCond *ca = g_ptr_array_index (ga, ui);
+               GnmStyleCond *cb = g_ptr_array_index (gb, ui);
+               unsigned oi, N;
+
+               if (ca->op != cb->op)
+                       return FALSE;
+
+               if (!gnm_style_equal (ca->overlay, cb->overlay))
+                       return FALSE;
+
+               N = gnm_style_cond_op_operands (ca->op);
+               for (oi = 0; oi < N; oi++) {
+                       if (ca->deps[oi].sheet != cb->deps[oi].sheet)
+                               return FALSE;
+                       if (!gnm_expr_top_equal (ca->deps[oi].texpr,
+                                                cb->deps[oi].texpr))
+                               return FALSE;
+               }
+       }
+
+       return TRUE;
+}
+
 
 /**
  * gnm_style_conditions_get_sheet:
diff --git a/src/style-conditions.h b/src/style-conditions.h
index 4229496..00d588e 100644
--- a/src/style-conditions.h
+++ b/src/style-conditions.h
@@ -84,6 +84,9 @@ void        gnm_style_conditions_set_sheet (GnmStyleConditions *sc,
 
 guint32     gnm_style_conditions_hash      (GnmStyleConditions const *sc);
 
+gboolean    gnm_style_conditions_equal     (GnmStyleConditions const *sca,
+                                           GnmStyleConditions const *scb);
+
 G_END_DECLS
 
 #endif /* _GNM_STYLE_CONDITIONS_H_ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]