1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2011 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/>. */
19 #include "dialog-common.h"
20 #include <ui/syntax-gen.h>
21 #include <libpspp/str.h>
23 #include "k-means-dialog.h"
24 #include "psppire-selector.h"
25 #include "psppire-dictview.h"
26 #include "psppire-dialog.h"
28 #include "psppire-data-window.h"
29 #include "psppire-var-view.h"
37 #define _(msgid) gettext (msgid)
38 #define N_(msgid) msgid
49 PsppireDataWindow *de ;
54 static char * generate_syntax (const struct k_means *rd);
58 refresh (struct k_means *fd)
60 GtkTreeModel *liststore =
61 gtk_tree_view_get_model (GTK_TREE_VIEW (fd->variables));
62 gtk_list_store_clear (GTK_LIST_STORE (liststore));
64 gtk_entry_set_text (GTK_ENTRY (fd->entry), "");
69 dialog_state_valid (gpointer data)
71 struct k_means *fd = data;
73 GtkTreeModel *liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (fd->variables));
75 if (gtk_tree_model_iter_n_children (liststore, NULL) < 2)
78 if (atoi (gtk_entry_get_text (GTK_ENTRY (fd->entry))) < 2)
85 /* Pops up the K_Means dialog box */
87 k_means_dialog (PsppireDataWindow *dw)
97 fd.xml = builder_new ("k-means.ui");
99 dialog = get_widget_assert (fd.xml, "k-means-dialog");
100 source = get_widget_assert (fd.xml, "dict-view");
102 fd.entry = get_widget_assert (fd.xml, "entry1");
106 g_signal_connect_swapped (dialog, "refresh", G_CALLBACK (refresh), &fd);
109 fd.variables = get_widget_assert (fd.xml, "psppire-var-view1");
111 g_object_get (fd.de->data_editor, "var-store", &vs, NULL);
113 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (fd.de));
115 g_object_get (vs, "dictionary", &fd.dict, NULL);
116 g_object_set (source, "model", fd.dict,
117 "predicate", var_is_numeric,
120 psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog),
121 dialog_state_valid, &fd);
123 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
127 case GTK_RESPONSE_OK:
128 g_free (execute_syntax_string (dw, generate_syntax (&fd)));
130 case PSPPIRE_RESPONSE_PASTE:
131 g_free (paste_syntax_to_window (generate_syntax (&fd)));
137 g_object_unref (fd.xml);
144 generate_syntax (const struct k_means *km)
148 GString *string = g_string_new ("QUICK CLUSTER ");
150 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (km->variables), 0, string);
152 g_string_append_printf (string, "\n\t/CRITERIA=CLUSTERS(%d)",
153 atoi (gtk_entry_get_text (GTK_ENTRY (km->entry))));
155 g_string_append (string, ".\n");
159 g_string_free (string, FALSE);