1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2012, 2013 Free Software Foundation
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "psppire-dialog-action-two-sample.h"
22 #include "psppire-var-view.h"
24 #include "psppire-selector.h"
25 #include "psppire-dialog.h"
26 #include "builder-wrapper.h"
29 #define _(msgid) gettext (msgid)
30 #define N_(msgid) msgid
33 static void psppire_dialog_action_two_sample_init (PsppireDialogActionTwoSample *act);
34 static void psppire_dialog_action_two_sample_class_init (PsppireDialogActionTwoSampleClass *class);
36 G_DEFINE_TYPE (PsppireDialogActionTwoSample, psppire_dialog_action_two_sample, PSPPIRE_TYPE_DIALOG_ACTION);
40 dialog_state_valid (gpointer data)
42 PsppireDialogActionTwoSample *pd = PSPPIRE_DIALOG_ACTION_TWO_SAMPLE (data);
43 gint n_rows = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (pd->list_store), NULL);
44 struct variable *v = NULL;
45 GtkTreeIter dest_iter;
50 /* Get the last row */
51 gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (pd->list_store), &dest_iter,
54 /* Get the last (2nd) column */
55 gtk_tree_model_get (GTK_TREE_MODEL (pd->list_store), &dest_iter, 1, &v, -1);
61 /* Now check that at least one toggle button is selected */
63 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (pd->nts[NT_WILCOXON].button)))
66 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (pd->nts[NT_SIGN].button)))
69 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (pd->nts[NT_MCNEMAR].button)))
76 refresh (PsppireDialogAction *rd_)
78 PsppireDialogActionTwoSample *pd = PSPPIRE_DIALOG_ACTION_TWO_SAMPLE (rd_);
80 gtk_list_store_clear (GTK_LIST_STORE (pd->list_store));
82 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pd->nts[NT_WILCOXON].button), FALSE);
83 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pd->nts[NT_SIGN].button), FALSE);
84 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pd->nts[NT_MCNEMAR].button), FALSE);
89 select_as_pair_member (GtkTreeIter source_iter,
91 GtkTreeModel *source_model,
97 GtkTreeIter dest_iter;
98 PsppireDialogActionTwoSample *tt_d = PSPPIRE_DIALOG_ACTION_TWO_SAMPLE (data);
101 gtk_tree_model_get (source_model, &source_iter,
102 DICT_TVM_COL_VAR, &v, -1);
104 n_rows = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (tt_d->list_store), NULL);
109 gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (tt_d->list_store),
110 &dest_iter, NULL, n_rows - 1);
112 gtk_tree_model_get (GTK_TREE_MODEL (tt_d->list_store), &dest_iter, 1, &v1, -1);
117 if ( n_rows == 0 || v1 != NULL)
119 gtk_list_store_append (tt_d->list_store, &dest_iter);
121 gtk_list_store_set (tt_d->list_store, &dest_iter,
128 gtk_list_store_set (tt_d->list_store, &dest_iter,
137 generate_syntax (PsppireDialogAction *pda)
141 PsppireDialogActionTwoSample *d = PSPPIRE_DIALOG_ACTION_TWO_SAMPLE (pda);
144 GString *str = g_string_new ("NPAR TEST");
146 for (i = 0 ; i < n_Tests; ++i)
148 if (! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (d->nts[i].button)))
151 g_string_append (str, "\n\t");
152 g_string_append (str, d->nts[i].syntax);
154 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (d->pairs_treeview), 0, str);
156 g_string_append (str, " WITH ");
158 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (d->pairs_treeview), 1, str);
160 g_string_append (str, " (PAIRED)");
163 g_string_append (str, ".\n");
166 g_string_free (str, FALSE);
172 psppire_dialog_action_two_sample_activate (GtkAction *a)
174 PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
175 PsppireDialogActionTwoSample *act = PSPPIRE_DIALOG_ACTION_TWO_SAMPLE (a);
177 GtkBuilder *xml = builder_new ("paired-samples.ui");
178 GtkWidget *selector = get_widget_assert (xml, "psppire-selector3");
180 pda->dialog = get_widget_assert (xml, "t-test-paired-samples-dialog");
181 pda->source = get_widget_assert (xml, "paired-samples-t-test-treeview1");
183 gtk_window_set_title (GTK_WINDOW (pda->dialog), _("Two-Related-Samples Tests"));
185 act->pairs_treeview = get_widget_assert (xml, "paired-samples-t-test-treeview2");
186 act->list_store = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (act->pairs_treeview)));
189 /* NPAR Specific options */
190 GtkWidget *frame = gtk_frame_new (_("Test Type"));
191 GtkWidget *bb = gtk_vbutton_box_new ();
192 GtkWidget *box = get_widget_assert (xml, "vbox3");
195 strcpy (act->nts[NT_WILCOXON].syntax, "/WILCOXON");
196 strcpy (act->nts[NT_SIGN].syntax, "/SIGN");
197 strcpy (act->nts[NT_MCNEMAR].syntax, "/MCNEMAR");
199 act->nts[NT_WILCOXON].button = gtk_check_button_new_with_mnemonic (_("_Wilcoxon"));
200 act->nts[NT_SIGN].button = gtk_check_button_new_with_mnemonic (_("_Sign"));
201 act->nts[NT_MCNEMAR].button = gtk_check_button_new_with_mnemonic (_("_McNemar"));
203 gtk_box_pack_start (GTK_BOX (bb), act->nts[NT_WILCOXON].button, FALSE, FALSE, 5);
204 gtk_box_pack_start (GTK_BOX (bb), act->nts[NT_SIGN].button, FALSE, FALSE, 5);
205 gtk_box_pack_start (GTK_BOX (bb), act->nts[NT_MCNEMAR].button, FALSE, FALSE, 5);
207 gtk_container_add (GTK_CONTAINER (frame), bb);
209 gtk_widget_show_all (frame);
211 gtk_box_pack_start (GTK_BOX (box), frame, FALSE, FALSE, 5);
214 psppire_dialog_action_set_valid_predicate (pda, dialog_state_valid);
215 psppire_dialog_action_set_refresh (pda, refresh);
217 g_object_set (pda->source,
218 "predicate", var_is_numeric,
221 psppire_selector_set_select_func (PSPPIRE_SELECTOR (selector),
222 select_as_pair_member,
225 g_object_unref (xml);
227 if (PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_two_sample_parent_class)->activate)
228 PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_two_sample_parent_class)->activate (pda);
232 psppire_dialog_action_two_sample_class_init (PsppireDialogActionTwoSampleClass *class)
234 GtkActionClass *action_class = GTK_ACTION_CLASS (class);
236 action_class->activate = psppire_dialog_action_two_sample_activate;
237 PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax;
242 psppire_dialog_action_two_sample_init (PsppireDialogActionTwoSample *act)