1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2007, 2008 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"
24 #include <language/syntax-string-source.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 append_variable_names (str, ed->dict, GTK_TREE_VIEW (ed->dep_list), 0);
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 append_variable_names (str, ed->dict, GTK_TREE_VIEW (ed->fct_list), 0);
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 (GObject *o, gpointer data)
239 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
241 struct examine_dialog ex_d;
243 GtkBuilder *xml = builder_new ("examine.ui");
245 GtkWidget *dialog = get_widget_assert (xml, "examine-dialog");
246 GtkWidget *source = get_widget_assert (xml, "treeview1");
248 GtkWidget *stats_button = get_widget_assert (xml, "stats-button");
249 GtkWidget *opts_button = get_widget_assert (xml, "opts-button");
252 GtkWidget *dep_selector = get_widget_assert (xml, "psppire-selector1");
253 GtkWidget *fct_selector = get_widget_assert (xml, "psppire-selector2");
254 GtkWidget *id_selector = get_widget_assert (xml, "psppire-selector3");
256 PsppireVarStore *vs = NULL;
258 g_object_get (de->data_editor, "var-store", &vs, NULL);
260 ex_d.dep_list = get_widget_assert (xml, "treeview2");
261 ex_d.fct_list = get_widget_assert (xml, "treeview3");
262 ex_d.id_entry = get_widget_assert (xml, "entry1");
263 ex_d.stats_dialog = get_widget_assert (xml, "statistics-dialog");
264 ex_d.opts_dialog = get_widget_assert (xml, "options-dialog");
265 ex_d.listwise = get_widget_assert (xml, "radiobutton1");
266 ex_d.pairwise = get_widget_assert (xml, "radiobutton2");
267 ex_d.report = get_widget_assert (xml, "radiobutton3");
269 ex_d.descriptives_button = GTK_TOGGLE_BUTTON
270 (get_widget_assert (xml, "descriptives-button"));
272 ex_d.extremes_button = GTK_TOGGLE_BUTTON
273 (get_widget_assert (xml, "extremes-button"));
275 ex_d.percentiles_button = GTK_TOGGLE_BUTTON
276 (get_widget_assert (xml, "percentiles-button"));
278 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de));
279 gtk_window_set_transient_for (GTK_WINDOW (ex_d.stats_dialog), GTK_WINDOW (de));
280 gtk_window_set_transient_for (GTK_WINDOW (ex_d.opts_dialog), GTK_WINDOW (de));
282 g_object_set (source, "dictionary", vs->dict, NULL);
284 set_dest_model (GTK_TREE_VIEW (ex_d.dep_list), vs->dict);
285 ex_d.dict = vs->dict;
288 psppire_selector_set_subjects (PSPPIRE_SELECTOR (dep_selector),
291 insert_source_row_into_tree_view,
294 psppire_selector_set_allow (PSPPIRE_SELECTOR (dep_selector),
297 set_dest_model (GTK_TREE_VIEW (ex_d.fct_list), vs->dict);
300 psppire_selector_set_subjects (PSPPIRE_SELECTOR (fct_selector),
303 insert_source_row_into_tree_view,
307 psppire_selector_set_subjects (PSPPIRE_SELECTOR (id_selector),
310 insert_source_row_into_entry,
313 g_signal_connect (dialog, "refresh", G_CALLBACK (refresh), &ex_d);
315 psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog),
316 dialog_state_valid, &ex_d);
319 g_signal_connect_swapped (stats_button, "clicked",
320 G_CALLBACK (run_stats_dialog), &ex_d);
322 g_signal_connect_swapped (opts_button, "clicked",
323 G_CALLBACK (run_opts_dialog), &ex_d);
325 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
330 case GTK_RESPONSE_OK:
332 gchar *syntax = generate_syntax (&ex_d);
334 struct getl_interface *sss = create_syntax_string_source (syntax);
336 execute_syntax (sss);
341 case PSPPIRE_RESPONSE_PASTE:
343 gchar *syntax = generate_syntax (&ex_d);
344 paste_syntax_in_new_window (syntax);
352 g_object_unref (xml);