[gnumeric] Conditional format: fix problem with updating dependents.



commit fb31af4048e8ce50121d9b44353f7e65eb35346a
Author: Morten Welinder <terra gnome org>
Date:   Sun May 5 19:45:50 2013 -0400

    Conditional format: fix problem with updating dependents.

 ChangeLog              |    5 +++++
 NEWS                   |    1 +
 src/dependent.c        |   28 +++++++++++++++++++++++-----
 src/rendered-value.c   |    5 +++--
 src/style-conditions.c |   27 +++++++++++++++++++++++++--
 5 files changed, 57 insertions(+), 9 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 2acfa41..e15716d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2013-05-05  Morten Welinder  <terra gnome org>
+
+       * src/dependent.c (style_dep_eval): New function.  Re-clear the
+       rendered value here.  Fixes #699647.
+
 2013-05-03  Morten Welinder  <terra gnome org>
 
        * src/wbc-gtk.c (create_undo_redo): Add Ctrl-Shift-z as alternate
diff --git a/NEWS b/NEWS
index e56df01..4e1b4e3 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,7 @@ Morten:
        * Don't write empty cells to .gnumeric.
        * Add MPSEUDOINVERSE function.
        * Add ctrl-shift-z as extra accelerator for redo.  [#699579]
+       * Fix conditional format problem.  [#699647]
 
 --------------------------------------------------------------------------
 Gnumeric 1.12.2
diff --git a/src/dependent.c b/src/dependent.c
index ed9b3b6..e042a92 100644
--- a/src/dependent.c
+++ b/src/dependent.c
@@ -283,11 +283,12 @@ static const GnmDependentClass managed_dep_class = {
        managed_dep_debug_name,
 };
 
+static void style_dep_eval (GnmDependent *dep);
 static GSList *style_dep_changed (GnmDependent *dep);
 static GnmCellPos const *style_dep_pos (GnmDependent const *dep);
 static void style_dep_debug_name (GnmDependent const *dep, GString *target);
 static const GnmDependentClass style_dep_class = {
-       dummy_dep_eval,
+       style_dep_eval,
        NULL,
        style_dep_changed,
        style_dep_pos,
@@ -1339,16 +1340,16 @@ debug_style_deps (void)
        return debug;
 }
 
-static GSList *
-style_dep_changed (GnmDependent *dep)
+static void
+style_dep_unrender (GnmDependent *dep, const char *what)
 {
        GnmCellPos const *pos = dependent_pos (dep);
        GnmCell *cell;
        Sheet *sheet = dep->sheet;
 
        if (debug_style_deps ())
-               g_printerr ("StyleDep %p at %s changed\n",
-                           dep, cellpos_as_string (pos));
+               g_printerr ("StyleDep %p at %s %s\n",
+                           dep, cellpos_as_string (pos), what);
 
        /*
         * If the cell exists, unrender it so format changes can take
@@ -1362,6 +1363,23 @@ style_dep_changed (GnmDependent *dep)
                             pos->col, pos->row,
                             pos->col, pos->row);
 
+
+}
+
+static void
+style_dep_eval (GnmDependent *dep)
+{
+       /*
+        * It is possible that the cell has been rendered between we ::changed
+        * was called.
+        */
+       style_dep_unrender (dep, "being evaluated");
+}
+
+static GSList *
+style_dep_changed (GnmDependent *dep)
+{
+       style_dep_unrender (dep, "changed");
        return NULL;
 }
 
diff --git a/src/rendered-value.c b/src/rendered-value.c
index db45a65..6215cc5 100644
--- a/src/rendered-value.c
+++ b/src/rendered-value.c
@@ -245,11 +245,12 @@ gnm_rendered_value_new (GnmCell const *cell,
                GnmEvalPos ep;
                int res;
                eval_pos_init_cell (&ep, cell);
-               if ((res = gnm_style_conditions_eval (mstyle->conditions, &ep)) >= 0)
+
+               res = gnm_style_conditions_eval (mstyle->conditions, &ep);
+               if (res >= 0)
                        mstyle = g_ptr_array_index (mstyle->cond_styles, res);
        }
 
-
        rotation = gnm_style_get_rotation (mstyle);
        if (rotation) {
                GnmRenderedRotatedValue *rrv;
diff --git a/src/style-conditions.c b/src/style-conditions.c
index 54d905e..328d262 100644
--- a/src/style-conditions.c
+++ b/src/style-conditions.c
@@ -33,6 +33,7 @@
 #include <gsf/gsf-impl-utils.h>
 #include <string.h>
 #include <parse-util.h>
+#include "gutils.h"
 
 #define BLANKS_STRING_FOR_MATCHING " \t\n\r"
 
@@ -45,6 +46,15 @@ struct _GnmStyleConditions {
 
 static GObjectClass *parent_class;
 
+static gboolean
+debug_style_conds (void)
+{
+       static int debug = -1;
+       if (debug < 0)
+               debug = gnm_debug_flag ("style-conds");
+       return debug;
+}
+
 static unsigned
 gnm_style_cond_op_operands (GnmStyleCondOp op)
 {
@@ -485,13 +495,20 @@ gnm_style_conditions_eval (GnmStyleConditions const *sc, GnmEvalPos const *ep)
        GnmParsePos pp;
        GnmCell const *cell = sheet_cell_get (ep->sheet, ep->eval.col, ep->eval.row);
        GnmValue const *cv = cell ? cell->value : NULL;
-       /*We should really assert that cv is not NULL, but asserts are apparently frowned upon.*/
 
        g_return_val_if_fail (sc != NULL, -1);
        g_return_val_if_fail (sc->conditions != NULL, -1);
 
        conds = sc->conditions;
        parse_pos_init_evalpos (&pp, ep);
+
+       if (debug_style_conds ()) {
+               g_printerr ("Evaluating conditions %p at %s with %d clauses\n",
+                           sc,
+                           parsepos_as_string (&pp),
+                           conds->len);
+       }
+
        for (i = 0 ; i < conds->len ; i++) {
                GnmStyleCond const *cond = g_ptr_array_index (conds, i);
 
@@ -583,8 +600,14 @@ gnm_style_conditions_eval (GnmStyleConditions const *sc, GnmEvalPos const *ep)
                        value_release (val);
                }
 
-               if (use_this)
+               if (use_this) {
+                       if (debug_style_conds ())
+                               g_printerr ("  Using clause %d\n", i);
                        return i;
+               }
        }
+
+       if (debug_style_conds ())
+               g_printerr ("  No matching clauses\n");
        return -1;
 }


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