1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2017 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-k-independent.h"
22 #include "psppire-var-view.h"
23 #include "psppire-value-entry.h"
24 #include "psppire-acr.h"
26 #include "psppire-dialog.h"
27 #include "builder-wrapper.h"
32 #define _(msgid) gettext (msgid)
33 #define N_(msgid) msgid
37 static void psppire_dialog_action_k_independent_init (PsppireDialogActionKIndependent *act);
38 static void psppire_dialog_action_k_independent_class_init (PsppireDialogActionKIndependentClass *class);
40 G_DEFINE_TYPE (PsppireDialogActionKIndependent, psppire_dialog_action_k_independent, PSPPIRE_TYPE_DIALOG_ACTION);
42 const static char *keyword[n_KIDS] =
49 generate_syntax (const PsppireDialogAction *act)
52 PsppireDialogActionKIndependent *kid = PSPPIRE_DIALOG_ACTION_K_INDEPENDENT (act);
54 GString *string = g_string_new ("NPAR TEST");
56 for (i = 0; i < n_KIDS; ++i)
58 g_string_append (string, "\n\t");
60 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (kid->checkbutton[i])))
62 g_string_append_printf (string, "/%s = ", keyword[i]);
63 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (kid->vars_treeview),
66 g_string_append (string, " BY ");
68 g_string_append (string,
69 gtk_entry_get_text (GTK_ENTRY (kid->groupvar_entry)));
72 g_string_append_printf (string, " (%g, %g)",
73 kid->lower_limit_value.f,
74 kid->upper_limit_value.f);
78 g_string_append (string, ".\n");
82 g_string_free (string, FALSE);
89 dialog_state_valid (gpointer data)
91 PsppireDialogActionKIndependent *kid = PSPPIRE_DIALOG_ACTION_K_INDEPENDENT (data);
94 gtk_tree_view_get_model (GTK_TREE_VIEW (kid->vars_treeview));
98 if ( !gtk_tree_model_get_iter_first (vars, ¬used) )
101 if ( 0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (kid->groupvar_entry))))
104 gboolean method_set = FALSE;
106 for (i = 0; i < n_KIDS; ++i)
108 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (kid->checkbutton[i])))
116 refresh (PsppireDialogAction *rd_)
118 PsppireDialogActionKIndependent *kid = PSPPIRE_DIALOG_ACTION_K_INDEPENDENT (rd_);
120 GtkTreeModel *model =
121 gtk_tree_view_get_model (GTK_TREE_VIEW (kid->vars_treeview));
123 gtk_entry_set_text (GTK_ENTRY (kid->groupvar_entry), "");
125 gtk_list_store_clear (GTK_LIST_STORE (model));
128 for (i = 0; i < n_KIDS; ++i)
130 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (kid->checkbutton[i]),
136 run_define_groups_dialog (PsppireDialogActionKIndependent *kid)
138 if (kid->lower_limit_value.f != SYSMIS)
139 psppire_value_entry_set_value (PSPPIRE_VALUE_ENTRY (kid->lower_limit_entry),
140 &kid->lower_limit_value, 0);
142 if (kid->upper_limit_value.f != SYSMIS)
143 psppire_value_entry_set_value (PSPPIRE_VALUE_ENTRY (kid->upper_limit_entry),
144 &kid->upper_limit_value, 0);
146 if (PSPPIRE_RESPONSE_CONTINUE ==
147 psppire_dialog_run (PSPPIRE_DIALOG (kid->subdialog)))
149 psppire_value_entry_get_value (PSPPIRE_VALUE_ENTRY (kid->lower_limit_entry),
150 &kid->lower_limit_value, 0);
152 psppire_value_entry_get_value (PSPPIRE_VALUE_ENTRY (kid->upper_limit_entry),
153 &kid->upper_limit_value, 0);
159 set_value_entry_variable (PsppireDialogActionKIndependent *kid, GtkEntry *entry)
161 PsppireDialogAction *da = PSPPIRE_DIALOG_ACTION (kid);
162 const gchar *text = gtk_entry_get_text (entry);
164 const struct variable *v = da->dict ?
165 psppire_dict_lookup_var (da->dict, text) : NULL;
167 psppire_value_entry_set_variable (PSPPIRE_VALUE_ENTRY (kid->lower_limit_entry), v);
168 psppire_value_entry_set_variable (PSPPIRE_VALUE_ENTRY (kid->upper_limit_entry), v);
173 psppire_dialog_action_k_independent_activate (PsppireDialogAction *a, GVariant *param)
175 PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
176 PsppireDialogActionKIndependent *kid = PSPPIRE_DIALOG_ACTION_K_INDEPENDENT (a);
178 GtkBuilder *xml = builder_new ( "k-independent.ui");
180 pda->dialog = get_widget_assert (xml, "k-independent-dialog");
181 pda->source = get_widget_assert (xml, "k-independent-treeview1");
183 kid->vars_treeview = get_widget_assert (xml, "k-independent-treeview2");
184 kid->groupvar_entry = get_widget_assert (xml, "k-independent-entry");
186 kid->subdialog = get_widget_assert (xml, "define-groups-dialog");
188 kid->lower_limit_entry = get_widget_assert (xml, "lower-limit-entry");
189 kid->upper_limit_entry = get_widget_assert (xml, "upper-limit-entry");
191 kid->checkbutton[KID_KRUSKAL_WALLIS] = get_widget_assert (xml,
194 kid->checkbutton[KID_MEDIAN] = get_widget_assert (xml, "median");
196 g_signal_connect_swapped (get_widget_assert (xml, "define-groups-button"),
198 G_CALLBACK (run_define_groups_dialog), kid);
200 g_signal_connect_swapped (kid->groupvar_entry, "changed",
201 G_CALLBACK (set_value_entry_variable), kid);
203 psppire_dialog_action_set_valid_predicate (pda, dialog_state_valid);
204 psppire_dialog_action_set_refresh (pda, refresh);
210 psppire_dialog_action_k_independent_class_init (PsppireDialogActionKIndependentClass *class)
212 PSPPIRE_DIALOG_ACTION_CLASS (class)->initial_activate = psppire_dialog_action_k_independent_activate;
213 PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax;
217 psppire_dialog_action_k_independent_init (PsppireDialogActionKIndependent *kid)
219 kid->lower_limit_value.f = SYSMIS;
220 kid->upper_limit_value.f = SYSMIS;