#include "xalloc.h"
#include "xmalloca.h"
-
+#include "value-variant.h"
static void psppire_data_store_init (PsppireDataStore *data_store);
static void psppire_data_store_class_init (PsppireDataStoreClass *class);
return FALSE;
}
- iter->user_data = n;
+ 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)
+{
+ PsppireDataStore *store = PSPPIRE_DATA_STORE (model);
+
+ const struct variable *variable = psppire_dict_get_variable (store->dict, col);
+ g_return_if_fail (variable);
+
+ const struct fmt_spec *fmt = var_get_print_format (variable);
+ int width = var_get_width (variable);
+
+ union value val;
+ value_init (&val, width);
+ char *xx =
+ data_in (ss_cstr (in), psppire_dict_encoding (store->dict),
+ fmt->type, &val, width, "UTF-8");
+
+ GVariant *vrnt = value_variant_new (&val, width);
+ value_destroy (&val, width);
+
+ g_value_init (out, G_TYPE_VARIANT);
+ g_value_set_variant (out, vrnt);
+ free (xx);
+}
+
+gchar *
+myconvfunc (GtkTreeModel *model, 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);
+
+ const struct fmt_spec *fmt = var_get_print_format (variable);
+ char *out = data_out (&val, psppire_dict_encoding (store->dict), fmt);
+ value_destroy_from_variant (&val, vrnt);
+
+ return out;
+}
static void
__get_value (GtkTreeModel *tree_model,
{
PsppireDataStore *store = PSPPIRE_DATA_STORE (tree_model);
- g_value_init (value, G_TYPE_DOUBLE);
+ g_return_if_fail (iter->stamp == store->stamp);
+
+ const struct variable *variable = psppire_dict_get_variable (store->dict, column);
+ if (NULL == variable)
+ return;
+
+ g_value_init (value, G_TYPE_VARIANT);
gint row = GPOINTER_TO_INT (iter->user_data);
struct ccase *cc = datasheet_get_row (store->datasheet, row);
+
+ const union value *val = case_data_idx (cc, column);
+
+ GVariant *vv = value_variant_new (val, var_get_width (variable));
+
+ g_value_set_variant (value, vv);
- g_value_set_double (value, case_data_idx (cc, column)->f);
case_unref (cc);
}
{
iface->get_flags = __tree_model_get_flags;
iface->get_n_columns = __tree_model_get_n_columns ;
- iface->get_column_type = NULL;
+ iface->get_column_type = NULL;
iface->get_iter = NULL;
iface->iter_next = NULL;
iface->get_path = NULL;
data_store->dict = NULL;
data_store->datasheet = NULL;
data_store->dispose_has_run = FALSE;
+ data_store->stamp = g_random_int ();
}
/*
return result;
}
+gboolean
+psppire_data_store_get_value (PsppireDataStore *store,
+ glong row, const struct variable *var,
+ union value *val)
+{
+ g_return_val_if_fail (store != NULL, FALSE);
+ g_return_val_if_fail (store->datasheet != NULL, FALSE);
+ g_return_val_if_fail (var != NULL, FALSE);
+
+ if (row < 0 || row >= datasheet_get_n_rows (store->datasheet))
+ return FALSE;
+
+ int width = var_get_width (var);
+ value_init (val, width);
+ datasheet_get_value (store->datasheet, row, var_get_case_index (var), val);
+
+ return TRUE;
+}
+
+
+
gchar *
psppire_data_store_get_string (PsppireDataStore *store,
glong row, const struct variable *var,
{
gchar *string;
union value v;
- int width;
-
- g_return_val_if_fail (store != NULL, NULL);
- g_return_val_if_fail (store->datasheet != NULL, NULL);
- g_return_val_if_fail (var != NULL, NULL);
-
- if (row < 0 || row >= datasheet_get_n_rows (store->datasheet))
+ int width = var_get_width (var);
+ if (! psppire_data_store_get_value (store, row, var, &v))
return NULL;
-
- width = var_get_width (var);
- value_init (&v, width);
- datasheet_get_value (store->datasheet, row, var_get_case_index (var), &v);
-
+
string = NULL;
if (use_value_label)
{