1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2008, 2010, 2011, 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-logistic.h"
21 #include "psppire-value-entry.h"
23 #include "dialog-common.h"
25 #include <ui/syntax-gen.h>
26 #include "psppire-var-view.h"
28 #include "psppire-dialog.h"
29 #include "builder-wrapper.h"
30 #include "checkbox-treeview.h"
31 #include "psppire-dict.h"
32 #include "libpspp/str.h"
35 #define _(msgid) gettext (msgid)
36 #define N_(msgid) msgid
40 psppire_dialog_action_logistic_class_init (PsppireDialogActionLogisticClass *class);
42 G_DEFINE_TYPE (PsppireDialogActionLogistic, psppire_dialog_action_logistic, PSPPIRE_TYPE_DIALOG_ACTION);
45 dialog_state_valid (gpointer data)
47 PsppireDialogActionLogistic *rd = PSPPIRE_DIALOG_ACTION_LOGISTIC (data);
49 const gchar *text = gtk_entry_get_text (GTK_ENTRY (rd->dep_var));
51 GtkTreeModel *indep_vars = gtk_tree_view_get_model (GTK_TREE_VIEW (rd->indep_vars));
55 return 0 != strcmp ("", text) &&
56 gtk_tree_model_get_iter_first (indep_vars, ¬used);
60 refresh (PsppireDialogAction *rd_)
62 PsppireDialogActionLogistic *rd = PSPPIRE_DIALOG_ACTION_LOGISTIC (rd_);
64 GtkTreeModel *liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (rd->indep_vars));
65 gtk_list_store_clear (GTK_LIST_STORE (liststore));
67 gtk_entry_set_text (GTK_ENTRY (rd->dep_var), "");
72 psppire_dialog_action_logistic_activate (GtkAction *a)
74 PsppireDialogActionLogistic *act = PSPPIRE_DIALOG_ACTION_LOGISTIC (a);
75 PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
77 GtkBuilder *xml = builder_new ("logistic.ui");
79 pda->dialog = get_widget_assert (xml, "logistic-dialog");
80 pda->source = get_widget_assert (xml, "dict-view");
82 act->dep_var = get_widget_assert (xml, "dependent-entry");
83 act->indep_vars = get_widget_assert (xml, "indep-view");
87 psppire_dialog_action_set_refresh (pda, refresh);
89 psppire_dialog_action_set_valid_predicate (pda,
92 if (PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_logistic_parent_class)->activate)
93 PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_logistic_parent_class)->activate (pda);
99 generate_syntax (PsppireDialogAction *a)
101 PsppireDialogActionLogistic *rd = PSPPIRE_DIALOG_ACTION_LOGISTIC (a);
104 GString *string = g_string_new ("LOGISTIC REGRESSION ");
106 const gchar *dep = gtk_entry_get_text (GTK_ENTRY (rd->dep_var));
108 g_string_append (string, dep);
110 g_string_append (string, " WITH ");
112 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (rd->indep_vars), 0, string);
114 g_string_append (string, ".\n");
118 g_string_free (string, FALSE);
124 psppire_dialog_action_logistic_class_init (PsppireDialogActionLogisticClass *class)
126 GtkActionClass *action_class = GTK_ACTION_CLASS (class);
128 action_class->activate = psppire_dialog_action_logistic_activate;
130 PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax;
135 psppire_dialog_action_logistic_init (PsppireDialogActionLogistic *act)