X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Fui%2Fgui%2Fselect-cases-dialog.c;h=c3bc123c051f2fd42cc8a121ba316056ee148706;hb=refs%2Fbuilds%2F20130214032106%2Fpspp;hp=599b212858aafe3a3438294665537736edd0836c;hpb=0bd0098aec2ee31d9460c8d4c1263d0b5ccc4324;p=pspp
diff --git a/src/ui/gui/select-cases-dialog.c b/src/ui/gui/select-cases-dialog.c
index 599b212858..c3bc123c05 100644
--- a/src/ui/gui/select-cases-dialog.c
+++ b/src/ui/gui/select-cases-dialog.c
@@ -1,35 +1,35 @@
-/*
- PSPPIRE --- A Graphical User Interface for PSPP
- Copyright (C) 2007 Free Software Foundation
+/* PSPPIRE - a graphical user interface for PSPP.
+ Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA. */
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see . */
#include
#include "select-cases-dialog.h"
#include
-#include
-#include "helper.h"
+#include "executor.h"
#include "psppire-dialog.h"
-#include "data-editor.h"
-#include "dialog-common.h"
+#include "psppire-data-window.h"
+#include "psppire-selector.h"
#include "dict-display.h"
+#include "dialog-common.h"
#include "widget-io.h"
-#include
-#include "syntax-editor.h"
+#include "psppire-scanf.h"
+#include "builder-wrapper.h"
+#include "helper.h"
+
+#include
#include
@@ -39,14 +39,13 @@
/* FIXME: These shouldn't be here */
-#include
#include "psppire-data-store.h"
struct select_cases_dialog
{
/* The XML that created the dialog */
- GladeXML *xml;
+ GtkBuilder *xml;
GtkWidget *spinbutton ;
GtkWidget *spinbutton1 ;
@@ -61,27 +60,6 @@ struct select_cases_dialog
static gchar * generate_syntax (const struct select_cases_dialog *scd);
-static void
-set_sensitivity_from_toggle (GtkToggleButton *togglebutton, gpointer data)
-{
- GtkWidget *w = data;
- gboolean active = gtk_toggle_button_get_active (togglebutton);
-
- gtk_widget_set_sensitive (w, active);
-}
-
-static void
-set_sensitivity_from_toggle_invert (GtkToggleButton *togglebutton,
- gpointer data)
-{
- GtkWidget *w = data;
- gboolean active = gtk_toggle_button_get_active (togglebutton);
-
- gtk_widget_set_sensitive (w, !active);
-}
-
-
-
static const gchar label1[]=N_("Approximately %3d%% of all cases.");
static const gchar label2[]=N_("Exactly %3d cases from the first %3d cases.");
@@ -107,14 +85,14 @@ sample_subdialog (GtkButton *b, gpointer data)
if ( ! scd->hbox1 )
{
- scd->hbox1 = widget_scanf (gettext (label1), &scd->spinbutton);
+ scd->hbox1 = psppire_scanf_new (gettext (label1), &scd->spinbutton);
gtk_widget_show (scd->hbox1);
gtk_table_attach_defaults (GTK_TABLE (table),
scd->hbox1, 1, 2, 0, 1);
- g_signal_connect (G_OBJECT (percent), "toggled",
+ g_signal_connect (percent, "toggled",
G_CALLBACK (set_sensitivity_from_toggle), scd->hbox1);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (percent), TRUE);
@@ -124,7 +102,7 @@ sample_subdialog (GtkButton *b, gpointer data)
if ( ! scd->hbox2 )
{
scd->hbox2 =
- widget_scanf (gettext (label2), &scd->spinbutton1, &scd->spinbutton2);
+ psppire_scanf_new (gettext (label2), &scd->spinbutton1, &scd->spinbutton2);
gtk_spin_button_set_range (GTK_SPIN_BUTTON (scd->spinbutton1),
1, case_count);
@@ -138,7 +116,7 @@ sample_subdialog (GtkButton *b, gpointer data)
gtk_table_attach_defaults (GTK_TABLE (table),
scd->hbox2, 1, 2, 1, 2);
- g_signal_connect (G_OBJECT (sample_n_cases), "toggled",
+ g_signal_connect (sample_n_cases, "toggled",
G_CALLBACK (set_sensitivity_from_toggle), scd->hbox2);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (sample_n_cases), FALSE);
@@ -209,9 +187,8 @@ range_subdialog (GtkButton *b, gpointer data)
"range-dialog-last");
- gtk_spin_button_set_range (GTK_SPIN_BUTTON (last), 1, n_cases);
-
- gtk_spin_button_set_range (GTK_SPIN_BUTTON (first), 1, n_cases);
+ gtk_spin_button_set_range (GTK_SPIN_BUTTON (last), 1, n_cases);
+ gtk_spin_button_set_range (GTK_SPIN_BUTTON (first), 1, n_cases);
gtk_window_set_transient_for (GTK_WINDOW (dialog),
GTK_WINDOW (parent_dialog));
@@ -240,25 +217,19 @@ set_radiobutton (GtkWidget *button, gpointer data)
/* Pops up the Select Cases dialog box */
void
-select_cases_dialog (GObject *o, gpointer data)
+select_cases_dialog (PsppireDataWindow *de)
{
gint response;
struct select_cases_dialog scd = {0,0,0,0,0,0};
GtkWidget *dialog ;
- struct data_editor *de = data;
GtkWidget *entry = NULL;
GtkWidget *selector ;
GtkWidget *button_range;
GtkWidget *button_sample;
- scd.xml = XML_NEW ("psppire.glade");
-
- {
- GtkSheet *data_sheet =
- GTK_SHEET (get_widget_assert (de->xml, "data_sheet"));
+ scd.xml = builder_new ("select-cases.ui");
- scd.data_store = PSPPIRE_DATA_STORE (gtk_sheet_get_model (data_sheet));
- }
+ g_object_get (de->data_editor, "data-store", &scd.data_store, NULL);
button_range = get_widget_assert (scd.xml, "button-range");
button_sample = get_widget_assert (scd.xml, "button-sample");
@@ -329,21 +300,18 @@ select_cases_dialog (GObject *o, gpointer data)
dialog = get_widget_assert (scd.xml, "select-cases-dialog");
- gtk_window_set_transient_for (GTK_WINDOW (dialog), de->parent.window);
+ gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de));
{
GtkWidget *source = get_widget_assert (scd.xml, "select-cases-treeview");
- attach_dictionary_to_treeview (GTK_TREE_VIEW (source),
- scd.data_store->dict,
- GTK_SELECTION_SINGLE, NULL);
+ g_object_set (source, "model",
+ scd.data_store->dict,
+ "selection-mode",
+ GTK_SELECTION_SINGLE, NULL);
- psppire_selector_set_subjects (PSPPIRE_SELECTOR (selector),
- source,
- entry,
- insert_source_row_into_entry,
- is_currently_in_entry,
- NULL);
+ psppire_selector_set_filter_func (PSPPIRE_SELECTOR (selector),
+ is_currently_in_entry);
}
@@ -361,25 +329,10 @@ select_cases_dialog (GObject *o, gpointer data)
switch (response)
{
case GTK_RESPONSE_OK:
- {
- gchar *syntax = generate_syntax (&scd);
- struct getl_interface *sss = create_syntax_string_source (syntax);
- execute_syntax (sss);
-
- g_free (syntax);
- }
+ g_free (execute_syntax_string (de, generate_syntax (&scd)));
break;
case PSPPIRE_RESPONSE_PASTE:
- {
- gchar *syntax = generate_syntax (&scd);
-
- struct syntax_editor *se =
- (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
-
- gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1);
-
- g_free (syntax);
- }
+ g_free (paste_syntax_to_window (generate_syntax (&scd)));
break;
default:
break;
@@ -390,19 +343,138 @@ select_cases_dialog (GObject *o, gpointer data)
static gchar *
-generate_syntax (const struct select_cases_dialog *scd)
+generate_syntax_filter (const struct select_cases_dialog *scd)
+{
+ gchar *text = NULL;
+ struct string dss;
+
+ const gchar *filter = "filter_$";
+ const gchar key[]="case_$";
+
+ ds_init_empty (&dss);
+
+ if (gtk_toggle_button_get_active
+ (GTK_TOGGLE_BUTTON (get_widget_assert (scd->xml,
+ "radiobutton-range"))))
+ {
+ GtkSpinButton *first =
+ GTK_SPIN_BUTTON (get_widget_assert (scd->xml,
+ "range-dialog-first"));
+
+ GtkSpinButton *last =
+ GTK_SPIN_BUTTON (get_widget_assert (scd->xml,
+ "range-dialog-last"));
+
+ ds_put_c_format (&dss,
+ "COMPUTE filter_$ = ($CASENUM >= %ld "
+ "AND $CASENUM <= %ld).\n",
+ (long) gtk_spin_button_get_value (first),
+ (long) gtk_spin_button_get_value (last)
+ );
+
+ ds_put_cstr (&dss, "EXECUTE.\n");
+ }
+ else if ( gtk_toggle_button_get_active
+ (GTK_TOGGLE_BUTTON (get_widget_assert (scd->xml,
+ "radiobutton-sample"))))
+ {
+ GtkWidget *random_sample =
+ get_widget_assert (scd->xml,
+ "radiobutton-sample-percent");
+
+ if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (random_sample)))
+ {
+ const double percentage =
+ gtk_spin_button_get_value (GTK_SPIN_BUTTON (scd->spinbutton));
+
+ ds_put_c_format (&dss,
+ "COMPUTE %s = RV.UNIFORM (0,1) < %g.\n",
+ filter,
+ percentage / 100.0 );
+ }
+ else
+ {
+ const gint n_cases =
+ gtk_spin_button_get_value (GTK_SPIN_BUTTON (scd->spinbutton1));
+ const gint from_n_cases =
+ gtk_spin_button_get_value (GTK_SPIN_BUTTON (scd->spinbutton2));
+
+
+ const gchar ranvar[]="rv_$";
+
+ ds_put_c_format (&dss,
+ "COMPUTE %s = $CASENUM.\n", key);
+
+ ds_put_c_format (&dss,
+ "COMPUTE %s = %s > %d.\n",
+ filter, key, from_n_cases);
+
+ ds_put_c_format (&dss,
+ "COMPUTE %s = RV.UNIFORM (0, 1).\n",
+ ranvar);
+
+ ds_put_c_format (&dss,
+ "SORT BY %s, %s.\n",
+ filter, ranvar);
+
+ ds_put_cstr (&dss, "EXECUTE.\n");
+
+
+ ds_put_c_format (&dss,
+ "COMPUTE %s = $CASENUM.\n",
+ filter );
+
+ ds_put_c_format (&dss,
+ "COMPUTE %s = %s <= %d\n",
+ filter,
+ filter,
+ n_cases );
+
+ ds_put_cstr (&dss, "EXECUTE.\n");
+
+
+ ds_put_c_format (&dss,
+ "SORT BY %s.\n",
+ key);
+
+ ds_put_c_format (&dss,
+ "DELETE VARIABLES %s, %s.\n",
+ key, ranvar);
+ }
+
+ ds_put_cstr (&dss, "EXECUTE.\n");
+ }
+ else
+ {
+ GtkEntry *entry =
+ GTK_ENTRY (get_widget_assert (scd->xml,
+ "filter-variable-entry"));
+ filter = gtk_entry_get_text (entry);
+ }
+
+ ds_put_c_format (&dss, "FILTER BY %s.\n", filter);
+
+ text = ds_steal_cstr (&dss);
+
+ ds_destroy (&dss);
+
+ return text;
+}
+
+static gchar *
+generate_syntax_delete (const struct select_cases_dialog *scd)
{
gchar *text = NULL;
- GString *string = NULL;
+ struct string dss;
if ( gtk_toggle_button_get_active
(GTK_TOGGLE_BUTTON (get_widget_assert (scd->xml,
"radiobutton-all"))))
{
- return strdup ("\n");
+ return xstrdup ("\n");
}
- string = g_string_new ("");
+ ds_init_empty (&dss);
if ( gtk_toggle_button_get_active
(GTK_TOGGLE_BUTTON (get_widget_assert (scd->xml,
@@ -412,13 +484,13 @@ generate_syntax (const struct select_cases_dialog *scd)
get_widget_assert (scd->xml,
"radiobutton-sample-percent");
- g_string_append (string, "SAMPLE ");
+ ds_put_cstr (&dss, "SAMPLE ");
if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (random_sample)))
{
const double percentage =
gtk_spin_button_get_value (GTK_SPIN_BUTTON (scd->spinbutton));
- g_string_append_printf (string, "%g.", percentage / 100.0);
+ ds_put_c_format (&dss, "%g.", percentage / 100.0);
}
else
{
@@ -427,7 +499,7 @@ generate_syntax (const struct select_cases_dialog *scd)
const gint from_n_cases =
gtk_spin_button_get_value (GTK_SPIN_BUTTON (scd->spinbutton2));
- g_string_append_printf (string, "%d FROM %d .", n_cases, from_n_cases);
+ ds_put_c_format (&dss, "%d FROM %d .", n_cases, from_n_cases);
}
}
@@ -443,14 +515,14 @@ generate_syntax (const struct select_cases_dialog *scd)
GTK_SPIN_BUTTON (get_widget_assert (scd->xml,
"range-dialog-last"));
- g_string_append_printf (string,
+ ds_put_c_format (&dss,
"COMPUTE filter_$ = ($CASENUM >= %ld "
"AND $CASENUM <= %ld).\n",
(long) gtk_spin_button_get_value (first),
(long) gtk_spin_button_get_value (last)
);
- g_string_append (string, "EXECUTE.\n");
- g_string_append_printf (string, "SELECT IF filter_$.\n");
+ ds_put_cstr (&dss, "EXECUTE.\n");
+ ds_put_c_format (&dss, "SELECT IF filter_$.\n");
}
else if ( gtk_toggle_button_get_active
@@ -462,12 +534,31 @@ generate_syntax (const struct select_cases_dialog *scd)
GTK_ENTRY (get_widget_assert (scd->xml,
"filter-variable-entry"));
- g_string_append_printf (string, "SELECT IF (%s <> 0).",
+ ds_put_c_format (&dss, "SELECT IF (%s <> 0).",
gtk_entry_get_text (entry));
}
- g_string_append (string, "\n");
+ ds_put_cstr (&dss, "\n");
+
+ text = ds_steal_cstr (&dss);
+
+ ds_destroy (&dss);
+
+ return text;
+}
+
+
+static gchar *
+generate_syntax (const struct select_cases_dialog *scd)
+{
+ /* In the simple case, all we need to do is cancel any existing filter */
+ if ( gtk_toggle_button_get_active
+ (GTK_TOGGLE_BUTTON (get_widget_assert (scd->xml,
+ "radiobutton-all"))))
+ {
+ return g_strdup ("FILTER OFF.\n");
+ }
/* Are we filtering or deleting ? */
@@ -475,18 +566,14 @@ generate_syntax (const struct select_cases_dialog *scd)
(GTK_TOGGLE_BUTTON (get_widget_assert (scd->xml,
"radiobutton-delete"))))
{
- g_string_append (string, "EXECUTE.\n");
-
- if ( gtk_toggle_button_get_active
- (GTK_TOGGLE_BUTTON (get_widget_assert (scd->xml,
- "radiobutton-range"))))
- {
- g_string_append (string, "DELETE VARIABLES filter_$.\n");
- }
+ return generate_syntax_delete (scd);
+ }
+ else
+ {
+ return generate_syntax_filter (scd);
}
-
- text = string->str;
- g_string_free (string, FALSE);
- return text;
}
+
+
+