1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2010, 2011, 2012, 2013, 2014 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"
24 #include "psppire-var-view.h"
26 #include "psppire-dialog.h"
27 #include "builder-wrapper.h"
28 #include "psppire-acr.h"
29 #include "dialog-common.h"
31 #include <libpspp/str.h>
33 static void psppire_dialog_action_chisquare_init (PsppireDialogActionChisquare *act);
34 static void psppire_dialog_action_chisquare_class_init (PsppireDialogActionChisquareClass *class);
36 G_DEFINE_TYPE (PsppireDialogActionChisquare, psppire_dialog_action_chisquare, PSPPIRE_TYPE_DIALOG_ACTION);
40 generate_syntax (const PsppireDialogAction *act)
42 PsppireDialogActionChisquare *scd = PSPPIRE_DIALOG_ACTION_CHISQUARE (act);
47 ds_init_cstr (&dss, "NPAR TEST\n\t/CHISQUARE=");
49 psppire_var_view_append_names_str (PSPPIRE_VAR_VIEW (scd->var_view), 0, &dss);
51 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (scd->range_button)))
53 ds_put_cstr (&dss, "(");
56 gtk_entry_get_text (GTK_ENTRY (scd->value_lower)));
58 ds_put_cstr (&dss, ", ");
61 gtk_entry_get_text (GTK_ENTRY (scd->value_upper)));
63 ds_put_cstr (&dss, ")");
66 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (scd->values_button)))
68 GtkListStore *ls = scd->expected_list;
72 ds_put_cstr (&dss, "\n\t");
73 ds_put_cstr (&dss, "/EXPECTED = ");
76 for (ok = gtk_tree_model_get_iter_first (GTK_TREE_MODEL(ls),
79 ok = gtk_tree_model_iter_next (GTK_TREE_MODEL (ls), &iter))
83 gtk_tree_model_get (GTK_TREE_MODEL (ls), &iter, 0, &v, -1);
85 ds_put_c_format (&dss, " %.*g", DBL_DIG + 1, v);
89 ds_put_cstr (&dss, ".\n");
91 text = ds_steal_cstr (&dss);
100 dialog_state_valid (gpointer a)
103 PsppireDialogActionChisquare *act = PSPPIRE_DIALOG_ACTION_CHISQUARE (a);
106 gtk_tree_view_get_model (GTK_TREE_VIEW (act->var_view));
108 if (!gtk_tree_model_get_iter_first (vars, ¬used))
115 refresh (PsppireDialogAction *rd_)
117 PsppireDialogActionChisquare *csd = PSPPIRE_DIALOG_ACTION_CHISQUARE (rd_);
119 GtkTreeModel *liststore =
120 gtk_tree_view_get_model (GTK_TREE_VIEW (csd->var_view));
122 gtk_list_store_clear (GTK_LIST_STORE (liststore));
124 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (csd->button1), TRUE);
126 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (csd->button2), TRUE);
127 gtk_entry_set_text (GTK_ENTRY (csd->value_lower), "");
128 gtk_entry_set_text (GTK_ENTRY (csd->value_upper), "");
132 psppire_dialog_action_chisquare_activate (PsppireDialogAction *a, GVariant *param)
134 PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
135 PsppireDialogActionChisquare *act = PSPPIRE_DIALOG_ACTION_CHISQUARE (a);
137 GtkBuilder *xml = builder_new ("chi-square.ui");
139 GtkWidget *range_table = get_widget_assert (xml, "range-table");
140 GtkWidget *values_acr = get_widget_assert (xml, "psppire-acr1");
141 GtkWidget *expected_value_entry =
142 get_widget_assert (xml, "expected-value-entry");
144 pda->dialog = get_widget_assert (xml, "chisquare-dialog");
145 pda->source = get_widget_assert (xml, "dict-view");
147 act->expected_list = gtk_list_store_new (1, G_TYPE_DOUBLE);
149 act->button1 = get_widget_assert (xml, "radiobutton1");
150 act->button2 = get_widget_assert (xml, "radiobutton3");
151 act->var_view = get_widget_assert (xml, "variables-treeview");
153 act->range_button = get_widget_assert (xml, "radiobutton4");
154 act->value_lower = get_widget_assert (xml, "entry1");
155 act->value_upper = get_widget_assert (xml, "entry2");
157 act->values_button = get_widget_assert (xml, "radiobutton2");
159 psppire_dialog_action_set_valid_predicate (pda, dialog_state_valid);
160 psppire_dialog_action_set_refresh (pda, refresh);
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);
184 psppire_dialog_action_chisquare_class_init (PsppireDialogActionChisquareClass *class)
186 PSPPIRE_DIALOG_ACTION_CLASS (class)->initial_activate = psppire_dialog_action_chisquare_activate;
187 PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax;
192 psppire_dialog_action_chisquare_init (PsppireDialogActionChisquare *act)