X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fpsppire-dialog-action-frequencies.c;h=adca915816cd0973edc8599e215aeb6ed6c15058;hb=d97c0f1ed2858c48173c023964cec8234b5bc831;hp=b2ddd196a3cd5b413c5626ca1896165086246ab6;hpb=fa1fffd5c789d9c7875fc3bdf556eaf017cf524e;p=pspp diff --git a/src/ui/gui/psppire-dialog-action-frequencies.c b/src/ui/gui/psppire-dialog-action-frequencies.c index b2ddd196a3..adca915816 100644 --- a/src/ui/gui/psppire-dialog-action-frequencies.c +++ b/src/ui/gui/psppire-dialog-action-frequencies.c @@ -1,18 +1,18 @@ /* PSPPIRE - a graphical user interface for PSPP. -Copyright (C) 2012 Free Software Foundation + Copyright (C) 2012, 2015 Free Software Foundation -This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program. If not, see . */ + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ #include @@ -27,7 +27,7 @@ This program is free software: you can redistribute it and/or modify #include "psppire-dialog.h" #include "builder-wrapper.h" -#include "checkbox-treeview.h" +#include "psppire-checkbox-treeview.h" #include "psppire-dict.h" #include "libpspp/str.h" @@ -55,21 +55,21 @@ This program is free software: you can redistribute it and/or modify enum -{ + { #define FS(NAME, LABEL) FS_##NAME, - FREQUENCY_STATS + FREQUENCY_STATS #undef FS - N_FREQUENCY_STATS -}; + N_FREQUENCY_STATS + }; enum -{ + { #define FS(NAME, LABEL) B_FS_##NAME = 1u << FS_##NAME, - FREQUENCY_STATS + FREQUENCY_STATS #undef FS B_FS_ALL = (1u << N_FREQUENCY_STATS) - 1, - B_FS_DEFAULT = B_FS_MEAN | B_FS_STDDEV | B_FS_MINIMUM | B_FS_MAXIMUM -}; + B_FS_DEFAULT = B_FS_MEAN | B_FS_STDDEV | B_FS_MINIMUM | B_FS_MAXIMUM + }; static const struct checkbox_entry_item stats[] = { @@ -178,26 +178,33 @@ on_charts_clicked (PsppireDialogActionFrequencies *fd) g_signal_emit_by_name (fd->pie, "toggled"); + + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fd->bar), fd->charts_opts_draw_bar); + g_signal_emit_by_name (fd->bar, "toggled"); + ret = psppire_dialog_run (PSPPIRE_DIALOG (fd->charts_dialog)); if ( ret == PSPPIRE_RESPONSE_CONTINUE ) { - fd->charts_opts_use_min = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd->min)); - fd->charts_opts_min = gtk_spin_button_get_value (GTK_SPIN_BUTTON (fd->min_spin)); - - fd->charts_opts_use_max = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd->max)); - fd->charts_opts_max = gtk_spin_button_get_value (GTK_SPIN_BUTTON (fd->max_spin)); - - fd->charts_opts_draw_hist = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd->hist)); - fd->charts_opts_draw_normal = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd->normal)); - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd->freqs))) - fd->charts_opts_scale = FRQ_FREQ; - else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd->percents))) - fd->charts_opts_scale = FRQ_PERCENT; - - fd->charts_opts_draw_pie = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd->pie)); - fd->charts_opts_pie_include_missing - = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd->pie_include_missing)); + fd->charts_opts_use_min = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd->min)); + fd->charts_opts_min = gtk_spin_button_get_value (GTK_SPIN_BUTTON (fd->min_spin)); + + fd->charts_opts_use_max = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd->max)); + fd->charts_opts_max = gtk_spin_button_get_value (GTK_SPIN_BUTTON (fd->max_spin)); + + fd->charts_opts_draw_hist = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd->hist)); + fd->charts_opts_draw_normal = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd->normal)); + if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd->freqs))) + fd->charts_opts_scale = FRQ_FREQ; + else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd->percents))) + fd->charts_opts_scale = FRQ_PERCENT; + + fd->charts_opts_draw_pie = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd->pie)); + fd->charts_opts_pie_include_missing + = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd->pie_include_missing)); + + + fd->charts_opts_draw_bar = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd->bar)); } } @@ -244,17 +251,21 @@ refresh (PsppireDialogAction * fdx) (B_FS_DEFAULT & (1u << i)) ? true : false, -1); } - - -static void -psppire_dialog_action_frequencies_activate (GtkAction * a) +static GtkBuilder * +psppire_dialog_action_frequencies_activate (PsppireDialogAction *a, GVariant *param) { PsppireDialogActionFrequencies *act = PSPPIRE_DIALOG_ACTION_FREQUENCIES (a); PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a); - GtkBuilder *xml = builder_new ("frequencies.ui"); + GtkBuilder *xml = builder_new ( "frequencies.ui"); GtkWidget *stats_treeview = get_widget_assert (xml, "stats-treeview"); + + psppire_checkbox_treeview_populate (PSPPIRE_CHECKBOX_TREEVIEW (stats_treeview), + B_FS_DEFAULT, N_FREQUENCY_STATS, stats); + + act->stats = gtk_tree_view_get_model (GTK_TREE_VIEW (stats_treeview)); + GtkWidget *tables_button = get_widget_assert (xml, "tables-button"); GtkWidget *charts_button = get_widget_assert (xml, "charts-button"); @@ -263,14 +274,7 @@ psppire_dialog_action_frequencies_activate (GtkAction * a) act->stat_vars = get_widget_assert (xml, "var-treeview"); - put_checkbox_items_in_treeview (GTK_TREE_VIEW (stats_treeview), - B_FS_DEFAULT, N_FREQUENCY_STATS, stats); - - act->stats = gtk_tree_view_get_model (GTK_TREE_VIEW (stats_treeview)); - act->include_missing = get_widget_assert (xml, "include_missing"); - - act->tables_dialog = get_widget_assert (xml, "tables-dialog"); act->charts_dialog = get_widget_assert (xml, "charts-dialog"); act->always = get_widget_assert (xml, "always"); @@ -279,8 +283,8 @@ psppire_dialog_action_frequencies_activate (GtkAction * a) act->limit_spinbutton = get_widget_assert (xml, "limit-spin"); g_signal_connect (act->limit, "toggled", - G_CALLBACK (set_sensitivity_from_toggle), - act->limit_spinbutton); + G_CALLBACK (set_sensitivity_from_toggle), + act->limit_spinbutton); act->avalue = get_widget_assert (xml, "avalue"); act->dvalue = get_widget_assert (xml, "dvalue"); @@ -295,6 +299,7 @@ psppire_dialog_action_frequencies_activate (GtkAction * a) act->charts_opts_draw_normal = false; act->charts_opts_scale = FRQ_FREQ; act->charts_opts_draw_pie = false; + act->charts_opts_draw_bar = false; act->charts_opts_pie_include_missing = false; act->freqs = get_widget_assert (xml, "freqs"); @@ -317,9 +322,7 @@ psppire_dialog_action_frequencies_activate (GtkAction * a) act->pie = (get_widget_assert (xml, "pie")); act->pie_include_missing = get_widget_assert (xml, "pie-include-missing"); - - g_object_unref (xml); - + act->bar = (get_widget_assert (xml, "bar")); act->tables_opts_order = FRQ_AVALUE; act->tables_opts_table = FRQ_TABLE; @@ -335,14 +338,11 @@ psppire_dialog_action_frequencies_activate (GtkAction * a) psppire_dialog_action_set_valid_predicate (pda, dialog_state_valid); - if (PSPPIRE_DIALOG_ACTION_CLASS - (psppire_dialog_action_frequencies_parent_class)->activate) - PSPPIRE_DIALOG_ACTION_CLASS - (psppire_dialog_action_frequencies_parent_class)->activate (pda); + return xml; } static char * -generate_syntax (PsppireDialogAction * a) +generate_syntax (const PsppireDialogAction * a) { PsppireDialogActionFrequencies *fd = PSPPIRE_DIALOG_ACTION_FREQUENCIES (a); gchar *text = NULL; @@ -350,44 +350,45 @@ generate_syntax (PsppireDialogAction * a) gboolean ok; GtkTreeIter iter; guint selected = 0; + struct string str; - GString *string = g_string_new ("FREQUENCIES"); + ds_init_cstr (&str, "FREQUENCIES"); - g_string_append (string, "\n\t/VARIABLES="); - psppire_var_view_append_names (PSPPIRE_VAR_VIEW (fd->stat_vars), 0, string); + ds_put_cstr (&str, "\n\t/VARIABLES="); + psppire_var_view_append_names_str (PSPPIRE_VAR_VIEW (fd->stat_vars), 0, &str); - g_string_append (string, "\n\t/FORMAT="); + ds_put_cstr (&str, "\n\t/FORMAT="); switch (fd->tables_opts_order) { case FRQ_AVALUE: - g_string_append (string, "AVALUE"); + ds_put_cstr (&str, "AVALUE"); break; case FRQ_DVALUE: - g_string_append (string, "DVALUE"); + ds_put_cstr (&str, "DVALUE"); break; case FRQ_ACOUNT: - g_string_append (string, "AFREQ"); + ds_put_cstr (&str, "AFREQ"); break; case FRQ_DCOUNT: - g_string_append (string, "DFREQ"); + ds_put_cstr (&str, "DFREQ"); break; default: g_assert_not_reached (); } - g_string_append (string, " "); + ds_put_cstr (&str, " "); switch (fd->tables_opts_table) { case FRQ_TABLE: - g_string_append (string, "TABLE"); + ds_put_cstr (&str, "TABLE"); break; case FRQ_NOTABLE: - g_string_append (string, "NOTABLE"); + ds_put_cstr (&str, "NOTABLE"); break; case FRQ_LIMIT: - g_string_append_printf (string, "LIMIT (%d)", fd->tables_opts_limit); + ds_put_c_format (&str, "LIMIT (%d)", fd->tables_opts_limit); break; } @@ -404,17 +405,17 @@ generate_syntax (PsppireDialogAction * a) if (selected != B_FS_DEFAULT) { - g_string_append (string, "\n\t/STATISTICS="); + ds_put_cstr (&str, "\n\t/STATISTICS="); if (selected == B_FS_ALL) - g_string_append (string, "ALL"); + ds_put_cstr (&str, "ALL"); else if (selected == 0) - g_string_append (string, "NONE"); + ds_put_cstr (&str, "NONE"); else { int n = 0; if ((selected & B_FS_DEFAULT) == B_FS_DEFAULT) { - g_string_append (string, "DEFAULT"); + ds_put_cstr (&str, "DEFAULT"); selected &= ~B_FS_DEFAULT; n++; } @@ -422,49 +423,64 @@ generate_syntax (PsppireDialogAction * a) if (selected & (1u << i)) { if (n++) - g_string_append (string, " "); - g_string_append (string, stats[i].name); + ds_put_cstr (&str, " "); + ds_put_cstr (&str, stats[i].name); } } } if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd->include_missing))) - g_string_append (string, "\n\t/MISSING=INCLUDE"); + ds_put_cstr (&str, "\n\t/MISSING=INCLUDE"); if (fd->charts_opts_draw_hist) { - g_string_append (string, "\n\t/HISTOGRAM="); - g_string_append (string, - fd->charts_opts_draw_normal ? "NORMAL" : "NONORMAL"); + ds_put_cstr (&str, "\n\t/HISTOGRAM="); + ds_put_cstr (&str, + fd->charts_opts_draw_normal ? "NORMAL" : "NONORMAL"); if (fd->charts_opts_scale == FRQ_PERCENT) - g_string_append (string, " PERCENT"); + ds_put_cstr (&str, " PERCENT"); if (fd->charts_opts_use_min) - g_string_append_printf (string, " MIN(%.15g)", fd->charts_opts_min); + ds_put_c_format (&str, " MIN(%.15g)", fd->charts_opts_min); if (fd->charts_opts_use_max) - g_string_append_printf (string, " MAX(%.15g)", fd->charts_opts_max); + ds_put_c_format (&str, " MAX(%.15g)", fd->charts_opts_max); } if (fd->charts_opts_draw_pie) { - g_string_append (string, "\n\t/PIECHART="); + ds_put_cstr (&str, "\n\t/PIECHART="); if (fd->charts_opts_pie_include_missing) - g_string_append (string, " MISSING"); + ds_put_cstr (&str, " MISSING"); if (fd->charts_opts_use_min) - g_string_append_printf (string, " MIN(%.15g)", fd->charts_opts_min); + ds_put_c_format (&str, " MIN(%.15g)", fd->charts_opts_min); if (fd->charts_opts_use_max) - g_string_append_printf (string, " MAX(%.15g)", fd->charts_opts_max); + ds_put_c_format (&str, " MAX(%.15g)", fd->charts_opts_max); } - g_string_append (string, ".\n"); - text = string->str; + if (fd->charts_opts_draw_bar) + { + ds_put_cstr (&str, "\n\t/BARCHART="); - g_string_free (string, FALSE); + if (fd->charts_opts_scale == FRQ_PERCENT) + ds_put_cstr (&str, " PERCENT"); + + if (fd->charts_opts_use_min) + ds_put_c_format (&str, " MIN(%.15g)", fd->charts_opts_min); + if (fd->charts_opts_use_max) + ds_put_c_format (&str, " MAX(%.15g)", fd->charts_opts_max); + } + + + ds_put_cstr (&str, ".\n"); + + text = ds_steal_cstr (&str); + + ds_destroy (&str); return text; } @@ -472,15 +488,12 @@ generate_syntax (PsppireDialogAction * a) static void psppire_dialog_action_frequencies_class_init (PsppireDialogActionFrequenciesClass *class) { - GtkActionClass *action_class = GTK_ACTION_CLASS (class); - - action_class->activate = psppire_dialog_action_frequencies_activate; - + PSPPIRE_DIALOG_ACTION_CLASS (class)->initial_activate = psppire_dialog_action_frequencies_activate; PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax; } static void -psppire_dialog_action_frequencies_init (PsppireDialogActionFrequencies * act) +psppire_dialog_action_frequencies_init (PsppireDialogActionFrequencies *act) { }