Display data in the var sheet properly
authorJohn Darrington <john@darrington.wattle.id.au>
Tue, 4 Apr 2017 08:30:40 +0000 (10:30 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Tue, 4 Apr 2017 08:30:40 +0000 (10:30 +0200)
src/ui/gui/psppire-data-editor.c

index 101b5e2782de7d8563f699a120ef3a76b6814af3..27d2f140991eaf220dbcae2b2a4a2ae64e682fea 100644 (file)
@@ -28,6 +28,7 @@
 #include "libpspp/str.h"
 #include "ui/gui/executor.h"
 #include "ui/gui/helper.h"
+#include "ui/gui/var-display.h"
 #include "ui/gui/psppire-data-store.h"
 #include "ui/gui/psppire-data-window.h"
 #include "ui/gui/psppire-value-entry.h"
@@ -91,13 +92,46 @@ create_combo_renderer (GType type)
   return r;
 }
 
+static gchar *
+var_sheet_data_to_string (GtkTreeModel *m, gint col, gint row, const GValue *in)
+{
+  if (col >= n_DICT_COLS - 1) /* -1 because psppire-dict has an extra column */
+    return NULL;
+
+  const struct variable *var = psppire_dict_get_variable (PSPPIRE_DICT (m), row);
+  if (var == NULL)
+    return NULL;
+
+  if (col == DICT_TVM_COL_TYPE)
+    {
+      const struct fmt_spec *print = var_get_print_format (var);
+      return strdup (fmt_gui_name (print->type));
+    }
+  else if (col == DICT_TVM_COL_MISSING_VALUES)
+    return missing_values_to_string (var, NULL);
+  else if (col == DICT_TVM_COL_VALUE_LABELS)
+    {
+      const struct val_labs *vls = var_get_value_labels (var);
+      if (vls == NULL)
+       return strdup (_("None"));
+      const struct val_lab **labels = val_labs_sorted (vls);
+      const struct val_lab *vl = labels[0];
+      gchar *vstr = value_to_text (vl->value, var);
+      char *text = xasprintf (_("{%s, %s}..."), vstr,
+                             val_lab_get_escaped_label (vl));
+      free (vstr);
+      free (labels);
+      return text;
+    }
+
+  return jmd_sheet_default_forward_conversion (m, col, row, in);
+}
+
 static GtkCellRenderer *spin_renderer;
 static GtkCellRenderer *column_width_renderer;
 static GtkCellRenderer *measure_renderer;
 static GtkCellRenderer *alignment_renderer;
 
-
-
 static GtkCellRenderer *
 select_renderer_func (gint col, gint row, GType type)
 {
@@ -435,7 +469,6 @@ psppire_data_editor_class_init (PsppireDataEditorClass *klass)
   g_object_class_install_property (object_class,
                                    PROP_SPLIT_WINDOW,
                                    split_window_spec);
-
 }
 
 
@@ -944,6 +977,9 @@ psppire_data_editor_init (PsppireDataEditor *de)
                "select-renderer-func", select_renderer_func,
                NULL);
 
+  jmd_sheet_set_conversion_func (JMD_SHEET (de->var_sheet),
+                                var_sheet_data_to_string, NULL);
+
   g_signal_connect (de->var_sheet, "row-header-pressed",
                    G_CALLBACK (show_variables_row_popup), de);