1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2011, 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/>. */
19 #include <ui/syntax-gen.h>
20 #include <libpspp/str.h>
22 #include "ks-one-sample-dialog.h"
23 #include "psppire-selector.h"
24 #include "psppire-dictview.h"
25 #include "psppire-dialog.h"
27 #include "psppire-data-window.h"
28 #include "psppire-var-view.h"
31 #include "builder-wrapper.h"
34 #include "dialog-common.h"
39 #define _(msgid) gettext (msgid)
40 #define N_(msgid) msgid
57 PsppireDataWindow *de ;
62 static char * generate_syntax (const struct ks_one_sample *rd);
66 refresh (struct ks_one_sample *fd)
69 GtkTreeModel *liststore =
70 gtk_tree_view_get_model (GTK_TREE_VIEW (fd->variables));
71 gtk_list_store_clear (GTK_LIST_STORE (liststore));
73 for (i = 0; i < 4; ++i)
74 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fd->cb[i]), FALSE);
79 dialog_state_valid (gpointer data)
82 struct ks_one_sample *fd = data;
84 GtkTreeModel *liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (fd->variables));
86 if (gtk_tree_model_iter_n_children (liststore, NULL) < 1)
89 for (i = 0; i < 4; ++i)
91 if ( TRUE == gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd->cb[i])))
102 /* Pops up the Ks_One_Sample dialog box */
104 ks_one_sample_dialog (PsppireDataWindow *dw)
106 struct ks_one_sample fd;
114 fd.xml = builder_new ("ks-one-sample.ui");
116 dialog = get_widget_assert (fd.xml, "ks-one-sample-dialog");
117 source = get_widget_assert (fd.xml, "dict-view");
119 fd.cb[CB_NORMAL] = get_widget_assert (fd.xml, "checkbutton-normal");
120 fd.cb[CB_POISSON] = get_widget_assert (fd.xml, "checkbutton-poisson");
121 fd.cb[CB_UNIFORM] = get_widget_assert (fd.xml, "checkbutton-uniform");
122 fd.cb[CB_EXPONENTIAL] = get_widget_assert (fd.xml, "checkbutton-exp");
126 g_signal_connect_swapped (dialog, "refresh", G_CALLBACK (refresh), &fd);
129 fd.variables = get_widget_assert (fd.xml, "psppire-var-view1");
131 g_object_get (fd.de->data_editor, "var-store", &vs, NULL);
133 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (fd.de));
135 g_object_get (vs, "dictionary", &fd.dict, NULL);
136 g_object_set (source, "model", fd.dict,
137 "predicate", var_is_numeric,
140 psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog),
141 dialog_state_valid, &fd);
143 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
147 case GTK_RESPONSE_OK:
148 g_free (execute_syntax_string (dw, generate_syntax (&fd)));
150 case PSPPIRE_RESPONSE_PASTE:
151 g_free (paste_syntax_to_window (generate_syntax (&fd)));
157 g_object_unref (fd.xml);
163 append_fragment (GString *string, const gchar *dist, PsppireVarView *vv)
165 g_string_append (string, "\n\t/KOLMOGOROV-SMIRNOV");
167 g_string_append (string, " ( ");
168 g_string_append (string, dist);
169 g_string_append (string, " ) = ");
171 psppire_var_view_append_names (vv, 0, string);
176 generate_syntax (const struct ks_one_sample *rd)
180 GString *string = g_string_new ("NPAR TEST");
182 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->cb[CB_NORMAL])))
183 append_fragment (string, "NORMAL", PSPPIRE_VAR_VIEW (rd->variables));
185 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->cb[CB_UNIFORM])))
186 append_fragment (string, "UNIFORM", PSPPIRE_VAR_VIEW (rd->variables));
188 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->cb[CB_POISSON])))
189 append_fragment (string, "POISSON", PSPPIRE_VAR_VIEW (rd->variables));
191 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->cb[CB_EXPONENTIAL])))
192 append_fragment (string, "EXPONENTIAL", PSPPIRE_VAR_VIEW (rd->variables));
194 g_string_append (string, ".\n");
198 g_string_free (string, FALSE);