From 8a8f2ec2ef0054d16a76a752c79b7968c590c166 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Sun, 29 Jan 2012 14:16:42 +0100 Subject: [PATCH] Converted roc-dialog to a PsppireDialogAction object --- src/ui/gui/automake.mk | 4 +- src/ui/gui/data-editor.ui | 3 +- src/ui/gui/psppire-data-window.c | 3 - ...c-dialog.c => psppire-dialog-action-roc.c} | 175 +++++++----------- src/ui/gui/psppire-dialog-action-roc.h | 85 +++++++++ src/ui/gui/roc-dialog.h | 25 --- src/ui/gui/widgets.c | 2 + 7 files changed, 163 insertions(+), 134 deletions(-) rename src/ui/gui/{roc-dialog.c => psppire-dialog-action-roc.c} (60%) create mode 100644 src/ui/gui/psppire-dialog-action-roc.h delete mode 100644 src/ui/gui/roc-dialog.h diff --git a/src/ui/gui/automake.mk b/src/ui/gui/automake.mk index c0624455..0dcd519c 100644 --- a/src/ui/gui/automake.mk +++ b/src/ui/gui/automake.mk @@ -216,6 +216,8 @@ src_ui_gui_psppire_SOURCES = \ src/ui/gui/psppire-dialog-action-kmeans.h \ src/ui/gui/psppire-dialog-action-var-info.c \ src/ui/gui/psppire-dialog-action-var-info.h \ + src/ui/gui/psppire-dialog-action-roc.c \ + src/ui/gui/psppire-dialog-action-roc.h \ src/ui/gui/psppire-dict.c \ src/ui/gui/psppire-dict.h \ src/ui/gui/psppire-dictview.c \ @@ -256,8 +258,6 @@ src_ui_gui_psppire_SOURCES = \ src/ui/gui/regression-dialog.h \ src/ui/gui/reliability-dialog.c \ src/ui/gui/reliability-dialog.h \ - src/ui/gui/roc-dialog.c \ - src/ui/gui/roc-dialog.h \ src/ui/gui/runs-dialog.c \ src/ui/gui/runs-dialog.h \ src/ui/gui/select-cases-dialog.c \ diff --git a/src/ui/gui/data-editor.ui b/src/ui/gui/data-editor.ui index f5f5405b..7762f584 100644 --- a/src/ui/gui/data-editor.ui +++ b/src/ui/gui/data-editor.ui @@ -480,8 +480,9 @@ - + roc-curve + uimanager1 ROC Cur_ve... diff --git a/src/ui/gui/psppire-data-window.c b/src/ui/gui/psppire-data-window.c index 6e57f5ba..57bc48af 100644 --- a/src/ui/gui/psppire-data-window.c +++ b/src/ui/gui/psppire-data-window.c @@ -56,7 +56,6 @@ #include "ui/gui/recode-dialog.h" #include "ui/gui/regression-dialog.h" #include "ui/gui/reliability-dialog.h" -#include "ui/gui/roc-dialog.h" #include "ui/gui/select-cases-dialog.h" #include "ui/gui/sort-cases-dialog.h" #include "ui/gui/split-file-dialog.h" @@ -1108,8 +1107,6 @@ psppire_data_window_finish_init (PsppireDataWindow *de, connect_action (de, "reliability", G_CALLBACK (reliability_dialog)); - connect_action (de, "roc-curve", G_CALLBACK (roc_dialog)); - connect_action (de, "analyze_explore", G_CALLBACK (examine_dialog)); connect_action (de, "univariate", G_CALLBACK (univariate_dialog)); diff --git a/src/ui/gui/roc-dialog.c b/src/ui/gui/psppire-dialog-action-roc.c similarity index 60% rename from src/ui/gui/roc-dialog.c rename to src/ui/gui/psppire-dialog-action-roc.c index 2ecb47e9..5d25132f 100644 --- a/src/ui/gui/roc-dialog.c +++ b/src/ui/gui/psppire-dialog-action-roc.c @@ -1,5 +1,5 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2009, 2010, 2011, 2012 Free Software Foundation + Copyright (C) 2012 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 @@ -14,70 +14,30 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ + #include +#include "psppire-dialog-action-roc.h" + #include "dialog-common.h" #include -#include - -#include "roc-dialog.h" -#include "psppire-selector.h" -#include "psppire-dictview.h" -#include "psppire-dialog.h" - -#include "psppire-data-window.h" #include "psppire-var-view.h" -#include "executor.h" +#include "psppire-dialog.h" #include "builder-wrapper.h" -#include "helper.h" - -#include - -#include "gettext.h" -#define _(msgid) gettext (msgid) -#define N_(msgid) msgid - - -struct roc -{ - PsppireDict *dict; - - GtkWidget *test_variables; - GtkWidget *state_variable; - GtkWidget *state_value; - - GtkWidget *curve; - GtkWidget *reference; - GtkWidget *standard_error; - GtkWidget *coordinates; -}; - - -static char * generate_syntax (const struct roc *rd); +#include "psppire-dict.h" +#include "libpspp/str.h" static void -refresh (struct roc *rd) -{ - GtkTreeModel *liststore = - gtk_tree_view_get_model (GTK_TREE_VIEW (rd->test_variables)); - gtk_list_store_clear (GTK_LIST_STORE (liststore)); - - gtk_entry_set_text (GTK_ENTRY (rd->state_variable), ""); - gtk_entry_set_text (GTK_ENTRY (rd->state_value), ""); - - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->curve), TRUE); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->reference), FALSE); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->standard_error), FALSE); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->coordinates), FALSE); -} +psppire_dialog_action_roc_class_init (PsppireDialogActionRocClass *class); +G_DEFINE_TYPE (PsppireDialogActionRoc, psppire_dialog_action_roc, PSPPIRE_TYPE_DIALOG_ACTION); static gboolean dialog_state_valid (gpointer data) { - struct roc *rd = data; + PsppireDialogActionRoc *rd = data; const gchar *text; GtkTreeModel *liststore = @@ -101,7 +61,7 @@ dialog_state_valid (gpointer data) } static void -on_curve_button_toggle (GtkCheckButton *curve, struct roc *rd) +on_curve_button_toggle (GtkCheckButton *curve, PsppireDialogActionRoc *rd) { if ( !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (curve))) { @@ -116,70 +76,62 @@ on_curve_button_toggle (GtkCheckButton *curve, struct roc *rd) } } - -/* Pops up the Roc dialog box */ -void -roc_dialog (PsppireDataWindow *de) +static void +refresh (PsppireDialogActionRoc *rd) { - struct roc rd; - gint response; - - GtkBuilder *xml = builder_new ("roc.ui"); - PsppireVarStore *vs; - - GtkWidget *dialog = get_widget_assert (xml, "roc-dialog"); - GtkWidget *source = get_widget_assert (xml, "dict-view"); - - rd.test_variables = get_widget_assert (xml, "psppire-var-view1"); - rd.state_variable = get_widget_assert (xml, "entry1"); - rd.state_value = get_widget_assert (xml, "entry2"); - - rd.curve = get_widget_assert (xml, "curve"); - rd.reference = get_widget_assert (xml, "reference-line"); - rd.standard_error = get_widget_assert (xml, "standard-error"); - rd.coordinates = get_widget_assert (xml, "co-ordinates"); + GtkTreeModel *liststore = + gtk_tree_view_get_model (GTK_TREE_VIEW (rd->test_variables)); + gtk_list_store_clear (GTK_LIST_STORE (liststore)); + gtk_entry_set_text (GTK_ENTRY (rd->state_variable), ""); + gtk_entry_set_text (GTK_ENTRY (rd->state_value), ""); - g_object_get (de->data_editor, "var-store", &vs, NULL); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->curve), TRUE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->reference), FALSE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->standard_error), FALSE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->coordinates), FALSE); +} - gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de)); +static void +psppire_dialog_action_roc_activate (GtkAction *a) +{ + PsppireDialogActionRoc *act = PSPPIRE_DIALOG_ACTION_ROC (a); + PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a); - g_object_get (vs, "dictionary", &rd.dict, NULL); - g_object_set (source, "model", rd.dict, NULL); + GtkBuilder *xml = builder_new ("roc.ui"); + pda->dialog = get_widget_assert (xml, "roc-dialog"); + pda->source = get_widget_assert (xml, "dict-view"); + pda->source = get_widget_assert (xml, "dict-view"); - g_signal_connect (rd.curve, "toggled", G_CALLBACK (on_curve_button_toggle), &rd); + act->test_variables = get_widget_assert (xml, "psppire-var-view1"); + act->state_variable = get_widget_assert (xml, "entry1"); + act->state_value = get_widget_assert (xml, "entry2"); - g_signal_connect_swapped (dialog, "refresh", G_CALLBACK (refresh), &rd); + act->curve = get_widget_assert (xml, "curve"); + act->reference = get_widget_assert (xml, "reference-line"); + act->standard_error = get_widget_assert (xml, "standard-error"); + act->coordinates = get_widget_assert (xml, "co-ordinates"); - psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog), - dialog_state_valid, &rd); + g_object_unref (xml); - psppire_selector_set_allow (PSPPIRE_SELECTOR (get_widget_assert (xml, "dep-selector")), - numeric_only); + g_signal_connect (act->curve, "toggled", + G_CALLBACK (on_curve_button_toggle), act); - response = psppire_dialog_run (PSPPIRE_DIALOG (dialog)); + psppire_dialog_action_set_refresh (pda, refresh); - switch (response) - { - case GTK_RESPONSE_OK: - g_free (execute_syntax_string (de, generate_syntax (&rd))); - break; - case PSPPIRE_RESPONSE_PASTE: - g_free (paste_syntax_to_window (generate_syntax (&rd))); - break; - default: - break; - } + psppire_dialog_action_set_valid_predicate (pda, + dialog_state_valid); - g_object_unref (xml); + if (PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_roc_parent_class)->activate) + PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_roc_parent_class)->activate (pda); } - static char * -generate_syntax (const struct roc *rd) +generate_syntax (PsppireDialogAction *a) { + PsppireDialogActionRoc *rd = PSPPIRE_DIALOG_ACTION_ROC (a); gchar *text; const gchar *var_name = gtk_entry_get_text (GTK_ENTRY (rd->state_variable)); GString *string = g_string_new ("ROC"); @@ -194,17 +146,17 @@ generate_syntax (const struct roc *rd) { const gchar *value = gtk_entry_get_text (GTK_ENTRY (rd->state_value)); - const struct variable *var = psppire_dict_lookup_var (rd->dict, var_name); + const struct variable *var = psppire_dict_lookup_var (PSPPIRE_DIALOG_ACTION(rd)->dict, var_name); g_return_val_if_fail (var, NULL); if ( var_is_alpha (var)) { - struct string xx; - ds_init_empty (&xx); - syntax_gen_string (&xx, ss_cstr (value)); - g_string_append (string, ds_cstr (&xx)); - ds_destroy (&xx); + struct string str; + ds_init_empty (&str); + syntax_gen_string (&str, ss_cstr (value)); + g_string_append (string, ds_cstr (&str)); + ds_destroy (&str); } else g_string_append (string, value); @@ -245,3 +197,20 @@ generate_syntax (const struct roc *rd) return text; } + +static void +psppire_dialog_action_roc_class_init (PsppireDialogActionRocClass *class) +{ + GtkActionClass *action_class = GTK_ACTION_CLASS (class); + + action_class->activate = psppire_dialog_action_roc_activate; + + PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax; +} + + +static void +psppire_dialog_action_roc_init (PsppireDialogActionRoc *act) +{ +} + diff --git a/src/ui/gui/psppire-dialog-action-roc.h b/src/ui/gui/psppire-dialog-action-roc.h new file mode 100644 index 00000000..a5b56c59 --- /dev/null +++ b/src/ui/gui/psppire-dialog-action-roc.h @@ -0,0 +1,85 @@ +/* PSPPIRE - a graphical user interface for PSPP. + Copyright (C) 2012 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 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 . */ + + +#include +#include + +#include "psppire-dialog-action.h" + +#ifndef __PSPPIRE_DIALOG_ACTION_ROC_H__ +#define __PSPPIRE_DIALOG_ACTION_ROC_H__ + +G_BEGIN_DECLS + + +#define PSPPIRE_TYPE_DIALOG_ACTION_ROC (psppire_dialog_action_roc_get_type ()) + +#define PSPPIRE_DIALOG_ACTION_ROC(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ + PSPPIRE_TYPE_DIALOG_ACTION_ROC, PsppireDialogActionRoc)) + +#define PSPPIRE_DIALOG_ACTION_ROC_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), \ + PSPPIRE_TYPE_DIALOG_ACTION_ROC, \ + PsppireDialogActionRocClass)) + + +#define PSPPIRE_IS_DIALOG_ACTION_ROC(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PSPPIRE_TYPE_DIALOG_ACTION_ROC)) + +#define PSPPIRE_IS_DIALOG_ACTION_ROC_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), PSPPIRE_TYPE_DIALOG_ACTION_ROC)) + + +#define PSPPIRE_DIALOG_ACTION_ROC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \ + PSPPIRE_TYPE_DIALOG_ACTION_ROC, \ + PsppireDialogActionRocClass)) + +typedef struct _PsppireDialogActionRoc PsppireDialogActionRoc; +typedef struct _PsppireDialogActionRocClass PsppireDialogActionRocClass; + + +struct _PsppireDialogActionRoc +{ + PsppireDialogAction parent; + + /*< private >*/ + gboolean dispose_has_run ; + + + GtkWidget *test_variables; + GtkWidget *state_variable; + GtkWidget *state_value ; + + GtkWidget *curve ; + GtkWidget *reference ; + GtkWidget *standard_error; + GtkWidget *coordinates ; +}; + + +struct _PsppireDialogActionRocClass +{ + PsppireDialogActionClass parent_class; +}; + + +GType psppire_dialog_action_roc_get_type (void) ; + +G_END_DECLS + +#endif /* __PSPPIRE_DIALOG_ACTION_ROC_H__ */ diff --git a/src/ui/gui/roc-dialog.h b/src/ui/gui/roc-dialog.h deleted file mode 100644 index 3a178c3f..00000000 --- a/src/ui/gui/roc-dialog.h +++ /dev/null @@ -1,25 +0,0 @@ -/* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2009 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 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 . */ - -#ifndef __ROC_DIALOG_H -#define __ROC_DIALOG_H - - -#include "psppire-data-window.h" - -void roc_dialog (PsppireDataWindow * data); - -#endif diff --git a/src/ui/gui/widgets.c b/src/ui/gui/widgets.c index da5935cb..9d97dd3e 100644 --- a/src/ui/gui/widgets.c +++ b/src/ui/gui/widgets.c @@ -16,6 +16,7 @@ #include "psppire-dialog-action-correlation.h" #include "psppire-dialog-action-descriptives.h" #include "psppire-dialog-action-kmeans.h" +#include "psppire-dialog-action-roc.h" #include "psppire-dialog-action-var-info.h" @@ -39,4 +40,5 @@ preregister_widgets (void) psppire_dialog_action_descriptives_get_type (); psppire_dialog_action_kmeans_get_type (); psppire_dialog_action_var_info_get_type (); + psppire_dialog_action_roc_get_type (); } -- 2.30.2