]> saetta.ns0.it Git - libgdaex/commitdiff
Bugfix on GdaEx::fill_liststore_from_* for int columns (fixes #223).
authorAndrea Zagli <azagli@libero.it>
Sat, 26 Nov 2011 10:20:45 +0000 (11:20 +0100)
committerAndrea Zagli <azagli@libero.it>
Sat, 26 Nov 2011 10:20:45 +0000 (11:20 +0100)
Added test for GdaEx::fill_liststore_from_*.

.anjuta_sym_db.db
.gitignore
src/gdaex.c
tests/Makefile.am
tests/fill_liststore.c [new file with mode: 0644]

index 60e368aaf52e5dbfba6aa892abae85b7cd99af56..84813a4956c312985bff0e78edeaf4557bb24c37 100644 (file)
Binary files a/.anjuta_sym_db.db and b/.anjuta_sym_db.db differ
index 97f9e2f777c61c212903cdcba8f15f654eda8aee..7c0a49ccbd43f2bf9f24133a16c6229c64ef08ad 100644 (file)
@@ -41,5 +41,6 @@ libgdaex*tar*
 tests/test_prefix*
 tests/query_editor
 tests/grid
+tests/fill_liststore
 tests/*.exe
 tests/select
index 867cf3de70c5dc684aa0c048d47f2062e90c5781..39bce68d2c6d766fdc6fb606b5c91df5ae4006c7 100644 (file)
@@ -2785,6 +2785,7 @@ gdaex_fill_liststore_from_datamodel (GdaEx *gdaex,
        gint *columns;
        GValue *values;
 
+       gint ival;
        gdouble dval;
        GDateTime *gdatetime;
 
@@ -2834,6 +2835,10 @@ gdaex_fill_liststore_from_datamodel (GdaEx *gdaex,
                                                                                        break;
 
                                                                                case G_TYPE_INT:
+                                                                                       ival = gdaex_data_model_iter_get_value_integer_at (gda_iter, col);
+                                                                                       g_value_set_string (&gval, gdaex_format_money ((gdouble)ival, 0, FALSE));
+                                                                                       break;
+
                                                                                case G_TYPE_FLOAT:
                                                                                case G_TYPE_DOUBLE:
                                                                                        dval = gdaex_data_model_iter_get_value_double_at (gda_iter, col);
index 325b705c2756fa7252ac1ec9ecb39b72d3386760..90578faf903939cb815e86355cb0f0d33bdc6f79 100644 (file)
@@ -5,7 +5,8 @@ AM_CPPFLAGS = $(GDAEX_CFLAGS) \
               -I$(top_srcdir)/src \
               -DTESTSDIR="\"@abs_builddir@\""
 
-noinst_PROGRAMS = grid \
+noinst_PROGRAMS = fill_liststore \
+                  grid \
                   query_editor \
                   select \
                   test_prefix
diff --git a/tests/fill_liststore.c b/tests/fill_liststore.c
new file mode 100644 (file)
index 0000000..214d1e6
--- /dev/null
@@ -0,0 +1,121 @@
+/*
+ * Copyright (C) 2011 Andrea Zagli <azagli@libero.it>
+ *
+ *  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 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <gtk/gtk.h>
+#include <libgdaex.h>
+
+int
+main (int argc, char **argv)
+{
+       GtkWidget *w;
+       GtkWidget *scrolledw;
+       GtkListStore *lstore;
+       GtkWidget *tview;
+       GtkTreeViewColumn *column;
+       GtkCellRenderer *renderer;
+
+       GdaEx *gdaex;
+
+       gchar *sql;
+
+       gtk_init (&argc, &argv);
+
+       gdaex = gdaex_new_from_string (g_strdup_printf ("SQLite://DB_DIR=%s;DB_NAME=grid.db", TESTSDIR));
+       if (gdaex == NULL)
+               {
+                       g_error ("Unable to connect to the db.");
+               }
+
+       w = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+       gtk_window_set_default_size (GTK_WINDOW (w), 550, 350);
+
+       scrolledw = gtk_scrolled_window_new (NULL, NULL);
+       gtk_container_add (GTK_CONTAINER (w), scrolledw);
+
+       lstore = gtk_list_store_new (7,
+                                    G_TYPE_STRING,
+                                    G_TYPE_STRING,
+                                    G_TYPE_STRING,
+                                    G_TYPE_STRING,
+                                    G_TYPE_STRING,
+                                    G_TYPE_STRING,
+                                    G_TYPE_STRING);
+
+       tview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (lstore));
+
+       renderer = gtk_cell_renderer_text_new ();
+       column = gtk_tree_view_column_new_with_attributes ("ID",
+                                                          renderer,
+                                                          "text", 0,
+                                                          NULL);
+       gtk_tree_view_append_column (GTK_TREE_VIEW (tview), column);
+
+       renderer = gtk_cell_renderer_text_new ();
+       column = gtk_tree_view_column_new_with_attributes ("Name",
+                                                          renderer,
+                                                          "text", 1,
+                                                          NULL);
+       gtk_tree_view_append_column (GTK_TREE_VIEW (tview), column);
+
+       renderer = gtk_cell_renderer_text_new ();
+       column = gtk_tree_view_column_new_with_attributes ("Surname",
+                                                          renderer,
+                                                          "text", 2,
+                                                          NULL);
+       gtk_tree_view_append_column (GTK_TREE_VIEW (tview), column);
+
+       renderer = gtk_cell_renderer_text_new ();
+       column = gtk_tree_view_column_new_with_attributes ("Age",
+                                                          renderer,
+                                                          "text", 3,
+                                                          NULL);
+       gtk_tree_view_append_column (GTK_TREE_VIEW (tview), column);
+
+       renderer = gtk_cell_renderer_text_new ();
+       column = gtk_tree_view_column_new_with_attributes ("Birthday",
+                                                          renderer,
+                                                          "text", 4,
+                                                          NULL);
+       gtk_tree_view_append_column (GTK_TREE_VIEW (tview), column);
+
+       renderer = gtk_cell_renderer_text_new ();
+       column = gtk_tree_view_column_new_with_attributes ("Incoming",
+                                                          renderer,
+                                                          "text", 5,
+                                                          NULL);
+       gtk_tree_view_append_column (GTK_TREE_VIEW (tview), column);
+
+       renderer = gtk_cell_renderer_text_new ();
+       column = gtk_tree_view_column_new_with_attributes ("Married",
+                                                          renderer,
+                                                          "text", 6,
+                                                          NULL);
+       gtk_tree_view_append_column (GTK_TREE_VIEW (tview), column);
+
+       sql = g_strdup_printf ("SELECT * FROM clients");
+       gdaex_fill_liststore_from_sql (gdaex, lstore, sql, NULL, NULL);
+       g_free (sql);
+
+       gtk_container_add (GTK_CONTAINER (scrolledw), tview);
+
+       gtk_widget_show_all (w);
+
+       gtk_main ();
+
+       return 0;
+}