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 "dialog-common.h"
24 #include "psppire-selector.h"
25 #include "psppire-dict.h"
26 #include "psppire-dialog.h"
27 #include "builder-wrapper.h"
30 #define _(msgid) gettext (msgid)
31 #define N_(msgid) msgid
33 static void psppire_dialog_action_examine_class_init (PsppireDialogActionExamineClass *class);
35 G_DEFINE_TYPE (PsppireDialogActionExamine, psppire_dialog_action_examine, PSPPIRE_TYPE_DIALOG_ACTION);
38 #define STAT_DESCRIPTIVES 0x01
39 #define STAT_EXTREMES 0x02
40 #define STAT_PERCENTILES 0x04
43 run_stats_dialog (PsppireDialogActionExamine *ed)
47 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ed->descriptives_button),
48 ed->stats & STAT_DESCRIPTIVES);
50 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ed->extremes_button),
51 ed->stats & STAT_EXTREMES);
53 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ed->percentiles_button),
54 ed->stats & STAT_PERCENTILES);
56 response = psppire_dialog_run (PSPPIRE_DIALOG (ed->stats_dialog));
58 if ( response == PSPPIRE_RESPONSE_CONTINUE )
61 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ed->descriptives_button) ))
62 ed->stats |= STAT_DESCRIPTIVES;
64 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ed->extremes_button) ))
65 ed->stats |= STAT_EXTREMES;
67 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ed->percentiles_button) ))
68 ed->stats |= STAT_PERCENTILES;
73 run_opts_dialog (PsppireDialogActionExamine *ed)
80 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ed->listwise), TRUE);
83 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ed->pairwise), TRUE);
86 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ed->report), TRUE);
89 g_assert_not_reached ();
93 response = psppire_dialog_run (PSPPIRE_DIALOG (ed->opts_dialog));
95 if ( response == PSPPIRE_RESPONSE_CONTINUE )
97 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ed->listwise)))
98 ed->opts = OPT_LISTWISE;
99 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ed->pairwise)))
100 ed->opts = OPT_PAIRWISE;
101 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ed->report)))
102 ed->opts = OPT_REPORT;
110 generate_syntax (PsppireDialogAction *act)
112 PsppireDialogActionExamine *ed = PSPPIRE_DIALOG_ACTION_EXAMINE (act);
116 GString *str = g_string_new ("EXAMINE ");
118 g_string_append (str, "\n\t/VARIABLES=");
119 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (ed->variables), 0, str);
121 if ( 0 < gtk_tree_model_iter_n_children
122 (gtk_tree_view_get_model (GTK_TREE_VIEW (ed->factors)), NULL))
124 g_string_append (str, "\n\tBY ");
125 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (ed->factors), 0, str);
128 label = gtk_entry_get_text (GTK_ENTRY (ed->id_var));
129 if ( 0 != strcmp (label, "") )
131 g_string_append (str, "\n\t/ID = ");
132 g_string_append (str, label);
135 if ( ed->stats & (STAT_DESCRIPTIVES | STAT_EXTREMES))
137 g_string_append (str, "\n\t/STATISTICS =");
139 if ( ed->stats & STAT_DESCRIPTIVES)
140 g_string_append (str, " DESCRIPTIVES");
142 if ( ed->stats & STAT_EXTREMES)
143 g_string_append (str, " EXTREME");
146 if ( ed->stats & STAT_PERCENTILES)
147 g_string_append (str, "\n\t/PERCENTILES");
150 g_string_append (str, "\n\t/MISSING=");
154 g_string_append (str, "REPORT");
157 g_string_append (str, "PAIRWISE");
160 g_string_append (str, "LISTWISE");
164 g_string_append (str, ".");
167 g_string_free (str, FALSE);
173 dialog_state_valid (PsppireDialogAction *da)
175 PsppireDialogActionExamine *pae = PSPPIRE_DIALOG_ACTION_EXAMINE (da);
178 gtk_tree_view_get_model (GTK_TREE_VIEW (pae->variables));
180 return gtk_tree_model_get_iter_first (vars, ¬used);
184 dialog_refresh (PsppireDialogAction *da)
186 PsppireDialogActionExamine *dae = PSPPIRE_DIALOG_ACTION_EXAMINE (da);
187 GtkTreeModel *liststore = NULL;
189 liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (dae->variables));
190 gtk_list_store_clear (GTK_LIST_STORE (liststore));
192 liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (dae->factors));
193 gtk_list_store_clear (GTK_LIST_STORE (liststore));
195 gtk_entry_set_text (GTK_ENTRY (dae->id_var), "");
197 dae->opts = OPT_LISTWISE;
201 psppire_dialog_action_examine_activate (GtkAction *a)
203 PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
204 PsppireDialogActionExamine *act = PSPPIRE_DIALOG_ACTION_EXAMINE (a);
206 GtkBuilder *xml = builder_new ("examine.ui");
208 GtkWidget *stats_button = get_widget_assert (xml, "stats-button");
209 GtkWidget *opts_button = get_widget_assert (xml, "opts-button");
211 GtkWidget *dep_sel = get_widget_assert (xml, "psppire-selector1");
213 pda->dialog = get_widget_assert (xml, "examine-dialog");
214 pda->source = get_widget_assert (xml, "treeview1");
215 act->variables = get_widget_assert (xml, "treeview2");
216 act->factors = get_widget_assert (xml, "treeview3");
217 act->id_var = get_widget_assert (xml, "entry1");
219 act->stats_dialog = get_widget_assert (xml, "statistics-dialog");
220 act->descriptives_button = get_widget_assert (xml, "descriptives-button");
221 act->extremes_button = get_widget_assert (xml, "extremes-button");
222 act->percentiles_button = get_widget_assert (xml, "percentiles-button");
224 act->opts_dialog = get_widget_assert (xml, "options-dialog");
225 act->listwise = get_widget_assert (xml, "radiobutton1");
226 act->pairwise = get_widget_assert (xml, "radiobutton2");
227 act->report = get_widget_assert (xml, "radiobutton3");
229 g_object_set (pda->source,
233 psppire_selector_set_allow (PSPPIRE_SELECTOR (dep_sel), numeric_only);
235 psppire_dialog_action_set_valid_predicate (pda, (void *) dialog_state_valid);
236 psppire_dialog_action_set_refresh (pda, dialog_refresh);
238 g_signal_connect_swapped (stats_button, "clicked",
239 G_CALLBACK (run_stats_dialog), act);
241 g_signal_connect_swapped (opts_button, "clicked",
242 G_CALLBACK (run_opts_dialog), act);
244 PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_examine_parent_class)->activate (pda);
246 g_object_unref (xml);
250 psppire_dialog_action_examine_class_init (PsppireDialogActionExamineClass *class)
252 GTK_ACTION_CLASS (class)->activate = psppire_dialog_action_examine_activate;
254 PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax;
258 psppire_dialog_action_examine_init (PsppireDialogActionExamine *act)