]> saetta.ns0.it Git - libgdaex/commitdiff
Adjustments.
authorAndrea Zagli <azagli@libero.it>
Sat, 4 Jun 2011 08:43:56 +0000 (10:43 +0200)
committerAndrea Zagli <azagli@libero.it>
Sat, 4 Jun 2011 08:43:56 +0000 (10:43 +0200)
src/grid.c
src/gridcolumn.c
src/gridcolumn.h
tests/Makefile.am
tests/grid.c
tests/grid.db [new file with mode: 0644]

index 55ea846cb570e96b444a459dba6720e4400cee1b..8127bf2b28670f74dd84be648be8e67572ce3eba 100644 (file)
@@ -207,6 +207,9 @@ static GtkTreeView
 
        GtkTreeModel *model;
        GdaExGridColumn *gcolumn;
+       GtkTreeViewColumn *vcolumn;
+
+       GList *cells;
 
        guint col;
 
@@ -222,7 +225,15 @@ static GtkTreeView
                        gcolumn = (GdaExGridColumn *)g_ptr_array_index (priv->columns, col);
                        if (gdaex_grid_column_get_visible (gcolumn))
                                {
-                                       gtk_tree_view_append_column (GTK_TREE_VIEW (view), gdaex_grid_column_get_column (gcolumn, col));
+                                       vcolumn = gdaex_grid_column_get_column (gcolumn);
+                                       if (vcolumn)
+                                               {
+                                                       cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (vcolumn));
+                                                       cells = g_list_first (cells);
+                                                       gtk_tree_view_column_add_attribute (vcolumn, (GtkCellRenderer *)cells->data, "text", col);
+
+                                                       gtk_tree_view_append_column (GTK_TREE_VIEW (view), vcolumn);
+                                               }
                                }
                }
 
index c9d51fc3c054ed3b4893d3307ff5e7aa1978f1ee..2a6c104c945b3c8eebf3e9a86fe3a6cd5cc78b7d 100644 (file)
@@ -25,6 +25,8 @@
        #include <config.h>
 #endif
 
+#include <libgda/libgda.h>
+
 #include "gridcolumn.h"
 
 static void gdaex_grid_column_class_init (GdaExGridColumnClass *klass);
@@ -52,6 +54,8 @@ struct _GdaExGridColumnPrivate
                gboolean sortable;
                gboolean reorderable;
                guint decimals;
+
+               GtkTreeViewColumn *vcolumn;
        };
 
 G_DEFINE_TYPE (GdaExGridColumn, gdaex_grid_column, G_TYPE_OBJECT)
@@ -79,7 +83,7 @@ gdaex_grid_column_init (GdaExGridColumn *gdaex_grid_column)
        priv->resizable = FALSE;
        priv->sortable = FALSE;
        priv->reorderable = FALSE;
-       priv->decimals = 0;
+       priv->decimals = -1;
 }
 
 GdaExGridColumn
@@ -271,10 +275,8 @@ gdaex_grid_column_get_decimals (GdaExGridColumn *column)
 }
 
 GtkTreeViewColumn
-*gdaex_grid_column_get_column (GdaExGridColumn *column, gint model_column_number)
+*gdaex_grid_column_get_column (GdaExGridColumn *column)
 {
-       GtkTreeViewColumn *col;
-
        GdaExGridColumnPrivate *priv;
 
        GtkCellRenderer *renderer;
@@ -284,36 +286,39 @@ GtkTreeViewColumn
        priv = GDAEX_GRID_COLUMN_GET_PRIVATE (column);
 
        renderer = NULL;
-       switch (priv->type)
+       if (priv->type == G_TYPE_STRING
+           || priv->type == G_TYPE_DATE
+           || priv->type == G_TYPE_DATE_TIME
+           || priv->type == GDA_TYPE_TIMESTAMP)
                {
-                       case G_TYPE_STRING:
-                               renderer = gtk_cell_renderer_text_new ();
-                               break;
-
-                       case G_TYPE_INT:
-                       case G_TYPE_FLOAT:
-                       case G_TYPE_DOUBLE:
-                               renderer = gtk_cell_renderer_spin_new ();
-                               break;
+                       renderer = gtk_cell_renderer_text_new ();
                }
-       if (renderer == NULL)
+       else if (priv->type == G_TYPE_INT
+           || priv->type == G_TYPE_FLOAT
+           || priv->type == G_TYPE_DOUBLE)
                {
-                       g_warning ("Error on creating the renderer.");
+                       renderer = gtk_cell_renderer_spin_new ();
+               }
+       else
+               {
+                       g_warning ("Error on creating the renderer for column «%s».", priv->title);
                        return NULL;
                }
 
-       col = gtk_tree_view_column_new ();
-
-       gtk_tree_view_column_pack_start (col, renderer, TRUE);
+       if (priv->vcolumn != NULL)
+               {
+                       g_object_unref (priv->vcolumn);
+               }
+       priv->vcolumn = gtk_tree_view_column_new ();
 
-       gtk_tree_view_column_add_attribute (col, renderer, "text", model_column_number);
+       gtk_tree_view_column_pack_start (priv->vcolumn, renderer, TRUE);
 
-       gtk_tree_view_column_set_title (col, priv->title);
-       gtk_tree_view_column_set_resizable (col, priv->resizable);
-       gtk_tree_view_column_set_clickable (col, priv->sortable);
-       gtk_tree_view_column_set_reorderable (col, priv->reorderable);
+       gtk_tree_view_column_set_title (priv->vcolumn, priv->title);
+       gtk_tree_view_column_set_resizable (priv->vcolumn, priv->resizable);
+       gtk_tree_view_column_set_clickable (priv->vcolumn, priv->sortable);
+       gtk_tree_view_column_set_reorderable (priv->vcolumn, priv->reorderable);
 
-       return col;
+       return priv->vcolumn;
 }
 
 /* PRIVATE */
