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-descriptives.h"
22 #include "psppire-checkbox-treeview.h"
24 #include "psppire-var-view.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_descriptives_class_init (PsppireDialogActionDescriptivesClass *class);
35 G_DEFINE_TYPE (PsppireDialogActionDescriptives, psppire_dialog_action_descriptives, PSPPIRE_TYPE_DIALOG_ACTION);
38 #define DESCRIPTIVE_STATS \
39 DS (MEAN, N_("Mean")) \
40 DS (STDDEV, N_("Standard deviation")) \
41 DS (MINIMUM, N_("Minimum")) \
42 DS (MAXIMUM, N_("Maximum")) \
43 DS (RANGE, N_("Range")) \
45 DS (SEMEAN, N_("Standard error")) \
46 DS (VARIANCE, N_("Variance")) \
47 DS (KURTOSIS, N_("Kurtosis")) \
48 DS (SKEWNESS, N_("Skewness"))
52 #define DS(NAME, LABEL) DS_##NAME,
60 #define DS(NAME, LABEL) B_DS_##NAME = 1u << DS_##NAME,
63 B_DS_ALL = (1u << N_DESCRIPTIVE_STATS) - 1,
64 B_DS_DEFAULT = B_DS_MEAN | B_DS_STDDEV | B_DS_MINIMUM | B_DS_MAXIMUM
68 static const struct checkbox_entry_item stats[] =
70 #define DS(NAME, LABEL) {#NAME, LABEL},
77 generate_syntax (PsppireDialogAction *act)
79 PsppireDialogActionDescriptives *scd = PSPPIRE_DIALOG_ACTION_DESCRIPTIVES (act);
83 unsigned int selected;
85 bool listwise, include;
88 string = g_string_new ("DESCRIPTIVES");
89 g_string_append (string, "\n /VARIABLES=");
90 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (scd->stat_vars), 0, string);
92 listwise = gtk_toggle_button_get_active (scd->exclude_missing_listwise);
93 include = gtk_toggle_button_get_active (scd->include_user_missing);
94 if (listwise || include)
96 g_string_append (string, "\n /MISSING=");
99 g_string_append (string, "LISTWISE");
101 g_string_append (string, " ");
104 g_string_append (string, "INCLUDE");
108 for (i = 0, ok = gtk_tree_model_get_iter_first (scd->stats, &iter); ok;
109 i++, ok = gtk_tree_model_iter_next (scd->stats, &iter))
112 gtk_tree_model_get (scd->stats, &iter,
113 CHECKBOX_COLUMN_SELECTED, &toggled, -1);
118 if (selected != B_DS_DEFAULT)
120 g_string_append (string, "\n /STATISTICS=");
121 if (selected == B_DS_ALL)
122 g_string_append (string, "ALL");
123 else if (selected == 0)
124 g_string_append (string, "NONE");
128 if ((selected & B_DS_DEFAULT) == B_DS_DEFAULT)
130 g_string_append (string, "DEFAULT");
131 selected &= ~B_DS_DEFAULT;
134 for (i = 0; i < N_DESCRIPTIVE_STATS; i++)
135 if (selected & (1u << i))
138 g_string_append (string, " ");
139 g_string_append (string, stats[i].name);
144 if (gtk_toggle_button_get_active (scd->save_z_scores))
145 g_string_append (string, "\n /SAVE");
147 g_string_append (string, ".");
149 if (gtk_toggle_button_get_active (scd->save_z_scores))
150 g_string_append (string, "\nEXECUTE.");
154 g_string_free (string, FALSE);
160 dialog_state_valid (gpointer data)
162 PsppireDialogActionDescriptives *dd = data;
164 GtkTreeModel *vars = gtk_tree_view_get_model (dd->stat_vars);
168 return gtk_tree_model_get_iter_first (vars, ¬used);
172 dialog_refresh (PsppireDialogAction *scd_)
174 PsppireDialogActionDescriptives *scd
175 = PSPPIRE_DIALOG_ACTION_DESCRIPTIVES (scd_);
176 GtkTreeModel *liststore;
181 liststore = gtk_tree_view_get_model (scd->stat_vars);
182 gtk_list_store_clear (GTK_LIST_STORE (liststore));
184 for (i = 0, ok = gtk_tree_model_get_iter_first (scd->stats, &iter); ok;
185 i++, ok = gtk_tree_model_iter_next (scd->stats, &iter))
186 gtk_list_store_set (GTK_LIST_STORE (scd->stats), &iter,
187 CHECKBOX_COLUMN_SELECTED,
188 (B_DS_DEFAULT & (1u << i)) ? true : false, -1);
190 gtk_toggle_button_set_active (scd->exclude_missing_listwise, false);
191 gtk_toggle_button_set_active (scd->include_user_missing, false);
192 gtk_toggle_button_set_active (scd->save_z_scores, false);
196 psppire_dialog_action_descriptives_activate (GtkAction *a)
198 PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
199 PsppireDialogActionDescriptives *act = PSPPIRE_DIALOG_ACTION_DESCRIPTIVES (a);
201 GtkBuilder *xml = builder_new ("descriptives.ui");
203 GtkWidget *stats_treeview = get_widget_assert (xml, "statistics");
205 pda->dialog = get_widget_assert (xml, "descriptives-dialog");
206 pda->source = get_widget_assert (xml, "all-variables");
207 act->variables = get_widget_assert (xml, "stat-variables");
209 g_object_set (pda->source, "model", pda->dict,
210 "predicate", var_is_numeric, NULL);
212 psppire_checkbox_treeview_populate (PSPPIRE_CHECKBOX_TREEVIEW (stats_treeview),
214 N_DESCRIPTIVE_STATS, stats);
216 act->stat_vars = GTK_TREE_VIEW (act->variables);
217 act->stats = gtk_tree_view_get_model (GTK_TREE_VIEW (stats_treeview));
219 act->include_user_missing =
220 GTK_TOGGLE_BUTTON (get_widget_assert (xml, "include_user_missing"));
221 act->exclude_missing_listwise =
222 GTK_TOGGLE_BUTTON (get_widget_assert (xml, "exclude_missing_listwise"));
224 GTK_TOGGLE_BUTTON (get_widget_assert (xml, "save_z_scores"));
226 psppire_dialog_action_set_valid_predicate (pda, dialog_state_valid);
227 psppire_dialog_action_set_refresh (pda, dialog_refresh);
229 PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_descriptives_parent_class)->activate (pda);
231 g_object_unref (xml);
235 psppire_dialog_action_descriptives_class_init (PsppireDialogActionDescriptivesClass *class)
237 GTK_ACTION_CLASS (class)->activate = psppire_dialog_action_descriptives_activate;
239 PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax;
243 psppire_dialog_action_descriptives_init (PsppireDialogActionDescriptives *act)