From 17d24f693f92db39158e0204d7125c5c0b9b5009 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Tue, 14 Feb 2012 11:13:15 +0100 Subject: [PATCH] Reliability Test: Do not allow splits greater than the number of variables. It's not meaningful to have a split point which is greater than the number of variables (and not useful when they are equal). And the system was exhaughsting its memory when such a test was run. This change therefore disallows such a combination and updates the behaviour of the GUI accordingly. --- src/language/stats/reliability.c | 6 +++ .../gui/psppire-dialog-action-reliability.c | 42 ++++++++++++++++--- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/language/stats/reliability.c b/src/language/stats/reliability.c index 5378ed8974..744763382a 100644 --- a/src/language/stats/reliability.c +++ b/src/language/stats/reliability.c @@ -263,6 +263,12 @@ cmd_reliability (struct lexer *lexer, struct dataset *ds) int i; const struct cronbach *s; + if ( reliability.split_point >= reliability.n_variables) + { + msg (ME, _("The split point must be less than the number of variables")); + goto error; + } + reliability.n_sc += 2 ; reliability.sc = xrealloc (reliability.sc, sizeof (struct cronbach) * reliability.n_sc); diff --git a/src/ui/gui/psppire-dialog-action-reliability.c b/src/ui/gui/psppire-dialog-action-reliability.c index 67d8c186a5..465aea8de0 100644 --- a/src/ui/gui/psppire-dialog-action-reliability.c +++ b/src/ui/gui/psppire-dialog-action-reliability.c @@ -29,6 +29,12 @@ static void psppire_dialog_action_reliability_class_init (PsppireDialogActi G_DEFINE_TYPE (PsppireDialogActionReliability, psppire_dialog_action_reliability, PSPPIRE_TYPE_DIALOG_ACTION); +enum + { + ALPHA = 0, + SPLIT = 1 + }; + static char * generate_syntax (PsppireDialogAction *act) { @@ -42,7 +48,7 @@ generate_syntax (PsppireDialogAction *act) g_string_append (string, "\n\t/MODEL="); - if ( 0 == gtk_combo_box_get_active (GTK_COMBO_BOX (rd->model_combo))) + if ( ALPHA == gtk_combo_box_get_active (GTK_COMBO_BOX (rd->model_combo))) g_string_append (string, "ALPHA"); else g_string_append_printf (string, "SPLIT (%d)", @@ -73,10 +79,23 @@ dialog_state_valid (gpointer user_data) } static void -on_method_change (PsppireDialogActionReliability *pda) +update_split_control (PsppireDialogActionReliability *pda) { + GtkTreeModel *liststore = + gtk_tree_view_get_model (GTK_TREE_VIEW (pda->variables)); + + gint n_vars = gtk_tree_model_iter_n_children (liststore, NULL); + + gint sp = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (pda->split_spinbutton)); + + if (sp >= n_vars) + gtk_spin_button_set_value (GTK_SPIN_BUTTON (pda->split_spinbutton), n_vars - 1); + + gtk_spin_button_set_range (GTK_SPIN_BUTTON (pda->split_spinbutton), + 0, n_vars - 1); + gtk_widget_set_sensitive (pda->split_point_hbox, - ( 1 == gtk_combo_box_get_active (GTK_COMBO_BOX (pda->model_combo)))); + ( SPLIT == gtk_combo_box_get_active (GTK_COMBO_BOX (pda->model_combo)))); } @@ -89,7 +108,7 @@ refresh (PsppireDialogAction *pda_) gtk_tree_view_get_model (GTK_TREE_VIEW (pda->variables)); gtk_list_store_clear (GTK_LIST_STORE (liststore)); - gtk_combo_box_set_active (GTK_COMBO_BOX (pda->model_combo), 0); + gtk_combo_box_set_active (GTK_COMBO_BOX (pda->model_combo), ALPHA); gtk_spin_button_set_value (GTK_SPIN_BUTTON (pda->split_spinbutton), 0); @@ -105,7 +124,7 @@ psppire_dialog_action_reliability_activate (GtkAction *a) { PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a); PsppireDialogActionReliability *act = PSPPIRE_DIALOG_ACTION_RELIABILITY (a); - + GtkTreeModel *liststore ; GtkBuilder *xml = builder_new ("reliability.ui"); pda->dialog = get_widget_assert (xml, "reliability-dialog"); pda->source = get_widget_assert (xml, "dict-view"); @@ -119,10 +138,21 @@ psppire_dialog_action_reliability_activate (GtkAction *a) act->model_combo = get_widget_assert (xml, "combobox1"); act->split_spinbutton = get_widget_assert (xml, "spinbutton1"); + liststore = + gtk_tree_view_get_model (GTK_TREE_VIEW (act->variables)); + + act->scale_if_item_deleted_checkbutton = get_widget_assert (xml, "totals-checkbutton"); g_signal_connect_swapped (act->model_combo, "changed", - G_CALLBACK (on_method_change), pda); + G_CALLBACK (update_split_control), pda); + + + g_signal_connect_swapped (liststore, "row-inserted", + G_CALLBACK (update_split_control), pda); + g_signal_connect_swapped (liststore, "row-deleted", + G_CALLBACK (update_split_control), pda); + psppire_dialog_action_set_refresh (pda, refresh); psppire_dialog_action_set_valid_predicate (pda, dialog_state_valid); -- 2.30.2