stage_var = xmalloc (sizeof *stage_var);
stage_var->var = var;
- stage_var->case_index = var_get_case_index (var);
+ stage_var->case_index = var_get_dict_index (var);
hmap_insert (&stage->stage_vars, &stage_var->hmap_node,
hash_pointer (var, 0));
}
const struct variable *var = dict_get_var (stage->dict, i);
const struct stage_var *stage_var = case_map_stage_find_var (stage, var);
- if (var_get_case_index (var) != stage_var->case_index)
+ if (var_get_dict_index (var) != stage_var->case_index)
identity_map = false;
- insert_mapping (map, stage_var->case_index, var_get_case_index (var));
+ insert_mapping (map, stage_var->case_index, var_get_dict_index (var));
}
if (identity_map)
struct variable *nv = dict_get_var (new, i);
struct variable *ov = dict_lookup_var_assert (old, var_get_name (nv));
assert (var_get_width (nv) == var_get_width (ov));
- insert_mapping (map, var_get_case_index (ov), var_get_case_index (nv));
+ insert_mapping (map, var_get_dict_index (ov), var_get_dict_index (nv));
}
return map;
}
case_data (const struct ccase *c, const struct variable *v)
{
assert_variable_matches_case (c, v);
- return &c->values[var_get_case_index (v)];
+ return &c->values[var_get_dict_index (v)];
}
/* Returns a pointer to the `union value' used for the element of
{
assert_variable_matches_case (c, v);
assert (!case_is_shared (c));
- return &c->values[var_get_case_index (v)];
+ return &c->values[var_get_dict_index (v)];
}
/* Returns a pointer to the `union value' used for the
case_num (const struct ccase *c, const struct variable *v)
{
assert_variable_matches_case (c, v);
- return c->values[var_get_case_index (v)].f;
+ return c->values[var_get_dict_index (v)].f;
}
/* Returns the numeric value of the `union value' in C numbered
{
assert_variable_matches_case (c, v);
assert (!case_is_shared (c));
- return &c->values[var_get_case_index (v)].f;
+ return &c->values[var_get_dict_index (v)].f;
}
/* Returns a pointer to the `double' in the `union value' in C numbered IDX.
case_str (const struct ccase *c, const struct variable *v)
{
assert_variable_matches_case (c, v);
- return c->values[var_get_case_index (v)].s;
+ return c->values[var_get_dict_index (v)].s;
}
/* Returns the string value of the `union value' in C numbered
case_ss (const struct ccase *c, const struct variable *v)
{
assert_variable_matches_case (c, v);
- return ss_buffer (CHAR_CAST (char *, c->values[var_get_case_index (v)].s),
+ return ss_buffer (CHAR_CAST (char *, c->values[var_get_dict_index (v)].s),
var_get_width (v));
}
case_str_rw (struct ccase *c, const struct variable *v)
{
assert_variable_matches_case (c, v);
- size_t idx = var_get_case_index (v);
+ size_t idx = var_get_dict_index (v);
assert (!case_is_shared (c));
return c->values[idx].s;
}
static void
assert_variable_matches_case (const struct ccase *c, const struct variable *v)
{
- size_t case_idx = var_get_case_index (v);
- assert (case_idx < caseproto_get_n_widths (c->proto));
- assert (caseproto_get_width (c->proto, case_idx) == var_get_width (v));
+ size_t var_idx = var_get_dict_index (v);
+ assert (var_idx < caseproto_get_n_widths (c->proto));
+ assert (caseproto_get_width (c->proto, var_idx) == var_get_width (v));
}
/* Internal helper function for case_copy(). */
for (size_t i = 0; i < n_vars; i++)
{
struct variable *v = dict_get_var (d, i);
- size_t case_index = var_get_case_index (v);
+ size_t case_index = var_get_dict_index (v);
struct init_value *iv;
/* Only include the correct class. */
struct csv_var *cv = &w->csv_vars[i];
cv->width = var_get_width (var);
- cv->case_index = var_get_case_index (var);
+ cv->case_index = var_get_dict_index (var);
cv->format = var_get_print_format (var);
if (opts->recode_user_missing)
struct caseinit *caseinit;
struct trns_chain permanent_trns_chain;
struct dictionary *permanent_dict;
+ struct variable *order_var;
struct casewriter *sink;
struct trns_chain temporary_trns_chain;
bool temporary;
caseinit_mark_as_preinited (ds->caseinit, ds->dict);
}
+void
+dataset_reorder_vars (struct dataset *ds, struct variable **vars, size_t n)
+{
+ assert (!proc_in_temporary_transformations (ds));
+ assert (!proc_has_transformations (ds));
+ assert (n <= dict_get_n_vars (ds->dict));
+
+ caseinit_mark_for_init (ds->caseinit, ds->dict);
+ ds->source = caseinit_translate_casereader_to_init_vars (
+ ds->caseinit, dict_get_proto (ds->dict), ds->source);
+ caseinit_clear (ds->caseinit);
+ caseinit_mark_as_preinited (ds->caseinit, ds->dict);
+
+ struct case_map_stage *stage = case_map_stage_create (ds->dict);
+ dict_reorder_vars (ds->dict, vars, n);
+ ds->source = case_map_create_input_translator (
+ case_map_stage_get_case_map (stage), ds->source);
+ case_map_stage_destroy (stage);
+ caseinit_clear (ds->caseinit);
+ caseinit_mark_as_preinited (ds->caseinit, ds->dict);
+}
+
/* Returns a number unique to DS. It can be used to distinguish one dataset
from any other within a given program run, even datasets that do not exist
at the same time. */
/* Write case to replacement dataset. */
ds->cases_written++;
if (ds->sink != NULL)
- casewriter_write (ds->sink,
- case_map_execute (ds->compactor, case_ref (c)));
+ {
+ if (ds->order_var)
+ *case_num_rw (c, ds->order_var) = case_nr;
+ casewriter_write (ds->sink,
+ case_map_execute (ds->compactor, case_ref (c)));
+ }
/* Execute temporary transformations. */
if (ds->temporary_trns_chain.n)
dict_clear_vectors (ds->dict);
ds->permanent_dict = NULL;
+ ds->order_var = NULL;
return ok;
}
return TRNS_CONTINUE;
}
-/* Add a variable which we can sort by to get back the original order. */
+/* Add a variable $ORDERING which we can sort by to get back the original order. */
struct variable *
add_permanent_ordering_transformation (struct dataset *ds)
{
- struct variable *temp_var = dict_create_var_assert (ds->dict, "$ORDER", 0);
- struct variable *order_var
- = (proc_in_temporary_transformations (ds)
- ? dict_clone_var_in_place_assert (ds->permanent_dict, temp_var)
- : temp_var);
+ struct dictionary *d = ds->permanent_dict ? ds->permanent_dict : ds->dict;
+ struct variable *order_var = dict_create_var_assert (d, "$ORDER", 0);
+ ds->order_var = order_var;
- static const struct trns_class trns_class = {
- .name = "ordering",
- .execute = store_case_num
- };
- const struct transformation t = { .class = &trns_class, .aux = order_var };
- trns_chain_append (&ds->permanent_trns_chain, &t);
+ if (ds->permanent_dict)
+ {
+ order_var = dict_create_var_assert (ds->dict, "$ORDER", 0);
+ static const struct trns_class trns_class = {
+ .name = "ordering",
+ .execute = store_case_num
+ };
+ const struct transformation t = { .class = &trns_class, .aux = order_var };
+ trns_chain_prepend (&ds->temporary_trns_chain, &t);
+ }
- return temp_var;
+ return order_var;
}
\f
/* Causes output from the next procedure to be discarded, instead
const struct casereader_translator_class *,
void *aux);
void dataset_delete_vars (struct dataset *, struct variable **, size_t n);
+void dataset_reorder_vars (struct dataset *, struct variable **, size_t n);
\f
/* Procedures. */
}
}
-/* Sets the case_index in V's vardict to CASE_INDEX. */
-static void
-set_var_case_index (struct variable *v, int case_index)
-{
- var_get_vardict (v)->case_index = case_index;
-}
-
/* Removes the dictionary variables with indexes from FROM to TO (exclusive)
from name_map. */
static void
void
dict_dump (const struct dictionary *d)
{
- int i;
- for (i = 0 ; i < d->n_vars ; ++i)
- {
- const struct variable *v = d->vars[i].var;
- printf ("Name: %s;\tdict_idx: %zu; case_idx: %zu\n",
- var_get_name (v),
- var_get_dict_index (v),
- var_get_case_index (v));
-
- }
+ for (size_t i = 0; i < d->n_vars; ++i)
+ printf ("%zu: %s\n", i, var_get_name (d->vars[i].var));
}
/* Associate CALLBACKS with DICT. Callbacks will be invoked whenever
for (size_t j = 0; j < var_get_n_short_names (sv); j++)
var_set_short_name (dv, j, var_get_short_name (sv, j));
-
- var_get_vardict (dv)->case_index = var_get_vardict (sv)->case_index;
}
d->n_splits = s->n_splits;
dict_delete_var (struct dictionary *d, struct variable *v)
{
dict_delete_var__ (d, v, false);
- dict_compact_values (d);
+ invalidate_proto (d);
}
while (count-- > 0)
dict_delete_var (d, *vars++);
- dict_compact_values (d);
+ invalidate_proto (d);
}
/* Deletes the COUNT variables in D starting at index IDX. This
{
assert (idx + count <= d->n_vars);
- /* We need to store the variable and the corresponding case_index
- for the delete callbacks later. We store them in a linked list.*/
- struct delvar {
- struct ll ll;
- struct variable *var;
- };
- struct ll_list list = LL_INITIALIZER (list);
+ struct variable **vars = xnmalloc (count, sizeof *vars);
- for (size_t i = idx; i < idx + count; i++)
+ for (size_t i = 0; i < count; i++)
{
- struct delvar *dv = xmalloc (sizeof (struct delvar));
- assert (dv);
- struct variable *v = d->vars[i].var;
+ struct variable *v = d->vars[idx + i].var;
+ vars[i] = v;
dict_unset_split_var (d, v, false);
dict_unset_mrset_var (d, v);
if (d->filter == v)
dict_set_filter (d, NULL);
-
- dv->var = v;
- ll_push_tail (&list, (struct ll *)dv);
}
dict_clear_vectors (d);
/* Now issue the variable delete callbacks and delete
the variables. The vardict is not valid at this point
- anymore. That is the reason why we stored the
- caseindex before reindexing. */
+ anymore. */
if (d->callbacks && d->callbacks->vars_deleted)
d->callbacks->vars_deleted (d, idx, count, d->cb_data);
- for (size_t vi = idx; vi < idx + count; vi++)
+ for (size_t i = 0; i < count; i++)
{
- struct delvar *dv = (struct delvar *) ll_pop_head (&list);
- var_clear_vardict (dv->var);
- var_unref (dv->var);
- free (dv);
+ var_clear_vardict (vars[i]);
+ var_unref (vars[i]);
}
+ free (vars);
- dict_compact_values (d);
+ invalidate_proto (d);
}
/* Deletes scratch variables from dictionary D. */
else
i++;
- dict_compact_values (d);
+ invalidate_proto (d);
}
\f
}
static struct variable *
-add_var_with_case_index (struct dictionary *d, struct variable *v,
- int case_index)
+add_var (struct dictionary *d, struct variable *v)
{
- struct vardict_info *vardict;
-
/* Update dictionary. */
if (d->n_vars >= d->allocated_vars)
{
}
}
- vardict = &d->vars[d->n_vars++];
- vardict->dict = d;
- vardict->var = v;
+ struct vardict_info *vardict = &d->vars[d->n_vars++];
+ *vardict = (struct vardict_info) {
+ .dict = d,
+ .var = v,
+ };
hmap_insert (&d->name_map, &vardict->name_node,
utf8_hash_case_string (var_get_name (v), 0));
- vardict->case_index = case_index;
var_set_vardict (v, vardict);
if (d->changed) d->changed (d, d->changed_data);
return v;
}
-static struct variable *
-add_var (struct dictionary *d, struct variable *v)
-{
- return add_var_with_case_index (d, v, dict_get_n_vars (d));
-}
-
/* Creates and returns a new variable in D with the given NAME
and WIDTH. Returns a null pointer if the given NAME would
duplicate that of an existing variable in the dictionary. */
return add_var (d, new_var);
}
-struct variable *
-dict_clone_var_in_place_assert (struct dictionary *d,
- const struct variable *old_var)
-{
- assert (dict_lookup_var (d, var_get_name (old_var)) == NULL);
- return add_var_with_case_index (d, var_clone (old_var),
- var_get_case_index (old_var));
-}
-
/* Returns the variable named NAME in D, or a null pointer if no
variable has that name. */
struct variable *
unindex_vars (d, MIN (old_index, new_index), MAX (old_index, new_index) + 1);
move_element (d->vars, d->n_vars, sizeof *d->vars, old_index, new_index);
reindex_vars (d, MIN (old_index, new_index), MAX (old_index, new_index) + 1, false);
+
+ if (d->callbacks && d->callbacks->var_moved)
+ d->callbacks->var_moved (d, new_index, old_index, d->cb_data);
}
/* Reorders the variables in D, placing the COUNT variables
{
short int *widths = xnmalloc (d->n_vars, sizeof *widths);
for (size_t i = 0; i < d->n_vars; i++)
- widths[i] = -1;
- for (size_t i = 0; i < d->n_vars; i++)
- {
- const struct variable *var = d->vars[i].var;
- size_t case_idx = var_get_case_index (var);
- assert (case_idx < d->n_vars);
- assert (widths[case_idx] == -1);
- widths[case_idx] = var_get_width (var);
- }
-
+ widths[i] = var_get_width (d->vars[i].var);
d->proto = caseproto_from_widths (widths, d->n_vars);
}
return d->proto;
}
-/* Reassigns values in dictionary D so that fragmentation is
- eliminated. */
-void
-dict_compact_values (struct dictionary *d)
-{
- for (size_t i = 0; i < d->n_vars; i++)
- {
- struct variable *v = d->vars[i].var;
- set_var_case_index (v, i);
- }
- invalidate_proto (d);
-}
-
/* Returns the number of values occupied by the variables in
dictionary D. All variables are considered if EXCLUDE_CLASSES
is 0, or it may contain one or more of DC_ORDINARY, DC_SYSTEM,
const struct variable *,
const char *);
-struct variable *dict_clone_var_in_place_assert (struct dictionary *,
- const struct variable *);
-
/* Deleting variables. */
void dict_delete_var (struct dictionary *, struct variable *);
void dict_delete_vars (struct dictionary *,
{
void (*var_added) (struct dictionary *, int, void *);
void (*vars_deleted) (struct dictionary *, int dict_index, unsigned int n, void *);
+ void (*var_moved) (struct dictionary *, int new_dict_index, int old_dict_index, void *);
void (*var_changed) (struct dictionary *, int, unsigned int, const struct variable *, void *);
void (*weight_changed) (struct dictionary *, int, void *);
void (*filter_changed) (struct dictionary *, int, void *);
const struct variable *dv = dict_get_var (dict, i);
struct pfm_var *pv = &w->vars[i];
pv->width = MIN (var_get_width (dv), MAX_POR_WIDTH);
- pv->case_index = var_get_case_index (dv);
+ pv->case_index = var_get_dict_index (dv);
}
w->digits = opts.digits;
bool
subcase_contains_var (const struct subcase *sc, const struct variable *var)
{
- return subcase_contains (sc, var_get_case_index (var));
+ return subcase_contains (sc, var_get_dict_index (var));
}
/* Returns true if CASE_INDEX already has a field in SC,
subcase_add_var_always (struct subcase *sc, const struct variable *var,
enum subcase_direction direction)
{
- return subcase_add_always (sc, var_get_case_index (var),
+ return subcase_add_always (sc, var_get_dict_index (var),
var_get_width (var), direction);
}
for (i = 0; i < n_vars; i++)
{
struct subcase_field *field = &sc->fields[sc->n_fields++];
- field->case_index = var_get_case_index (vars[i]);
+ field->case_index = var_get_dict_index (vars[i]);
field->width = var_get_width (vars[i]);
field->direction = SC_ASCEND;
}
sv = &(*sfm_vars)[(*sfm_n_vars)++];
sv->var_width = width;
sv->segment_width = width == 0 ? 0 : used_bytes;
- sv->case_index = var_get_case_index (dv);
+ sv->case_index = var_get_dict_index (dv);
sv->offset = sfm_segment_offset (width, j);
sv->padding = padding;
}
#include <assert.h>
#include <stdlib.h>
+#include "libpspp/array.h"
#include "libpspp/str.h"
#include "gl/xalloc.h"
return ok;
}
+void
+trns_chain_prepend (struct trns_chain *chain, const struct transformation *t)
+{
+ if (chain->n >= chain->allocated)
+ chain->xforms = x2nrealloc (chain->xforms, &chain->allocated,
+ sizeof *chain->xforms);
+
+ insert_element (chain->xforms, 1, sizeof *chain->xforms, 0);
+ chain->xforms[0] = *t;
+ chain->n++;
+}
+
void
trns_chain_append (struct trns_chain *chain, const struct transformation *t)
{
bool trns_chain_clear (struct trns_chain *);
+void trns_chain_prepend (struct trns_chain *, const struct transformation *);
void trns_chain_append (struct trns_chain *, const struct transformation *);
void trns_chain_splice (struct trns_chain *, struct trns_chain *);
struct dictionary *dict;
struct variable *var;
struct hmap_node name_node; /* In struct dictionary's name_map. */
- int case_index; /* Index into case of variable data. */
};
/* Called by dictionary code, defined in variable.c. */
int vardict_get_dict_index (const struct vardict_info *);
-static inline int
-vardict_get_case_index (const struct vardict_info *vardict)
-{
- return vardict->case_index;
-}
-
static inline struct dictionary *
vardict_get_dictionary (const struct vardict_info *vardict)
{
assert (var_has_vardict (v));
return vardict_get_dict_index (v->vardict);
}
-
-/* Returns V's index within the case represented by its
- dictionary, that is, the value for which "case_data_idx (case,
- index)" will return the data for V in that case.
- V must be in a dictionary. */
-size_t
-var_get_case_index (const struct variable *v)
-{
- assert (var_has_vardict (v));
- return vardict_get_case_index (v->vardict);
-}
\f
/* Returns variable V's attribute set. The caller may examine or
modify the attribute set, but must not destroy it. Destroying
/* Relationship with dictionary. */
size_t var_get_dict_index (const struct variable *);
-size_t var_get_case_index (const struct variable *);
/* Custom attributes. */
struct attrset *var_get_attributes (const struct variable *);
struct arc_spec *spec = &arc->specs[i];
spec->width = var_get_width (src_vars[i]);
- spec->src_idx = var_get_case_index (src_vars[i]);
+ spec->src_idx = var_get_dict_index (src_vars[i]);
spec->src_name = xstrdup (var_get_name (src_vars[i]));
spec->format = var_get_print_format (src_vars[i]);
/* Create destination variable. */
struct variable *dst = dict_create_var_assert (dict, dst_names[i], 0);
- spec->dst_idx = var_get_case_index (dst);
+ spec->dst_idx = var_get_dict_index (dst);
var_set_label (dst, spec->label);
/* Set print format. */
}
data_parser_add_fixed_field (parser, *f,
- var_get_case_index (v),
+ var_get_dict_index (v),
var_get_name (v), record, column);
column += f->w;
var_set_both_formats (v, output);
data_parser_add_delimited_field (parser,
- input, var_get_case_index (v),
+ input, var_get_dict_index (v),
var_get_name (v));
}
}
if (examine.id_var)
{
- examine.id_idx = var_get_case_index (examine.id_var);
+ examine.id_idx = var_get_dict_index (examine.id_var);
examine.id_width = var_get_width (examine.id_var);
}
var_set_both_formats (v, output);
if (type == DP_DELIMITED)
data_parser_add_delimited_field (parser, input,
- var_get_case_index (v),
+ var_get_dict_index (v),
name);
else
- data_parser_add_fixed_field (parser, input, var_get_case_index (v),
+ data_parser_add_fixed_field (parser, input, var_get_dict_index (v),
name, record, fc);
free (name);
name = NULL;
struct ccase *c;
const struct variable *wv = dict_get_weight (dict);
const int w_idx = wv ?
- var_get_case_index (wv) :
+ var_get_dict_index (wv) :
caseproto_get_n_widths (casereader_get_proto (r)) ;
r = sort_execute_1var (r, var);
$ORDER). */
struct rank_trns *trns = xmalloc (sizeof *trns);
*trns = (struct rank_trns) {
- .order_case_idx = var_get_case_index (order_var),
+ .order_case_idx = var_get_dict_index (order_var),
.input_vars = xnmalloc (cmd->n_vars, sizeof *trns->input_vars),
.n_input_vars = cmd->n_vars,
.n_funcs = cmd->n_rs,
var_set_label (var, rs->dest_labels[i]);
var_set_measure (var, rank_measures[rs->rfunc]);
- iv->output_var_indexes[j] = var_get_case_index (var);
+ iv->output_var_indexes[j] = var_get_dict_index (var);
}
}
free (outputs);
struct casereader *r1 =
casereader_create_distinct (sort_execute_1var (reader, var), var, w);
- const int weight_idx = w ? var_get_case_index (w) :
+ const int weight_idx = w ? var_get_dict_index (w) :
caseproto_get_n_widths (casereader_get_proto (r1)) - 1;
struct ccase *c1;
size_t n_vars;
dict_get_vars_mutable (d, &vars, &n_vars, 0);
sort (vars, n_vars, sizeof *vars, compare_vars, &c);
- dict_reorder_vars (d, CONST_CAST (struct variable *const *, vars), n_vars);
+ proc_execute (ds);
+ dataset_reorder_vars (ds, vars, n_vars);
free (vars);
result = CMD_SUCCESS;
exclude, NULL, NULL);
order_stats_accumulate_idx (os, n_os, reader,
- weight_var ? var_get_case_index (weight_var) : -1,
- var_get_case_index (data_var));
+ weight_var ? var_get_dict_index (weight_var) : -1,
+ var_get_dict_index (data_var));
}
i != ip->end (current_row, fd->data);
ip->next (&i, fd->data))
{
- datasheet_get_value (fd->data, i, var_get_case_index (var), &val);
+ datasheet_get_value (fd->data, i, var_get_dict_index (var), &val);
if (comparator_compare (cmptr, &val))
{
VOID:POINTER,INT,INT
VOID:INT,UINT,POINTER
VOID:UINT,UINT,UINT
-VOID:INT,UINT
\ No newline at end of file
+VOID:INT,INT
+VOID:INT,UINT
posn, NULL);
psppire_data_store_insert_value (data_store, var_get_width(v),
- var_get_case_index (v));
+ var_get_dict_index (v));
ssw_sheet_scroll_to (SSW_SHEET (sheet), posn, -1);
g_value_init (value, G_TYPE_VARIANT);
- const union value *val = case_data_idx (cc, var_get_case_index (variable));
+ const union value *val = case_data_idx (cc, var_get_dict_index (variable));
GVariant *vv = value_variant_new (val, var_get_width (variable));
psppire_data_store_delete_values (store, dict_index, n);
}
+/*
+ A callback which occurs after variables have been deleted.
+ */
+static void
+move_variable_callback (GObject *obj, gint new_dict_index, int old_dict_index, gpointer data)
+{
+ PsppireDataStore *store = PSPPIRE_DATA_STORE (data);
+
+ datasheet_move_columns (store->datasheet, old_dict_index, new_dict_index, 1);
+}
+
struct resize_datum_aux
{
const struct dictionary *dict;
if (what & VAR_TRAIT_WIDTH)
{
- int posn = var_get_case_index (variable);
+ int posn = var_get_dict_index (variable);
struct resize_datum_aux aux;
aux.old_variable = oldvar;
aux.new_variable = variable;
store = PSPPIRE_DATA_STORE (data);
variable = psppire_dict_get_variable (store->dict, var_num);
- posn = var_get_case_index (variable);
+ posn = var_get_dict_index (variable);
psppire_data_store_insert_value (store, var_get_width (variable), posn);
}
G_CALLBACK (delete_variables_callback),
data_store);
+ data_store->dict_handler_id [VARIABLE_MOVED] =
+ g_signal_connect (dict, "variable-moved",
+ G_CALLBACK (move_variable_callback),
+ data_store);
+
data_store->dict_handler_id [VARIABLE_CHANGED] =
g_signal_connect (dict, "variable-changed",
G_CALLBACK (variable_changed_callback),
int width = var_get_width (var);
value_init (val, width);
- datasheet_get_value (store->datasheet, row, var_get_case_index (var), val);
+ datasheet_get_value (store->datasheet, row, var_get_dict_index (var), val);
return TRUE;
}
if (row == n_cases)
psppire_data_store_insert_new_case (store, row);
- case_index = var_get_case_index (var);
+ case_index = var_get_dict_index (var);
if (use_value_label)
{
const struct val_labs *vls = var_get_value_labels (var);
if (casenum == n_cases)
psppire_data_store_insert_new_case (ds, casenum);
- ok = datasheet_put_value (ds->datasheet, casenum, var_get_case_index (var),
+ ok = datasheet_put_value (ds->datasheet, casenum, var_get_dict_index (var),
v);
if (ok)
{
g_return_val_if_fail (var_is_numeric (filter), FALSE);
value_init (&val, 0);
if (! datasheet_get_value (ds->datasheet, row,
- var_get_case_index (filter),
+ var_get_dict_index (filter),
&val))
return FALSE;
VARIABLE_INSERTED,
VARIABLE_CHANGED,
VARIABLES_DELETED,
+ VARIABLE_MOVED,
n_dict_signals
};
VARIABLE_CHANGED,
VARIABLE_INSERTED,
VARIABLES_DELETED,
+ VARIABLE_MOVED,
WEIGHT_CHANGED,
FILTER_CHANGED,
G_TYPE_INT,
G_TYPE_UINT);
+ signals [VARIABLE_MOVED] =
+ g_signal_new ("variable-moved",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_FIRST,
+ 0,
+ NULL, NULL,
+ psppire_marshal_VOID__INT_INT,
+ G_TYPE_NONE,
+ 2,
+ G_TYPE_INT,
+ G_TYPE_INT);
+
signals [WEIGHT_CHANGED] =
g_signal_new ("weight-changed",
G_TYPE_FROM_CLASS (class),
/* Pass on callbacks from src/data/dictionary, as
signals in the Gtk library */
static void
-addcb (struct dictionary *d, int idx, void *pd)
+var_added_callback (struct dictionary *d, int idx, void *pd)
{
PsppireDict *dict = PSPPIRE_DICT (pd);
}
static void
-delcb (struct dictionary *d, int dict_idx, unsigned int n, void *pd)
+vars_deleted_callback (struct dictionary *d, int dict_idx, unsigned int n, void *pd)
{
g_signal_emit (pd, signals [VARIABLES_DELETED], 0, dict_idx, n);
g_signal_emit_by_name (pd, "items-changed", dict_idx, 1, 0);
}
static void
-mutcb (struct dictionary *d, int idx, unsigned int what, const struct variable *oldvar, void *pd)
+var_moved_callback (struct dictionary *d, int new_dict_index, int old_dict_index, void *pd)
+{
+ g_signal_emit (pd, signals [VARIABLE_MOVED], 0, new_dict_index, old_dict_index);
+}
+
+static void
+var_changed_callback (struct dictionary *d, int idx, unsigned int what, const struct variable *oldvar, void *pd)
{
g_signal_emit (pd, signals [VARIABLE_CHANGED], 0, idx, what, oldvar);
g_signal_emit_by_name (pd, "items-changed", idx, 1, 1);
static const struct dict_callbacks gui_callbacks =
{
- addcb,
- delcb,
- mutcb,
- weight_changed_callback,
- filter_changed_callback,
- split_changed_callback
+ .var_added = var_added_callback,
+ .vars_deleted = vars_deleted_callback,
+ .var_moved = var_moved_callback,
+ .var_changed = var_changed_callback,
+ .weight_changed = weight_changed_callback,
+ .filter_changed = filter_changed_callback,
+ .split_changed = split_changed_callback
};
static void