From 3cc9782b5f4d9cb108a246a3cd676d233d26ed06 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Fri, 4 Oct 2013 17:01:05 +0200 Subject: [PATCH] Univariate Dialog: Convert from old style to PsppireDialogAction --- src/ui/gui/automake.mk | 4 +- src/ui/gui/data-editor.ui | 3 +- src/ui/gui/psppire-data-window.c | 9 - src/ui/gui/psppire-dialog-action-univariate.c | 121 ++++++++++++++ src/ui/gui/psppire-dialog-action-univariate.h | 79 +++++++++ src/ui/gui/univariate-dialog.c | 158 ------------------ src/ui/gui/univariate-dialog.h | 24 --- src/ui/gui/widgets.c | 2 + 8 files changed, 206 insertions(+), 194 deletions(-) create mode 100644 src/ui/gui/psppire-dialog-action-univariate.c create mode 100644 src/ui/gui/psppire-dialog-action-univariate.h delete mode 100644 src/ui/gui/univariate-dialog.c delete mode 100644 src/ui/gui/univariate-dialog.h diff --git a/src/ui/gui/automake.mk b/src/ui/gui/automake.mk index 06825dd568..d25b28ff5f 100644 --- a/src/ui/gui/automake.mk +++ b/src/ui/gui/automake.mk @@ -227,6 +227,8 @@ src_ui_gui_psppire_SOURCES = \ src/ui/gui/psppire-dialog-action-runs.h \ src/ui/gui/psppire-dialog-action-sort.c \ src/ui/gui/psppire-dialog-action-sort.h \ + src/ui/gui/psppire-dialog-action-univariate.c \ + src/ui/gui/psppire-dialog-action-univariate.h \ src/ui/gui/psppire-dialog-action-var-info.c \ src/ui/gui/psppire-dialog-action-var-info.h \ src/ui/gui/psppire-dict.c \ @@ -299,8 +301,6 @@ src_ui_gui_psppire_SOURCES = \ src/ui/gui/t-test-paired-samples.h \ src/ui/gui/npar-two-sample-related.c \ src/ui/gui/npar-two-sample-related.h \ - src/ui/gui/univariate-dialog.c \ - src/ui/gui/univariate-dialog.h \ src/ui/gui/val-labs-dialog.c \ src/ui/gui/val-labs-dialog.h \ src/ui/gui/var-display.c \ diff --git a/src/ui/gui/data-editor.ui b/src/ui/gui/data-editor.ui index 9fe45ecaa6..99ddbfa446 100644 --- a/src/ui/gui/data-editor.ui +++ b/src/ui/gui/data-editor.ui @@ -353,8 +353,9 @@ - + univariate + uimanager1 _Univariate Analysis... False diff --git a/src/ui/gui/psppire-data-window.c b/src/ui/gui/psppire-data-window.c index 69a8c6385f..890d795543 100644 --- a/src/ui/gui/psppire-data-window.c +++ b/src/ui/gui/psppire-data-window.c @@ -50,7 +50,6 @@ #include "ui/gui/t-test-one-sample.h" #include "ui/gui/t-test-paired-samples.h" #include "ui/gui/text-data-import-dialog.h" -#include "ui/gui/univariate-dialog.h" #include "ui/gui/weight-cases-dialog.h" #include "ui/syntax-gen.h" @@ -948,19 +947,12 @@ psppire_data_window_finish_init (PsppireDataWindow *de, enable_save (de); connect_action (de, "file_new_data", G_CALLBACK (create_data_window)); - connect_action (de, "file_import", G_CALLBACK (text_data_import_assistant)); - connect_action (de, "file_save", G_CALLBACK (psppire_window_save)); - connect_action (de, "file_open", G_CALLBACK (psppire_window_open)); - connect_action (de, "file_save_as", G_CALLBACK (psppire_window_save_as)); - connect_action (de, "rename_dataset", G_CALLBACK (on_rename_dataset)); - connect_action (de, "file_information_working-file", G_CALLBACK (display_dict)); - connect_action (de, "file_information_external-file", G_CALLBACK (sysfile_info)); g_signal_connect_swapped (get_action_assert (de->builder, "view_value-labels"), "toggled", G_CALLBACK (toggle_value_labels), de); @@ -978,7 +970,6 @@ psppire_data_window_finish_init (PsppireDataWindow *de, connect_action (de, "transform_count", G_CALLBACK (count_dialog)); connect_action (de, "transform_recode-same", G_CALLBACK (recode_same_dialog)); connect_action (de, "transform_recode-different", G_CALLBACK (recode_different_dialog)); - connect_action (de, "univariate", G_CALLBACK (univariate_dialog)); connect_action (de, "ks-one-sample", G_CALLBACK (ks_one_sample_dialog)); connect_action (de, "k-related-samples", G_CALLBACK (k_related_dialog)); connect_action (de, "two-related-samples", G_CALLBACK (two_related_dialog)); diff --git a/src/ui/gui/psppire-dialog-action-univariate.c b/src/ui/gui/psppire-dialog-action-univariate.c new file mode 100644 index 0000000000..79bf5ee0d3 --- /dev/null +++ b/src/ui/gui/psppire-dialog-action-univariate.c @@ -0,0 +1,121 @@ +/* PSPPIRE - a graphical user interface for PSPP. + Copyright (C) 2012, 2013 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 "psppire-dialog-action-univariate.h" + +#include "psppire-var-view.h" + +#include "psppire-dialog.h" +#include "builder-wrapper.h" + +static void psppire_dialog_action_univariate_init (PsppireDialogActionUnivariate *act); +static void psppire_dialog_action_univariate_class_init (PsppireDialogActionUnivariateClass *class); + +G_DEFINE_TYPE (PsppireDialogActionUnivariate, psppire_dialog_action_univariate, PSPPIRE_TYPE_DIALOG_ACTION); + +static char * +generate_syntax (PsppireDialogAction *act) +{ + PsppireDialogActionUnivariate *uvd = PSPPIRE_DIALOG_ACTION_UNIVARIATE (act); + + gchar *text = NULL; + GString *str = g_string_new ("GLM "); + + g_string_append (str, gtk_entry_get_text (GTK_ENTRY (uvd->dep_entry))); + + g_string_append (str, " BY "); + + psppire_var_view_append_names (PSPPIRE_VAR_VIEW (uvd->factor_list), 0, str); + + g_string_append (str, ".\n"); + + text = str->str; + + g_string_free (str, FALSE); + + return text; +} + + +static gboolean +dialog_state_valid (gpointer data) +{ + PsppireDialogActionUnivariate *ud = PSPPIRE_DIALOG_ACTION_UNIVARIATE (data); + GtkTreeModel *vars; + GtkTreeIter notused; + + if ( 0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (ud->dep_entry)))) + return false; + + vars = + gtk_tree_view_get_model (GTK_TREE_VIEW (ud->factor_list)); + + return gtk_tree_model_get_iter_first (vars, ¬used); +} + +static void +refresh (PsppireDialogAction *rd_) +{ + PsppireDialogActionUnivariate *uv = PSPPIRE_DIALOG_ACTION_UNIVARIATE (rd_); + GtkTreeModel *liststore ; + + gtk_entry_set_text (GTK_ENTRY (uv->dep_entry), ""); + + liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (uv->factor_list)); + + gtk_list_store_clear (GTK_LIST_STORE (liststore)); +} + +static void +psppire_dialog_action_univariate_activate (GtkAction *a) +{ + PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a); + PsppireDialogActionUnivariate *act = PSPPIRE_DIALOG_ACTION_UNIVARIATE (a); + + GtkBuilder *xml = builder_new ("univariate.ui"); + pda->dialog = get_widget_assert (xml, "univariate-dialog"); + pda->source = get_widget_assert (xml, "dict-view"); + + act->dep_entry = get_widget_assert (xml, "dep-entry"); + act->factor_list = get_widget_assert (xml, "factors-view"); + + psppire_dialog_action_set_valid_predicate (pda, dialog_state_valid); + psppire_dialog_action_set_refresh (pda, refresh); + + g_object_unref (xml); + + if (PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_univariate_parent_class)->activate) + PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_univariate_parent_class)->activate (pda); +} + +static void +psppire_dialog_action_univariate_class_init (PsppireDialogActionUnivariateClass *class) +{ + GtkActionClass *action_class = GTK_ACTION_CLASS (class); + + action_class->activate = psppire_dialog_action_univariate_activate; + PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax; +} + + +static void +psppire_dialog_action_univariate_init (PsppireDialogActionUnivariate *act) +{ +} + diff --git a/src/ui/gui/psppire-dialog-action-univariate.h b/src/ui/gui/psppire-dialog-action-univariate.h new file mode 100644 index 0000000000..be43ab3c6d --- /dev/null +++ b/src/ui/gui/psppire-dialog-action-univariate.h @@ -0,0 +1,79 @@ +/* PSPPIRE - a graphical user interface for PSPP. + Copyright (C) 2013 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_UNIVARIATE_H__ +#define __PSPPIRE_DIALOG_ACTION_UNIVARIATE_H__ + +G_BEGIN_DECLS + + +#define PSPPIRE_TYPE_DIALOG_ACTION_UNIVARIATE (psppire_dialog_action_univariate_get_type ()) + +#define PSPPIRE_DIALOG_ACTION_UNIVARIATE(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ + PSPPIRE_TYPE_DIALOG_ACTION_UNIVARIATE, PsppireDialogActionUnivariate)) + +#define PSPPIRE_DIALOG_ACTION_UNIVARIATE_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), \ + PSPPIRE_TYPE_DIALOG_ACTION_UNIVARIATE, \ + PsppireDialogActionUnivariateClass)) + + +#define PSPPIRE_IS_DIALOG_ACTION_UNIVARIATE(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PSPPIRE_TYPE_DIALOG_ACTION_UNIVARIATE)) + +#define PSPPIRE_IS_DIALOG_ACTION_UNIVARIATE_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), PSPPIRE_TYPE_DIALOG_ACTION_UNIVARIATE)) + + +#define PSPPIRE_DIALOG_ACTION_UNIVARIATE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \ + PSPPIRE_TYPE_DIALOG_ACTION_UNIVARIATE, \ + PsppireDialogActionUnivariateClass)) + +typedef struct _PsppireDialogActionUnivariate PsppireDialogActionUnivariate; +typedef struct _PsppireDialogActionUnivariateClass PsppireDialogActionUnivariateClass; + + +struct _PsppireDialogActionUnivariate +{ + PsppireDialogAction parent; + + /*< private >*/ + gboolean dispose_has_run ; + + /* Entry box for the dependent variable */ + GtkWidget *dep_entry; + GtkWidget *factor_list; +}; + + +struct _PsppireDialogActionUnivariateClass +{ + PsppireDialogActionClass parent_class; +}; + + +GType psppire_dialog_action_univariate_get_type (void) ; + +G_END_DECLS + +#endif /* __PSPPIRE_DIALOG_ACTION_UNIVARIATE_H__ */ diff --git a/src/ui/gui/univariate-dialog.c b/src/ui/gui/univariate-dialog.c deleted file mode 100644 index 2f24149860..0000000000 --- a/src/ui/gui/univariate-dialog.c +++ /dev/null @@ -1,158 +0,0 @@ -/* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2011, 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 -#include "psppire-dialog.h" -#include "dict-display.h" - -#include "psppire-var-view.h" -#include "psppire-selector.h" -#include "psppire-dictview.h" -#include - -#include "executor.h" -#include "helper.h" - -#include "univariate-dialog.h" - -struct uni_dialog -{ - struct dictionary *dict; - - /* Entry box for the dependent variable */ - GtkWidget *dep_entry; - - GtkWidget *factor_list; -}; - - -/* Dialog is valid iff at least one variable has been selected in both - the dependent variable box and the factor list. */ -static gboolean -dialog_state_valid (gpointer data) -{ - struct uni_dialog *uv_d = data; - GtkTreeModel *vars; - GtkTreeIter notused; - - if ( 0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (uv_d->dep_entry)))) - return false; - - vars = - gtk_tree_view_get_model (GTK_TREE_VIEW (uv_d->factor_list)); - - return gtk_tree_model_get_iter_first (vars, ¬used); -} - -/* Reset the dialog to its default state */ -static void -refresh (PsppireDialog *dialog, struct uni_dialog *uv_d) -{ - GtkTreeModel *liststore ; - - gtk_entry_set_text (GTK_ENTRY (uv_d->dep_entry), ""); - - liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (uv_d->factor_list)); - - gtk_list_store_clear (GTK_LIST_STORE (liststore)); -} - - -static char * -generate_syntax (const struct uni_dialog *uvd) -{ - gchar *text = NULL; - GString *str = g_string_new ("GLM "); - - - g_string_append (str, gtk_entry_get_text (GTK_ENTRY (uvd->dep_entry))); - - - g_string_append (str, " BY "); - - psppire_var_view_append_names (PSPPIRE_VAR_VIEW (uvd->factor_list), 0, str); - - - g_string_append (str, "."); - - text = str->str; - - g_string_free (str, FALSE); - - return text; -} - -void -univariate_dialog (PsppireDataWindow * de) -{ - struct uni_dialog uv_d; - - gint response; - - GtkBuilder *xml = builder_new ("univariate.ui"); - - GtkWidget *dialog = get_widget_assert (xml, "univariate-dialog"); - GtkWidget *source = get_widget_assert (xml, "dict-view"); - - GtkWidget *dep_selector = get_widget_assert (xml, "dep-selector"); - GtkWidget *factor_selector = get_widget_assert (xml, "factor-selector"); - - - uv_d.dep_entry = get_widget_assert (xml, "dep-entry"); - uv_d.factor_list = get_widget_assert (xml, "factors-view"); - - gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de)); - g_signal_connect (dialog, "refresh", G_CALLBACK (refresh), &uv_d); - - psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog), - dialog_state_valid, &uv_d); - - - g_object_get (de->data_editor, "dictionary", &uv_d.dict, NULL); - g_object_set (source, "model", uv_d.dict, NULL); - - psppire_selector_set_allow (PSPPIRE_SELECTOR (dep_selector), - numeric_only); - - psppire_selector_set_filter_func (PSPPIRE_SELECTOR (dep_selector), - is_currently_in_entry); - - - psppire_selector_set_filter_func (PSPPIRE_SELECTOR (factor_selector), - is_currently_in_varview); - - response = psppire_dialog_run (PSPPIRE_DIALOG (dialog)); - - - switch (response) - { - case GTK_RESPONSE_OK: - g_free (execute_syntax_string (de, generate_syntax (&uv_d))); - break; - case PSPPIRE_RESPONSE_PASTE: - g_free (paste_syntax_to_window (generate_syntax (&uv_d))); - break; - default: - break; - } - - g_object_unref (xml); -} - - diff --git a/src/ui/gui/univariate-dialog.h b/src/ui/gui/univariate-dialog.h deleted file mode 100644 index 5fef0ba7a3..0000000000 --- a/src/ui/gui/univariate-dialog.h +++ /dev/null @@ -1,24 +0,0 @@ -/* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2011 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 __UNIVARIATE_DIALOG_H -#define __UNIVARIATE_DIALOG_H - -#include "psppire-data-window.h" - -void univariate_dialog (PsppireDataWindow * data); - -#endif diff --git a/src/ui/gui/widgets.c b/src/ui/gui/widgets.c index 00942a4a67..62790a2d81 100644 --- a/src/ui/gui/widgets.c +++ b/src/ui/gui/widgets.c @@ -36,6 +36,7 @@ #include "psppire-dialog-action-roc.h" #include "psppire-dialog-action-runs.h" #include "psppire-dialog-action-sort.h" +#include "psppire-dialog-action-univariate.h" #include "psppire-dialog-action-var-info.h" #include "psppire-value-entry.h" @@ -80,6 +81,7 @@ preregister_widgets (void) psppire_dialog_action_roc_get_type (); psppire_dialog_action_runs_get_type (); psppire_dialog_action_sort_get_type (); + psppire_dialog_action_univariate_get_type (); /* This seems to be necessary on Cygwin. It ought not to be necessary. Having it here can't do any harm. */ -- 2.30.2