1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2007 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 "checkbox-treeview.h"
20 #include "descriptives-dialog.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
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},
75 struct descriptives_dialog
77 GtkTreeView *stat_vars;
80 GtkToggleButton *exclude_missing_listwise;
81 GtkToggleButton *include_user_missing;
82 GtkToggleButton *save_z_scores;
86 refresh (PsppireDialog *dialog, struct descriptives_dialog *scd)
88 GtkTreeModel *liststore;
93 liststore = gtk_tree_view_get_model (scd->stat_vars);
94 gtk_list_store_clear (GTK_LIST_STORE (liststore));
96 for (i = 0, ok = gtk_tree_model_get_iter_first (scd->stats, &iter); ok;
97 i++, ok = gtk_tree_model_iter_next (scd->stats, &iter))
98 gtk_list_store_set (GTK_LIST_STORE (scd->stats), &iter,
99 CHECKBOX_COLUMN_SELECTED,
100 (B_DS_DEFAULT & (1u << i)) ? true : false, -1);
102 gtk_toggle_button_set_active (scd->exclude_missing_listwise, false);
103 gtk_toggle_button_set_active (scd->include_user_missing, false);
104 gtk_toggle_button_set_active (scd->save_z_scores, false);
108 generate_syntax (const struct descriptives_dialog *scd)
113 unsigned int selected;
115 bool listwise, include;
118 string = g_string_new ("DESCRIPTIVES");
119 g_string_append (string, "\n /VARIABLES=");
120 append_variable_names (string, scd->dict, GTK_TREE_VIEW (scd->stat_vars), 0);
122 listwise = gtk_toggle_button_get_active (scd->exclude_missing_listwise);
123 include = gtk_toggle_button_get_active (scd->include_user_missing);
124 if (listwise || include)
126 g_string_append (string, "\n /MISSING=");
129 g_string_append (string, "LISTWISE");
131 g_string_append (string, " ");
134 g_string_append (string, "INCLUDE");
138 for (i = 0, ok = gtk_tree_model_get_iter_first (scd->stats, &iter); ok;
139 i++, ok = gtk_tree_model_iter_next (scd->stats, &iter))
142 gtk_tree_model_get (scd->stats, &iter,
143 CHECKBOX_COLUMN_SELECTED, &toggled, -1);
148 if (selected != B_DS_DEFAULT)
150 g_string_append (string, "\n /STATISTICS=");
151 if (selected == B_DS_ALL)
152 g_string_append (string, "ALL");
153 else if (selected == 0)
154 g_string_append (string, "NONE");
158 if ((selected & B_DS_DEFAULT) == B_DS_DEFAULT)
160 g_string_append (string, "DEFAULT");
161 selected &= ~B_DS_DEFAULT;
164 for (i = 0; i < N_DESCRIPTIVE_STATS; i++)
165 if (selected & (1u << i))
168 g_string_append (string, " ");
169 g_string_append (string, stats[i].name);
174 if (gtk_toggle_button_get_active (scd->save_z_scores))
175 g_string_append (string, "\n /SAVE");
177 g_string_append (string, ".");
181 g_string_free (string, FALSE);
187 /* Dialog is valid iff at least one variable has been selected */
189 dialog_state_valid (gpointer data)
191 struct descriptives_dialog *dd = data;
193 GtkTreeModel *vars = gtk_tree_view_get_model (dd->stat_vars);
197 return gtk_tree_model_get_iter_first (vars, ¬used);
200 /* Pops up the Descriptives dialog box */
202 descriptives_dialog (GObject *o, gpointer data)
205 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
207 struct descriptives_dialog scd;
209 GtkBuilder *xml = builder_new ("descriptives-dialog.ui");
211 GtkWidget *dialog = get_widget_assert (xml, "descriptives-dialog");
214 GtkWidget *source = get_widget_assert (xml, "all-variables");
215 GtkWidget *selector = get_widget_assert (xml, "stat-var-selector");
216 GtkWidget *dest = get_widget_assert (xml, "stat-variables");
218 GtkWidget *stats_treeview = get_widget_assert (xml, "statistics");
220 PsppireVarStore *vs = NULL;
222 g_object_get (de->data_editor, "var-store", &vs, NULL);
224 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de));
226 g_object_set (source, "dictionary", vs->dict,
227 "predicate", var_is_numeric, NULL);
229 set_dest_model (GTK_TREE_VIEW (dest), vs->dict);
232 psppire_selector_set_subjects (PSPPIRE_SELECTOR (selector),
235 insert_source_row_into_tree_view,
239 put_checkbox_items_in_treeview (GTK_TREE_VIEW (stats_treeview),
241 N_DESCRIPTIVE_STATS, stats);
243 scd.stat_vars = GTK_TREE_VIEW (dest);
244 scd.stats = gtk_tree_view_get_model (GTK_TREE_VIEW (stats_treeview));
246 scd.include_user_missing =
247 GTK_TOGGLE_BUTTON (get_widget_assert (xml, "include_user_missing"));
248 scd.exclude_missing_listwise =
249 GTK_TOGGLE_BUTTON (get_widget_assert (xml, "exclude_missing_listwise"));
251 GTK_TOGGLE_BUTTON (get_widget_assert (xml, "save_z_scores"));
253 g_signal_connect (dialog, "refresh", G_CALLBACK (refresh), &scd);
255 psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog),
256 dialog_state_valid, &scd);
258 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
263 case GTK_RESPONSE_OK:
265 gchar *syntax = generate_syntax (&scd);
267 struct getl_interface *sss = create_syntax_string_source (syntax);
268 execute_syntax (sss);
273 case PSPPIRE_RESPONSE_PASTE:
275 gchar *syntax = generate_syntax (&scd);
276 paste_syntax_in_new_window (syntax);
284 g_object_unref (xml);