1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2008 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 <glade/glade.h>
21 #include <language/syntax-string-source.h>
23 #include "data-editor.h"
25 #include "psppire-dict.h"
26 #include "psppire-var-store.h"
27 #include "t-test-paired-samples.h"
28 #include "t-test-options.h"
30 #include "dict-display.h"
31 #include "dialog-common.h"
32 #include "psppire-dialog.h"
34 #include "syntax-editor.h"
38 #include "psppire-var-ptr.h"
42 #define _(msgid) gettext (msgid)
43 #define N_(msgid) msgid
46 struct tt_paired_samples_dialog
49 GtkWidget *pairs_treeview;
50 GtkTreeModel *list_store;
51 struct tt_options_dialog *opt;
55 generate_syntax (const struct tt_paired_samples_dialog *d)
58 GString *str = g_string_new ("T-TEST \n\tPAIRS = ");
60 append_variable_names (str, d->dict, GTK_TREE_VIEW (d->pairs_treeview), 0);
62 g_string_append (str, " WITH ");
64 append_variable_names (str, d->dict, GTK_TREE_VIEW (d->pairs_treeview), 1);
66 g_string_append (str, " (PAIRED)");
67 g_string_append (str, "\n");
69 tt_options_dialog_append_syntax (d->opt, str);
71 g_string_append (str, ".\n");
74 g_string_free (str, FALSE);
80 refresh (struct tt_paired_samples_dialog *tt_d)
82 gtk_list_store_clear (GTK_LIST_STORE (tt_d->list_store));
86 dialog_state_valid (gpointer data)
88 struct variable *v = NULL;
89 struct tt_paired_samples_dialog *tt_d = data;
90 GtkTreeIter dest_iter;
92 gint n_rows = gtk_tree_model_iter_n_children (tt_d->list_store, NULL);
97 /* Get the last row */
98 gtk_tree_model_iter_nth_child (tt_d->list_store, &dest_iter,
101 /* Get the last (2nd) column */
102 gtk_tree_model_get (tt_d->list_store, &dest_iter, 1, &v, -1);
111 select_as_pair_member (GtkTreeIter source_iter,
113 GtkTreeModel *source_model,
119 GtkTreeIter dest_iter;
120 struct tt_paired_samples_dialog *tt_d = data;
123 gtk_tree_model_get (source_model, &source_iter,
124 DICT_TVM_COL_VAR, &v, -1);
126 n_rows = gtk_tree_model_iter_n_children (tt_d->list_store, NULL);
131 gtk_tree_model_iter_nth_child (tt_d->list_store,
132 &dest_iter, NULL, n_rows - 1);
134 gtk_tree_model_get (tt_d->list_store, &dest_iter, 1, &v1, -1);
137 if ( n_rows == 0 || v1 != NULL)
139 gtk_list_store_append (GTK_LIST_STORE (tt_d->list_store), &dest_iter);
141 gtk_list_store_set (GTK_LIST_STORE (tt_d->list_store), &dest_iter,
148 gtk_list_store_set (GTK_LIST_STORE (tt_d->list_store), &dest_iter,
156 /* Append a new column to TV at position C, and heading TITLE */
158 add_new_column (GtkTreeView *tv, const gchar *title, gint c)
160 GtkTreeViewColumn *col = gtk_tree_view_column_new ();
161 GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
163 gtk_tree_view_column_set_min_width (col, 100);
164 gtk_tree_view_column_set_sizing (col, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
165 gtk_tree_view_column_set_resizable (col, TRUE);
168 gtk_tree_view_column_set_title (col, title);
170 gtk_tree_view_column_pack_start (col, renderer, TRUE);
172 gtk_tree_view_column_set_sizing (col, GTK_TREE_VIEW_COLUMN_FIXED);
174 gtk_tree_view_append_column (tv, col);
176 gtk_tree_view_column_add_attribute (col, renderer, "text", c);
180 /* Pops up the dialog box */
182 t_test_paired_samples_dialog (GObject *o, gpointer data)
184 struct tt_paired_samples_dialog tt_d;
186 struct data_editor *de = data;
188 PsppireVarStore *vs = NULL;
190 GladeXML *xml = XML_NEW ("t-test.glade");
192 GtkWidget *dict_view =
193 get_widget_assert (xml, "paired-samples-t-test-treeview1");
195 GtkWidget *options_button = get_widget_assert (xml, "paired-samples-t-test-options-button");
197 GtkWidget *selector = get_widget_assert (xml, "psppire-selector3");
199 GtkWidget *dialog = get_widget_assert (xml, "t-test-paired-samples-dialog");
201 g_object_get (de->data_editor, "var-store", &vs, NULL);
203 tt_d.dict = vs->dict;
204 tt_d.pairs_treeview =
205 get_widget_assert (xml, "paired-samples-t-test-treeview2");
206 tt_d.opt = tt_options_dialog_create (xml, de->parent.window);
208 gtk_window_set_transient_for (GTK_WINDOW (dialog), de->parent.window);
211 attach_dictionary_to_treeview (GTK_TREE_VIEW (dict_view),
213 GTK_SELECTION_MULTIPLE,
219 gtk_list_store_new (2,
220 PSPPIRE_VAR_PTR_TYPE,
221 PSPPIRE_VAR_PTR_TYPE));
224 gtk_tree_view_set_model (GTK_TREE_VIEW (tt_d.pairs_treeview),
225 GTK_TREE_MODEL (tt_d.list_store));
228 add_new_column (GTK_TREE_VIEW (tt_d.pairs_treeview), _("Var 1"), 0);
229 add_new_column (GTK_TREE_VIEW (tt_d.pairs_treeview), _("Var 2"), 1);
233 psppire_selector_set_subjects (PSPPIRE_SELECTOR (selector),
236 select_as_pair_member,
241 g_signal_connect_swapped (dialog, "refresh",
242 G_CALLBACK (refresh), &tt_d);
245 g_signal_connect_swapped (options_button, "clicked",
246 G_CALLBACK (tt_options_dialog_run), tt_d.opt);
248 psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog),
249 dialog_state_valid, &tt_d);
251 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
255 case GTK_RESPONSE_OK:
257 gchar *syntax = generate_syntax (&tt_d);
258 struct getl_interface *sss = create_syntax_string_source (syntax);
259 execute_syntax (sss);
264 case PSPPIRE_RESPONSE_PASTE:
266 gchar *syntax = generate_syntax (&tt_d);
268 struct syntax_editor *se =
269 (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
271 gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1);
281 g_object_unref (xml);
283 tt_options_dialog_destroy (tt_d.opt);