X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fpsppire-data-store.c;h=f97b8eaf1cdc5b246ec81685e590640b79686fd0;hb=4eb2e820b01d92ef662c741f5ac30f08bedd1de6;hp=630ee4379b628a9bf5553821159cda3aac86335c;hpb=1fdf781696f879bb3321bfe37f7923be810c7a8f;p=pspp diff --git a/src/ui/gui/psppire-data-store.c b/src/ui/gui/psppire-data-store.c index 630ee4379b..f97b8eaf1c 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 @@ -81,6 +81,9 @@ __tree_model_iter_n_children (GtkTreeModel *tree_model, { PsppireDataStore *store = PSPPIRE_DATA_STORE (tree_model); + if (store->datasheet == NULL) + return 0; + gint n = datasheet_get_n_rows (store->datasheet); return n; @@ -99,7 +102,7 @@ __tree_model_get_n_columns (GtkTreeModel *tree_model) { PsppireDataStore *store = PSPPIRE_DATA_STORE (tree_model); - return psppire_dict_get_value_cnt (store->dict); + return psppire_dict_get_var_cnt (store->dict); } @@ -110,33 +113,42 @@ __iter_nth_child (GtkTreeModel *tree_model, gint n) { PsppireDataStore *store = PSPPIRE_DATA_STORE (tree_model); - - g_assert (parent == NULL); + g_assert (parent == NULL); g_return_val_if_fail (store, FALSE); - g_return_val_if_fail (store->datasheet, FALSE); - if (n >= datasheet_get_n_rows (store->datasheet)) + if (!store->datasheet || n >= datasheet_get_n_rows (store->datasheet)) { iter->stamp = -1; iter->user_data = NULL; return FALSE; } - + iter->user_data = GINT_TO_POINTER (n); iter->stamp = store->stamp; - + return TRUE; } -void -myreversefunc (GtkTreeModel *model, gint col, gint row, - const gchar *in, GValue *out) +/* Set the contents of OUT to reflect the information provided by IN, COL, and + ROW, for MODEL. Returns TRUE if successful. */ +gboolean +psppire_data_store_string_to_value (GtkTreeModel *model, gint col, gint row, + const gchar *in, GValue *out) { - PsppireDataStore *store = PSPPIRE_DATA_STORE (model); + PsppireDataStore *store = PSPPIRE_DATA_STORE (model); + + while (col >= psppire_dict_get_var_cnt (store->dict)) + { + const struct variable *var = + psppire_dict_insert_variable (store->dict, + psppire_dict_get_var_cnt (store->dict), + NULL); + g_return_val_if_fail (var, FALSE); + } const struct variable *variable = psppire_dict_get_variable (store->dict, col); - g_return_if_fail (variable); + g_return_val_if_fail (variable, FALSE); const struct fmt_spec *fmt = var_get_print_format (variable); @@ -144,7 +156,7 @@ myreversefunc (GtkTreeModel *model, gint col, gint row, union value val; value_init (&val, width); - char *xx = + char *xx = data_in (ss_cstr (in), psppire_dict_encoding (store->dict), fmt->type, &val, width, "UTF-8"); @@ -154,13 +166,36 @@ myreversefunc (GtkTreeModel *model, gint col, gint row, g_value_init (out, G_TYPE_VARIANT); g_value_set_variant (out, vrnt); free (xx); + 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 * -myconvfunc (GtkTreeModel *model, gint col, gint row, const GValue *v) +psppire_data_store_value_to_string (gpointer unused, PsppireDataStore *store, gint col, gint row, const GValue *v) { - PsppireDataStore *store = PSPPIRE_DATA_STORE (model); + 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 = 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 ("???")); @@ -168,8 +203,15 @@ myconvfunc (GtkTreeModel *model, gint col, gint row, const GValue *v) 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 = 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; @@ -184,7 +226,7 @@ __get_value (GtkTreeModel *tree_model, PsppireDataStore *store = PSPPIRE_DATA_STORE (tree_model); g_return_if_fail (iter->stamp == store->stamp); - + const struct variable *variable = psppire_dict_get_variable (store->dict, column); if (NULL == variable) return; @@ -200,7 +242,7 @@ __get_value (GtkTreeModel *tree_model, GVariant *vv = value_variant_new (val, var_get_width (variable)); g_value_set_variant (value, vv); - + case_unref (cc); } @@ -211,16 +253,16 @@ __tree_model_init (GtkTreeModelIface *iface) iface->get_flags = __tree_model_get_flags; iface->get_n_columns = __tree_model_get_n_columns ; iface->get_column_type = NULL; - iface->get_iter = NULL; - iface->iter_next = NULL; - iface->get_path = NULL; + iface->get_iter = NULL; + iface->iter_next = NULL; + iface->get_path = NULL; iface->get_value = __get_value; - iface->iter_children = NULL; - iface->iter_has_child = NULL; + iface->iter_children = NULL; + iface->iter_has_child = NULL; iface->iter_n_children = __tree_model_iter_n_children; iface->iter_nth_child = __iter_nth_child; - iface->iter_parent = NULL; + iface->iter_parent = NULL; } @@ -327,6 +369,16 @@ psppire_data_store_init (PsppireDataStore *data_store) data_store->stamp = g_random_int (); } + +static void +psppire_data_store_delete_value (PsppireDataStore *store, gint case_index) +{ + g_return_if_fail (store->datasheet); + datasheet_delete_columns (store->datasheet, case_index, 1); + datasheet_insert_column (store->datasheet, NULL, -1, case_index); +} + + /* A callback which occurs after a variable has been deleted. */ @@ -337,10 +389,7 @@ delete_variable_callback (GObject *obj, const struct variable *var UNUSED, { PsppireDataStore *store = PSPPIRE_DATA_STORE (data); - g_return_if_fail (store->datasheet); - - datasheet_delete_columns (store->datasheet, case_index, 1); - datasheet_insert_column (store->datasheet, NULL, -1, case_index); + psppire_data_store_delete_value (store, case_index); } struct resize_datum_aux @@ -434,7 +483,7 @@ psppire_data_store_set_reader (PsppireDataStore *ds, ds->datasheet = datasheet_create (reader); gint new_n = datasheet_get_n_rows (ds->datasheet); - + if ( ds->dict ) for (i = 0 ; i < n_dict_signals; ++i ) { @@ -582,7 +631,7 @@ psppire_data_store_get_value (PsppireDataStore *store, return TRUE; } - + gchar * psppire_data_store_get_string (PsppireDataStore *store, @@ -594,7 +643,7 @@ psppire_data_store_get_string (PsppireDataStore *store, int width = var_get_width (var); if (! psppire_data_store_get_value (store, row, var, &v)) return NULL; - + string = NULL; if (use_value_label) { @@ -772,7 +821,10 @@ psppire_data_store_set_value (PsppireDataStore *ds, casenumber casenum, ok = datasheet_put_value (ds->datasheet, casenum, var_get_case_index (var), v); if (ok) - g_signal_emit (ds, signals [CASE_CHANGED], 0, casenum); + { + g_signal_emit (ds, signals [CASE_CHANGED], 0, casenum); + g_signal_emit (ds, signals [ITEMS_CHANGED], 0, casenum, 1, 1); + } return ok; }