[gnumeric] Graphs: fix in-place data issues.



commit 0218bc560aadbe26be76ee6910cd67b35a4bba73
Author: Morten Welinder <terra gnome org>
Date:   Fri May 29 22:59:15 2020 -0400

    Graphs: fix in-place data issues.
    
    See #492.

 ChangeLog                    |  9 +++++++++
 NEWS                         |  2 ++
 src/expr.c                   | 27 +++++++++++++++++++++++++++
 src/expr.h                   |  3 +++
 src/graph.c                  | 20 +++++++++++++++++---
 src/widgets/ChangeLog        |  6 ++++++
 src/widgets/gnm-expr-entry.c |  5 ++++-
 7 files changed, 68 insertions(+), 4 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 52d907bf6..01ae83dc5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2020-05-29  Morten Welinder  <terra gnome org>
+
+       * src/expr.c (gnm_expr_top_multiple_as_string): New function.
+
+       * src/graph.c (gnm_go_data_serialize): Use
+       gnm_expr_top_multiple_as_string for vectors.
+       (gnm_go_data_unserialize): Handle "(1,2)" as "1,2" for vectors
+       because we have managed to create files with the former.
+
 2020-05-27  Jean Brefort  <jean brefort normalesup org>
 
        * src/sheet-object.c (sheet_object_set_print_flag): protect against a NULL
diff --git a/NEWS b/NEWS
index 6cc9acf38..ca409ddb5 100644
--- a/NEWS
+++ b/NEWS
@@ -9,10 +9,12 @@ Andreas:
 
 Jean:
        * Fix xlsx object non-import crash.
