Enable the show value labels feature
authorJohn Darrington <john@darrington.wattle.id.au>
Fri, 23 Jun 2017 10:06:57 +0000 (12:06 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Sat, 24 Jun 2017 05:20:16 +0000 (07:20 +0200)
src/ui/gui/psppire-data-editor.c
src/ui/gui/psppire-data-sheet.c
src/ui/gui/psppire-data-store.c
src/ui/gui/psppire-data-store.h

index 7c2ff2ad05b1a77c244bdf0cdb5cb7656e2d08ee..f1712ad4b7f683b74110ebbdc641dd8af13840a8 100644 (file)
@@ -167,7 +167,16 @@ psppire_data_editor_set_property (GObject         *object,
 
       g_object_set (de->var_sheet, "data-model", de->dict, NULL);
       break;
+
     case PROP_VALUE_LABELS:
+      {
+       gboolean l = g_value_get_boolean (value);
+       g_object_set (de->data_sheet, "forward-conversion",
+                     l ?
+                     psppire_data_store_value_to_string_with_labels :
+                     psppire_data_store_value_to_string,
+                     NULL);
+      }
       break;
 
     default:
index ca22471c8897d059730ab4b6aa6e5bc8ccede32d..089ab8f4795c5a8cf365fdd4f29c8c138fc88670 100644 (file)
@@ -102,16 +102,9 @@ change_data_value (PsppireDataSheet *sheet, gint col, gint row, GValue *value)
   value_destroy_from_variant (&v, vrnt);
 }
 
-static gchar *
-data_store_value_to_string (SswSheet *data_sheet, PsppireDataStore *store, gint col, gint row, const GValue *v)
-{
-  return psppire_data_store_value_to_string (store, col, row, v);
-}
-
 gboolean myreversefunc (GtkTreeModel *model, gint col, gint row, const gchar *in,
                    GValue *out);
 
-
 \f
 
 static void
@@ -355,7 +348,7 @@ psppire_data_sheet_new (void)
 {
   GObject *obj =
     g_object_new (PSPPIRE_TYPE_DATA_SHEET,
-                 "forward-conversion", data_store_value_to_string,
+                 "forward-conversion", psppire_data_store_value_to_string,
                  "reverse-conversion", myreversefunc,
                  NULL);
 
index 7b6aa7fb7f7fe0f85d1925d6b315b005afb17edd..c0843b1a6729496ee445c954c72b3da3055c4436 100644 (file)
@@ -20,7 +20,7 @@
 #include <stdlib.h>
 #include <gettext.h>
 #define _(msgid) gettext (msgid)
-#define N_(msgid) msgid
+#define P_(msgid) msgid
 
 #include <data/datasheet.h>
 #include <data/data-out.h>
@@ -158,8 +158,15 @@ myreversefunc (GtkTreeModel *model, gint col, gint row,
   return TRUE;
 }
 
+static char *
+unlabeled_value (PsppireDataStore *store, const struct variable *variable, const union value *val)
+{
+  const struct fmt_spec *fmt = var_get_print_format (variable);
+  return data_out (val, psppire_dict_encoding (store->dict),  fmt);
+}
+
 gchar *
-psppire_data_store_value_to_string (PsppireDataStore *store, gint col, gint row, const GValue *v)
+psppire_data_store_value_to_string (gpointer unused, PsppireDataStore *store, gint col, gint row, const GValue *v)
 {
   const struct variable *variable = psppire_dict_get_variable (store->dict, col);
   g_return_val_if_fail (variable, g_strdup ("???"));
@@ -168,8 +175,32 @@ psppire_data_store_value_to_string (PsppireDataStore *store, gint col, gint row,
   union value val;
   value_variant_get (&val, vrnt);
 
-  const struct fmt_spec *fmt = var_get_print_format (variable);
-  char *out =  data_out (&val, psppire_dict_encoding (store->dict),  fmt);
+  char *out = unlabeled_value (store, variable, &val);
+
+  value_destroy_from_variant (&val, vrnt);
+
+  return out;
+}
+
+gchar *
+psppire_data_store_value_to_string_with_labels (gpointer unused, PsppireDataStore *store, gint col, gint row, const GValue *v)
+{
+  const struct variable *variable = psppire_dict_get_variable (store->dict, col);
+  g_return_val_if_fail (variable, g_strdup ("???"));
+
+  GVariant *vrnt = g_value_get_variant (v);
+  union value val;
+  value_variant_get (&val, vrnt);
+
+  char *out = NULL;
+
+  const struct val_labs *vls = var_get_value_labels (variable);
+  struct val_lab *vl = val_labs_lookup (vls, &val);
+  if (vl != NULL)
+    out = strdup (val_lab_get_label (vl));
+  else
+    out = unlabeled_value (store, variable, &val);
+
   value_destroy_from_variant (&val, vrnt);
 
   return out;
index bbdb7eb9643bdc709ecda27b3a2711a08e7f7e8f..65e3d24ad3d495fe4531f63da7d51443ebd4546b 100644 (file)
@@ -109,7 +109,11 @@ gchar *psppire_data_store_get_string (PsppireDataStore *,
                                       glong row, const struct variable *,
                                       bool use_value_label);
 
-gchar * psppire_data_store_value_to_string (PsppireDataStore *store,
+gchar * psppire_data_store_value_to_string (gpointer unused, PsppireDataStore *store,
+                                           gint col, gint row,
+                                           const GValue *v);
+
+gchar * psppire_data_store_value_to_string_with_labels (gpointer unused, PsppireDataStore *store,
                                            gint col, gint row,
                                            const GValue *v);