1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2012, 2013 Free Software Foundation
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "psppire-dialog-action-paired.h"
22 #include "psppire-var-view.h"
24 #include "psppire-selector.h"
25 #include "psppire-dialog.h"
26 #include "builder-wrapper.h"
28 #include "t-test-options.h"
31 #define _(msgid) gettext (msgid)
32 #define N_(msgid) msgid
35 static void psppire_dialog_action_paired_init (PsppireDialogActionPaired
*act
);
36 static void psppire_dialog_action_paired_class_init (PsppireDialogActionPairedClass
*class);
38 G_DEFINE_TYPE (PsppireDialogActionPaired
, psppire_dialog_action_paired
, PSPPIRE_TYPE_DIALOG_ACTION
);
42 dialog_state_valid (gpointer data
)
44 PsppireDialogActionPaired
*pd
= PSPPIRE_DIALOG_ACTION_PAIRED (data
);
45 gint n_rows
= gtk_tree_model_iter_n_children (GTK_TREE_MODEL (pd
->list_store
), NULL
);
46 struct variable
*v
= NULL
;
47 GtkTreeIter dest_iter
;
52 /* Get the last row */
53 gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (pd
->list_store
), &dest_iter
,
56 /* Get the last (2nd) column */
57 gtk_tree_model_get (GTK_TREE_MODEL (pd
->list_store
), &dest_iter
, 1, &v
, -1);
62 /* if ( NULL == pd->valid) */
66 // return pd->valid (pd->aux);
70 refresh (PsppireDialogAction
*rd_
)
72 PsppireDialogActionPaired
*pd
= PSPPIRE_DIALOG_ACTION_PAIRED (rd_
);
74 gtk_list_store_clear (GTK_LIST_STORE (pd
->list_store
));
79 select_as_pair_member (GtkTreeIter source_iter
,
81 GtkTreeModel
*source_model
,
87 GtkTreeIter dest_iter
;
88 PsppireDialogActionPaired
*tt_d
= PSPPIRE_DIALOG_ACTION_PAIRED (data
);
91 gtk_tree_model_get (source_model
, &source_iter
,
92 DICT_TVM_COL_VAR
, &v
, -1);
94 n_rows
= gtk_tree_model_iter_n_children (GTK_TREE_MODEL (tt_d
->list_store
), NULL
);
99 gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (tt_d
->list_store
),
100 &dest_iter
, NULL
, n_rows
- 1);
102 gtk_tree_model_get (GTK_TREE_MODEL (tt_d
->list_store
), &dest_iter
, 1, &v1
, -1);
107 if ( n_rows
== 0 || v1
!= NULL
)
109 gtk_list_store_append (tt_d
->list_store
, &dest_iter
);
111 gtk_list_store_set (tt_d
->list_store
, &dest_iter
,
118 gtk_list_store_set (tt_d
->list_store
, &dest_iter
,
127 generate_syntax (PsppireDialogAction
*pda
)
129 PsppireDialogActionPaired
*d
= PSPPIRE_DIALOG_ACTION_PAIRED (pda
);
131 GString
*str
= g_string_new ("T-TEST \n\tPAIRS = ");
133 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (d
->pairs_treeview
), 0, str
);
135 g_string_append (str
, " WITH ");
137 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (d
->pairs_treeview
), 1, str
);
139 g_string_append (str
, " (PAIRED)");
140 g_string_append (str
, "\n");
142 tt_options_dialog_append_syntax (d
->opt
, str
);
144 g_string_append (str
, ".\n");
147 g_string_free (str
, FALSE
);
153 psppire_dialog_action_paired_activate (PsppireDialogAction
*a
)
155 PsppireDialogAction
*pda
= PSPPIRE_DIALOG_ACTION (a
);
156 PsppireDialogActionPaired
*act
= PSPPIRE_DIALOG_ACTION_PAIRED (a
);
158 GHashTable
*thing
= psppire_dialog_action_get_hash_table (pda
);
159 GtkBuilder
*xml
= g_hash_table_lookup (thing
, a
);
162 xml
= builder_new ("paired-samples.ui");
163 g_hash_table_insert (thing
, a
, xml
);
165 GtkWidget
*selector
= get_widget_assert (xml
, "psppire-selector3");
166 GtkWidget
*bb
= gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL
);
167 GtkWidget
*button
= gtk_button_new_with_mnemonic (_("O_ptions..."));
168 GtkWidget
*box
= get_widget_assert (xml
, "dynamic-populate");
170 pda
->dialog
= get_widget_assert (xml
, "t-test-paired-samples-dialog");
171 pda
->source
= get_widget_assert (xml
, "paired-samples-t-test-treeview1");
173 gtk_window_set_title (GTK_WINDOW (pda
->dialog
), _("Paired Samples T Test"));
175 act
->pairs_treeview
= get_widget_assert (xml
, "paired-samples-t-test-treeview2");
176 act
->list_store
= GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (act
->pairs_treeview
)));
178 act
->opt
= tt_options_dialog_create (GTK_WINDOW (pda
->toplevel
));
180 g_signal_connect_swapped (button
, "clicked", G_CALLBACK (tt_options_dialog_run
), act
->opt
);
183 gtk_box_pack_start (GTK_BOX (bb
), button
, TRUE
, TRUE
, 5);
184 gtk_box_pack_start (GTK_BOX (box
), bb
, FALSE
, FALSE
, 5);
185 gtk_widget_show_all (box
);
188 psppire_dialog_action_set_valid_predicate (pda
, dialog_state_valid
);
189 psppire_dialog_action_set_refresh (pda
, refresh
);
191 g_object_set (pda
->source
,
192 "predicate", var_is_numeric
,
195 psppire_selector_set_select_func (PSPPIRE_SELECTOR (selector
),
196 select_as_pair_member
,
200 if (PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_paired_parent_class
)->activate
)
201 PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_paired_parent_class
)->activate (pda
);
205 psppire_dialog_action_paired_finalize (GObject
*o
)
207 PsppireDialogActionPaired
*act
= PSPPIRE_DIALOG_ACTION_PAIRED (o
);
208 tt_options_dialog_destroy (act
->opt
);
212 psppire_dialog_action_paired_class_init (PsppireDialogActionPairedClass
*class)
214 GObjectClass
*object_class
= G_OBJECT_CLASS (class);
215 psppire_dialog_action_set_activation (class, psppire_dialog_action_paired_activate
);
216 PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax
= generate_syntax
;
218 object_class
->finalize
= psppire_dialog_action_paired_finalize
;
223 psppire_dialog_action_paired_init (PsppireDialogActionPaired
*act
)