1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2010, 2011, 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-chisquare.h"
22 #include "psppire-var-view.h"
24 #include "psppire-dialog.h"
25 #include "builder-wrapper.h"
26 #include "psppire-acr.h"
27 #include "dialog-common.h"
29 #include <libpspp/str.h>
31 static void psppire_dialog_action_chisquare_init (PsppireDialogActionChisquare *act);
32 static void psppire_dialog_action_chisquare_class_init (PsppireDialogActionChisquareClass *class);
34 G_DEFINE_TYPE (PsppireDialogActionChisquare, psppire_dialog_action_chisquare, PSPPIRE_TYPE_DIALOG_ACTION);
38 generate_syntax (PsppireDialogAction *act)
40 PsppireDialogActionChisquare *scd = PSPPIRE_DIALOG_ACTION_CHISQUARE (act);
45 ds_init_cstr (&dss, "NPAR TEST\n\t/CHISQUARE=");
47 psppire_var_view_append_names_str (PSPPIRE_VAR_VIEW (scd->var_view), 0, &dss);
49 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (scd->range_button)))
51 ds_put_cstr (&dss, "(");
54 gtk_entry_get_text (GTK_ENTRY (scd->value_lower)));
56 ds_put_cstr (&dss, ", ");
59 gtk_entry_get_text (GTK_ENTRY (scd->value_upper)));
61 ds_put_cstr (&dss, ")");
64 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (scd->values_button)))
66 GtkListStore *ls = scd->expected_list;
70 ds_put_cstr (&dss, "\n\t");
71 ds_put_cstr (&dss, "/EXPECTED = ");
74 for (ok = gtk_tree_model_get_iter_first (GTK_TREE_MODEL(ls),
77 ok = gtk_tree_model_iter_next (GTK_TREE_MODEL (ls), &iter))
81 gtk_tree_model_get (GTK_TREE_MODEL (ls), &iter, 0, &v, -1);
83 ds_put_c_format (&dss, " %g", v);
87 ds_put_cstr (&dss, ".\n");
89 text = ds_steal_cstr (&dss);
98 dialog_state_valid (gpointer a)
101 PsppireDialogActionChisquare *act = PSPPIRE_DIALOG_ACTION_CHISQUARE (a);
104 gtk_tree_view_get_model (GTK_TREE_VIEW (act->var_view));
106 if ( !gtk_tree_model_get_iter_first (vars, ¬used) )
113 refresh (PsppireDialogAction *rd_)
115 PsppireDialogActionChisquare *csd = PSPPIRE_DIALOG_ACTION_CHISQUARE (rd_);
117 GtkTreeModel *liststore =
118 gtk_tree_view_get_model (GTK_TREE_VIEW (csd->var_view));
120 gtk_list_store_clear (GTK_LIST_STORE (liststore));
122 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (csd->button1), TRUE);
124 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (csd->button2), TRUE);
125 gtk_entry_set_text (GTK_ENTRY (csd->value_lower), "");
126 gtk_entry_set_text (GTK_ENTRY (csd->value_upper), "");
130 psppire_dialog_action_chisquare_activate (GtkAction *a)
132 PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
133 PsppireDialogActionChisquare *act = PSPPIRE_DIALOG_ACTION_CHISQUARE (a);
135 GtkBuilder *xml = builder_new ("chi-square.ui");
137 GtkWidget *range_table = get_widget_assert (xml, "range-table");
138 GtkWidget *values_acr = get_widget_assert (xml, "psppire-acr1");
139 GtkWidget *expected_value_entry =
140 get_widget_assert (xml, "expected-value-entry");
142 pda->dialog = get_widget_assert (xml, "chisquare-dialog");
143 pda->source = get_widget_assert (xml, "dict-view");
145 act->expected_list = gtk_list_store_new (1, G_TYPE_DOUBLE);
147 act->button1 = get_widget_assert (xml, "radiobutton1");
148 act->button2 = get_widget_assert (xml, "radiobutton3");
149 act->var_view = get_widget_assert (xml, "variables-treeview");
151 act->range_button = get_widget_assert (xml, "radiobutton4");
152 act->value_lower = get_widget_assert (xml, "entry1");
153 act->value_upper = get_widget_assert (xml, "entry2");
155 act->values_button = get_widget_assert (xml, "radiobutton2");
157 psppire_dialog_action_set_valid_predicate (pda, dialog_state_valid);
158 psppire_dialog_action_set_refresh (pda, refresh);
160 g_object_unref (xml);
162 g_signal_connect (act->range_button, "toggled",
163 G_CALLBACK (set_sensitivity_from_toggle),
167 g_signal_connect (act->values_button, "toggled",
168 G_CALLBACK (set_sensitivity_from_toggle),
171 g_signal_connect (act->values_button, "toggled",
172 G_CALLBACK (set_sensitivity_from_toggle),
173 expected_value_entry);
175 psppire_acr_set_entry (PSPPIRE_ACR (values_acr),
176 GTK_ENTRY (expected_value_entry));
178 psppire_acr_set_model(PSPPIRE_ACR (values_acr), act->expected_list);
181 if (PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_chisquare_parent_class)->activate)
182 PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_chisquare_parent_class)->activate (pda);
186 psppire_dialog_action_chisquare_class_init (PsppireDialogActionChisquareClass *class)
188 GtkActionClass *action_class = GTK_ACTION_CLASS (class);
190 action_class->activate = psppire_dialog_action_chisquare_activate;
191 PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax;
196 psppire_dialog_action_chisquare_init (PsppireDialogActionChisquare *act)