1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2010, 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/>. */
19 #include "chi-square-dialog.h"
21 #include "psppire-dialog.h"
22 #include "psppire-var-view.h"
23 #include "psppire-acr.h"
24 #include "dialog-common.h"
26 #include "builder-wrapper.h"
32 struct chisquare_dialog
40 GtkWidget *range_button;
41 GtkWidget *value_lower;
42 GtkWidget *value_upper;
44 GtkWidget *values_button;
46 GtkListStore *expected_list;
50 dialog_state_valid (gpointer data)
52 struct chisquare_dialog *csd = data;
55 gtk_tree_view_get_model (GTK_TREE_VIEW (csd->var_view));
59 if ( !gtk_tree_model_get_iter_first (vars, ¬used) )
67 refresh (struct chisquare_dialog *csd)
69 GtkTreeModel *liststore =
70 gtk_tree_view_get_model (GTK_TREE_VIEW (csd->var_view));
72 gtk_list_store_clear (GTK_LIST_STORE (liststore));
74 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (csd->button1), TRUE);
76 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (csd->button2), TRUE);
82 generate_syntax (const struct chisquare_dialog *scd)
88 string = g_string_new ("NPAR TEST\n\t/CHISQUARE=");
90 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (scd->var_view), 0, string);
93 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (scd->range_button)))
95 g_string_append (string, "(");
97 g_string_append (string,
98 gtk_entry_get_text (GTK_ENTRY (scd->value_lower)));
100 g_string_append (string, ", ");
102 g_string_append (string,
103 gtk_entry_get_text (GTK_ENTRY (scd->value_upper)));
105 g_string_append (string, ")");
111 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (scd->values_button)))
113 GtkListStore *ls = scd->expected_list;
117 g_string_append (string, "\n\t");
118 g_string_append (string, "/EXPECTED = ");
121 for (ok = gtk_tree_model_get_iter_first (GTK_TREE_MODEL(ls),
124 ok = gtk_tree_model_iter_next (GTK_TREE_MODEL (ls), &iter))
128 gtk_tree_model_get (GTK_TREE_MODEL (ls), &iter, 0, &v, -1);
130 g_string_append_printf (string, " %g", v);
137 g_string_append (string, ".\n");
141 g_string_free (string, FALSE);
148 /* Pops up the Chi-Square dialog box */
150 chisquare_dialog (PsppireDataWindow *dw)
154 struct chisquare_dialog csd;
156 GtkBuilder *xml = builder_new ("chi-square.ui");
158 GtkWidget *dialog = get_widget_assert (xml, "chisquare-dialog");
160 GtkWidget *range_table = get_widget_assert (xml, "range-table");
164 GtkWidget *values_acr = get_widget_assert (xml, "psppire-acr1");
165 GtkWidget *expected_value_entry =
166 get_widget_assert (xml, "expected-value-entry");
169 GtkWidget *dict_view = get_widget_assert (xml, "dict-view");
171 csd.expected_list = gtk_list_store_new (1, G_TYPE_DOUBLE);
173 csd.button1 = get_widget_assert (xml, "radiobutton1");
174 csd.button2 = get_widget_assert (xml, "radiobutton3");
175 csd.var_view = get_widget_assert (xml, "variables-treeview");
177 csd.range_button = get_widget_assert (xml, "radiobutton4");
178 csd.value_lower = get_widget_assert (xml, "entry1");
179 csd.value_upper = get_widget_assert (xml, "entry2");
181 csd.values_button = get_widget_assert (xml, "radiobutton2");
183 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (dw));
186 g_object_get (dw->data_editor, "dictionary", &csd.dict, NULL);
187 g_object_set (dict_view,
189 "predicate", var_is_numeric,
193 g_signal_connect (csd.range_button, "toggled", G_CALLBACK (set_sensitivity_from_toggle),
197 g_signal_connect (csd.values_button, "toggled", G_CALLBACK (set_sensitivity_from_toggle),
200 g_signal_connect (csd.values_button, "toggled", G_CALLBACK (set_sensitivity_from_toggle),
201 expected_value_entry);
204 psppire_acr_set_entry (PSPPIRE_ACR (values_acr),
205 GTK_ENTRY (expected_value_entry));
207 psppire_acr_set_model(PSPPIRE_ACR (values_acr), csd.expected_list);
209 g_signal_connect_swapped (dialog, "refresh", G_CALLBACK (refresh), &csd);
211 psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog),
212 dialog_state_valid, &csd);
214 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
219 case GTK_RESPONSE_OK:
220 g_free (execute_syntax_string (dw, generate_syntax (&csd)));
222 case PSPPIRE_RESPONSE_PASTE:
223 g_free (paste_syntax_to_window (generate_syntax (&csd)));
229 g_object_unref (csd.expected_list);
230 g_object_unref (xml);