From 2648cb6603262653fa660d0b7045450d5df6e6a9 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Sun, 20 May 2012 09:12:04 +0200 Subject: [PATCH] Regression Dialog: Convert to PsppireDialogAction object --- src/ui/gui/automake.mk | 9 +- src/ui/gui/data-editor.ui | 3 +- src/ui/gui/psppire-data-window.c | 2 - ...g.c => psppire-dialog-action-regression.c} | 238 ++++++++---------- src/ui/gui/psppire-dialog-action-regression.h | 91 +++++++ src/ui/gui/regression-dialog.h | 25 -- src/ui/gui/widgets.c | 2 + 7 files changed, 204 insertions(+), 166 deletions(-) rename src/ui/gui/{regression-dialog.c => psppire-dialog-action-regression.c} (52%) create mode 100644 src/ui/gui/psppire-dialog-action-regression.h delete mode 100644 src/ui/gui/regression-dialog.h diff --git a/src/ui/gui/automake.mk b/src/ui/gui/automake.mk index 3e2280a5d7..9c237b0031 100644 --- a/src/ui/gui/automake.mk +++ b/src/ui/gui/automake.mk @@ -238,14 +238,16 @@ src_ui_gui_psppire_SOURCES = \ src/ui/gui/psppire-dialog-action-means.h \ src/ui/gui/psppire-dialog-action-rank.c \ src/ui/gui/psppire-dialog-action-rank.h \ + src/ui/gui/psppire-dialog-action-regression.c \ + src/ui/gui/psppire-dialog-action-regression.h \ src/ui/gui/psppire-dialog-action-reliability.c \ src/ui/gui/psppire-dialog-action-reliability.h \ + src/ui/gui/psppire-dialog-action-roc.c \ + src/ui/gui/psppire-dialog-action-roc.h \ src/ui/gui/psppire-dialog-action-sort.c \ src/ui/gui/psppire-dialog-action-sort.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 \ @@ -290,8 +292,6 @@ src_ui_gui_psppire_SOURCES = \ src/ui/gui/psppire-window-register.h \ src/ui/gui/recode-dialog.c \ src/ui/gui/recode-dialog.h \ - src/ui/gui/regression-dialog.c \ - src/ui/gui/regression-dialog.h \ src/ui/gui/runs-dialog.c \ src/ui/gui/runs-dialog.h \ src/ui/gui/select-cases-dialog.c \ @@ -383,3 +383,4 @@ src/ui/gui/include/gtk/gtk.h: src/ui/gui/include/gtk/gtk.in.h mv $@-t $@ CLEANFILES += src/ui/gui/include/gtk/gtk.h EXTRA_DIST += src/ui/gui/include/gtk/gtk.in.h + diff --git a/src/ui/gui/data-editor.ui b/src/ui/gui/data-editor.ui index 19014e9cf1..cfa5b3e918 100644 --- a/src/ui/gui/data-editor.ui +++ b/src/ui/gui/data-editor.ui @@ -445,8 +445,9 @@ - + linear-regression + uimanager1 Linear _Regression... diff --git a/src/ui/gui/psppire-data-window.c b/src/ui/gui/psppire-data-window.c index 4e8d41a821..6dc422e340 100644 --- a/src/ui/gui/psppire-data-window.c +++ b/src/ui/gui/psppire-data-window.c @@ -51,7 +51,6 @@ #include "ui/gui/runs-dialog.h" #include "ui/gui/ks-one-sample-dialog.h" #include "ui/gui/recode-dialog.h" -#include "ui/gui/regression-dialog.h" #include "ui/gui/select-cases-dialog.h" #include "ui/gui/split-file-dialog.h" #include "ui/gui/t-test-one-sample.h" @@ -1072,7 +1071,6 @@ psppire_data_window_finish_init (PsppireDataWindow *de, connect_action (de, "transform_recode-different", G_CALLBACK (recode_different_dialog)); connect_action (de, "analyze_frequencies", G_CALLBACK (frequencies_dialog)); connect_action (de, "crosstabs", G_CALLBACK (crosstabs_dialog)); - connect_action (de, "linear-regression", G_CALLBACK (regression_dialog)); connect_action (de, "univariate", G_CALLBACK (univariate_dialog)); connect_action (de, "chi-square", G_CALLBACK (chisquare_dialog)); connect_action (de, "binomial", G_CALLBACK (binomial_dialog)); diff --git a/src/ui/gui/regression-dialog.c b/src/ui/gui/psppire-dialog-action-regression.c similarity index 52% rename from src/ui/gui/regression-dialog.c rename to src/ui/gui/psppire-dialog-action-regression.c index 06cdf82e5a..29df2a4392 100644 --- a/src/ui/gui/regression-dialog.c +++ b/src/ui/gui/psppire-dialog-action-regression.c @@ -14,24 +14,22 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include -#include "checkbox-treeview.h" -#include "regression-dialog.h" -#include "executor.h" +#include -#include -#include +#include "psppire-dialog-action-regression.h" +#include "psppire-value-entry.h" -#include -#include -#include -#include -#include -#include -#include -#include +#include "dialog-common.h" +#include "helper.h" +#include +#include "psppire-var-view.h" +#include "psppire-dialog.h" +#include "builder-wrapper.h" +#include "checkbox-treeview.h" +#include "psppire-dict.h" +#include "libpspp/str.h" #include "gettext.h" #define _(msgid) gettext (msgid) @@ -67,39 +65,38 @@ static const struct checkbox_entry_item stats[] = #undef RG }; -struct save_options -{ - gboolean pred; - gboolean resid; -}; -struct regression_dialog -{ - GtkTreeView *dep_vars; - GtkTreeView *indep_vars; - PsppireDict *dict; +static void +psppire_dialog_action_regression_class_init (PsppireDialogActionRegressionClass *class); + +G_DEFINE_TYPE (PsppireDialogActionRegression, psppire_dialog_action_regression, PSPPIRE_TYPE_DIALOG_ACTION); - GtkToggleButton *resid_button; - GtkToggleButton *pred_button; +static gboolean +dialog_state_valid (gpointer data) +{ + PsppireDialogActionRegression *rd = PSPPIRE_DIALOG_ACTION_REGRESSION (data); + GtkTreeModel *dep_vars = gtk_tree_view_get_model (GTK_TREE_VIEW (rd->dep_vars)); + GtkTreeModel *indep_vars = gtk_tree_view_get_model (GTK_TREE_VIEW (rd->indep_vars)); - GtkWidget *stat_dialog; - GtkWidget *save_dialog; + GtkTreeIter notused; - GtkWidget *stat_view; - struct save_options current_opts; -}; + return (gtk_tree_model_get_iter_first (dep_vars, ¬used) + && gtk_tree_model_get_iter_first (indep_vars, ¬used)); +} static void -refresh (PsppireDialog *dialog, struct regression_dialog *rd) +refresh (PsppireDialogAction *rd_) { - GtkTreeModel *liststore = gtk_tree_view_get_model (rd->dep_vars); + PsppireDialogActionRegression *rd = PSPPIRE_DIALOG_ACTION_REGRESSION (rd_); + + GtkTreeModel *liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (rd->dep_vars)); gtk_list_store_clear (GTK_LIST_STORE (liststore)); - liststore = gtk_tree_view_get_model (rd->indep_vars); + liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (rd->indep_vars)); gtk_list_store_clear (GTK_LIST_STORE (liststore)); } static void -on_statistics_clicked (struct regression_dialog *rd) +on_statistics_clicked (PsppireDialogActionRegression *rd) { int ret; GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (rd->stat_view)); @@ -118,39 +115,88 @@ on_statistics_clicked (struct regression_dialog *rd) } static void -on_save_clicked (struct regression_dialog *rd) +on_save_clicked (PsppireDialogActionRegression *rd) { int ret; - if (rd->current_opts.pred) + if (rd->pred) { - gtk_toggle_button_set_active (rd->pred_button, TRUE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->pred_button), TRUE); } - if (rd->current_opts.resid) + if (rd->resid) { - gtk_toggle_button_set_active (rd->resid_button, TRUE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->resid_button), TRUE); } ret = psppire_dialog_run (PSPPIRE_DIALOG (rd->save_dialog)); if ( ret == PSPPIRE_RESPONSE_CONTINUE ) { - rd->current_opts.pred = (gtk_toggle_button_get_active (rd->pred_button) == TRUE) + rd->pred = (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->pred_button)) == TRUE) ? TRUE : FALSE; - rd->current_opts.resid = (gtk_toggle_button_get_active (rd->resid_button) == TRUE) + rd->resid = (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->resid_button)) == TRUE) ? TRUE : FALSE; } } + +static void +psppire_dialog_action_regression_activate (GtkAction *a) +{ + PsppireDialogActionRegression *act = PSPPIRE_DIALOG_ACTION_REGRESSION (a); + PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a); + + GtkBuilder *xml = builder_new ("regression.ui"); + GtkWidget *stat_button = get_widget_assert (xml, "stat-button"); + GtkWidget *save_button = get_widget_assert (xml, "save-button"); + + pda->dialog = get_widget_assert (xml, "regression-dialog"); + pda->source = get_widget_assert (xml, "dict-view"); + + act->dep_vars = get_widget_assert (xml, "dep-view"); + act->indep_vars = get_widget_assert (xml, "indep-view"); + act->stat_view = get_widget_assert (xml, "stat-view"); + act->stat_dialog = get_widget_assert (xml, "statistics-dialog"); + act->save_dialog = get_widget_assert (xml, "save-dialog"); + act->pred_button = get_widget_assert (xml, "pred-button"); + act->resid_button = get_widget_assert (xml, "resid-button"); + + g_object_unref (xml); + + put_checkbox_items_in_treeview (GTK_TREE_VIEW (act->stat_view), + B_RG_STATS_DEFAULT, + N_REGRESSION_STATS, + stats); + + psppire_dialog_action_set_refresh (pda, refresh); + + psppire_dialog_action_set_valid_predicate (pda, + dialog_state_valid); + + g_signal_connect_swapped (stat_button, "clicked", + G_CALLBACK (on_statistics_clicked), act); + + g_signal_connect_swapped (save_button, "clicked", + G_CALLBACK (on_save_clicked), act); + + + if (PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_regression_parent_class)->activate) + PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_regression_parent_class)->activate (pda); +} + + + static char * -generate_syntax (const struct regression_dialog *rd) +generate_syntax (PsppireDialogAction *a) { + PsppireDialogActionRegression *rd = PSPPIRE_DIALOG_ACTION_REGRESSION (a); + gchar *text = NULL; + gint i; int n; guint selected; GtkTreeIter iter; gboolean ok; - gchar *text; GString *string = g_string_new ("REGRESSION"); GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (rd->stat_view)); @@ -185,14 +231,16 @@ generate_syntax (const struct regression_dialog *rd) g_string_append (string, stats[i].name); } } - if (rd->current_opts.pred || rd->current_opts.resid) + + if (rd->pred || rd->resid) { g_string_append (string, "\n\t/SAVE="); - if (rd->current_opts.pred) + if (rd->pred) g_string_append (string, " PRED"); - if (rd->current_opts.resid) + if (rd->resid) g_string_append (string, " RESID"); } + g_string_append (string, ".\n"); text = string->str; @@ -202,97 +250,19 @@ generate_syntax (const struct regression_dialog *rd) return text; } -/* Dialog is valid iff at least one dependent and one independent variable have - been selected. */ -static gboolean -dialog_state_valid (gpointer data) +static void +psppire_dialog_action_regression_class_init (PsppireDialogActionRegressionClass *class) { - struct regression_dialog *rd = data; + GtkActionClass *action_class = GTK_ACTION_CLASS (class); - GtkTreeModel *dep_vars = gtk_tree_view_get_model (rd->dep_vars); - GtkTreeModel *indep_vars = gtk_tree_view_get_model (rd->indep_vars); + action_class->activate = psppire_dialog_action_regression_activate; - GtkTreeIter notused; - - return (gtk_tree_model_get_iter_first (dep_vars, ¬used) - && gtk_tree_model_get_iter_first (indep_vars, ¬used)); + PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax; } -/* Pops up the Regression dialog box */ -void -regression_dialog (PsppireDataWindow *de) -{ - gint response; - struct regression_dialog rd; - - GtkBuilder *xml = builder_new ("regression.ui"); - PsppireVarStore *vs; - - GtkWidget *dialog = get_widget_assert (xml, "regression-dialog"); - GtkWidget *source = get_widget_assert (xml, "dict-view"); - GtkWidget *dest_dep = get_widget_assert (xml, "dep-view"); - GtkWidget *dest_indep = get_widget_assert (xml, "indep-view"); - GtkWidget *stat_button = get_widget_assert (xml, "stat-button"); - GtkWidget *save_button = get_widget_assert (xml, "save-button"); - - GtkWidget *dep_selector = get_widget_assert (xml, "dep-selector"); - - rd.stat_view = get_widget_assert (xml, "stat-view"); - - g_object_get (de->data_editor, "var-store", &vs, NULL); - - - put_checkbox_items_in_treeview (GTK_TREE_VIEW(rd.stat_view), - B_RG_STATS_DEFAULT, - N_REGRESSION_STATS, - stats - ); - gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de)); - - g_object_get (vs, "dictionary", &rd.dict, NULL); - g_object_set (source, "model", rd.dict, NULL); - - rd.dep_vars = GTK_TREE_VIEW (dest_dep); - rd.indep_vars = GTK_TREE_VIEW (dest_indep); - - psppire_selector_set_allow (PSPPIRE_SELECTOR (dep_selector), numeric_only); - - rd.save_dialog = get_widget_assert (xml, "save-dialog"); - rd.pred_button = GTK_TOGGLE_BUTTON (get_widget_assert (xml, "pred-button")); - rd.resid_button = GTK_TOGGLE_BUTTON (get_widget_assert (xml, "resid-button")); - rd.stat_dialog = get_widget_assert (xml, "statistics-dialog"); - - rd.current_opts.pred = FALSE; - rd.current_opts.resid = FALSE; - - gtk_window_set_transient_for (GTK_WINDOW (rd.save_dialog), GTK_WINDOW (de)); - gtk_window_set_transient_for (GTK_WINDOW (rd.stat_dialog), GTK_WINDOW (de)); - - g_signal_connect (dialog, "refresh", G_CALLBACK (refresh), &rd); - - psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog), - dialog_state_valid, &rd); - - g_signal_connect_swapped (stat_button, "clicked", - G_CALLBACK (on_statistics_clicked), &rd); - g_signal_connect_swapped (save_button, "clicked", - G_CALLBACK (on_save_clicked), &rd); - - response = psppire_dialog_run (PSPPIRE_DIALOG (dialog)); - - - 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; - } - - g_object_unref (xml); +static void +psppire_dialog_action_regression_init (PsppireDialogActionRegression *act) +{ } + diff --git a/src/ui/gui/psppire-dialog-action-regression.h b/src/ui/gui/psppire-dialog-action-regression.h new file mode 100644 index 0000000000..bb78a36e0b --- /dev/null +++ b/src/ui/gui/psppire-dialog-action-regression.h @@ -0,0 +1,91 @@ +/* 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_REGRESSION_H__ +#define __PSPPIRE_DIALOG_ACTION_REGRESSION_H__ + +G_BEGIN_DECLS + + +#define PSPPIRE_TYPE_DIALOG_ACTION_REGRESSION (psppire_dialog_action_regression_get_type ()) + +#define PSPPIRE_DIALOG_ACTION_REGRESSION(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ + PSPPIRE_TYPE_DIALOG_ACTION_REGRESSION, PsppireDialogActionRegression)) + +#define PSPPIRE_DIALOG_ACTION_REGRESSION_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), \ + PSPPIRE_TYPE_DIALOG_ACTION_REGRESSION, \ + PsppireDialogActionRegressionClass)) + + +#define PSPPIRE_IS_DIALOG_ACTION_REGRESSION(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PSPPIRE_TYPE_DIALOG_ACTION_REGRESSION)) + +#define PSPPIRE_IS_DIALOG_ACTION_REGRESSION_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), PSPPIRE_TYPE_DIALOG_ACTION_REGRESSION)) + + +#define PSPPIRE_DIALOG_ACTION_REGRESSION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \ + PSPPIRE_TYPE_DIALOG_ACTION_REGRESSION, \ + PsppireDialogActionRegressionClass)) + +typedef struct _PsppireDialogActionRegression PsppireDialogActionRegression; +typedef struct _PsppireDialogActionRegressionClass PsppireDialogActionRegressionClass; + + +struct _PsppireDialogActionRegression +{ + PsppireDialogAction parent; + + /*< private >*/ + gboolean dispose_has_run ; + + GtkWidget *dep_vars; + GtkWidget *indep_vars; + + GtkWidget *resid_button; + GtkWidget *pred_button; + + GtkWidget *stat_dialog; + GtkWidget *save_dialog; + + GtkWidget *stat_view; + + + /* Save Options */ + gboolean pred; + gboolean resid; +}; + + +struct _PsppireDialogActionRegressionClass +{ + PsppireDialogActionClass parent_class; +}; + + +GType psppire_dialog_action_regression_get_type (void) ; + +G_END_DECLS + +#endif /* __PSPPIRE_DIALOG_ACTION_REGRESSION_H__ */ diff --git a/src/ui/gui/regression-dialog.h b/src/ui/gui/regression-dialog.h deleted file mode 100644 index 32067cc972..0000000000 --- a/src/ui/gui/regression-dialog.h +++ /dev/null @@ -1,25 +0,0 @@ -/* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2008 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 __REGRESSION_DIALOG_H -#define __REGRESSION_DIALOG_H - - -#include "psppire-data-window.h" - -void regression_dialog (PsppireDataWindow * data); - -#endif diff --git a/src/ui/gui/widgets.c b/src/ui/gui/widgets.c index 74cfd4cf94..0da5c6c73f 100644 --- a/src/ui/gui/widgets.c +++ b/src/ui/gui/widgets.c @@ -22,6 +22,7 @@ #include "psppire-dialog-action-means.h" #include "psppire-means-layer.h" #include "psppire-dialog-action-rank.h" +#include "psppire-dialog-action-regression.h" #include "psppire-dialog-action-reliability.h" #include "psppire-dialog-action-roc.h" #include "psppire-dialog-action-sort.h" @@ -57,6 +58,7 @@ preregister_widgets (void) psppire_dialog_action_var_info_get_type (); psppire_dialog_action_rank_get_type (); psppire_dialog_action_reliability_get_type (); + psppire_dialog_action_regression_get_type (); psppire_dialog_action_roc_get_type (); psppire_dialog_action_sort_get_type (); } -- 2.30.2