+Mon May 15 20:01:25 WST 2006 John Darrington <john@darrington.wattle.id.au>
+
+ * 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 <john@darrington.wattle.id.au>
* data-sheet.c, helper.c, helper.h, psppire-data-store.c,
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;
}
}
}
+/* 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,
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:
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);
}
}
-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
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);
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,
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);
}
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);
gint v;
PsppireDict *d = PSPPIRE_DICT (object);
-
-
for (v = 0 ; v < psppire_dict_get_var_cnt(d) ; ++v )
g_free(d->variables[v]);
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);
return pv->v->width;
}
+
+/* FIXME: This name is misleading */
gint
psppire_variable_get_index(const struct PsppireVariable *pv)
{