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-examine.h"
22 #include "psppire-var-view.h"
23 #include "psppire-dict.h"
24 #include "psppire-dialog.h"
25 #include "builder-wrapper.h"
28 #define _(msgid) gettext (msgid)
29 #define N_(msgid) msgid
31 static void psppire_dialog_action_examine_class_init (PsppireDialogActionExamineClass *class);
33 G_DEFINE_TYPE (PsppireDialogActionExamine, psppire_dialog_action_examine, PSPPIRE_TYPE_DIALOG_ACTION);
36 #define STAT_DESCRIPTIVES 0x01
37 #define STAT_EXTREMES 0x02
38 #define STAT_PERCENTILES 0x04
41 run_stats_dialog (PsppireDialogActionExamine *ed)
45 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ed->descriptives_button),
46 ed->stats & STAT_DESCRIPTIVES);
48 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ed->extremes_button),
49 ed->stats & STAT_EXTREMES);
51 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ed->percentiles_button),
52 ed->stats & STAT_PERCENTILES);
54 response = psppire_dialog_run (PSPPIRE_DIALOG (ed->stats_dialog));
56 if ( response == PSPPIRE_RESPONSE_CONTINUE )
59 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ed->descriptives_button) ))
60 ed->stats |= STAT_DESCRIPTIVES;
62 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ed->extremes_button) ))
63 ed->stats |= STAT_EXTREMES;
65 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ed->percentiles_button) ))
66 ed->stats |= STAT_PERCENTILES;
71 run_opts_dialog (PsppireDialogActionExamine *ed)
78 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ed->listwise), TRUE);
81 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ed->pairwise), TRUE);
84 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ed->report), TRUE);
87 g_assert_not_reached ();
91 response = psppire_dialog_run (PSPPIRE_DIALOG (ed->opts_dialog));
93 if ( response == PSPPIRE_RESPONSE_CONTINUE )
95 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ed->listwise)))
96 ed->opts = OPT_LISTWISE;
97 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ed->pairwise)))
98 ed->opts = OPT_PAIRWISE;
99 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ed->report)))
100 ed->opts = OPT_REPORT;
108 generate_syntax (PsppireDialogAction *act)
110 PsppireDialogActionExamine *ed = PSPPIRE_DIALOG_ACTION_EXAMINE (act);
114 GString *str = g_string_new ("EXAMINE ");
116 g_string_append (str, "\n\t/VARIABLES=");
117 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (ed->variables), 0, str);
119 if ( 0 < gtk_tree_model_iter_n_children
120 (gtk_tree_view_get_model (GTK_TREE_VIEW (ed->factors)), NULL))
122 g_string_append (str, "\n\tBY ");
123 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (ed->factors), 0, str);
126 label = gtk_entry_get_text (GTK_ENTRY (ed->id_var));
127 if ( 0 != strcmp (label, "") )
129 g_string_append (str, "\n\t/ID = ");
130 g_string_append (str, label);
133 if ( ed->stats & (STAT_DESCRIPTIVES | STAT_EXTREMES))
135 g_string_append (str, "\n\t/STATISTICS =");
137 if ( ed->stats & STAT_DESCRIPTIVES)
138 g_string_append (str, " DESCRIPTIVES");
140 if ( ed->stats & STAT_EXTREMES)
141 g_string_append (str, " EXTREME");
144 if ( ed->stats & STAT_PERCENTILES)
145 g_string_append (str, "\n\t/PERCENTILES");
148 g_string_append (str, "\n\t/MISSING=");
152 g_string_append (str, "REPORT");
155 g_string_append (str, "PAIRWISE");
158 g_string_append (str, "LISTWISE");
162 g_string_append (str, ".");
165 g_string_free (str, FALSE);
171 dialog_state_valid (PsppireDialogAction *da)
173 PsppireDialogActionExamine *pae = PSPPIRE_DIALOG_ACTION_EXAMINE (da);
176 gtk_tree_view_get_model (GTK_TREE_VIEW (pae->variables));
178 return gtk_tree_model_get_iter_first (vars, ¬used);
182 dialog_refresh (PsppireDialogAction *da)
184 PsppireDialogActionExamine *dae = PSPPIRE_DIALOG_ACTION_EXAMINE (da);
185 GtkTreeModel *liststore = NULL;
187 liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (dae->variables));
188 gtk_list_store_clear (GTK_LIST_STORE (liststore));
190 liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (dae->factors));
191 gtk_list_store_clear (GTK_LIST_STORE (liststore));
193 gtk_entry_set_text (GTK_ENTRY (dae->id_var), "");
195 dae->opts = OPT_LISTWISE;
199 psppire_dialog_action_examine_activate (GtkAction *a)
201 PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
202 PsppireDialogActionExamine *act = PSPPIRE_DIALOG_ACTION_EXAMINE (a);
204 GtkBuilder *xml = builder_new ("examine.ui");
206 GtkWidget *stats_button = get_widget_assert (xml, "stats-button");
207 GtkWidget *opts_button = get_widget_assert (xml, "opts-button");
209 pda->dialog = get_widget_assert (xml, "examine-dialog");
210 pda->source = get_widget_assert (xml, "treeview1");
211 act->variables = get_widget_assert (xml, "treeview2");
212 act->factors = get_widget_assert (xml, "treeview3");
213 act->id_var = get_widget_assert (xml, "entry1");
215 act->stats_dialog = get_widget_assert (xml, "statistics-dialog");
216 act->descriptives_button = get_widget_assert (xml, "descriptives-button");
217 act->extremes_button = get_widget_assert (xml, "extremes-button");
218 act->percentiles_button = get_widget_assert (xml, "percentiles-button");
220 act->opts_dialog = get_widget_assert (xml, "options-dialog");
221 act->listwise = get_widget_assert (xml, "radiobutton1");
222 act->pairwise = get_widget_assert (xml, "radiobutton2");
223 act->report = get_widget_assert (xml, "radiobutton3");
225 g_object_set (pda->source,
229 psppire_dialog_action_set_valid_predicate (pda, (void *) dialog_state_valid);
230 psppire_dialog_action_set_refresh (pda, dialog_refresh);
232 g_signal_connect_swapped (stats_button, "clicked",
233 G_CALLBACK (run_stats_dialog), act);
235 g_signal_connect_swapped (opts_button, "clicked",
236 G_CALLBACK (run_opts_dialog), act);
238 PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_examine_parent_class)->activate (pda);
242 psppire_dialog_action_examine_class_init (PsppireDialogActionExamineClass *class)
244 GTK_ACTION_CLASS (class)->activate = psppire_dialog_action_examine_activate;
246 PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax;
250 psppire_dialog_action_examine_init (PsppireDialogActionExamine *act)