1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 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/>. */
20 #include "psppire-dialog-action-roc.h"
21 #include "psppire-value-entry.h"
23 #include "dialog-common.h"
24 #include <ui/syntax-gen.h>
25 #include "psppire-var-view.h"
27 #include "psppire-dialog.h"
28 #include "builder-wrapper.h"
30 #include "psppire-dict.h"
31 #include "libpspp/str.h"
34 psppire_dialog_action_roc_class_init (PsppireDialogActionRocClass *class);
36 G_DEFINE_TYPE (PsppireDialogActionRoc, psppire_dialog_action_roc, PSPPIRE_TYPE_DIALOG_ACTION);
39 dialog_state_valid (gpointer data)
44 PsppireDialogActionRoc *rd = data;
45 const gchar *var_name;
46 const struct variable *var;
48 GtkTreeModel *liststore =
49 gtk_tree_view_get_model (GTK_TREE_VIEW (rd->test_variables));
51 if (gtk_tree_model_iter_n_children (liststore, NULL) < 1)
54 var_name = gtk_entry_get_text (GTK_ENTRY (rd->state_variable));
56 var = psppire_dict_lookup_var (PSPPIRE_DIALOG_ACTION (rd)->dict, var_name);
61 width = var_get_width (var);
62 value_init (&val, width);
64 result = psppire_value_entry_get_value (PSPPIRE_VALUE_ENTRY (rd->state_value), &val, width);
66 if (var_is_value_missing (var, &val, MV_SYSTEM))
69 value_destroy (&val, width);
75 on_curve_button_toggle (GtkCheckButton *curve, PsppireDialogActionRoc *rd)
77 if ( !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (curve)))
79 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->reference)))
80 g_object_set (rd->reference, "inconsistent", TRUE, NULL);
81 g_object_set (rd->reference, "sensitive", FALSE, NULL);
85 g_object_set (rd->reference, "inconsistent", FALSE, NULL);
86 g_object_set (rd->reference, "sensitive", TRUE, NULL);
91 refresh (PsppireDialogAction *rd_)
93 PsppireDialogActionRoc *rd = PSPPIRE_DIALOG_ACTION_ROC (rd_);
94 GtkTreeModel *liststore =
95 gtk_tree_view_get_model (GTK_TREE_VIEW (rd->test_variables));
96 gtk_list_store_clear (GTK_LIST_STORE (liststore));
98 gtk_entry_set_text (GTK_ENTRY (rd->state_variable), "");
99 psppire_value_entry_set_variable (PSPPIRE_VALUE_ENTRY (rd->state_value), NULL);
101 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->curve), TRUE);
102 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->reference), FALSE);
103 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->standard_error), FALSE);
104 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->coordinates), FALSE);
108 on_state_var_changed (PsppireDialogAction *a)
110 PsppireDialogActionRoc *act = PSPPIRE_DIALOG_ACTION_ROC (a);
112 const gchar *var_name = gtk_entry_get_text (GTK_ENTRY(act->state_variable));
114 const struct variable *var =
115 psppire_dict_lookup_var (PSPPIRE_DIALOG_ACTION(act)->dict, var_name);
120 psppire_value_entry_set_variable (PSPPIRE_VALUE_ENTRY (act->state_value), var);
124 psppire_dialog_action_roc_activate (PsppireDialogAction *a)
126 PsppireDialogActionRoc *act = PSPPIRE_DIALOG_ACTION_ROC (a);
127 PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
129 GHashTable *thing = psppire_dialog_action_get_hash_table (pda);
130 GtkBuilder *xml = g_hash_table_lookup (thing, a);
133 xml = builder_new ("roc.ui");
134 g_hash_table_insert (thing, a, xml);
138 pda->dialog = get_widget_assert (xml, "roc-dialog");
139 pda->source = get_widget_assert (xml, "dict-view");
141 act->test_variables = get_widget_assert (xml, "psppire-var-view1");
142 act->state_variable = get_widget_assert (xml, "entry1");
143 act->state_value = get_widget_assert (xml, "entry2");
145 act->curve = get_widget_assert (xml, "curve");
146 act->reference = get_widget_assert (xml, "reference-line");
147 act->standard_error = get_widget_assert (xml, "standard-error");
148 act->coordinates = get_widget_assert (xml, "co-ordinates");
150 g_signal_connect_swapped (act->state_variable, "changed",
151 G_CALLBACK (on_state_var_changed), act);
153 g_signal_connect (act->curve, "toggled",
154 G_CALLBACK (on_curve_button_toggle), act);
156 psppire_dialog_action_set_refresh (pda, refresh);
158 psppire_dialog_action_set_valid_predicate (pda,
166 generate_syntax (const PsppireDialogAction *a)
168 PsppireDialogActionRoc *rd = PSPPIRE_DIALOG_ACTION_ROC (a);
170 const gchar *var_name = gtk_entry_get_text (GTK_ENTRY (rd->state_variable));
171 GString *string = g_string_new ("ROC");
173 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (rd->test_variables), 0, string);
175 g_string_append (string, " BY ");
177 g_string_append (string, var_name);
179 g_string_append (string, " (");
181 const struct variable *var =
182 psppire_dict_lookup_var (PSPPIRE_DIALOG_ACTION(rd)->dict, var_name);
185 value_init (&val, var_get_width (var));
187 psppire_value_entry_get_value (PSPPIRE_VALUE_ENTRY (rd->state_value),
188 &val, var_get_width (var));
190 g_return_val_if_fail (var, NULL);
194 ds_init_empty (&str);
196 syntax_gen_value (&str, &val, var_get_width (var),
197 var_get_print_format (var));
199 g_string_append (string, ds_cstr (&str));
202 value_destroy (&val, var_get_width (var));
205 g_string_append (string, ")");
208 /* The /PLOT subcommand */
209 g_string_append (string, "\n\t/PLOT ");
210 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->curve)))
212 g_string_append (string, "CURVE");
213 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->reference)))
214 g_string_append (string, " (REFERENCE)");
217 g_string_append (string, "NONE");
220 /* The /PRINT subcommand */
221 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->standard_error)) ||
222 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->coordinates)) )
224 g_string_append (string, "\n\t/PRINT");
226 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->standard_error)))
227 g_string_append (string, " SE");
229 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->coordinates)))
230 g_string_append (string, " COORDINATES");
233 g_string_append (string, ".\n");
237 g_string_free (string, FALSE);
243 psppire_dialog_action_roc_class_init (PsppireDialogActionRocClass *class)
245 psppire_dialog_action_set_activation (class, psppire_dialog_action_roc_activate);
247 PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax;
252 psppire_dialog_action_roc_init (PsppireDialogActionRoc *act)