psppire-var-sheet: Add measurement level icons to variable sheet. 20130729030504/pspp
authorBen Pfaff <blp@cs.stanford.edu>
Mon, 29 Jul 2013 04:28:32 +0000 (21:28 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Mon, 29 Jul 2013 04:28:58 +0000 (21:28 -0700)
Suggested by Bastián Díaz <diaz.bastian@ymail.com>.

src/ui/gui/psppire-dictview.c
src/ui/gui/psppire-dictview.h
src/ui/gui/psppire-var-sheet.c

index 5554eb0adebf9cbd8ea9a701461e3f7c72eed9b2..19aa0a3774912a22183b76412746bd54616381aa 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 2009, 2010, 2011, 2012  Free Software Foundation
+   Copyright (C) 2009, 2010, 2011, 2012, 2013  Free Software Foundation
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -340,35 +340,43 @@ var_icon_cell_data_func (GtkTreeViewColumn *col,
   struct variable *var;
   gtk_tree_model_get (model, iter, DICT_TVM_COL_VAR, &var, -1);
 
+  g_object_set (cell, "stock_id",
+                psppire_dict_view_get_var_measurement_stock_id (var), NULL);
+}
+
+const char *
+psppire_dict_view_get_var_measurement_stock_id (const struct variable *var)
+{
   if ( var_is_alpha (var))
-    {
-      g_object_set (cell, "stock-id", "var-string", NULL);
-    }
+    return "var-string";
   else
     {
       const struct fmt_spec *fs = var_get_print_format (var);
       int cat = fmt_get_category (fs->type);
+
       switch ( var_get_measure (var))
        {
        case MEASURE_NOMINAL:
-         g_object_set (cell, "stock-id", "var-nominal", NULL);
-         break;
+          return "var-nominal";
+
        case MEASURE_ORDINAL:
-         g_object_set (cell, "stock-id", "var-ordinal", NULL);
-         break;
+          return "var-ordinal";
+
        case MEASURE_SCALE:
          if ( ( FMT_CAT_DATE | FMT_CAT_TIME ) & cat )
-           g_object_set (cell, "stock-id", "var-date-scale", NULL);
+            return "var-date-scale";
          else
-           g_object_set (cell, "stock-id", "var-scale", NULL);
+            return "var-scale";
          break;
+
        default:
-         g_assert_not_reached ();
-       };
+         g_return_val_if_reached ("");
+       }
     }
 }
 
 
+
 /* Sets the tooltip to be the name of the variable under the cursor */
 static gboolean
 set_tooltip_for_variable (GtkTreeView  *treeview,
index 1a8ddbb9235d1708ee4de4dbefb09f738bcbbfff..fb8eda20efb03b0b171a6b42d2b7d8a9906a9630 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 2009, 2010  Free Software Foundation
+   Copyright (C) 2009, 2010, 2013  Free Software Foundation
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -62,6 +62,8 @@ struct _PsppireDictViewClass
 GType      psppire_dict_view_get_type        (void);
 struct variable * psppire_dict_view_get_selected_variable (PsppireDictView *);
 
+const char *psppire_dict_view_get_var_measurement_stock_id (
+  const struct variable *);
 
 G_END_DECLS
 
index d62a97e1fd1fa08866827dc05ae3d83b729e42bd..016824d42863d23a9d80de1ac269ea834121943a 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 2008, 2009, 2011, 2012 Free Software Foundation, Inc.
+   Copyright (C) 2008, 2009, 2011, 2012, 2013 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -29,6 +29,7 @@
 #include "ui/gui/psppire-data-editor.h"
 #include "ui/gui/psppire-data-window.h"
 #include "ui/gui/psppire-dialog-action-var-info.h"
+#include "ui/gui/psppire-dictview.h"
 #include "ui/gui/psppire-empty-list-store.h"
 #include "ui/gui/psppire-marshal.h"
 #include "ui/gui/val-labs-dialog.h"
@@ -311,14 +312,19 @@ render_var_cell (PsppSheetViewColumn *tree_column,
 
   if (row >= psppire_dict_get_var_cnt (var_sheet->dict))
     {
-      g_object_set (cell,
-                    "text", "",
-                    "editable", column_id == VS_NAME,
-                    NULL);
-      if (column_id == VS_WIDTH
-          || column_id == VS_DECIMALS
-          || column_id == VS_COLUMNS)
-        g_object_set (cell, "adjustment", NULL, NULL);
+      if (GTK_IS_CELL_RENDERER_TEXT (cell))
+        {
+          g_object_set (cell,
+                        "text", "",
+                        "editable", column_id == VS_NAME,
+                        NULL);
+          if (column_id == VS_WIDTH
+              || column_id == VS_DECIMALS
+              || column_id == VS_COLUMNS)
+            g_object_set (cell, "adjustment", NULL, NULL);
+        }
+      else
+        g_object_set (cell, "stock-id", "", NULL);
       return;
     }
 
@@ -414,10 +420,15 @@ render_var_cell (PsppSheetViewColumn *tree_column,
       break;
 
     case VS_MEASURE:
-      g_object_set (cell,
-                    "text", measure_to_string (var_get_measure (var)),
-                    "editable", TRUE,
-                    NULL);
+      if (GTK_IS_CELL_RENDERER_TEXT (cell))
+        g_object_set (cell,
+                      "text", measure_to_string (var_get_measure (var)),
+                      "editable", TRUE,
+                      NULL);
+      else
+        g_object_set (cell, "stock-id",
+                      psppire_dict_view_get_var_measurement_stock_id (var),
+                      NULL);
       break;
     }
 }
@@ -1179,6 +1190,7 @@ psppire_var_sheet_init (PsppireVarSheet *obj)
 {
   PsppSheetView *sheet_view = PSPP_SHEET_VIEW (obj);
   PsppSheetViewColumn *column;
+  GtkCellRenderer *cell;
   GtkAction *action;
   GList *list;
 
@@ -1224,11 +1236,16 @@ psppire_var_sheet_init (PsppireVarSheet *obj)
                     alignment_to_string (ALIGN_RIGHT), ALIGN_RIGHT,
                     NULL);
 
-  add_combo_column (obj, VS_MEASURE, _("Measure"), 10,
-                    measure_to_string (MEASURE_NOMINAL), MEASURE_NOMINAL,
-                    measure_to_string (MEASURE_ORDINAL), MEASURE_ORDINAL,
-                    measure_to_string (MEASURE_SCALE), MEASURE_SCALE,
-                    NULL);
+  column
+    = add_combo_column (obj, VS_MEASURE, _("Measure"), 12,
+                        measure_to_string (MEASURE_NOMINAL), MEASURE_NOMINAL,
+                        measure_to_string (MEASURE_ORDINAL), MEASURE_ORDINAL,
+                        measure_to_string (MEASURE_SCALE), MEASURE_SCALE,
+                        NULL);
+  cell = gtk_cell_renderer_pixbuf_new ();
+  pspp_sheet_view_column_pack_end (column, cell, FALSE);
+  pspp_sheet_view_column_set_cell_data_func (
+    column, cell, render_var_cell, obj, NULL);
 
   pspp_sheet_view_set_rubber_banding (sheet_view, TRUE);
   pspp_sheet_selection_set_mode (pspp_sheet_view_get_selection (sheet_view),