1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2011, 2012 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/>.
23 #include "paired-dialog.h"
25 #include "psppire-data-window.h"
26 #include "psppire-selector.h"
27 #include "psppire-var-view.h"
29 #include "psppire-dict.h"
31 #include "dialog-common.h"
32 #include "psppire-dialog.h"
34 #include "psppire-var-ptr.h"
37 #include "builder-wrapper.h"
42 refresh (struct paired_samples_dialog *tt_d)
44 gtk_list_store_clear (GTK_LIST_STORE (tt_d->list_store));
47 tt_d->refresh (tt_d->aux);
51 dialog_state_valid (gpointer data)
53 struct variable *v = NULL;
54 struct paired_samples_dialog *tt_d = data;
55 GtkTreeIter dest_iter;
57 gint n_rows = gtk_tree_model_iter_n_children (tt_d->list_store, NULL);
62 /* Get the last row */
63 gtk_tree_model_iter_nth_child (tt_d->list_store, &dest_iter,
66 /* Get the last (2nd) column */
67 gtk_tree_model_get (tt_d->list_store, &dest_iter, 1, &v, -1);
73 if ( NULL == tt_d->valid)
76 return tt_d->valid (tt_d->aux);
82 select_as_pair_member (GtkTreeIter source_iter,
84 GtkTreeModel *source_model,
90 GtkTreeIter dest_iter;
91 struct paired_samples_dialog *tt_d = data;
94 gtk_tree_model_get (source_model, &source_iter,
95 DICT_TVM_COL_VAR, &v, -1);
97 n_rows = gtk_tree_model_iter_n_children (tt_d->list_store, NULL);
102 gtk_tree_model_iter_nth_child (tt_d->list_store,
103 &dest_iter, NULL, n_rows - 1);
105 gtk_tree_model_get (tt_d->list_store, &dest_iter, 1, &v1, -1);
110 if ( n_rows == 0 || v1 != NULL)
112 gtk_list_store_append (GTK_LIST_STORE (tt_d->list_store), &dest_iter);
114 gtk_list_store_set (GTK_LIST_STORE (tt_d->list_store), &dest_iter,
121 gtk_list_store_set (GTK_LIST_STORE (tt_d->list_store), &dest_iter,
129 two_sample_dialog_add_widget (struct paired_samples_dialog *psd, GtkWidget *w)
131 GtkWidget *box = get_widget_assert (psd->xml, "vbox3");
132 gtk_box_pack_start (GTK_BOX (box), w, FALSE, FALSE, 5);
136 two_sample_dialog_destroy (struct paired_samples_dialog *psd)
138 g_object_unref (psd->xml);
142 struct paired_samples_dialog *
143 two_sample_dialog_create (PsppireDataWindow *de)
145 GtkWidget *dict_view ;
146 GtkWidget *selector ;
147 struct paired_samples_dialog *tt_d = g_malloc (sizeof *tt_d);
149 tt_d->xml = builder_new ("paired-samples.ui");
151 dict_view = get_widget_assert (tt_d->xml, "paired-samples-t-test-treeview1");
153 selector = get_widget_assert (tt_d->xml, "psppire-selector3");
155 tt_d->dialog = get_widget_assert (tt_d->xml, "t-test-paired-samples-dialog");
157 g_object_get (de->data_editor, "dictionary", &tt_d->dict, NULL);
158 tt_d->pairs_treeview =
159 get_widget_assert (tt_d->xml, "paired-samples-t-test-treeview2");
161 gtk_window_set_transient_for (GTK_WINDOW (tt_d->dialog), GTK_WINDOW (de));
164 g_object_set (dict_view, "model", tt_d->dict,
166 var_is_numeric, NULL);
169 tt_d->list_store = gtk_tree_view_get_model (GTK_TREE_VIEW (tt_d->pairs_treeview));
171 psppire_selector_set_select_func (PSPPIRE_SELECTOR (selector),
172 select_as_pair_member,
175 g_signal_connect_swapped (tt_d->dialog, "refresh",
176 G_CALLBACK (refresh), tt_d);
178 psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (tt_d->dialog),
179 dialog_state_valid, tt_d);