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"
30 #include "psppire-var-store.h"
32 #include "dialog-common.h"
33 #include "psppire-dialog.h"
35 #include "psppire-var-ptr.h"
38 #include "builder-wrapper.h"
43 refresh (struct paired_samples_dialog *tt_d)
45 gtk_list_store_clear (GTK_LIST_STORE (tt_d->list_store));
48 tt_d->refresh (tt_d->aux);
52 dialog_state_valid (gpointer data)
54 struct variable *v = NULL;
55 struct paired_samples_dialog *tt_d = data;
56 GtkTreeIter dest_iter;
58 gint n_rows = gtk_tree_model_iter_n_children (tt_d->list_store, NULL);
63 /* Get the last row */
64 gtk_tree_model_iter_nth_child (tt_d->list_store, &dest_iter,
67 /* Get the last (2nd) column */
68 gtk_tree_model_get (tt_d->list_store, &dest_iter, 1, &v, -1);
74 if ( NULL == tt_d->valid)
77 return tt_d->valid (tt_d->aux);
83 select_as_pair_member (GtkTreeIter source_iter,
85 GtkTreeModel *source_model,
91 GtkTreeIter dest_iter;
92 struct paired_samples_dialog *tt_d = data;
95 gtk_tree_model_get (source_model, &source_iter,
96 DICT_TVM_COL_VAR, &v, -1);
98 n_rows = gtk_tree_model_iter_n_children (tt_d->list_store, NULL);
103 gtk_tree_model_iter_nth_child (tt_d->list_store,
104 &dest_iter, NULL, n_rows - 1);
106 gtk_tree_model_get (tt_d->list_store, &dest_iter, 1, &v1, -1);
111 if ( n_rows == 0 || v1 != NULL)
113 gtk_list_store_append (GTK_LIST_STORE (tt_d->list_store), &dest_iter);
115 gtk_list_store_set (GTK_LIST_STORE (tt_d->list_store), &dest_iter,
122 gtk_list_store_set (GTK_LIST_STORE (tt_d->list_store), &dest_iter,
130 two_sample_dialog_add_widget (struct paired_samples_dialog *psd, GtkWidget *w)
132 GtkWidget *box = get_widget_assert (psd->xml, "vbox3");
133 gtk_box_pack_start (GTK_BOX (box), w, FALSE, FALSE, 5);
137 two_sample_dialog_destroy (struct paired_samples_dialog *psd)
139 g_object_unref (psd->xml);
143 struct paired_samples_dialog *
144 two_sample_dialog_create (PsppireDataWindow *de)
146 GtkWidget *dict_view ;
147 GtkWidget *selector ;
148 struct paired_samples_dialog *tt_d = g_malloc (sizeof *tt_d);
150 PsppireVarStore *vs = NULL;
152 tt_d->xml = builder_new ("paired-samples.ui");
154 dict_view = get_widget_assert (tt_d->xml, "paired-samples-t-test-treeview1");
156 selector = get_widget_assert (tt_d->xml, "psppire-selector3");
158 tt_d->dialog = get_widget_assert (tt_d->xml, "t-test-paired-samples-dialog");
160 g_object_get (de->data_editor, "var-store", &vs, NULL);
162 g_object_get (vs, "dictionary", &tt_d->dict, NULL);
163 tt_d->pairs_treeview =
164 get_widget_assert (tt_d->xml, "paired-samples-t-test-treeview2");
166 gtk_window_set_transient_for (GTK_WINDOW (tt_d->dialog), GTK_WINDOW (de));
169 g_object_set (dict_view, "model", tt_d->dict,
171 var_is_numeric, NULL);
174 tt_d->list_store = gtk_tree_view_get_model (GTK_TREE_VIEW (tt_d->pairs_treeview));
176 psppire_selector_set_select_func (PSPPIRE_SELECTOR (selector),
177 select_as_pair_member,
180 g_signal_connect_swapped (tt_d->dialog, "refresh",
181 G_CALLBACK (refresh), tt_d);
183 psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (tt_d->dialog),
184 dialog_state_valid, tt_d);