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"
22 #include "dialog-common.h"
23 #include <ui/syntax-gen.h>
24 #include "psppire-var-view.h"
26 #include "psppire-dialog.h"
27 #include "builder-wrapper.h"
29 #include "psppire-dict.h"
30 #include "libpspp/str.h"
33 psppire_dialog_action_roc_class_init (PsppireDialogActionRocClass *class);
35 G_DEFINE_TYPE (PsppireDialogActionRoc, psppire_dialog_action_roc, PSPPIRE_TYPE_DIALOG_ACTION);
38 dialog_state_valid (gpointer data)
40 PsppireDialogActionRoc *rd = data;
43 GtkTreeModel *liststore =
44 gtk_tree_view_get_model (GTK_TREE_VIEW (rd->test_variables));
46 if (gtk_tree_model_iter_n_children (liststore, NULL) < 1)
50 text = gtk_entry_get_text (GTK_ENTRY (rd->state_variable));
51 if ( 0 == strcmp ("", text))
55 text = gtk_entry_get_text (GTK_ENTRY (rd->state_value));
56 if ( 0 == strcmp ("", text))
64 on_curve_button_toggle (GtkCheckButton *curve, PsppireDialogActionRoc *rd)
66 if ( !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (curve)))
68 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->reference)))
69 g_object_set (rd->reference, "inconsistent", TRUE, NULL);
70 g_object_set (rd->reference, "sensitive", FALSE, NULL);
74 g_object_set (rd->reference, "inconsistent", FALSE, NULL);
75 g_object_set (rd->reference, "sensitive", TRUE, NULL);
80 refresh (PsppireDialogAction *rd_)
82 PsppireDialogActionRoc *rd = PSPPIRE_DIALOG_ACTION_ROC (rd_);
83 GtkTreeModel *liststore =
84 gtk_tree_view_get_model (GTK_TREE_VIEW (rd->test_variables));
85 gtk_list_store_clear (GTK_LIST_STORE (liststore));
87 gtk_entry_set_text (GTK_ENTRY (rd->state_variable), "");
88 gtk_entry_set_text (GTK_ENTRY (rd->state_value), "");
90 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->curve), TRUE);
91 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->reference), FALSE);
92 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->standard_error), FALSE);
93 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->coordinates), FALSE);
97 psppire_dialog_action_roc_activate (GtkAction *a)
99 PsppireDialogActionRoc *act = PSPPIRE_DIALOG_ACTION_ROC (a);
100 PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
102 GtkBuilder *xml = builder_new ("roc.ui");
103 pda->dialog = get_widget_assert (xml, "roc-dialog");
104 pda->source = get_widget_assert (xml, "dict-view");
105 pda->source = get_widget_assert (xml, "dict-view");
107 act->test_variables = get_widget_assert (xml, "psppire-var-view1");
108 act->state_variable = get_widget_assert (xml, "entry1");
109 act->state_value = get_widget_assert (xml, "entry2");
111 act->curve = get_widget_assert (xml, "curve");
112 act->reference = get_widget_assert (xml, "reference-line");
113 act->standard_error = get_widget_assert (xml, "standard-error");
114 act->coordinates = get_widget_assert (xml, "co-ordinates");
116 g_object_unref (xml);
118 g_signal_connect (act->curve, "toggled",
119 G_CALLBACK (on_curve_button_toggle), act);
121 psppire_dialog_action_set_refresh (pda, refresh);
123 psppire_dialog_action_set_valid_predicate (pda,
126 if (PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_roc_parent_class)->activate)
127 PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_roc_parent_class)->activate (pda);
133 generate_syntax (PsppireDialogAction *a)
135 PsppireDialogActionRoc *rd = PSPPIRE_DIALOG_ACTION_ROC (a);
137 const gchar *var_name = gtk_entry_get_text (GTK_ENTRY (rd->state_variable));
138 GString *string = g_string_new ("ROC");
140 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (rd->test_variables), 0, string);
142 g_string_append (string, " BY ");
144 g_string_append (string, var_name);
146 g_string_append (string, " (");
148 const gchar *value = gtk_entry_get_text (GTK_ENTRY (rd->state_value));
150 const struct variable *var = psppire_dict_lookup_var (PSPPIRE_DIALOG_ACTION(rd)->dict, var_name);
152 g_return_val_if_fail (var, NULL);
154 if ( var_is_alpha (var))
157 ds_init_empty (&str);
158 syntax_gen_string (&str, ss_cstr (value));
159 g_string_append (string, ds_cstr (&str));
163 g_string_append (string, value);
165 g_string_append (string, ")");
168 /* The /PLOT subcommand */
169 g_string_append (string, "\n\t/PLOT ");
170 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->curve)))
172 g_string_append (string, "CURVE");
173 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->reference)))
174 g_string_append (string, " (REFERENCE)");
177 g_string_append (string, "NONE");
180 /* The /PRINT subcommand */
181 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->standard_error)) ||
182 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->coordinates)) )
184 g_string_append (string, "\n\t/PRINT");
186 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->standard_error)))
187 g_string_append (string, " SE");
189 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->coordinates)))
190 g_string_append (string, " COORDINATES");
193 g_string_append (string, ".\n");
197 g_string_free (string, FALSE);
203 psppire_dialog_action_roc_class_init (PsppireDialogActionRocClass *class)
205 GtkActionClass *action_class = GTK_ACTION_CLASS (class);
207 action_class->activate = psppire_dialog_action_roc_activate;
209 PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax;
214 psppire_dialog_action_roc_init (PsppireDialogActionRoc *act)