From: John Darrington Date: Sun, 13 Oct 2013 10:38:28 +0000 (+0200) Subject: Oneway anova dialog: Converted to PsppireDialogAction X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=394b64d4075a9e3fc7037758d65ff31522a7c642;p=pspp Oneway anova dialog: Converted to PsppireDialogAction --- diff --git a/src/ui/gui/automake.mk b/src/ui/gui/automake.mk index 98f67e8aa0..6b71475e34 100644 --- a/src/ui/gui/automake.mk +++ b/src/ui/gui/automake.mk @@ -158,8 +158,6 @@ src_ui_gui_psppire_SOURCES = \ src/ui/gui/main.c \ src/ui/gui/missing-val-dialog.c \ src/ui/gui/missing-val-dialog.h \ - src/ui/gui/oneway-anova-dialog.c \ - src/ui/gui/oneway-anova-dialog.h \ src/ui/gui/psppire.c \ src/ui/gui/psppire.h \ src/ui/gui/psppire-acr.h \ @@ -213,6 +211,8 @@ src_ui_gui_psppire_SOURCES = \ src/ui/gui/psppire-dialog-action-k-related.h \ src/ui/gui/psppire-dialog-action-means.c \ src/ui/gui/psppire-dialog-action-means.h \ + src/ui/gui/psppire-dialog-action-oneway.c \ + src/ui/gui/psppire-dialog-action-oneway.h \ src/ui/gui/psppire-dialog-action-paired.c \ src/ui/gui/psppire-dialog-action-paired.h \ src/ui/gui/psppire-dialog-action-rank.c \ diff --git a/src/ui/gui/data-editor.ui b/src/ui/gui/data-editor.ui index f7d0a6c8db..2a1f88c429 100644 --- a/src/ui/gui/data-editor.ui +++ b/src/ui/gui/data-editor.ui @@ -351,8 +351,9 @@ - + oneway-anova + uimanager1 One Way _ANOVA... diff --git a/src/ui/gui/oneway-anova-dialog.c b/src/ui/gui/oneway-anova-dialog.c deleted file mode 100644 index d656366cf0..0000000000 --- a/src/ui/gui/oneway-anova-dialog.c +++ /dev/null @@ -1,430 +0,0 @@ -/* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2007, 2010, 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 "oneway-anova-dialog.h" -#include "psppire-dict.h" -#include "psppire-var-view.h" -#include "builder-wrapper.h" -#include "psppire-data-window.h" -#include "psppire-dialog.h" -#include "dialog-common.h" -#include "psppire-acr.h" -#include "psppire-selector.h" -#include "dict-display.h" - -#include "executor.h" -#include "helper.h" - -#include "gettext.h" -#define _(msgid) gettext (msgid) -#define N_(msgid) msgid - - -struct contrasts_subdialog; -struct oneway_anova_dialog; - - -static void run_contrasts_dialog (struct oneway_anova_dialog *); -static void push_new_store (GArray *, struct contrasts_subdialog *); - -static void next (GtkWidget *, gpointer); -static void prev (GtkWidget *, gpointer); - - -struct contrasts_subdialog -{ - /* Contrasts Dialog widgets */ - GtkWidget *contrasts_dialog; - GtkWidget *stack_label; - PsppireAcr *acr; - - - /* Gets copied into contrasts when "Continue" - is clicked */ - GArray *temp_contrasts; - - /* Index into the temp_contrasts */ - guint c; - - GtkWidget *prev; - GtkWidget *next; - - GtkWidget *ctotal; -}; - - -struct oneway_anova_dialog -{ - PsppireDict *dict; - - GtkWidget *factor_entry; - GtkWidget *vars_treeview; - GtkWindow *dialog; - GArray *contrasts_array; - - GtkToggleButton *descriptives; - GtkToggleButton *homogeneity; - - struct contrasts_subdialog contrasts; -}; - -static gboolean -dialog_state_valid (gpointer data) -{ - struct oneway_anova_dialog *ow = data; - - GtkTreeModel *vars = - gtk_tree_view_get_model (GTK_TREE_VIEW (ow->vars_treeview)); - - GtkTreeIter notused; - - if ( !gtk_tree_model_get_iter_first (vars, ¬used) ) - return FALSE; - - if ( 0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (ow->factor_entry)))) - return FALSE; - - return TRUE; -} - -static gchar * generate_syntax (const struct oneway_anova_dialog *); - - -static void -refresh (struct oneway_anova_dialog *ow) -{ - GtkTreeModel *model = - gtk_tree_view_get_model (GTK_TREE_VIEW (ow->vars_treeview)); - - gtk_entry_set_text (GTK_ENTRY (ow->factor_entry), ""); - - gtk_list_store_clear (GTK_LIST_STORE (model)); -} - - - -/* Pops up the dialog box */ -void -oneway_anova_dialog (PsppireDataWindow *de) -{ - gint response; - - struct oneway_anova_dialog ow; - - GtkBuilder *builder = builder_new ("oneway.ui"); - - GtkWidget *dict_view = - get_widget_assert (builder, "oneway-anova-treeview1"); - - GtkWidget *selector2 = - get_widget_assert (builder, "oneway-anova-selector2"); - - GtkWidget *contrasts_button = - get_widget_assert (builder, "contrasts-button"); - - - g_signal_connect_swapped (contrasts_button, "clicked", - G_CALLBACK (run_contrasts_dialog), &ow); - - - ow.factor_entry = get_widget_assert (builder, "oneway-anova-entry"); - ow.vars_treeview = - get_widget_assert (builder, "oneway-anova-treeview2"); - - ow.descriptives = - GTK_TOGGLE_BUTTON (get_widget_assert (builder, "checkbutton1")); - - ow.homogeneity = - GTK_TOGGLE_BUTTON (get_widget_assert (builder, "checkbutton2")); - - g_object_get (de->data_editor, "dictionary", &ow.dict, NULL); - - ow.dialog = - GTK_WINDOW (get_widget_assert (builder, "oneway-anova-dialog")); - - gtk_window_set_transient_for (ow.dialog, GTK_WINDOW (de)); - - g_object_set (dict_view, "model", ow.dict, NULL); - - - psppire_selector_set_filter_func (PSPPIRE_SELECTOR (selector2), - is_currently_in_entry); - - - g_signal_connect_swapped (ow.dialog, "refresh", G_CALLBACK (refresh), &ow); - - - - psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (ow.dialog), - dialog_state_valid, &ow); - - - { - struct contrasts_subdialog *cd = &ow.contrasts; - GtkEntry *entry = GTK_ENTRY (get_widget_assert (builder, "entry1")); - - cd->acr = PSPPIRE_ACR (get_widget_assert (builder, "psppire-acr1")); - cd->contrasts_dialog = get_widget_assert (builder, "contrasts-dialog"); - - cd->next = get_widget_assert (builder, "next-button"); - cd->prev = get_widget_assert (builder, "prev-button"); - cd->ctotal = get_widget_assert (builder, "entry2"); - - cd->stack_label = get_widget_assert (builder, "contrast-stack-label"); - - /* Contrasts */ - ow.contrasts_array = g_array_new (FALSE, FALSE, sizeof (GtkListStore *)); - - g_signal_connect (cd->next, "clicked", G_CALLBACK (next), cd); - g_signal_connect (cd->prev, "clicked", G_CALLBACK (prev), cd); - - psppire_acr_set_entry (cd->acr, entry); - - gtk_window_set_transient_for (GTK_WINDOW (cd->contrasts_dialog), - GTK_WINDOW (de)); - } - - response = psppire_dialog_run (PSPPIRE_DIALOG (ow.dialog)); - - switch (response) - { - case GTK_RESPONSE_OK: - g_free (execute_syntax_string (de, generate_syntax (&ow))); - break; - case PSPPIRE_RESPONSE_PASTE: - g_free (paste_syntax_to_window (generate_syntax (&ow))); - break; - default: - break; - } - - g_array_free (ow.contrasts_array, FALSE); - - g_object_unref (builder); -} - - -static gchar * generate_syntax (const struct oneway_anova_dialog *ow) -{ - gchar *text; - gint i; - gboolean descriptives = gtk_toggle_button_get_active (ow->descriptives); - gboolean homogeneity = gtk_toggle_button_get_active (ow->homogeneity); - struct string dss; - - ds_init_cstr (&dss, "ONEWAY /VARIABLES="); - - psppire_var_view_append_names_str (PSPPIRE_VAR_VIEW (ow->vars_treeview), 0, &dss); - - ds_put_cstr (&dss, " BY "); - - ds_put_cstr (&dss, gtk_entry_get_text (GTK_ENTRY (ow->factor_entry))); - - if (descriptives || homogeneity ) - { - ds_put_cstr (&dss, "\n\t/STATISTICS="); - if (descriptives) - ds_put_cstr (&dss, "DESCRIPTIVES "); - if (homogeneity) - ds_put_cstr (&dss, "HOMOGENEITY "); - } - - for (i = 0 ; i < ow->contrasts_array->len ; ++i ) - { - GtkListStore *ls = g_array_index (ow->contrasts_array, GtkListStore*, i); - GtkTreeIter iter; - gboolean ok; - - ds_put_cstr (&dss, "\n\t/CONTRAST="); - - for (ok = gtk_tree_model_get_iter_first (GTK_TREE_MODEL(ls), - &iter); - ok; - ok = gtk_tree_model_iter_next (GTK_TREE_MODEL (ls), &iter)) - { - gdouble v; - - gtk_tree_model_get (GTK_TREE_MODEL (ls), &iter, 0, &v, -1); - - ds_put_c_format (&dss, " %g", v); - } - } - - ds_put_cstr (&dss, ".\n"); - - text = ds_steal_cstr (&dss); - ds_destroy (&dss); - - return text; -} - - - -/* Contrasts stuff */ - - - - -/* Callback for when the list store currently associated with the - treeview has changed. It sets the widgets of the subdialog - to reflect the store's new state. -*/ -static void -list_store_changed (struct contrasts_subdialog *csd) -{ - gboolean ok; - gdouble total = 0.0; - GtkTreeIter iter; - GtkTreeModel *ls = NULL; - gchar *text = - g_strdup_printf (_("Contrast %d of %d"), - csd->c, csd->temp_contrasts->len); - - gtk_label_set_label (GTK_LABEL (csd->stack_label), text); - - g_free (text); - - gtk_widget_set_sensitive (csd->prev, csd->c > 1); - - if ( csd->c > 0 ) - ls = g_array_index (csd->temp_contrasts, GtkTreeModel*, csd->c - 1); - - psppire_acr_set_model (csd->acr, GTK_LIST_STORE (ls)); - - /* Sensitive iff the liststore has two items or more */ - gtk_widget_set_sensitive (csd->next, - gtk_tree_model_iter_nth_child - (ls, &iter, NULL, 1)); - - for (ok = gtk_tree_model_get_iter_first (ls, &iter); - ok; - ok = gtk_tree_model_iter_next (ls, &iter) - ) - { - gdouble v; - gtk_tree_model_get (ls, &iter, 0, &v, -1); - total += v; - } - - text = g_strdup_printf ("%g", total); - - gtk_entry_set_text (GTK_ENTRY (csd->ctotal), text); - - g_free (text); -} - - - -/* Copy the contrasts array into the local array */ -static GArray * -clone_contrasts_array (GArray *src_array) -{ - gint i; - - GArray *dest_array = - g_array_sized_new (FALSE, FALSE, sizeof (GtkListStore *), - src_array->len); - - for (i = 0 ; i < src_array->len ; ++i ) - { - - GtkTreeIter src_iter; - GtkListStore *src = g_array_index (src_array, GtkListStore*, i); - GtkListStore *dest; - - /* Refuse to copy empty stores */ - if (! gtk_tree_model_get_iter_first (GTK_TREE_MODEL (src), - &src_iter)) - continue; - - dest = clone_list_store (src); - - g_array_append_val (dest_array, dest); - } - - return dest_array; -} - - -static void -run_contrasts_dialog (struct oneway_anova_dialog *ow) -{ - struct contrasts_subdialog *csd = &ow->contrasts; - gint response; - - csd->temp_contrasts = clone_contrasts_array (ow->contrasts_array); - - csd->c = 1; - - push_new_store (csd->temp_contrasts, csd); - - response = psppire_dialog_run (PSPPIRE_DIALOG (csd->contrasts_dialog)); - - if ( response == PSPPIRE_RESPONSE_CONTINUE ) - { - ow->contrasts_array = clone_contrasts_array (csd->temp_contrasts); - } - - /* Destroy the temp contrasts here */ - -} - - -static void -push_new_store (GArray *contrast_stack, struct contrasts_subdialog *csd) -{ - GtkListStore *ls = gtk_list_store_new (1, G_TYPE_DOUBLE); - - g_array_append_val (contrast_stack, ls); - - g_signal_connect_swapped (ls, "row-deleted", - G_CALLBACK (list_store_changed), csd); - - g_signal_connect_swapped (ls, "row-changed", - G_CALLBACK (list_store_changed), csd); - - list_store_changed (csd); -} - -static void -next (GtkWidget *widget, gpointer data) -{ - struct contrasts_subdialog *csd = data; - - if (csd->c >= csd->temp_contrasts->len) - push_new_store (csd->temp_contrasts, csd); - - csd->c++; - - list_store_changed (csd); -} - - -static void -prev (GtkWidget *widget, gpointer data) -{ - struct contrasts_subdialog *csd = data; - - if ( csd->c > 0 ) - --csd->c; - - list_store_changed (csd); -} - - diff --git a/src/ui/gui/oneway-anova-dialog.h b/src/ui/gui/oneway-anova-dialog.h deleted file mode 100644 index d9e29af19d..0000000000 --- a/src/ui/gui/oneway-anova-dialog.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef ONEWAY_ANOVA_DIALOG -#define ONEWAY_ANOVA_DIALOG - -#include "psppire-data-window.h" - -void oneway_anova_dialog (PsppireDataWindow * data); - - -#endif diff --git a/src/ui/gui/psppire-data-window.c b/src/ui/gui/psppire-data-window.c index 1b1ba315e8..e820e9daa5 100644 --- a/src/ui/gui/psppire-data-window.c +++ b/src/ui/gui/psppire-data-window.c @@ -33,7 +33,6 @@ #include "ui/gui/help-menu.h" #include "ui/gui/helper.h" #include "ui/gui/helper.h" -#include "ui/gui/oneway-anova-dialog.h" #include "ui/gui/psppire-data-window.h" #include "ui/gui/psppire-dialog-action.h" #include "ui/gui/psppire-syntax-window.h" @@ -955,7 +954,6 @@ psppire_data_window_finish_init (PsppireDataWindow *de, connect_action (de, "transform_autorecode", G_CALLBACK (autorecode_dialog)); connect_action (de, "data_split-file", G_CALLBACK (split_file_dialog)); connect_action (de, "data_weight-cases", G_CALLBACK (weight_cases_dialog)); - connect_action (de, "oneway-anova", G_CALLBACK (oneway_anova_dialog)); connect_action (de, "utilities_comments", G_CALLBACK (comments_dialog)); connect_action (de, "transform_recode-same", G_CALLBACK (recode_same_dialog)); connect_action (de, "transform_recode-different", G_CALLBACK (recode_different_dialog)); diff --git a/src/ui/gui/psppire-dialog-action-oneway.c b/src/ui/gui/psppire-dialog-action-oneway.c new file mode 100644 index 0000000000..66b80f6417 --- /dev/null +++ b/src/ui/gui/psppire-dialog-action-oneway.c @@ -0,0 +1,350 @@ +/* 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-oneway.h" + +#include "psppire-var-view.h" +#include "psppire-acr.h" + +#include "psppire-dialog.h" +#include "builder-wrapper.h" +#include "helper.h" + + +#include "gettext.h" +#define _(msgid) gettext (msgid) +#define N_(msgid) msgid + + +static void next (GtkWidget *widget, PsppireDialogActionOneway *); +static void prev (GtkWidget *widget, PsppireDialogActionOneway *); +static void run_contrasts_dialog (PsppireDialogActionOneway *csd); +static void push_new_store (GArray *contrast_stack, PsppireDialogActionOneway *csd); + + +static void psppire_dialog_action_oneway_init (PsppireDialogActionOneway *act); +static void psppire_dialog_action_oneway_class_init (PsppireDialogActionOnewayClass *class); + +G_DEFINE_TYPE (PsppireDialogActionOneway, psppire_dialog_action_oneway, PSPPIRE_TYPE_DIALOG_ACTION); + + +static char * +generate_syntax (PsppireDialogAction *act) +{ + PsppireDialogActionOneway *ow = PSPPIRE_DIALOG_ACTION_ONEWAY (act); + gchar *text; + gint i; + + gboolean descriptives = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ow->descriptives)); + gboolean homogeneity = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ow->homogeneity)); + struct string dss; + + ds_init_cstr (&dss, "ONEWAY /VARIABLES="); + + psppire_var_view_append_names_str (PSPPIRE_VAR_VIEW (ow->vars_treeview), 0, &dss); + + ds_put_cstr (&dss, " BY "); + + ds_put_cstr (&dss, gtk_entry_get_text (GTK_ENTRY (ow->factor_entry))); + + if (descriptives || homogeneity ) + { + ds_put_cstr (&dss, "\n\t/STATISTICS="); + if (descriptives) + ds_put_cstr (&dss, "DESCRIPTIVES "); + if (homogeneity) + ds_put_cstr (&dss, "HOMOGENEITY "); + } + + for (i = 0 ; i < ow->contrasts_array->len ; ++i ) + { + GtkListStore *ls = g_array_index (ow->contrasts_array, GtkListStore*, i); + GtkTreeIter iter; + gboolean ok; + + ds_put_cstr (&dss, "\n\t/CONTRAST="); + + for (ok = gtk_tree_model_get_iter_first (GTK_TREE_MODEL(ls), + &iter); + ok; + ok = gtk_tree_model_iter_next (GTK_TREE_MODEL (ls), &iter)) + { + gdouble v; + + gtk_tree_model_get (GTK_TREE_MODEL (ls), &iter, 0, &v, -1); + + ds_put_c_format (&dss, " %g", v); + } + } + + ds_put_cstr (&dss, ".\n"); + + text = ds_steal_cstr (&dss); + ds_destroy (&dss); + + return text; +} + + +static gboolean +dialog_state_valid (gpointer data) +{ + PsppireDialogActionOneway *ow = PSPPIRE_DIALOG_ACTION_ONEWAY (data); + + GtkTreeModel *vars = + gtk_tree_view_get_model (GTK_TREE_VIEW (ow->vars_treeview)); + + GtkTreeIter notused; + + if ( !gtk_tree_model_get_iter_first (vars, ¬used) ) + return FALSE; + + if ( 0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (ow->factor_entry)))) + return FALSE; + + + return TRUE; +} + +static void +refresh (PsppireDialogAction *rd_) +{ + PsppireDialogActionOneway *ow = PSPPIRE_DIALOG_ACTION_ONEWAY (rd_); + + GtkTreeModel *model = + gtk_tree_view_get_model (GTK_TREE_VIEW (ow->vars_treeview)); + + gtk_entry_set_text (GTK_ENTRY (ow->factor_entry), ""); + + gtk_list_store_clear (GTK_LIST_STORE (model)); +} + + +/* Callback for when the list store currently associated with the + treeview has changed. It sets the widgets of the subdialog + to reflect the store's new state. +*/ +static void +list_store_changed (PsppireDialogActionOneway *csd) +{ + gboolean ok; + gdouble total = 0.0; + GtkTreeIter iter; + GtkTreeModel *ls = NULL; + gchar *text = + g_strdup_printf (_("Contrast %d of %d"), + csd->c, csd->temp_contrasts->len); + + gtk_label_set_label (GTK_LABEL (csd->stack_label), text); + + g_free (text); + + gtk_widget_set_sensitive (csd->prev, csd->c > 1); + + if ( csd->c > 0 ) + ls = g_array_index (csd->temp_contrasts, GtkTreeModel*, csd->c - 1); + + psppire_acr_set_model (PSPPIRE_ACR (csd->acr), GTK_LIST_STORE (ls)); + + /* Sensitive iff the liststore has two items or more */ + gtk_widget_set_sensitive (csd->next, + gtk_tree_model_iter_nth_child + (ls, &iter, NULL, 1)); + + for (ok = gtk_tree_model_get_iter_first (ls, &iter); + ok; + ok = gtk_tree_model_iter_next (ls, &iter) + ) + { + gdouble v; + gtk_tree_model_get (ls, &iter, 0, &v, -1); + total += v; + } + + text = g_strdup_printf ("%g", total); + + gtk_entry_set_text (GTK_ENTRY (csd->ctotal), text); + + g_free (text); +} + + +/* Copy the contrasts array into the local array */ +static GArray * +clone_contrasts_array (GArray *src_array) +{ + gint i; + + GArray *dest_array = + g_array_sized_new (FALSE, FALSE, sizeof (GtkListStore *), + src_array->len); + + for (i = 0 ; i < src_array->len ; ++i ) + { + + GtkTreeIter src_iter; + GtkListStore *src = g_array_index (src_array, GtkListStore*, i); + GtkListStore *dest; + + /* Refuse to copy empty stores */ + if (! gtk_tree_model_get_iter_first (GTK_TREE_MODEL (src), + &src_iter)) + continue; + + dest = clone_list_store (src); + + g_array_append_val (dest_array, dest); + } + + return dest_array; +} + + + + +static void +psppire_dialog_action_oneway_activate (GtkAction *a) +{ + PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a); + PsppireDialogActionOneway *act = PSPPIRE_DIALOG_ACTION_ONEWAY (a); + + GtkBuilder *xml = builder_new ("oneway.ui"); + GtkWidget *contrasts_button = + get_widget_assert (xml, "contrasts-button"); + GtkEntry *entry = GTK_ENTRY (get_widget_assert (xml, "entry1")); + + pda->dialog = get_widget_assert (xml, "oneway-anova-dialog"); + pda->source = get_widget_assert (xml, "oneway-anova-treeview1"); + + act->vars_treeview = get_widget_assert (xml, "oneway-anova-treeview2"); + act->factor_entry = get_widget_assert (xml, "oneway-anova-entry"); + + act->descriptives = get_widget_assert (xml, "checkbutton1"); + act->homogeneity = get_widget_assert (xml, "checkbutton2"); + + act->contrasts_dialog = get_widget_assert (xml, "contrasts-dialog"); + + act->next = get_widget_assert (xml, "next-button"); + act->prev = get_widget_assert (xml, "prev-button"); + act->ctotal = get_widget_assert (xml, "entry2"); + act->acr = get_widget_assert (xml, "psppire-acr1"); + act->stack_label = get_widget_assert (xml, "contrast-stack-label"); + act->contrasts_array = g_array_new (FALSE, FALSE, sizeof (GtkListStore *)); + + + g_signal_connect (act->next, "clicked", G_CALLBACK (next), act); + g_signal_connect (act->prev, "clicked", G_CALLBACK (prev), act); + + psppire_acr_set_entry (PSPPIRE_ACR (act->acr), entry); + + gtk_window_set_transient_for (GTK_WINDOW (act->contrasts_dialog), + GTK_WINDOW (pda->toplevel)); + + + g_signal_connect_swapped (contrasts_button, "clicked", + G_CALLBACK (run_contrasts_dialog), act); + + + 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_oneway_parent_class)->activate) + PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_oneway_parent_class)->activate (pda); +} + +static void +psppire_dialog_action_oneway_class_init (PsppireDialogActionOnewayClass *class) +{ + GtkActionClass *action_class = GTK_ACTION_CLASS (class); + + action_class->activate = psppire_dialog_action_oneway_activate; + PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax; +} + + +static void +psppire_dialog_action_oneway_init (PsppireDialogActionOneway *act) +{ + act->contrasts_array = NULL; + act->c = -1; + +} + + + + +static void +run_contrasts_dialog (PsppireDialogActionOneway *csd) +{ + gint response; + + csd->temp_contrasts = clone_contrasts_array (csd->contrasts_array); + + csd->c = 1; + + push_new_store (csd->temp_contrasts, csd); + + response = psppire_dialog_run (PSPPIRE_DIALOG (csd->contrasts_dialog)); + + if ( response == PSPPIRE_RESPONSE_CONTINUE ) + { + csd->contrasts_array = clone_contrasts_array (csd->temp_contrasts); + } +} + + +static void +push_new_store (GArray *contrast_stack, PsppireDialogActionOneway *csd) +{ + GtkListStore *ls = gtk_list_store_new (1, G_TYPE_DOUBLE); + + g_array_append_val (contrast_stack, ls); + + g_signal_connect_swapped (ls, "row-deleted", + G_CALLBACK (list_store_changed), csd); + + g_signal_connect_swapped (ls, "row-changed", + G_CALLBACK (list_store_changed), csd); + + list_store_changed (csd); +} + + +static void +next (GtkWidget *widget, PsppireDialogActionOneway *csd) +{ + if (csd->c >= csd->temp_contrasts->len) + push_new_store (csd->temp_contrasts, csd); + + csd->c++; + + list_store_changed (csd); +} + + +static void +prev (GtkWidget *widget, PsppireDialogActionOneway *csd) +{ + if ( csd->c > 0 ) + --csd->c; + + list_store_changed (csd); +} diff --git a/src/ui/gui/psppire-dialog-action-oneway.h b/src/ui/gui/psppire-dialog-action-oneway.h new file mode 100644 index 0000000000..4483728524 --- /dev/null +++ b/src/ui/gui/psppire-dialog-action-oneway.h @@ -0,0 +1,101 @@ +/* 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_ONEWAY_H__ +#define __PSPPIRE_DIALOG_ACTION_ONEWAY_H__ + +G_BEGIN_DECLS + + +#define PSPPIRE_TYPE_DIALOG_ACTION_ONEWAY (psppire_dialog_action_oneway_get_type ()) + +#define PSPPIRE_DIALOG_ACTION_ONEWAY(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ + PSPPIRE_TYPE_DIALOG_ACTION_ONEWAY, PsppireDialogActionOneway)) + +#define PSPPIRE_DIALOG_ACTION_ONEWAY_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), \ + PSPPIRE_TYPE_DIALOG_ACTION_ONEWAY, \ + PsppireDialogActionOnewayClass)) + + +#define PSPPIRE_IS_DIALOG_ACTION_ONEWAY(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PSPPIRE_TYPE_DIALOG_ACTION_ONEWAY)) + +#define PSPPIRE_IS_DIALOG_ACTION_ONEWAY_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), PSPPIRE_TYPE_DIALOG_ACTION_ONEWAY)) + + +#define PSPPIRE_DIALOG_ACTION_ONEWAY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \ + PSPPIRE_TYPE_DIALOG_ACTION_ONEWAY, \ + PsppireDialogActionOnewayClass)) + +typedef struct _PsppireDialogActionOneway PsppireDialogActionOneway; +typedef struct _PsppireDialogActionOnewayClass PsppireDialogActionOnewayClass; + + +struct _PsppireDialogActionOneway +{ + PsppireDialogAction parent; + + /*< private >*/ + gboolean dispose_has_run ; + + GtkWidget *descriptives; + GtkWidget *homogeneity; + + + GtkWidget *contrasts_dialog; + + GtkWidget *next; + GtkWidget *prev; + GtkWidget *acr; + GtkWidget *vars_treeview; + GtkWidget *factor_entry; + + + /* Gets copied into contrasts when "Continue" + is clicked */ + GArray *temp_contrasts; + + /* Index into the temp_contrasts */ + guint c; + + + GArray *contrasts_array; + + GtkWidget *ctotal; + GtkWidget *stack_label; +}; + + +struct _PsppireDialogActionOnewayClass +{ + PsppireDialogActionClass parent_class; +}; + + +GType psppire_dialog_action_oneway_get_type (void) ; + +G_END_DECLS + +#endif /* __PSPPIRE_DIALOG_ACTION_ONEWAY_H__ */ diff --git a/src/ui/gui/widgets.c b/src/ui/gui/widgets.c index 3d78f1f4a5..c8b21e69a9 100644 --- a/src/ui/gui/widgets.c +++ b/src/ui/gui/widgets.c @@ -34,6 +34,7 @@ #include "psppire-dialog-action-logistic.h" #include "psppire-dialog-action-means.h" #include "psppire-dialog-action-paired.h" +#include "psppire-dialog-action-oneway.h" #include "psppire-means-layer.h" #include "psppire-dialog-action-rank.h" #include "psppire-dialog-action-regression.h" @@ -83,6 +84,7 @@ preregister_widgets (void) psppire_dialog_action_kmeans_get_type (); psppire_dialog_action_k_related_get_type (); psppire_dialog_action_means_get_type (); + psppire_dialog_action_oneway_get_type (); psppire_dialog_action_paired_get_type (); psppire_dialog_action_indep_samps_get_type (); psppire_means_layer_get_type ();