1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2010 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/>. */
19 #include "chi-square-dialog.h"
21 #include <language/syntax-string-source.h>
23 #include "psppire-dialog.h"
24 #include "psppire-var-view.h"
25 #include "psppire-acr.h"
26 #include "dialog-common.h"
34 struct chisquare_dialog
42 GtkWidget *range_button;
43 GtkWidget *value_lower;
44 GtkWidget *value_upper;
46 GtkWidget *values_button;
48 GtkListStore *expected_list;
52 set_sensitivity (GtkToggleButton *button, GtkWidget *w)
54 gboolean state = gtk_toggle_button_get_active (button);
55 gtk_widget_set_sensitive (w, state);
60 dialog_state_valid (gpointer data)
62 struct chisquare_dialog *csd = data;
65 gtk_tree_view_get_model (GTK_TREE_VIEW (csd->var_view));
69 if ( !gtk_tree_model_get_iter_first (vars, ¬used) )
77 refresh (struct chisquare_dialog *csd)
79 GtkTreeModel *liststore =
80 gtk_tree_view_get_model (GTK_TREE_VIEW (csd->var_view));
82 gtk_list_store_clear (GTK_LIST_STORE (liststore));
84 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (csd->button1), TRUE);
86 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (csd->button2), TRUE);
92 generate_syntax (const struct chisquare_dialog *scd)
98 string = g_string_new ("NPAR TEST\n\t/CHISQUARE=");
100 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (scd->var_view), 0, string);
103 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (scd->range_button)))
105 g_string_append (string, "(");
107 g_string_append (string,
108 gtk_entry_get_text (GTK_ENTRY (scd->value_lower)));
110 g_string_append (string, ", ");
112 g_string_append (string,
113 gtk_entry_get_text (GTK_ENTRY (scd->value_upper)));
115 g_string_append (string, ")");
121 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (scd->values_button)))
123 GtkListStore *ls = scd->expected_list;
127 g_string_append (string, "\n\t");
128 g_string_append (string, "/EXPECTED = ");
131 for (ok = gtk_tree_model_get_iter_first (GTK_TREE_MODEL(ls),
134 ok = gtk_tree_model_iter_next (GTK_TREE_MODEL (ls), &iter))
138 gtk_tree_model_get (GTK_TREE_MODEL (ls), &iter, 0, &v, -1);
140 g_string_append_printf (string, " %g", v);
147 g_string_append (string, ".\n");
151 g_string_free (string, FALSE);
158 /* Pops up the Chi-Square dialog box */
160 chisquare_dialog (PsppireDataWindow *dw)
164 struct chisquare_dialog csd;
166 GtkBuilder *xml = builder_new ("chi-square.ui");
169 GtkWidget *dialog = get_widget_assert (xml, "chisquare-dialog");
171 GtkWidget *range_table = get_widget_assert (xml, "range-table");
175 GtkWidget *values_acr = get_widget_assert (xml, "psppire-acr1");
176 GtkWidget *expected_value_entry =
177 get_widget_assert (xml, "expected-value-entry");
180 GtkWidget *dict_view = get_widget_assert (xml, "dict-view");
182 csd.expected_list = gtk_list_store_new (1, G_TYPE_DOUBLE);
184 csd.button1 = get_widget_assert (xml, "radiobutton1");
185 csd.button2 = get_widget_assert (xml, "radiobutton3");
186 csd.var_view = get_widget_assert (xml, "variables-treeview");
188 csd.range_button = get_widget_assert (xml, "radiobutton4");
189 csd.value_lower = get_widget_assert (xml, "entry1");
190 csd.value_upper = get_widget_assert (xml, "entry2");
192 csd.values_button = get_widget_assert (xml, "radiobutton2");
194 g_object_get (dw->data_editor, "var-store", &vs, NULL);
196 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (dw));
199 g_object_get (vs, "dictionary", &csd.dict, NULL);
200 g_object_set (dict_view,
202 "predicate", var_is_numeric,
206 g_signal_connect (csd.range_button, "toggled", G_CALLBACK (set_sensitivity),
210 g_signal_connect (csd.values_button, "toggled", G_CALLBACK (set_sensitivity),
213 g_signal_connect (csd.values_button, "toggled", G_CALLBACK (set_sensitivity),
214 expected_value_entry);
217 psppire_acr_set_entry (PSPPIRE_ACR (values_acr),
218 GTK_ENTRY (expected_value_entry));
220 psppire_acr_set_model(PSPPIRE_ACR (values_acr), csd.expected_list);
222 g_signal_connect_swapped (dialog, "refresh", G_CALLBACK (refresh), &csd);
224 psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog),
225 dialog_state_valid, &csd);
227 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
232 case GTK_RESPONSE_OK:
234 gchar *syntax = generate_syntax (&csd);
236 struct getl_interface *sss = create_syntax_string_source (syntax);
237 execute_syntax (sss);
242 case PSPPIRE_RESPONSE_PASTE:
244 gchar *syntax = generate_syntax (&csd);
245 paste_syntax_to_window (syntax);
253 g_object_unref (xml);