1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2007, 2008, 2009, 2010, 2011 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 "examine-dialog.h"
20 #include "psppire-var-view.h"
25 #include <ui/gui/psppire-data-window.h>
26 #include <ui/gui/dialog-common.h>
27 #include <ui/gui/dict-display.h>
28 #include <ui/gui/helper.h>
29 #include <ui/gui/psppire-dialog.h>
30 #include <ui/gui/psppire-var-store.h>
34 #define _(msgid) gettext (msgid)
35 #define N_(msgid) msgid
45 #define STAT_DESCRIPTIVES 0x01
46 #define STAT_EXTREMES 0x02
47 #define STAT_PERCENTILES 0x04
58 GtkWidget *stats_dialog;
59 GtkWidget *opts_dialog;
68 GtkToggleButton *descriptives_button;
69 GtkToggleButton *extremes_button;
70 GtkToggleButton *percentiles_button;
74 refresh (PsppireDialog *dialog, struct examine_dialog *ex_d)
76 GtkTreeModel *liststore =
77 gtk_tree_view_get_model (GTK_TREE_VIEW (ex_d->dep_list));
79 gtk_list_store_clear (GTK_LIST_STORE (liststore));
81 liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (ex_d->fct_list));
82 gtk_list_store_clear (GTK_LIST_STORE (liststore));
85 gtk_entry_set_text (GTK_ENTRY (ex_d->id_entry), "");
87 ex_d->opts = OPT_LISTWISE;
92 generate_syntax (const struct examine_dialog *ed)
96 GString *str = g_string_new ("EXAMINE ");
98 g_string_append (str, "\n\t/VARIABLES=");
99 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (ed->dep_list), 0, str);
101 if ( 0 < gtk_tree_model_iter_n_children
102 (gtk_tree_view_get_model (GTK_TREE_VIEW (ed->fct_list)), NULL))
104 g_string_append (str, "\n\tBY ");
105 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (ed->fct_list), 0, str);
108 label = gtk_entry_get_text (GTK_ENTRY (ed->id_entry));
109 if ( 0 != strcmp (label, "") )
111 g_string_append (str, "\n\t/ID = ");
112 g_string_append (str, label);
115 if ( ed->stats & (STAT_DESCRIPTIVES | STAT_EXTREMES))
117 g_string_append (str, "\n\t/STATISTICS =");
119 if ( ed->stats & STAT_DESCRIPTIVES)
120 g_string_append (str, " DESCRIPTIVES");
122 if ( ed->stats & STAT_EXTREMES)
123 g_string_append (str, " EXTREME");
126 if ( ed->stats & STAT_PERCENTILES)
127 g_string_append (str, "\n\t/PERCENTILES");
129 g_string_append (str, "\n\t/MISSING=");
133 g_string_append (str, "REPORT");
136 g_string_append (str, "PAIRWISE");
139 g_string_append (str, "LISTWISE");
143 g_string_append (str, ".");
147 g_string_free (str, FALSE);
152 /* Dialog is valid iff at least one variable has been selected */
154 dialog_state_valid (gpointer data)
156 struct examine_dialog *ex_d = data;
159 gtk_tree_view_get_model (GTK_TREE_VIEW (ex_d->dep_list));
163 return gtk_tree_model_get_iter_first (vars, ¬used);
168 run_stats_dialog (struct examine_dialog *ed)
172 gtk_toggle_button_set_active (ed->descriptives_button,
173 ed->stats & STAT_DESCRIPTIVES);
175 gtk_toggle_button_set_active (ed->extremes_button,
176 ed->stats & STAT_EXTREMES);
178 gtk_toggle_button_set_active (ed->percentiles_button,
179 ed->stats & STAT_PERCENTILES);
181 response = psppire_dialog_run (PSPPIRE_DIALOG (ed->stats_dialog));
183 if ( response == PSPPIRE_RESPONSE_CONTINUE )
186 if ( gtk_toggle_button_get_active (ed->descriptives_button) )
187 ed->stats |= STAT_DESCRIPTIVES;
189 if ( gtk_toggle_button_get_active (ed->extremes_button) )
190 ed->stats |= STAT_EXTREMES;
192 if ( gtk_toggle_button_get_active (ed->percentiles_button) )
193 ed->stats |= STAT_PERCENTILES;
198 run_opts_dialog (struct examine_dialog *ed)
206 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ed->listwise), TRUE);
209 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ed->pairwise), TRUE);
212 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ed->report), TRUE);
215 g_assert_not_reached ();
219 response = psppire_dialog_run (PSPPIRE_DIALOG (ed->opts_dialog));
221 if ( response == PSPPIRE_RESPONSE_CONTINUE )
223 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ed->listwise)))
224 ed->opts = OPT_LISTWISE;
225 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ed->pairwise)))
226 ed->opts = OPT_PAIRWISE;
227 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ed->report)))
228 ed->opts = OPT_REPORT;
234 /* Pops up the Examine dialog box */
236 examine_dialog (PsppireDataWindow *de)
240 struct examine_dialog ex_d;
242 GtkBuilder *xml = builder_new ("examine.ui");
244 GtkWidget *dialog = get_widget_assert (xml, "examine-dialog");
245 GtkWidget *source = get_widget_assert (xml, "treeview1");
247 GtkWidget *stats_button = get_widget_assert (xml, "stats-button");
248 GtkWidget *opts_button = get_widget_assert (xml, "opts-button");
251 GtkWidget *dep_selector = get_widget_assert (xml, "psppire-selector1");
253 PsppireVarStore *vs = NULL;
255 g_object_get (de->data_editor, "var-store", &vs, NULL);
257 ex_d.dep_list = get_widget_assert (xml, "treeview2");
258 ex_d.fct_list = get_widget_assert (xml, "treeview3");
259 ex_d.id_entry = get_widget_assert (xml, "entry1");
260 ex_d.stats_dialog = get_widget_assert (xml, "statistics-dialog");
261 ex_d.opts_dialog = get_widget_assert (xml, "options-dialog");
262 ex_d.listwise = get_widget_assert (xml, "radiobutton1");
263 ex_d.pairwise = get_widget_assert (xml, "radiobutton2");
264 ex_d.report = get_widget_assert (xml, "radiobutton3");
266 ex_d.descriptives_button = GTK_TOGGLE_BUTTON
267 (get_widget_assert (xml, "descriptives-button"));
269 ex_d.extremes_button = GTK_TOGGLE_BUTTON
270 (get_widget_assert (xml, "extremes-button"));
272 ex_d.percentiles_button = GTK_TOGGLE_BUTTON
273 (get_widget_assert (xml, "percentiles-button"));
275 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de));
276 gtk_window_set_transient_for (GTK_WINDOW (ex_d.stats_dialog), GTK_WINDOW (de));
277 gtk_window_set_transient_for (GTK_WINDOW (ex_d.opts_dialog), GTK_WINDOW (de));
279 g_object_get (vs, "dictionary", &ex_d.dict, NULL);
280 g_object_set (source, "model", ex_d.dict, NULL);
282 psppire_selector_set_allow (PSPPIRE_SELECTOR (dep_selector),
285 g_signal_connect (dialog, "refresh", G_CALLBACK (refresh), &ex_d);
287 psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog),
288 dialog_state_valid, &ex_d);
291 g_signal_connect_swapped (stats_button, "clicked",
292 G_CALLBACK (run_stats_dialog), &ex_d);
294 g_signal_connect_swapped (opts_button, "clicked",
295 G_CALLBACK (run_opts_dialog), &ex_d);
297 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
302 case GTK_RESPONSE_OK:
303 g_free (execute_syntax_string (de, generate_syntax (&ex_d)));
305 case PSPPIRE_RESPONSE_PASTE:
306 g_free (paste_syntax_to_window (generate_syntax (&ex_d)));
312 g_object_unref (xml);