1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2007, 2008, 2009 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 <language/syntax-string-source.h>
26 #include <ui/gui/psppire-data-window.h>
27 #include <ui/gui/dialog-common.h>
28 #include <ui/gui/dict-display.h>
29 #include <ui/gui/helper.h>
30 #include <ui/gui/psppire-dialog.h>
31 #include <ui/gui/psppire-var-store.h>
35 #define _(msgid) gettext (msgid)
36 #define N_(msgid) msgid
46 #define STAT_DESCRIPTIVES 0x01
47 #define STAT_EXTREMES 0x02
48 #define STAT_PERCENTILES 0x04
59 GtkWidget *stats_dialog;
60 GtkWidget *opts_dialog;
69 GtkToggleButton *descriptives_button;
70 GtkToggleButton *extremes_button;
71 GtkToggleButton *percentiles_button;
75 refresh (PsppireDialog *dialog, struct examine_dialog *ex_d)
77 GtkTreeModel *liststore =
78 gtk_tree_view_get_model (GTK_TREE_VIEW (ex_d->dep_list));
80 gtk_list_store_clear (GTK_LIST_STORE (liststore));
82 liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (ex_d->fct_list));
83 gtk_list_store_clear (GTK_LIST_STORE (liststore));
86 gtk_entry_set_text (GTK_ENTRY (ex_d->id_entry), "");
88 ex_d->opts = OPT_LISTWISE;
93 generate_syntax (const struct examine_dialog *ed)
97 GString *str = g_string_new ("EXAMINE ");
99 g_string_append (str, "\n\t/VARIABLES=");
100 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (ed->dep_list), 0, str);
102 if ( 0 < gtk_tree_model_iter_n_children
103 (gtk_tree_view_get_model (GTK_TREE_VIEW (ed->fct_list)), NULL))
105 g_string_append (str, "\n\tBY ");
106 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (ed->fct_list), 0, str);
109 label = gtk_entry_get_text (GTK_ENTRY (ed->id_entry));
110 if ( 0 != strcmp (label, "") )
112 g_string_append (str, "\n\t/ID = ");
113 g_string_append (str, label);
116 if ( ed->stats & (STAT_DESCRIPTIVES | STAT_EXTREMES))
118 g_string_append (str, "\n\t/STATISTICS =");
120 if ( ed->stats & STAT_DESCRIPTIVES)
121 g_string_append (str, " DESCRIPTIVES");
123 if ( ed->stats & STAT_EXTREMES)
124 g_string_append (str, " EXTREME");
127 if ( ed->stats & STAT_PERCENTILES)
128 g_string_append (str, "\n\t/PERCENTILES");
130 g_string_append (str, "\n\t/MISSING=");
134 g_string_append (str, "REPORT");
137 g_string_append (str, "PAIRWISE");
140 g_string_append (str, "LISTWISE");
144 g_string_append (str, ".");
148 g_string_free (str, FALSE);
153 /* Dialog is valid iff at least one variable has been selected */
155 dialog_state_valid (gpointer data)
157 struct examine_dialog *ex_d = data;
160 gtk_tree_view_get_model (GTK_TREE_VIEW (ex_d->dep_list));
164 return gtk_tree_model_get_iter_first (vars, ¬used);
169 run_stats_dialog (struct examine_dialog *ed)
173 gtk_toggle_button_set_active (ed->descriptives_button,
174 ed->stats & STAT_DESCRIPTIVES);
176 gtk_toggle_button_set_active (ed->extremes_button,
177 ed->stats & STAT_EXTREMES);
179 gtk_toggle_button_set_active (ed->percentiles_button,
180 ed->stats & STAT_PERCENTILES);
182 response = psppire_dialog_run (PSPPIRE_DIALOG (ed->stats_dialog));
184 if ( response == PSPPIRE_RESPONSE_CONTINUE )
187 if ( gtk_toggle_button_get_active (ed->descriptives_button) )
188 ed->stats |= STAT_DESCRIPTIVES;
190 if ( gtk_toggle_button_get_active (ed->extremes_button) )
191 ed->stats |= STAT_EXTREMES;
193 if ( gtk_toggle_button_get_active (ed->percentiles_button) )
194 ed->stats |= STAT_PERCENTILES;
199 run_opts_dialog (struct examine_dialog *ed)
207 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ed->listwise), TRUE);
210 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ed->pairwise), TRUE);
213 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ed->report), TRUE);
216 g_assert_not_reached ();
220 response = psppire_dialog_run (PSPPIRE_DIALOG (ed->opts_dialog));
222 if ( response == PSPPIRE_RESPONSE_CONTINUE )
224 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ed->listwise)))
225 ed->opts = OPT_LISTWISE;
226 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ed->pairwise)))
227 ed->opts = OPT_PAIRWISE;
228 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ed->report)))
229 ed->opts = OPT_REPORT;
235 /* Pops up the Examine dialog box */
237 examine_dialog (PsppireDataWindow *de)
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");
254 PsppireVarStore *vs = NULL;
256 g_object_get (de->data_editor, "var-store", &vs, NULL);
258 ex_d.dep_list = get_widget_assert (xml, "treeview2");
259 ex_d.fct_list = get_widget_assert (xml, "treeview3");
260 ex_d.id_entry = get_widget_assert (xml, "entry1");
261 ex_d.stats_dialog = get_widget_assert (xml, "statistics-dialog");
262 ex_d.opts_dialog = get_widget_assert (xml, "options-dialog");
263 ex_d.listwise = get_widget_assert (xml, "radiobutton1");
264 ex_d.pairwise = get_widget_assert (xml, "radiobutton2");
265 ex_d.report = get_widget_assert (xml, "radiobutton3");
267 ex_d.descriptives_button = GTK_TOGGLE_BUTTON
268 (get_widget_assert (xml, "descriptives-button"));
270 ex_d.extremes_button = GTK_TOGGLE_BUTTON
271 (get_widget_assert (xml, "extremes-button"));
273 ex_d.percentiles_button = GTK_TOGGLE_BUTTON
274 (get_widget_assert (xml, "percentiles-button"));
276 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de));
277 gtk_window_set_transient_for (GTK_WINDOW (ex_d.stats_dialog), GTK_WINDOW (de));
278 gtk_window_set_transient_for (GTK_WINDOW (ex_d.opts_dialog), GTK_WINDOW (de));
280 g_object_get (vs, "dictionary", &ex_d.dict, NULL);
281 g_object_set (source, "model", ex_d.dict, NULL);
283 psppire_selector_set_allow (PSPPIRE_SELECTOR (dep_selector),
286 g_signal_connect (dialog, "refresh", G_CALLBACK (refresh), &ex_d);
288 psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog),
289 dialog_state_valid, &ex_d);
292 g_signal_connect_swapped (stats_button, "clicked",
293 G_CALLBACK (run_stats_dialog), &ex_d);
295 g_signal_connect_swapped (opts_button, "clicked",
296 G_CALLBACK (run_opts_dialog), &ex_d);
298 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
303 case GTK_RESPONSE_OK:
305 gchar *syntax = generate_syntax (&ex_d);
307 struct getl_interface *sss = create_syntax_string_source (syntax);
309 execute_syntax (sss);
314 case PSPPIRE_RESPONSE_PASTE:
316 gchar *syntax = generate_syntax (&ex_d);
317 paste_syntax_to_window (syntax);
325 g_object_unref (xml);