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-tt1s.h"
22 #include "psppire-var-view.h"
23 #include "t-test-options.h"
25 #include "psppire-dialog.h"
26 #include "builder-wrapper.h"
28 static void psppire_dialog_action_tt1s_init (PsppireDialogActionTt1s *act);
29 static void psppire_dialog_action_tt1s_class_init (PsppireDialogActionTt1sClass *class);
31 G_DEFINE_TYPE (PsppireDialogActionTt1s, psppire_dialog_action_tt1s, PSPPIRE_TYPE_DIALOG_ACTION);
35 generate_syntax (PsppireDialogAction *act)
37 PsppireDialogActionTt1s *d = PSPPIRE_DIALOG_ACTION_TT1S (act);
40 GString *str = g_string_new ("T-TEST ");
42 g_string_append_printf (str, "/TESTVAL=%s",
43 gtk_entry_get_text (GTK_ENTRY (d->test_value_entry)));
45 g_string_append (str, "\n\t/VARIABLES=");
47 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (d->vars_treeview), 0, str);
49 tt_options_dialog_append_syntax (d->opt, str);
51 g_string_append (str, ".\n");
55 g_string_free (str, FALSE);
62 dialog_state_valid (gpointer data)
64 PsppireDialogActionTt1s *tt_d = PSPPIRE_DIALOG_ACTION_TT1S (data);
70 gtk_tree_view_get_model (GTK_TREE_VIEW (tt_d->vars_treeview));
74 text = gtk_entry_get_text (GTK_ENTRY (tt_d->test_value_entry));
76 if ( 0 == strcmp ("", text))
79 /* Check to see if the entry is numeric */
82 if (s - text != strlen (text))
86 if ( 0 == gtk_tree_model_get_iter_first (vars, ¬used))
93 refresh (PsppireDialogAction *rd_)
95 PsppireDialogActionTt1s *d = PSPPIRE_DIALOG_ACTION_TT1S (rd_);
98 gtk_tree_view_get_model (GTK_TREE_VIEW (d->vars_treeview));
100 gtk_entry_set_text (GTK_ENTRY (d->test_value_entry), "");
102 gtk_list_store_clear (GTK_LIST_STORE (model));
106 psppire_dialog_action_tt1s_activate (GtkAction *a)
108 PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
109 PsppireDialogActionTt1s *act = PSPPIRE_DIALOG_ACTION_TT1S (a);
111 GtkBuilder *xml = builder_new ("t-test.ui");
112 GtkWidget *options_button = get_widget_assert (xml, "button1");
114 pda->dialog = get_widget_assert (xml, "t-test-one-sample-dialog");
115 pda->source = get_widget_assert (xml, "one-sample-t-test-treeview2");
117 g_object_set (pda->source,
118 "predicate", var_is_numeric, NULL);
120 act->vars_treeview = get_widget_assert (xml, "one-sample-t-test-treeview1");
121 act->test_value_entry = get_widget_assert (xml, "test-value-entry");
123 act->opt = tt_options_dialog_create (GTK_WINDOW (pda->toplevel));
125 psppire_dialog_action_set_valid_predicate (pda, dialog_state_valid);
126 psppire_dialog_action_set_refresh (pda, refresh);
128 g_signal_connect_swapped (options_button, "clicked",
129 G_CALLBACK (tt_options_dialog_run), act->opt);
132 g_object_unref (xml);
134 if (PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_tt1s_parent_class)->activate)
135 PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_tt1s_parent_class)->activate (pda);
139 psppire_dialog_action_tt1s_finalize (GObject *a)
141 PsppireDialogActionTt1s *act = PSPPIRE_DIALOG_ACTION_TT1S (a);
142 tt_options_dialog_destroy (act->opt);
146 psppire_dialog_action_tt1s_class_init (PsppireDialogActionTt1sClass *class)
148 GtkActionClass *action_class = GTK_ACTION_CLASS (class);
149 GObjectClass *object_class = G_OBJECT_CLASS (class);
151 object_class->finalize = psppire_dialog_action_tt1s_finalize;
152 action_class->activate = psppire_dialog_action_tt1s_activate;
153 PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax;
158 psppire_dialog_action_tt1s_init (PsppireDialogActionTt1s *act)