1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 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/>. */
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"
33 #include "builder-wrapper.h"
38 #define _(msgid) gettext (msgid)
39 #define N_(msgid) msgid
50 PsppireDataWindow *de ;
55 static char * generate_syntax (const struct k_means *rd);
59 refresh (struct k_means *fd)
61 GtkTreeModel *liststore =
62 gtk_tree_view_get_model (GTK_TREE_VIEW (fd->variables));
63 gtk_list_store_clear (GTK_LIST_STORE (liststore));
65 gtk_entry_set_text (GTK_ENTRY (fd->entry), "");
70 dialog_state_valid (gpointer data)
72 struct k_means *fd = data;
74 GtkTreeModel *liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (fd->variables));
76 if (gtk_tree_model_iter_n_children (liststore, NULL) < 2)
79 if (atoi (gtk_entry_get_text (GTK_ENTRY (fd->entry))) < 2)
86 /* Pops up the K_Means dialog box */
88 k_means_dialog (PsppireDataWindow *dw)
98 fd.xml = builder_new ("k-means.ui");
100 dialog = get_widget_assert (fd.xml, "k-means-dialog");
101 source = get_widget_assert (fd.xml, "dict-view");
103 fd.entry = get_widget_assert (fd.xml, "entry1");
107 g_signal_connect_swapped (dialog, "refresh", G_CALLBACK (refresh), &fd);
110 fd.variables = get_widget_assert (fd.xml, "psppire-var-view1");
112 g_object_get (fd.de->data_editor, "var-store", &vs, NULL);
114 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (fd.de));
116 g_object_get (vs, "dictionary", &fd.dict, NULL);
117 g_object_set (source, "model", fd.dict,
118 "predicate", var_is_numeric,
121 psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog),
122 dialog_state_valid, &fd);
124 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
128 case GTK_RESPONSE_OK:
129 g_free (execute_syntax_string (dw, generate_syntax (&fd)));
131 case PSPPIRE_RESPONSE_PASTE:
132 g_free (paste_syntax_to_window (generate_syntax (&fd)));
138 g_object_unref (fd.xml);
145 generate_syntax (const struct k_means *km)
149 GString *string = g_string_new ("QUICK CLUSTER ");
151 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (km->variables), 0, string);
153 g_string_append_printf (string, "\n\t/CRITERIA=CLUSTERS(%d)",
154 atoi (gtk_entry_get_text (GTK_ENTRY (km->entry))));
156 g_string_append (string, ".\n");
160 g_string_free (string, FALSE);