From ab74a869bc2ee9f6b50565f47459d42445705204 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Tue, 29 Jan 2008 11:26:05 +0000 Subject: [PATCH] Oops --- src/ui/gui/psppire-var-ptr.c | 97 ++++++++++ src/ui/gui/psppire-var-ptr.h | 44 +++++ src/ui/gui/t-test-paired-samples.c | 290 +++++++++++++++++++++++++++++ src/ui/gui/t-test-paired-samples.h | 6 + 4 files changed, 437 insertions(+) create mode 100644 src/ui/gui/psppire-var-ptr.c create mode 100644 src/ui/gui/psppire-var-ptr.h create mode 100644 src/ui/gui/t-test-paired-samples.c create mode 100644 src/ui/gui/t-test-paired-samples.h diff --git a/src/ui/gui/psppire-var-ptr.c b/src/ui/gui/psppire-var-ptr.c new file mode 100644 index 00000000..52eb3e4d --- /dev/null +++ b/src/ui/gui/psppire-var-ptr.c @@ -0,0 +1,97 @@ +/* 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 . +*/ + +#include +#include +#include "psppire-var-ptr.h" + + +/* This module registers a type with Glib to hold pointers + to a {struct variable}. It also registers some tranformation functions so + that variables may be converted to strings and ints. + Note that the type is just a pointer. It's the user's responsibility to + ensure that it always points to something valid. +*/ + + +/* Shallow copy the pointer */ +static gpointer +variable_copy (gpointer var) +{ + return var; +} + +/* Do nothing. It's a pointer only! */ +static void +variable_free (gpointer var) +{ +} + + +/* Convert to a string, by using the variable's name */ +static void +variable_to_string (const GValue *src, + GValue *dest) +{ + const struct variable *v = g_value_get_boxed (src); + + if ( v == NULL) + g_value_set_string (dest, ""); + else + g_value_set_string (dest, var_get_name (v)); +} + + +/* Convert to an int, using the dictionary index. */ +static void +variable_to_int (const GValue *src, + GValue *dest) +{ + const struct variable *v = g_value_get_boxed (src); + + if ( v == NULL) + g_value_set_int (dest, -1); + else + g_value_set_int (dest, var_get_dict_index (v)); +} + + + + +GType +psppire_var_ptr_get_type (void) +{ + static GType t = 0; + + if (t == 0 ) + { + t = g_boxed_type_register_static ("psppire-var-ptr", + (GBoxedCopyFunc) variable_copy, + (GBoxedFreeFunc) variable_free); + + g_value_register_transform_func (t, G_TYPE_STRING, + variable_to_string); + + g_value_register_transform_func (t, G_TYPE_INT, + variable_to_int); + + } + + return t; +} + + diff --git a/src/ui/gui/psppire-var-ptr.h b/src/ui/gui/psppire-var-ptr.h new file mode 100644 index 00000000..f94e5432 --- /dev/null +++ b/src/ui/gui/psppire-var-ptr.h @@ -0,0 +1,44 @@ +/* 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 __PSPPIRE_VAR_PTR_TYPE__ +#define __PSPPIRE_VAR_PTR_TYPE__ 1 + +#include +#include + + +/* This module registers a type with Glib to hold pointers + to a {struct variable}. It also registers some tranformation functions so + that variables may be converted to strings and ints. + Note that the type is just a pointer. It's the user's responsibility to + ensure that it always points to something valid. + + The intended use of this module is to assist gui code which has to display + variables (eg in a GtkTreeView). +*/ + +G_BEGIN_DECLS + +GType psppire_var_ptr_get_type (void); + +#define PSPPIRE_VAR_PTR_TYPE (psppire_var_ptr_get_type ()) + +G_END_DECLS + +#endif /* __PSPPIRE_VAR_PTR_H__ */ + diff --git a/src/ui/gui/t-test-paired-samples.c b/src/ui/gui/t-test-paired-samples.c new file mode 100644 index 00000000..6b5a6e9e --- /dev/null +++ b/src/ui/gui/t-test-paired-samples.c @@ -0,0 +1,290 @@ +/* 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 . +*/ + +#include +#include +#include +#include +#include + +#include "data-editor.h" + +#include "psppire-dict.h" +#include "psppire-var-store.h" +#include "t-test-paired-samples.h" +#include "t-test-options.h" + +#include "dict-display.h" +#include "dialog-common.h" +#include "psppire-dialog.h" + +#include "syntax-editor.h" + +#include "helper.h" + +#include "psppire-var-ptr.h" + + +#include +#define _(msgid) gettext (msgid) +#define N_(msgid) msgid + + +struct tt_paired_samples_dialog +{ + PsppireDict *dict; + GtkWidget *pairs_treeview; + GtkTreeModel *list_store; + struct tt_options_dialog *opt; +}; + +static gchar * +generate_syntax (const struct tt_paired_samples_dialog *d) +{ + gchar *text = NULL; + GString *str = g_string_new ("T-TEST \n\tPAIRS = "); + + append_variable_names (str, d->dict, GTK_TREE_VIEW (d->pairs_treeview), 0); + + g_string_append (str, " WITH "); + + append_variable_names (str, d->dict, GTK_TREE_VIEW (d->pairs_treeview), 1); + + g_string_append (str, " (PAIRED)"); + g_string_append (str, "\n"); + + tt_options_dialog_append_syntax (d->opt, str); + + g_string_append (str, ".\n"); + + text = str->str; + g_string_free (str, FALSE); + + return text; +} + +static void +refresh (struct tt_paired_samples_dialog *tt_d) +{ + gtk_list_store_clear (GTK_LIST_STORE (tt_d->list_store)); +} + +static gboolean +dialog_state_valid (gpointer data) +{ + struct variable *v = NULL; + struct tt_paired_samples_dialog *tt_d = data; + GtkTreeIter dest_iter; + + gint n_rows = gtk_tree_model_iter_n_children (tt_d->list_store, NULL); + + if ( n_rows == 0 ) + return FALSE; + + /* Get the last row */ + gtk_tree_model_iter_nth_child (tt_d->list_store, &dest_iter, + NULL, n_rows - 1); + + /* Get the last (2nd) column */ + gtk_tree_model_get (tt_d->list_store, &dest_iter, 1, &v, -1); + + + return (v != NULL); +} + + + +static void +select_as_pair_member (GtkTreeIter source_iter, + GtkWidget *dest, + GtkTreeModel *source_model, + gpointer data) +{ + struct variable *v; + struct variable *v1; + gint n_rows; + GtkTreeIter dest_iter; + struct tt_paired_samples_dialog *tt_d = data; + + + gtk_tree_model_get (source_model, &source_iter, + DICT_TVM_COL_VAR, &v, -1); + + n_rows = gtk_tree_model_iter_n_children (tt_d->list_store, NULL); + + if ( n_rows > 0 ) + { + + gtk_tree_model_iter_nth_child (tt_d->list_store, + &dest_iter, NULL, n_rows - 1); + + gtk_tree_model_get (tt_d->list_store, &dest_iter, 1, &v1, -1); + } + + if ( n_rows == 0 || v1 != NULL) + { + gtk_list_store_append (GTK_LIST_STORE (tt_d->list_store), &dest_iter); + + gtk_list_store_set (GTK_LIST_STORE (tt_d->list_store), &dest_iter, + 0, v, + 1, NULL, + -1); + } + else + { + gtk_list_store_set (GTK_LIST_STORE (tt_d->list_store), &dest_iter, + 1, v, + -1); + + } +} + + +/* Append a new column to TV at position C, and heading TITLE */ +static void +add_new_column (GtkTreeView *tv, const gchar *title, gint c) +{ + GtkTreeViewColumn *col = gtk_tree_view_column_new (); + GtkCellRenderer *renderer = gtk_cell_renderer_text_new (); + + gtk_tree_view_column_set_min_width (col, 100); + gtk_tree_view_column_set_sizing (col, GTK_TREE_VIEW_COLUMN_AUTOSIZE); + gtk_tree_view_column_set_resizable (col, TRUE); + + + gtk_tree_view_column_set_title (col, title); + + gtk_tree_view_column_pack_start (col, renderer, TRUE); + + gtk_tree_view_column_set_sizing (col, GTK_TREE_VIEW_COLUMN_FIXED); + + gtk_tree_view_append_column (tv, col); + + gtk_tree_view_column_add_attribute (col, renderer, "text", c); +} + + +/* Pops up the dialog box */ +void +t_test_paired_samples_dialog (GObject *o, gpointer data) +{ + struct tt_paired_samples_dialog tt_d; + gint response; + struct data_editor *de = data; + + PsppireVarStore *vs; + + GladeXML *xml = XML_NEW ("t-test.glade"); + + GtkSheet *var_sheet = + GTK_SHEET (get_widget_assert (de->xml, "variable_sheet")); + + GtkWidget *dict_view = + get_widget_assert (xml, "paired-samples-t-test-treeview1"); + + GtkWidget *options_button = get_widget_assert (xml, "options-button"); + + GtkWidget *selector = get_widget_assert (xml, "psppire-selector3"); + + GtkWidget *dialog = get_widget_assert (xml, "t-test-paired-samples-dialog"); + + vs = PSPPIRE_VAR_STORE (gtk_sheet_get_model (var_sheet)); + + tt_d.dict = vs->dict; + tt_d.pairs_treeview = + get_widget_assert (xml, "paired-samples-t-test-treeview2"); + tt_d.opt = tt_options_dialog_create (xml, de->parent.window); + + gtk_window_set_transient_for (GTK_WINDOW (dialog), de->parent.window); + + + attach_dictionary_to_treeview (GTK_TREE_VIEW (dict_view), + vs->dict, + GTK_SELECTION_MULTIPLE, + var_is_numeric); + + { + tt_d.list_store = + GTK_TREE_MODEL ( + gtk_list_store_new (2, + PSPPIRE_VAR_PTR_TYPE, + PSPPIRE_VAR_PTR_TYPE)); + + + gtk_tree_view_set_model (GTK_TREE_VIEW (tt_d.pairs_treeview), + GTK_TREE_MODEL (tt_d.list_store)); + + + add_new_column (GTK_TREE_VIEW (tt_d.pairs_treeview), _("Var 1"), 0); + add_new_column (GTK_TREE_VIEW (tt_d.pairs_treeview), _("Var 2"), 1); + } + + + psppire_selector_set_subjects (PSPPIRE_SELECTOR (selector), + dict_view, + tt_d.pairs_treeview, + select_as_pair_member, + NULL, + &tt_d); + + + g_signal_connect_swapped (dialog, "refresh", + G_CALLBACK (refresh), &tt_d); + + + g_signal_connect_swapped (options_button, "clicked", + G_CALLBACK (tt_options_dialog_run), tt_d.opt); + + psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog), + dialog_state_valid, &tt_d); + + response = psppire_dialog_run (PSPPIRE_DIALOG (dialog)); + + switch (response) + { + case GTK_RESPONSE_OK: + { + gchar *syntax = generate_syntax (&tt_d); + struct getl_interface *sss = create_syntax_string_source (syntax); + execute_syntax (sss); + + g_free (syntax); + } + break; + case PSPPIRE_RESPONSE_PASTE: + { + gchar *syntax = generate_syntax (&tt_d); + + struct syntax_editor *se = + (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL); + + gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1); + + g_free (syntax); + } + break; + default: + break; + } + + + g_object_unref (xml); + + tt_options_dialog_destroy (tt_d.opt); +} + + diff --git a/src/ui/gui/t-test-paired-samples.h b/src/ui/gui/t-test-paired-samples.h new file mode 100644 index 00000000..c77d9c11 --- /dev/null +++ b/src/ui/gui/t-test-paired-samples.h @@ -0,0 +1,6 @@ +#ifndef T_TEST_PAIRED_SAMPLES_DIALOG +#define T_TEST_PAIRED_SAMPLES_DIALOG + +void t_test_paired_samples_dialog (GObject *, gpointer) ; + +#endif -- 2.30.2