+       * Fix in-place graph data problem.  [#492]
 
 Morten:
        * Fix performace issue with sample_datasource.  [#491]
        * Fix partial-line issue with sample_datasource.
+       * Fix load of in-place graph data with extra ()s.  [#492]
 
 --------------------------------------------------------------------------
 Gnumeric 1.12.47
diff --git a/src/expr.c b/src/expr.c
index 3df2f32e3..e6e35ffab 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -3098,6 +3098,33 @@ gnm_expr_top_as_string (GnmExprTop const *texpr,
        return gnm_expr_as_string (texpr->expr, pp, convs);
 }
 
+// This differs from gnm_expr_as_string in that a top-level set
+// representing multiple expressions is rendered as a comma-separated
+// list of expressions with no outside parenthesis.
+char *
+gnm_expr_top_multiple_as_string  (GnmExprTop const *texpr,
+                                 GnmParsePos const *pp,
+                                 GnmConventions const *convs)
+{
+       char *res;
+
+       g_return_val_if_fail (GNM_IS_EXPR_TOP (texpr), NULL);
+
+       res = gnm_expr_top_as_string (texpr, pp, convs);
+
+       if (GNM_EXPR_GET_OPER (texpr->expr) == GNM_EXPR_OP_SET) {
+               // Get rid of '(' and ')'.  This is crude and probably should
+               // have made it into convs, but it'll do.
+               size_t l = strlen (res);
+               if (l >= 2 && res[0] == '(' && res[l - 1] == ')') {
+                       g_memmove (res, res + 1, l - 2);
+                       res[l - 2] = 0;
+               }
+       }
+
+       return res;
+}
+
 void
 gnm_expr_top_as_gstring (GnmExprTop const *texpr,
                         GnmConventionsOut *out)
diff --git a/src/expr.h b/src/expr.h
index f066e1670..fbad3f09a 100644
--- a/src/expr.h
+++ b/src/expr.h
@@ -215,6 +215,9 @@ char         *gnm_expr_top_as_string  (GnmExprTop const *texpr,
                                   GnmConventions const *convs);
 void     gnm_expr_top_as_gstring (GnmExprTop const *texpr,
                                   GnmConventionsOut *out);
+char    *gnm_expr_top_multiple_as_string  (GnmExprTop const *texpr,
+                                           GnmParsePos const *pp,
+                                           GnmConventions const *convs);
 
 /*****************************************************************************/
 
diff --git a/src/graph.c b/src/graph.c
index 59a8fce23..e6c7143d6 100644
--- a/src/graph.c
+++ b/src/graph.c
@@ -197,9 +197,12 @@ gnm_go_data_serialize (GOData const *dat, gpointer user)
                convs = gnm_conventions_default;
        }
 
-       res = gnm_expr_top_as_string (dep->texpr,
-                                     parse_pos_init_dep (&pp, dep),
-                                     convs);
+       parse_pos_init_dep (&pp, dep);
+
+       res = GO_IS_DATA_VECTOR (dat)
+               ? gnm_expr_top_multiple_as_string (dep->texpr, &pp, convs)
+               : gnm_expr_top_as_string (dep->texpr, &pp, convs);
+
 #if 0
        g_printerr ("Serializing %s\n", res);
 #endif
@@ -213,6 +216,7 @@ gnm_go_data_unserialize (GOData *dat, char const *str, gpointer user)
        GnmExprTop const *texpr;
        GnmParsePos   pp;
        GnmDependent *dep = gnm_go_data_get_dep (dat);
+       size_t len;
 
        if (!convs) {
                g_warning ("NULL convs in gnm_go_data_serialize");
@@ -233,6 +237,16 @@ gnm_go_data_unserialize (GOData *dat, char const *str, gpointer user)
                                    GNM_EXPR_PARSE_PERMIT_MULTIPLE_EXPRESSIONS:
                                    GNM_EXPR_PARSE_DEFAULT,
                                    convs, NULL);
+       // Bummer.  We have managed to create files containing (1,2)
+       // which should be read as a vector.  See #492
+       if (!texpr && GO_IS_DATA_VECTOR (dat) && ((len = strlen (str)) > 2) &&
+           str[0] == '(' && str[len - 1] == ')') {
+               char *str2 = g_strndup (str + 1, len - 2);
+               texpr = gnm_expr_parse_str (str2, &pp,
+                                           GNM_EXPR_PARSE_PERMIT_MULTIPLE_EXPRESSIONS,
+                                           convs, NULL);
+               g_free (str2);
+       }
        if (texpr != NULL) {
                dependent_set_expr (dep, texpr);
                gnm_expr_top_unref (texpr);
diff --git a/src/widgets/ChangeLog b/src/widgets/ChangeLog
index 4d80ed3b9..dc78f9568 100644
--- a/src/widgets/ChangeLog
+++ b/src/widgets/ChangeLog
@@ -1,3 +1,9 @@
+2020-05-29  Morten Welinder  <terra gnome org>
+
+       * gnm-expr-entry.c (gnm_expr_entry_parse): Use
+       gnm_expr_top_multiple_as_string when we are dealing with multiple
+       expressions.
+
 2020-05-12  Jean Brefort  <jean brefort normalesup org>
 
        * gnm-fontbutton.c (_gtk_font_chooser_install_properties),
diff --git a/src/widgets/gnm-expr-entry.c b/src/widgets/gnm-expr-entry.c
index 5942ffe39..27167d7c8 100644
--- a/src/widgets/gnm-expr-entry.c
+++ b/src/widgets/gnm-expr-entry.c
@@ -2650,7 +2650,10 @@ gnm_expr_entry_parse (GnmExprEntry *gee, GnmParsePos const *pp,
        }
 
        /* Reset the entry in case something changed */
-       str = gnm_expr_top_as_string (texpr, pp, gee_convs (gee));
+       str = (flags & GNM_EXPR_PARSE_PERMIT_MULTIPLE_EXPRESSIONS)
+               ? gnm_expr_top_multiple_as_string (texpr, pp, gee_convs (gee))
+               : gnm_expr_top_as_string (texpr, pp, gee_convs (gee));
+
        if (strcmp (str, text)) {
                SheetControlGUI *scg = wbcg_cur_scg (gee->wbcg);
                Rangesel const *rs = &gee->rangesel;


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