1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2007, 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/>. */
20 #include "psppire-dialog-action-rank.h"
22 #include "psppire-var-view.h"
23 #include "dialog-common.h"
24 #include "psppire-selector.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_rank_class_init (PsppireDialogActionRankClass *class);
35 G_DEFINE_TYPE (PsppireDialogActionRank, psppire_dialog_action_rank, PSPPIRE_TYPE_DIALOG_ACTION);
39 generate_syntax (PsppireDialogAction *act)
41 PsppireDialogActionRank *rd = PSPPIRE_DIALOG_ACTION_RANK (act);
44 GtkTreeModel *gs = gtk_tree_view_get_model (GTK_TREE_VIEW (rd->group_vars));
48 GString *str = g_string_new ("RANK VARIABLES=");
50 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (rd->rank_vars), 0, str);
52 g_string_append_printf (str, " (%c)",
53 gtk_toggle_button_get_active (rd->ascending_togglebutton)
56 if ( gtk_tree_model_get_iter_first (gs, ¬used) )
58 g_string_append (str, "\n\tBY ");
60 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (rd->group_vars), 0, str);
63 g_string_append (str, "\n\t/PRINT = ");
64 if (gtk_toggle_button_get_active (rd->summary_togglebutton))
65 g_string_append (str, "YES");
67 g_string_append (str, "NO");
70 if (gtk_toggle_button_get_active (rd->func_button [RANK]))
71 g_string_append (str, "\n\t/RANK");
72 if (gtk_toggle_button_get_active (rd->func_button [NORMAL]))
73 g_string_append (str, "\n\t/NORMAL");
74 if (gtk_toggle_button_get_active (rd->func_button [PROPORTION]))
75 g_string_append (str, "\n\t/PROPORTION");
76 if (gtk_toggle_button_get_active (rd->func_button [PERCENT]))
77 g_string_append (str, "\n\t/PERCENT");
78 if (gtk_toggle_button_get_active (rd->func_button [RFRACTION]))
79 g_string_append (str, "\n\t/RFRACTION");
80 if (gtk_toggle_button_get_active (rd->func_button [N]))
81 g_string_append (str, "\n\t/N");
82 if (gtk_toggle_button_get_active (rd->func_button [SAVAGE]))
83 g_string_append (str, "\n\t/SAVAGE");
84 if (gtk_toggle_button_get_active (rd->func_button [NTILES]))
86 gint n = gtk_spin_button_get_value (GTK_SPIN_BUTTON (rd->ntiles_entry));
87 g_string_append_printf (str, "\n\t/NTILES(%d)", n);
91 if (gtk_toggle_button_get_active (rd->func_button [NORMAL])
93 gtk_toggle_button_get_active (rd->func_button [PROPORTION]))
95 g_string_append (str, "\n\t/FRACTION=");
97 if ( gtk_toggle_button_get_active (rd->blom))
98 g_string_append (str, "BLOM");
99 else if ( gtk_toggle_button_get_active (rd->tukey))
100 g_string_append (str, "TUKEY");
101 else if ( gtk_toggle_button_get_active (rd->rankit))
102 g_string_append (str, "RANKIT");
103 else if ( gtk_toggle_button_get_active (rd->vw))
104 g_string_append (str, "VW");
107 g_string_append (str, "\n\t/TIES=");
108 if ( gtk_toggle_button_get_active (rd->mean))
109 g_string_append (str, "MEAN");
110 else if ( gtk_toggle_button_get_active (rd->low))
111 g_string_append (str, "LOW");
112 else if ( gtk_toggle_button_get_active (rd->high))
113 g_string_append (str, "HIGH");
114 else if ( gtk_toggle_button_get_active (rd->condense))
115 g_string_append (str, "CONDENSE");
118 g_string_append (str, ".");
121 g_string_free (str, FALSE);
127 dialog_state_valid (PsppireDialogAction *da)
129 PsppireDialogActionRank *dar = PSPPIRE_DIALOG_ACTION_RANK (da);
131 GtkTreeModel *vars = gtk_tree_view_get_model (GTK_TREE_VIEW (dar->rank_vars));
133 return gtk_tree_model_get_iter_first (vars, ¬used);
137 dialog_refresh (PsppireDialogAction *act)
139 PsppireDialogActionRank *dar = PSPPIRE_DIALOG_ACTION_RANK (act);
141 GtkTreeModel *liststore;
143 liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (dar->rank_vars));
144 gtk_list_store_clear (GTK_LIST_STORE (liststore));
146 liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (dar->group_vars));
147 gtk_list_store_clear (GTK_LIST_STORE (liststore));
149 gtk_toggle_button_set_active (dar->ascending_togglebutton, TRUE);
150 gtk_toggle_button_set_active (dar->summary_togglebutton, FALSE);
154 types_dialog_reset (PsppireDialogActionRank *rd)
158 for (i = 0 ; i < n_RANK_FUNCS ; ++i )
159 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->func_button [i]),
162 gtk_widget_set_sensitive (rd->ntiles_entry, FALSE);
164 gtk_widget_set_sensitive (rd->formula_box, FALSE);
168 run_types_dialog (GtkButton *b, PsppireDialogActionRank *dar)
170 PsppireDialogAction *act = PSPPIRE_DIALOG_ACTION (dar);
172 gtk_window_set_transient_for (GTK_WINDOW (dar->types_dialog),
173 GTK_WINDOW (act->dialog));
175 types_dialog_reset (dar);
177 psppire_dialog_run (PSPPIRE_DIALOG (dar->types_dialog));
181 run_ties_dialog (GtkButton *b, PsppireDialogActionRank *dar)
183 PsppireDialogAction *act = PSPPIRE_DIALOG_ACTION (dar);
185 gtk_window_set_transient_for (GTK_WINDOW (dar->ties_dialog),
186 GTK_WINDOW (act->dialog));
188 psppire_dialog_run (PSPPIRE_DIALOG (dar->ties_dialog));
192 on_ntiles_toggle (GtkToggleButton *toggle_button, PsppireDialogActionRank *dar)
194 gboolean active = gtk_toggle_button_get_active (toggle_button);
195 gtk_widget_set_sensitive (GTK_WIDGET (dar), active);
199 set_sensitivity (PsppireDialogActionRank *dar)
201 gboolean sens = gtk_toggle_button_get_active
202 (GTK_TOGGLE_BUTTON (dar->func_button[PROPORTION]))
204 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dar->func_button[NORMAL]));
206 gtk_widget_set_sensitive (dar->formula_box, sens);
210 psppire_dialog_action_rank_activate (GtkAction *a)
212 PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
213 PsppireDialogActionRank *act = PSPPIRE_DIALOG_ACTION_RANK (a);
215 GHashTable *thing = psppire_dialog_action_get_pointer (pda);
216 GtkBuilder *xml = g_hash_table_lookup (thing, a);
219 xml = builder_new ("rank.ui");
220 g_hash_table_insert (thing, a, xml);
223 GtkWidget *types_button = get_widget_assert (xml, "button1");
224 GtkWidget *ties_button = get_widget_assert (xml, "button2");
226 pda->dialog = get_widget_assert (xml, "rank-dialog");
227 pda->source = get_widget_assert (xml, "dict-treeview");
228 act->rank_vars = get_widget_assert (xml, "variables-treeview");
229 act->group_vars = get_widget_assert (xml, "group-vars-treeview");
230 act->ascending_togglebutton =
231 GTK_TOGGLE_BUTTON (get_widget_assert (xml, "radiobutton1"));
233 act->summary_togglebutton =
234 GTK_TOGGLE_BUTTON (get_widget_assert (xml, "summary-checkbutton"));
236 act->types_dialog = get_widget_assert (xml, "rank-types-dialog");
239 act->ntiles_entry = get_widget_assert (xml, "ntiles-entry");
241 act->func_button[RANK] =
242 GTK_TOGGLE_BUTTON (get_widget_assert (xml, "rank-checkbutton"));
244 act->func_button[SAVAGE] =
245 GTK_TOGGLE_BUTTON (get_widget_assert (xml, "savage-checkbutton"));
247 act->func_button[RFRACTION] =
248 GTK_TOGGLE_BUTTON (get_widget_assert (xml, "rfrac-checkbutton"));
250 act->func_button[PERCENT] =
251 GTK_TOGGLE_BUTTON (get_widget_assert (xml, "percent-checkbutton"));
253 act->func_button[N] =
254 GTK_TOGGLE_BUTTON (get_widget_assert (xml, "sum-checkbutton"));
256 act->func_button[NTILES] =
257 GTK_TOGGLE_BUTTON (get_widget_assert (xml, "ntiles-checkbutton"));
259 act->func_button[PROPORTION] =
260 GTK_TOGGLE_BUTTON (get_widget_assert (xml, "prop-checkbutton"));
262 act->func_button[NORMAL] =
263 GTK_TOGGLE_BUTTON (get_widget_assert (xml, "normal-checkbutton"));
265 act->formula_box = get_widget_assert (xml, "formula-frame");
267 act->blom = GTK_TOGGLE_BUTTON (get_widget_assert (xml, "blom-button"));
268 act->tukey = GTK_TOGGLE_BUTTON (get_widget_assert (xml, "tukey-button"));
269 act->rankit = GTK_TOGGLE_BUTTON (get_widget_assert (xml, "rankit-button"));
270 act->vw = GTK_TOGGLE_BUTTON (get_widget_assert (xml, "vw-button"));
273 act->ties_dialog = PSPPIRE_DIALOG (get_widget_assert (xml, "ties-dialog"));
275 act->mean = GTK_TOGGLE_BUTTON (get_widget_assert (xml, "mean-button"));
276 act->low = GTK_TOGGLE_BUTTON (get_widget_assert (xml, "low-button"));
277 act->high = GTK_TOGGLE_BUTTON (get_widget_assert (xml, "high-button"));
278 act->condense = GTK_TOGGLE_BUTTON (get_widget_assert (xml, "condense-button"));
280 g_signal_connect_swapped (act->func_button[PROPORTION], "toggled",
281 G_CALLBACK (set_sensitivity),
284 g_signal_connect_swapped (act->func_button[NORMAL], "toggled",
285 G_CALLBACK (set_sensitivity),
288 g_signal_connect (types_button, "clicked",
289 G_CALLBACK (run_types_dialog), act);
291 g_signal_connect (ties_button, "clicked",
292 G_CALLBACK (run_ties_dialog), act);
294 g_signal_connect (act->func_button[NTILES], "toggled",
295 G_CALLBACK (on_ntiles_toggle),
298 psppire_dialog_action_set_valid_predicate (pda, (void *) dialog_state_valid);
299 psppire_dialog_action_set_refresh (pda, dialog_refresh);
301 PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_rank_parent_class)->activate (pda);
305 psppire_dialog_action_rank_class_init (PsppireDialogActionRankClass *class)
307 psppire_dialog_action_set_activation (class, psppire_dialog_action_rank_activate);
309 PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax;
313 psppire_dialog_action_rank_init (PsppireDialogActionRank *act)