From: Ben Pfaff Date: Mon, 2 Sep 2013 23:14:28 +0000 (-0700) Subject: psppire-dictview: Generalize psppire_dict_view_get_var_measurement_stock_id(). X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=159abf428abd3028a73d064508fac95e542d9f09;p=pspp psppire-dictview: Generalize psppire_dict_view_get_var_measurement_stock_id(). This change allows finding a stock-id speculatively, without having a variable on hand. --- diff --git a/src/ui/gui/psppire-dictview.c b/src/ui/gui/psppire-dictview.c index b75cf3dd9c..1820d41179 100644 --- a/src/ui/gui/psppire-dictview.c +++ b/src/ui/gui/psppire-dictview.c @@ -338,74 +338,53 @@ var_icon_cell_data_func (GtkTreeViewColumn *col, gpointer data) { 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); + get_var_measurement_stock_id (var_get_print_format (var)->type, + var_get_measure (var)), + NULL); } const char * -psppire_dict_view_get_var_measurement_stock_id (const struct variable *var) +get_var_measurement_stock_id (enum fmt_type type, enum measure measure) { - if ( var_is_alpha (var)) + switch (fmt_get_category (type)) { - switch ( var_get_measure (var)) + case FMT_CAT_STRING: + switch (measure) { - case MEASURE_NOMINAL: - return ("variable-string-nominal"); - break; - case MEASURE_ORDINAL: - return ("variable-string-ordinal"); - break; - case MEASURE_SCALE: - return ("variable-string-scale"); - break; - - default: - g_return_val_if_reached (""); + case MEASURE_NOMINAL: return "variable-string-nominal"; + case MEASURE_ORDINAL: return "variable-string-ordinal"; + case MEASURE_SCALE: return "variable-string-scale"; + case n_MEASURES: break; } - } - else - { - const struct fmt_spec *fs = var_get_print_format (var); - int cat = fmt_get_category (fs->type); + break; - if ( ( FMT_CAT_DATE | FMT_CAT_TIME ) & cat ) - { - switch ( var_get_measure (var)) - { - case MEASURE_NOMINAL: - return ("variable-date-nominal"); - break; - case MEASURE_ORDINAL: - return ("variable-date-ordinal"); - break; - case MEASURE_SCALE: - return ("variable-date-scale"); - break; - default: - g_assert_not_reached (); - }; - } - else - { - switch ( var_get_measure (var)) - { - case MEASURE_NOMINAL: - return ("variable-nominal"); - break; - case MEASURE_ORDINAL: - return ("variable-ordinal"); - break; - case MEASURE_SCALE: - return ("variable-scale"); - break; - default: - g_assert_not_reached (); - }; + case FMT_CAT_DATE: + case FMT_CAT_TIME: + switch (measure) + { + case MEASURE_NOMINAL: return "variable-date-nominal"; + case MEASURE_ORDINAL: return "variable-date-ordinal"; + case MEASURE_SCALE: return "variable-date-scale"; + case n_MEASURES: break; + } + break; + + default: + switch (measure) + { + case MEASURE_NOMINAL: return "variable-nominal"; + case MEASURE_ORDINAL: return "variable-ordinal"; + case MEASURE_SCALE: return "variable-scale"; + case n_MEASURES: break; } + break; } - return NULL; + + g_return_val_if_reached (""); } diff --git a/src/ui/gui/psppire-dictview.h b/src/ui/gui/psppire-dictview.h index fb8eda20ef..bf41778ea9 100644 --- a/src/ui/gui/psppire-dictview.h +++ b/src/ui/gui/psppire-dictview.h @@ -23,6 +23,7 @@ #include #include +#include "data/format.h" #include "psppire-dict.h" #include "dict-display.h" @@ -62,8 +63,7 @@ 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 *); +const char *get_var_measurement_stock_id (enum fmt_type, enum measure); G_END_DECLS diff --git a/src/ui/gui/psppire-var-sheet.c b/src/ui/gui/psppire-var-sheet.c index b5f305cee3..837d112580 100644 --- a/src/ui/gui/psppire-var-sheet.c +++ b/src/ui/gui/psppire-var-sheet.c @@ -464,9 +464,14 @@ render_var_cell (PsppSheetViewColumn *tree_column, "editable", TRUE, NULL); else - g_object_set (cell, "stock-id", - psppire_dict_view_get_var_measurement_stock_id (var), - NULL); + { + enum fmt_type type = var_get_print_format (var)->type; + enum measure measure = var_get_measure (var); + + g_object_set (cell, "stock-id", + get_var_measurement_stock_id (type, measure), + NULL); + } break; case VS_ROLE: