1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2012 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-means.h"
22 #include "psppire-means-layer.h"
24 #include "psppire-var-view.h"
25 #include "psppire-dict.h"
26 #include "psppire-dialog.h"
27 #include "builder-wrapper.h"
30 #define _(msgid) gettext (msgid)
31 #define N_(msgid) msgid
33 static void psppire_dialog_action_means_class_init (PsppireDialogActionMeansClass *class);
35 G_DEFINE_TYPE (PsppireDialogActionMeans, psppire_dialog_action_means, PSPPIRE_TYPE_DIALOG_ACTION);
39 generate_syntax (PsppireDialogAction *act)
42 PsppireDialogActionMeans *scd = PSPPIRE_DIALOG_ACTION_MEANS (act);
44 GString *string = g_string_new ("MEANS TABLES = ");
45 PsppireMeansLayer *layer = PSPPIRE_MEANS_LAYER (scd->layer);
46 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (scd->variables), 0, string);
48 for (l = 0; l < layer->n_layers; ++l)
52 PsppireVarView *vv = PSPPIRE_VAR_VIEW (layer->var_view);
53 psppire_var_view_set_current_model (vv, l);
54 g_string_append (string, "\n\tBY");
55 for (ok = psppire_var_view_get_iter_first (vv, &iter);
57 ok = psppire_var_view_get_iter_next (vv, &iter))
59 const struct variable *var = psppire_var_view_get_variable (vv, 0, &iter);
60 g_string_append (string, " ");
61 g_string_append (string, var_get_name (var));
65 g_string_append (string, ".");
68 g_string_free (string, FALSE);
74 dialog_state_valid (PsppireDialogAction *da)
76 PsppireDialogActionMeans *pdm = PSPPIRE_DIALOG_ACTION_MEANS (da);
79 gtk_tree_view_get_model (GTK_TREE_VIEW (pdm->variables));
81 return gtk_tree_model_get_iter_first (vars, ¬used);
85 dialog_refresh (PsppireDialogAction *da)
87 PsppireDialogActionMeans *pdm = PSPPIRE_DIALOG_ACTION_MEANS (da);
88 GtkTreeModel *liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (pdm->variables));
90 gtk_list_store_clear (GTK_LIST_STORE (liststore));
92 psppire_means_layer_clear (PSPPIRE_MEANS_LAYER (pdm->layer));
96 psppire_dialog_action_means_activate (GtkAction *a)
98 PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
99 PsppireDialogActionMeans *act = PSPPIRE_DIALOG_ACTION_MEANS (a);
101 GtkBuilder *xml = builder_new ("means.ui");
103 GtkWidget *vb = get_widget_assert (xml, "alignment3");
104 act->layer = psppire_means_layer_new ();
105 gtk_container_add (GTK_CONTAINER (vb), act->layer);
106 gtk_widget_show (act->layer);
108 pda->dialog = get_widget_assert (xml, "means-dialog");
109 pda->source = get_widget_assert (xml, "all-variables");
110 act->variables = get_widget_assert (xml, "stat-variables");
112 g_object_set (pda->source,
114 "predicate", var_is_numeric,
117 psppire_means_layer_set_source (PSPPIRE_MEANS_LAYER (act->layer), pda->source);
119 psppire_dialog_action_set_valid_predicate (pda, (void *) dialog_state_valid);
120 psppire_dialog_action_set_refresh (pda, dialog_refresh);
122 PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_means_parent_class)->activate (pda);
124 g_object_unref (xml);
128 psppire_dialog_action_means_class_init (PsppireDialogActionMeansClass *class)
130 GTK_ACTION_CLASS (class)->activate = psppire_dialog_action_means_activate;
132 PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax;
136 psppire_dialog_action_means_init (PsppireDialogActionMeans *act)