From: John Darrington Date: Mon, 15 May 2006 12:03:58 +0000 (+0000) Subject: When inserting new cases into the data sheet, initialise them with blank/SYSMIS X-Git-Tag: v0.6.0~846 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9d888a2e774f76e66e31b2ab60a1d4b2d451e635;p=pspp-builds.git When inserting new cases into the data sheet, initialise them with blank/SYSMIS --- diff --git a/src/ui/gui/ChangeLog b/src/ui/gui/ChangeLog index c5311ede..3d1b900e 100644 --- a/src/ui/gui/ChangeLog +++ b/src/ui/gui/ChangeLog @@ -1,3 +1,11 @@ +Mon May 15 20:01:25 WST 2006 John Darrington + + * menu-actions.c psppire-case-array.c psppire-case-array.h + psppire-data-store.c psppire-dict.c psppire-dict.h + psppire-variable.c: + + Initialised new cases to SYSMIS/blank when inserting in data sheet. + Sat May 13 08:00:50 WST 2006 John Darrington * data-sheet.c, helper.c, helper.h, psppire-data-store.c, diff --git a/src/ui/gui/menu-actions.c b/src/ui/gui/menu-actions.c index 31800452..38f73ebe 100644 --- a/src/ui/gui/menu-actions.c +++ b/src/ui/gui/menu-actions.c @@ -200,9 +200,9 @@ on_open1_activate (GtkMenuItem *menuitem, for(case_num=0;;case_num++) { - if (!psppire_case_array_add_case(the_cases, - populate_case_from_reader, - reader)) + if (!psppire_case_array_append_case(the_cases, + populate_case_from_reader, + reader)) break; } } @@ -325,6 +325,35 @@ on_paste1_activate (GtkMenuItem *menuitem, } +/* Fill a case with SYSMIS for numeric and whitespace for string + variables respectively */ +static gboolean +blank_case(struct ccase *cc, gpointer _dict) +{ + gint i; + PsppireDict *dict = _dict; + + for(i = 0 ; i < psppire_dict_get_var_cnt(dict); ++i ) + { + union value *val ; + + const struct PsppireVariable *var = psppire_dict_get_variable(dict, i); + + gint idx = psppire_variable_get_index(var); + + val = case_data_rw(cc, idx) ; + + if ( psppire_variable_get_type(var) == ALPHA ) + memset(val->s, ' ', psppire_variable_get_width(var)); + else + val->f = SYSMIS; + + case_unshare(cc); + } + + return TRUE; +} + void on_insert1_activate (GtkMenuItem *menuitem, @@ -343,7 +372,9 @@ on_insert1_activate (GtkMenuItem *menuitem, PsppireDataStore *data_store = PSPPIRE_DATA_STORE(gtk_sheet_get_model(data_sheet)); - psppire_case_array_insert_case(data_store->cases, data_sheet->range.row0); + psppire_case_array_insert_case(data_store->cases, + data_sheet->range.row0, + blank_case, the_dictionary); } break; case PAGE_VAR_SHEET: diff --git a/src/ui/gui/psppire-case-array.c b/src/ui/gui/psppire-case-array.c index edff51fa..871e9e15 100644 --- a/src/ui/gui/psppire-case-array.c +++ b/src/ui/gui/psppire-case-array.c @@ -176,24 +176,15 @@ psppire_case_array_resize(PsppireCaseArray *ca, gint new_size) ca->width = new_size; } -/* FIXME: add_case and insert_case need to be merged/refactored */ -gboolean -psppire_case_array_add_case(PsppireCaseArray *ca, + +/* Append a case to the case array. If FILL_CASE_FUNC is not NULL, + * then use it to populate the case */ +inline gboolean +psppire_case_array_append_case(PsppireCaseArray *ca, psppire_case_array_fill_case_func fill_case_func, gpointer aux) { - g_return_val_if_fail(ca->size < ca->capacity, FALSE); - - case_create(&ca->cases[ca->size], ca->width); - - if ( !fill_case_func(&ca->cases[ca->size], aux)) - return FALSE; - - ca->size++; - - g_signal_emit(ca, signal[CASE_INSERTED], 0, ca->size - 1); - - return TRUE; + return psppire_case_array_insert_case(ca, ca->size, fill_case_func, aux); } @@ -215,24 +206,33 @@ psppire_case_array_iterate_case(PsppireCaseArray *ca, } -void -psppire_case_array_insert_case(PsppireCaseArray *ca, gint posn) +/* Insert a new case before case POSN. + * If FILL_CASE_FUNC is not NULL, then use it to populate the new case */ +gboolean +psppire_case_array_insert_case(PsppireCaseArray *ca, gint posn, + psppire_case_array_fill_case_func fill_case_func, + gpointer aux) + { gint i; - g_return_if_fail(posn >= 0); - g_return_if_fail(posn <= ca->size); - - g_assert(ca->size + 1 <= ca->capacity); + g_return_val_if_fail(posn >= 0, FALSE); + g_return_val_if_fail(posn <= ca->size, FALSE); + g_return_val_if_fail(ca->size < ca->capacity, FALSE); for(i = ca->size; i > posn ; --i) case_move(&ca->cases[i], &ca->cases[i - 1]); case_create(&ca->cases[posn], ca->width); + if ( fill_case_func && !fill_case_func(&ca->cases[posn], aux)) + return FALSE; + ca->size++; g_signal_emit(ca, signal[CASE_INSERTED], 0, posn); + + return TRUE; } void diff --git a/src/ui/gui/psppire-case-array.h b/src/ui/gui/psppire-case-array.h index a405b414..bb227f96 100644 --- a/src/ui/gui/psppire-case-array.h +++ b/src/ui/gui/psppire-case-array.h @@ -72,7 +72,6 @@ PsppireCaseArray *psppire_case_array_new (gint capacity, gint width); void psppire_case_array_resize(PsppireCaseArray *ca, gint new_size); -void psppire_case_array_insert_case(PsppireCaseArray *ca, gint posn); void psppire_case_array_delete_cases(PsppireCaseArray *ca, gint first, gint n_cases); @@ -81,10 +80,13 @@ typedef gboolean psppire_case_array_fill_case_func(struct ccase *, gpointer aux) typedef gboolean psppire_case_array_use_case_func(const struct ccase *, gpointer aux); +gboolean psppire_case_array_insert_case(PsppireCaseArray *ca, gint posn, + psppire_case_array_fill_case_func fill_case_func, + gpointer aux); -gboolean psppire_case_array_add_case(PsppireCaseArray *ca, - psppire_case_array_fill_case_func fill_case_func, - gpointer aux); +inline gboolean psppire_case_array_append_case(PsppireCaseArray *ca, + psppire_case_array_fill_case_func fill_case_func, + gpointer aux); gboolean psppire_case_array_iterate_case(PsppireCaseArray *ca, diff --git a/src/ui/gui/psppire-data-store.c b/src/ui/gui/psppire-data-store.c index 53aa827d..116092fd 100644 --- a/src/ui/gui/psppire-data-store.c +++ b/src/ui/gui/psppire-data-store.c @@ -187,14 +187,15 @@ static void insert_case_callback(GtkWidget *w, gint casenum, gpointer data) { PsppireDataStore *store ; + g_return_if_fail (data); store = PSPPIRE_DATA_STORE(data); g_sheet_model_range_changed (G_SHEET_MODEL(store), - casenum, -1, - psppire_case_array_get_n_cases(store->cases), - -1); + casenum, -1, + psppire_case_array_get_n_cases(store->cases), + -1); } @@ -453,7 +454,7 @@ psppire_data_store_set_string(GSheetModel *model, for(r = psppire_case_array_get_n_cases(store->cases) ; r <= row ; ++r ) { gint c; - psppire_case_array_insert_case(store->cases, r); + psppire_case_array_insert_case(store->cases, r, 0, 0); for (c = 0 ; c < psppire_dict_get_var_cnt(store->dict); ++c ) psppire_data_store_clear_datum(model, r, c); diff --git a/src/ui/gui/psppire-dict.c b/src/ui/gui/psppire-dict.c index 5f2975a1..a8a8f636 100644 --- a/src/ui/gui/psppire-dict.c +++ b/src/ui/gui/psppire-dict.c @@ -151,8 +151,6 @@ psppire_dict_finalize (GObject *object) gint v; PsppireDict *d = PSPPIRE_DICT (object); - - for (v = 0 ; v < psppire_dict_get_var_cnt(d) ; ++v ) g_free(d->variables[v]); diff --git a/src/ui/gui/psppire-dict.h b/src/ui/gui/psppire-dict.h index 173ed486..96753ab5 100644 --- a/src/ui/gui/psppire-dict.h +++ b/src/ui/gui/psppire-dict.h @@ -72,11 +72,6 @@ PsppireDict* psppire_dict_new_from_dict (struct dictionary *d); void psppire_dict_set_name (PsppireDict* s, gint idx, const gchar *name); void psppire_dict_delete_var (PsppireDict *s, gint idx); -/* Return the variable indexed by IDX. - returns NULL if IDX is not valid. -*/ -struct variable *psppire_dict_get_var(PsppireDict *d, gint idx); - /* Return the number of variables in the dictionary */ gint psppire_dict_get_var_cnt(const PsppireDict *d); diff --git a/src/ui/gui/psppire-variable.c b/src/ui/gui/psppire-variable.c index 49dd84b6..1256c82f 100644 --- a/src/ui/gui/psppire-variable.c +++ b/src/ui/gui/psppire-variable.c @@ -345,6 +345,8 @@ psppire_variable_get_width(const struct PsppireVariable *pv) return pv->v->width; } + +/* FIXME: This name is misleading */ gint psppire_variable_get_index(const struct PsppireVariable *pv) {