@@ -321,7 +326,6 @@ static void
 gdaex_grid_column_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
 {
        GdaExGridColumn *gdaex_grid_column = GDAEX_GRID_COLUMN (object);
-
        GdaExGridColumnPrivate *priv = GDAEX_GRID_COLUMN_GET_PRIVATE (gdaex_grid_column);
 
        switch (property_id)
@@ -336,7 +340,6 @@ static void
 gdaex_grid_column_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
 {
        GdaExGridColumn *gdaex_grid_column = GDAEX_GRID_COLUMN (object);
-
        GdaExGridColumnPrivate *priv = GDAEX_GRID_COLUMN_GET_PRIVATE (gdaex_grid_column);
 
        switch (property_id)
index fa2acb17881d954c62a82ef6eede8c7e19569ada..7703bfc14cabc87e64e8741ba6a69856ea00546b 100644 (file)
@@ -89,7 +89,7 @@ gboolean gdaex_grid_column_get_reorderable (GdaExGridColumn *column);
 void gdaex_grid_column_set_decimals (GdaExGridColumn *column, guint decimals);
 guint gdaex_grid_column_get_decimals (GdaExGridColumn *column);
 
-GtkTreeViewColumn *gdaex_grid_column_get_column (GdaExGridColumn *column, gint model_column_number);
+GtkTreeViewColumn *gdaex_grid_column_get_column (GdaExGridColumn *column);
 
 
 G_END_DECLS
index 0d65354418288b65c8f0c16c8c086fa3c59b69aa..8081d400d8109ccd344767b36574993f61756869 100644 (file)
@@ -10,4 +10,5 @@ noinst_PROGRAMS = test_prefix \
 
 LDADD = $(top_builddir)/src/libgdaex.la
 
-EXTRA_DIST = test_prefix.db
+EXTRA_DIST = test_prefix.db \
+             grid.db
index 775c13e05006f568ec9c22576cc554a12a426b74..e072c97bb398f787a8d892f6c5d13eb14ce51c9c 100644 (file)
@@ -21,6 +21,9 @@
 int
 main (int argc, char **argv)
 {
+       GdaEx *gdaex;
+       GdaDataModel *dm;
+
        GtkWidget *w;
 
        GdaExGrid *grid;
@@ -29,6 +32,12 @@ main (int argc, char **argv)
 
        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);
 
        grid = gdaex_grid_new ();
@@ -39,9 +48,20 @@ main (int argc, char **argv)
        gcol = gdaex_grid_column_new ("Name", "name", G_TYPE_STRING, TRUE, TRUE, TRUE, TRUE, 0);
        gdaex_grid_add_column (grid, gcol);
 
+       gcol = gdaex_grid_column_new ("Surname", "surname", G_TYPE_STRING, TRUE, TRUE, TRUE, TRUE, 0);
+       gdaex_grid_add_column (grid, gcol);
+
+       gcol = gdaex_grid_column_new ("Age", "age", G_TYPE_INT, TRUE, TRUE, TRUE, TRUE, 0);
+       gdaex_grid_add_column (grid, gcol);
+
+       gcol = gdaex_grid_column_new ("Birthday", "birthday", G_TYPE_DATE, TRUE, TRUE, TRUE, TRUE, 0);
+       gdaex_grid_add_column (grid, gcol);
+
        wgrid = gdaex_grid_get_widget (grid);
        gtk_container_add (GTK_CONTAINER (w), wgrid);
 
+       dm = gdaex_query (gdaex, "SELECT * FROM clients");
+
        gtk_widget_show_all (w);
 
        gtk_main ();
diff --git a/tests/grid.db b/tests/grid.db
new file mode 100644 (file)
index 0000000..d9dad15
Binary files /dev/null and b/tests/grid.db differ