From: Ben Pfaff Date: Mon, 29 Jul 2013 04:28:32 +0000 (-0700) Subject: psppire-var-sheet: Add measurement level icons to variable sheet. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bb748df7e4165e0c58692f6506026359b740f34d;p=pspp psppire-var-sheet: Add measurement level icons to variable sheet. Suggested by Bastián Díaz . --- diff --git a/src/ui/gui/psppire-dictview.c b/src/ui/gui/psppire-dictview.c index 5554eb0ade..19aa0a3774 100644 --- a/src/ui/gui/psppire-dictview.c +++ b/src/ui/gui/psppire-dictview.c @@ -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, diff --git a/src/ui/gui/psppire-dictview.h b/src/ui/gui/psppire-dictview.h index 1a8ddbb923..fb8eda20ef 100644 --- a/src/ui/gui/psppire-dictview.h +++ b/src/ui/gui/psppire-dictview.h @@ -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 diff --git a/src/ui/gui/psppire-var-sheet.c b/src/ui/gui/psppire-var-sheet.c index d62a97e1fd..016824d428 100644 --- a/src/ui/gui/psppire-var-sheet.c +++ b/src/ui/gui/psppire-var-sheet.c @@ -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),