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-paired.h"
22 #include "psppire-var-view.h"
24 #include "psppire-selector.h"
25 #include "psppire-dialog.h"
26 #include "builder-wrapper.h"
28 #include "t-test-options.h"
31 #define _(msgid) gettext (msgid)
32 #define N_(msgid) msgid
35 static void psppire_dialog_action_paired_init (PsppireDialogActionPaired *act);
36 static void psppire_dialog_action_paired_class_init (PsppireDialogActionPairedClass *class);
38 G_DEFINE_TYPE (PsppireDialogActionPaired, psppire_dialog_action_paired, PSPPIRE_TYPE_DIALOG_ACTION);
42 dialog_state_valid (gpointer data)
44 PsppireDialogActionPaired *pd = PSPPIRE_DIALOG_ACTION_PAIRED (data);
45 gint n_rows = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (pd->list_store), NULL);
46 struct variable *v = NULL;
47 GtkTreeIter dest_iter;
52 /* Get the last row */
53 gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (pd->list_store), &dest_iter,
56 /* Get the last (2nd) column */
57 gtk_tree_model_get (GTK_TREE_MODEL (pd->list_store), &dest_iter, 1, &v, -1);
62 /* if ( NULL == pd->valid) */
66 // return pd->valid (pd->aux);
70 refresh (PsppireDialogAction *rd_)
72 PsppireDialogActionPaired *pd = PSPPIRE_DIALOG_ACTION_PAIRED (rd_);
74 gtk_list_store_clear (GTK_LIST_STORE (pd->list_store));
79 select_as_pair_member (GtkTreeIter source_iter,
81 GtkTreeModel *source_model,
87 GtkTreeIter dest_iter;
88 PsppireDialogActionPaired *tt_d = PSPPIRE_DIALOG_ACTION_PAIRED (data);
91 gtk_tree_model_get (source_model, &source_iter,
92 DICT_TVM_COL_VAR, &v, -1);
94 n_rows = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (tt_d->list_store), NULL);
99 gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (tt_d->list_store),
100 &dest_iter, NULL, n_rows - 1);
102 gtk_tree_model_get (GTK_TREE_MODEL (tt_d->list_store), &dest_iter, 1, &v1, -1);
107 if ( n_rows == 0 || v1 != NULL)
109 gtk_list_store_append (tt_d->list_store, &dest_iter);
111 gtk_list_store_set (tt_d->list_store, &dest_iter,
118 gtk_list_store_set (tt_d->list_store, &dest_iter,
127 generate_syntax (PsppireDialogAction *pda)
129 PsppireDialogActionPaired *d = PSPPIRE_DIALOG_ACTION_PAIRED (pda);
131 GString *str = g_string_new ("T-TEST \n\tPAIRS = ");
133 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (d->pairs_treeview), 0, str);
135 g_string_append (str, " WITH ");
137 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (d->pairs_treeview), 1, str);
139 g_string_append (str, " (PAIRED)");
140 g_string_append (str, "\n");
142 tt_options_dialog_append_syntax (d->opt, str);
144 g_string_append (str, ".\n");
147 g_string_free (str, FALSE);
153 psppire_dialog_action_paired_activate (GtkAction *a)
155 PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
156 PsppireDialogActionPaired *act = PSPPIRE_DIALOG_ACTION_PAIRED (a);
158 GtkBuilder *xml = builder_new ("paired-samples.ui");
159 GtkWidget *selector = get_widget_assert (xml, "psppire-selector3");
160 GtkWidget *bb = gtk_hbutton_box_new ();
161 GtkWidget *button = gtk_button_new_with_mnemonic (_("O_ptions..."));
162 GtkWidget *box = get_widget_assert (xml, "vbox3");
165 pda->dialog = get_widget_assert (xml, "t-test-paired-samples-dialog");
166 pda->source = get_widget_assert (xml, "paired-samples-t-test-treeview1");
168 gtk_window_set_title (GTK_WINDOW (pda->dialog), _("Paired Samples T Test"));
170 act->pairs_treeview = get_widget_assert (xml, "paired-samples-t-test-treeview2");
171 act->list_store = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (act->pairs_treeview)));
173 act->opt = tt_options_dialog_create (GTK_WINDOW (pda->toplevel));
176 g_signal_connect_swapped (button, "clicked", G_CALLBACK (tt_options_dialog_run), act->opt);
179 gtk_box_pack_start (GTK_BOX (bb), button, TRUE, TRUE, 5);
180 gtk_box_pack_start (GTK_BOX (box), bb, FALSE, FALSE, 5);
181 gtk_widget_show_all (box);
184 psppire_dialog_action_set_valid_predicate (pda, dialog_state_valid);
185 psppire_dialog_action_set_refresh (pda, refresh);
187 g_object_set (pda->source,
188 "predicate", var_is_numeric,
191 psppire_selector_set_select_func (PSPPIRE_SELECTOR (selector),
192 select_as_pair_member,
195 g_object_unref (xml);
197 if (PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_paired_parent_class)->activate)
198 PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_paired_parent_class)->activate (pda);
202 psppire_dialog_action_paired_finalize (GObject *o)
204 PsppireDialogActionPaired *act = PSPPIRE_DIALOG_ACTION_PAIRED (o);
205 tt_options_dialog_destroy (act->opt);
209 psppire_dialog_action_paired_class_init (PsppireDialogActionPairedClass *class)
211 GtkActionClass *action_class = GTK_ACTION_CLASS (class);
212 GObjectClass *object_class = G_OBJECT_CLASS (class);
214 action_class->activate = psppire_dialog_action_paired_activate;
215 PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax;
217 object_class->finalize = psppire_dialog_action_paired_finalize;
222 psppire_dialog_action_paired_init (PsppireDialogActionPaired *act)