From: John Darrington Date: Fri, 23 Jun 2017 10:06:57 +0000 (+0200) Subject: Enable the show value labels feature X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;ds=sidebyside;h=b5a56f8d1592fd0d9bf981d71e28851c4e733fef;hp=-c;p=pspp Enable the show value labels feature --- b5a56f8d1592fd0d9bf981d71e28851c4e733fef diff --git a/src/ui/gui/psppire-data-editor.c b/src/ui/gui/psppire-data-editor.c index 7c2ff2ad05..f1712ad4b7 100644 --- a/src/ui/gui/psppire-data-editor.c +++ b/src/ui/gui/psppire-data-editor.c @@ -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: diff --git a/src/ui/gui/psppire-data-sheet.c b/src/ui/gui/psppire-data-sheet.c index ca22471c88..089ab8f479 100644 --- a/src/ui/gui/psppire-data-sheet.c +++ b/src/ui/gui/psppire-data-sheet.c @@ -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); - 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); diff --git a/src/ui/gui/psppire-data-store.c b/src/ui/gui/psppire-data-store.c index 7b6aa7fb7f..c0843b1a67 100644 --- a/src/ui/gui/psppire-data-store.c +++ b/src/ui/gui/psppire-data-store.c @@ -20,7 +20,7 @@ #include #include #define _(msgid) gettext (msgid) -#define N_(msgid) msgid +#define P_(msgid) msgid #include #include @@ -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; diff --git a/src/ui/gui/psppire-data-store.h b/src/ui/gui/psppire-data-store.h index bbdb7eb964..65e3d24ad3 100644 --- a/src/ui/gui/psppire-data-store.h +++ b/src/ui/gui/psppire-data-store.h @@ -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);