#include <stdlib.h>
#include <gettext.h>
#define _(msgid) gettext (msgid)
-#define N_(msgid) msgid
+#define P_(msgid) msgid
#include <data/datasheet.h>
#include <data/data-out.h>
#include <math/sort.h>
-#include "xalloc.h"
#include "xmalloca.h"
#include "value-variant.h"
{
PsppireDataStore *store = PSPPIRE_DATA_STORE (tree_model);
+ if (store->datasheet == NULL)
+ return 0;
+
gint n = datasheet_get_n_rows (store->datasheet);
return n;
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;
}
+/* Set the contents of OUT to reflect the information provided by IN, COL, and
+ ROW, for MODEL. Returns TRUE if successful. */
gboolean
-myreversefunc (GtkTreeModel *model, gint col, gint row,
- const gchar *in, GValue *out)
+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_val_if_fail (variable, FALSE);
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");
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 *
-psppire_data_store_value_to_string (PsppireDataStore *store, gint col, gint row, const GValue *v)
+psppire_data_store_value_to_string (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 ("???"));
GVariant *vrnt = g_value_get_variant (v);
+ g_return_val_if_fail (vrnt, g_strdup ("???"));
+
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 = 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 ("???"));
+
+ GVariant *vrnt = g_value_get_variant (v);
+ union value val;
+ value_variant_get (&val, vrnt);
+
+ 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;
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;
- g_value_init (value, G_TYPE_VARIANT);
-
gint row = GPOINTER_TO_INT (iter->user_data);
struct ccase *cc = datasheet_get_row (store->datasheet, row);
+ g_return_if_fail (cc);
+
+ g_value_init (value, G_TYPE_VARIANT);
+
const union value *val = case_data_idx (cc, var_get_case_index (variable));
GVariant *vv = value_variant_new (val, var_get_width (variable));
g_value_set_variant (value, vv);
-
+
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_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;
}
psppire_data_store_delete_value (PsppireDataStore *store, gint case_index)
{
g_return_if_fail (store->datasheet);
+ g_return_if_fail (case_index < datasheet_get_n_columns (store->datasheet));
+
datasheet_delete_columns (store->datasheet, case_index, 1);
datasheet_insert_column (store->datasheet, NULL, -1, case_index);
}
{
gint i;
gint old_n = 0;
- if ( ds->datasheet)
+ if (ds->datasheet)
{
old_n = datasheet_get_n_rows (ds->datasheet);
datasheet_destroy (ds->datasheet);
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 )
+
+ if (ds->dict)
+ for (i = 0 ; i < n_dict_signals; ++i)
{
- if ( ds->dict_handler_id [i] > 0)
+ if (ds->dict_handler_id [i] > 0)
{
g_signal_handler_unblock (ds->dict,
ds->dict_handler_id[i]);
int i;
/* Disconnect any existing handlers */
- if ( data_store->dict )
- for (i = 0 ; i < n_dict_signals; ++i )
+ if (data_store->dict)
+ for (i = 0 ; i < n_dict_signals; ++i)
{
g_signal_handler_disconnect (data_store->dict,
data_store->dict_handler_id[i]);
data_store->dict = dict;
- if ( dict != NULL)
+ if (dict != NULL)
{
data_store->dict_handler_id [VARIABLE_INSERTED] =
/* The entire model has changed */
- if ( data_store->dict )
- for (i = 0 ; i < n_dict_signals; ++i )
+ if (data_store->dict)
+ for (i = 0 ; i < n_dict_signals; ++i)
{
- if ( data_store->dict_handler_id [i] > 0)
+ if (data_store->dict_handler_id [i] > 0)
{
g_signal_handler_block (data_store->dict,
data_store->dict_handler_id[i]);
return TRUE;
}
-
+
gchar *
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)
{
int i;
struct casereader *reader ;
- if ( ds->dict )
- for (i = 0 ; i < n_dict_signals; ++i )
+ if (ds->dict)
+ for (i = 0 ; i < n_dict_signals; ++i)
{
g_signal_handler_block (ds->dict,
ds->dict_handler_id[i]);
cc = case_ref (cc);
result = datasheet_insert_rows (ds->datasheet, posn, &cc, 1);
- if ( result )
+ if (result)
{
g_signal_emit (ds, signals[ITEMS_CHANGED], 0, posn, 0, 1);
}
g_return_val_if_fail (ds->datasheet, FALSE);
n_cases = psppire_data_store_get_case_count (ds);
- if ( casenum > n_cases)
+ if (casenum > n_cases)
return FALSE;
if (casenum == n_cases)
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;
}
g_assert (width >= 0);
- if ( ! ds->datasheet )
+ if (! ds->datasheet)
ds->datasheet = datasheet_create (NULL);
value_init (&value, width);
const struct dictionary *dict;
const struct variable *filter;
- if ( row < 0 || row >= datasheet_get_n_rows (ds->datasheet))
+ if (row < 0 || row >= datasheet_get_n_rows (ds->datasheet))
return FALSE;
dict = ds->dict->dict;
g_return_val_if_fail (dict, FALSE);
filter = dict_get_filter (dict);
- if ( ! filter)
+ if (! filter)
return FALSE;
g_return_val_if_fail (var_is_numeric (filter), FALSE);
value_init (&val, 0);
- if ( ! datasheet_get_value (ds->datasheet, row,
+ if (! datasheet_get_value (ds->datasheet, row,
var_get_case_index (filter),
- &val) )
+ &val))
return FALSE;
return (val.f == 0.0);