1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2010, 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 "k-related-dialog.h"
21 #include "psppire-dialog.h"
22 #include "psppire-var-view.h"
23 #include "psppire-acr.h"
24 #include "dialog-common.h"
26 #include "builder-wrapper.h"
32 struct k_related_dialog
43 dialog_state_valid (gpointer data)
45 struct k_related_dialog *krd = data;
48 gtk_tree_view_get_model (GTK_TREE_VIEW (krd->var_view));
50 /* Tests using less than 3 variables are not useful */
51 if (gtk_tree_model_iter_n_children (vars, NULL) < 3)
54 /* At least one checkbutton must be active */
56 ! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (krd->friedman))
58 ! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (krd->kendal))
60 ! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (krd->cochran))
69 refresh (struct k_related_dialog *krd)
71 GtkTreeModel *liststore =
72 gtk_tree_view_get_model (GTK_TREE_VIEW (krd->var_view));
74 gtk_list_store_clear (GTK_LIST_STORE (liststore));
77 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (krd->friedman), TRUE);
78 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (krd->kendal), FALSE);
79 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (krd->cochran), FALSE);
84 generate_syntax (const struct k_related_dialog *krd)
89 string = g_string_new ("NPAR TEST");
91 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (krd->friedman)))
93 g_string_append (string, "\n\t/FRIEDMAN = ");
94 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (krd->var_view), 0, string);
97 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (krd->kendal)))
99 g_string_append (string, "\n\t/KENDALL = ");
100 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (krd->var_view), 0, string);
103 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (krd->cochran)))
105 g_string_append (string, "\n\t/COCHRAN = ");
106 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (krd->var_view), 0, string);
109 g_string_append (string, ".\n");
113 g_string_free (string, FALSE);
120 /* Pops up the K-Related dialog box */
122 k_related_dialog (PsppireDataWindow *dw)
126 struct k_related_dialog krd;
128 GtkBuilder *xml = builder_new ("k-related.ui");
131 GtkWidget *dialog = get_widget_assert (xml, "k-related-dialog");
133 GtkWidget *dict_view = get_widget_assert (xml, "dict-view");
135 g_object_get (dw->data_editor, "var-store", &vs, NULL);
137 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (dw));
139 krd.var_view = get_widget_assert (xml, "variables-treeview");
141 krd.friedman = get_widget_assert (xml, "friedman-checkbutton");
142 krd.kendal = get_widget_assert (xml, "kendal-checkbutton");
143 krd.cochran = get_widget_assert (xml, "cochran-checkbutton");
145 g_object_get (vs, "dictionary", &krd.dict, NULL);
146 g_object_set (dict_view,
148 "predicate", var_is_numeric,
152 g_signal_connect_swapped (dialog, "refresh", G_CALLBACK (refresh), &krd);
154 psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog),
155 dialog_state_valid, &krd);
157 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
162 case GTK_RESPONSE_OK:
163 g_free (execute_syntax_string (dw, generate_syntax (&krd)));
165 case PSPPIRE_RESPONSE_PASTE:
166 g_free (paste_syntax_to_window (generate_syntax (&krd)));
172 g_object_unref (xml);