]> saetta.ns0.it Git - libgdaex/commitdiff
Adjustments.
authorAndrea Zagli <azagli@libero.it>
Sat, 4 Jun 2011 09:42:09 +0000 (11:42 +0200)
committerAndrea Zagli <azagli@libero.it>
Sat, 4 Jun 2011 09:42:09 +0000 (11:42 +0200)
src/grid.c
src/gridcolumn.c
tests/grid.c
tests/grid.db

index 247787b8458c02f29efccc6959860ce426e57793..57736188f2c70448d1ae33784c7fcd1e662b9c14 100644 (file)
@@ -307,6 +307,7 @@ static GtkTreeModel
 
        guint col;
        GType *gtype;
+       GType col_gtype;
 
        g_return_val_if_fail (GDAEX_IS_GRID (grid), NULL);
 
@@ -316,7 +317,21 @@ static GtkTreeModel
 
        for (col = 0; col < priv->columns->len; col++)
                {
-                       gtype[col] = gdaex_grid_column_get_gtype ((GdaExGridColumn *)g_ptr_array_index (priv->columns, col));
+                       col_gtype = gdaex_grid_column_get_gtype ((GdaExGridColumn *)g_ptr_array_index (priv->columns, col));
+                       if (col_gtype == G_TYPE_DATE
+                           || col_gtype == G_TYPE_DATE_TIME
+                           || col_gtype == GDA_TYPE_TIMESTAMP
+                           || ((col_gtype == G_TYPE_INT
+                                || col_gtype == G_TYPE_FLOAT
+                                || col_gtype == G_TYPE_DOUBLE)
+                               && gdaex_grid_column_get_decimals ((GdaExGridColumn *)g_ptr_array_index (priv->columns, col)) > -1))
+                               {
+                                       gtype[col] = G_TYPE_STRING;
+                               }
+                       else
+                               {
+                                       gtype[col] = col_gtype;
+                               }
                }
 
        if (priv->model != NULL)
index 295c7587c4e54aefec94e90315d61bca12c699f7..75a9532d980546cebf980c997e639826c64227d7 100644 (file)
@@ -297,7 +297,14 @@ GtkTreeViewColumn
            || priv->type == G_TYPE_FLOAT
            || priv->type == G_TYPE_DOUBLE)
                {
-                       renderer = gtk_cell_renderer_spin_new ();
+                       if (priv->decimals > -1)
+                               {
+                                       renderer = gtk_cell_renderer_text_new ();
+                               }
+                       else
+                               {
+                                       renderer = gtk_cell_renderer_spin_new ();
+                               }
                        gtk_cell_renderer_set_alignment (renderer, 1.0, 0.5);
                }
        else
index b7a8b95f10d7a949898f2f4c24e6c495d53b04b5..ea5ed43ca51d86eecb8cc43795f65c1b6c0ec1a7 100644 (file)
@@ -24,6 +24,7 @@ main (int argc, char **argv)
        GdaEx *gdaex;
 
        GtkWidget *w;
+       GtkWidget *scrolledw;
 
        GdaExGrid *grid;
        GdaExGridColumn *gcol;
@@ -38,26 +39,33 @@ main (int argc, char **argv)
                }
 
        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);
 
        grid = gdaex_grid_new ();
 
-       gcol = gdaex_grid_column_new ("ID", "id", G_TYPE_INT, TRUE, FALSE, FALSE, FALSE, 0);
+       gcol = gdaex_grid_column_new ("ID", "id", G_TYPE_INT, TRUE, FALSE, FALSE, FALSE, -1);
+       gdaex_grid_add_column (grid, gcol);
+
+       gcol = gdaex_grid_column_new ("Name", "name", G_TYPE_STRING, TRUE, TRUE, TRUE, TRUE, -1);
        gdaex_grid_add_column (grid, gcol);
 
-       gcol = gdaex_grid_column_new ("Name", "name", G_TYPE_STRING, TRUE, TRUE, TRUE, TRUE, 0);
+       gcol = gdaex_grid_column_new ("Surname", "surname", G_TYPE_STRING, TRUE, TRUE, TRUE, TRUE, -1);
        gdaex_grid_add_column (grid, gcol);
 
-       gcol = gdaex_grid_column_new ("Surname", "surname", G_TYPE_STRING, TRUE, TRUE, TRUE, TRUE, 0);
+       gcol = gdaex_grid_column_new ("Age", "age", G_TYPE_INT, TRUE, TRUE, TRUE, TRUE, -1);
        gdaex_grid_add_column (grid, gcol);
 
-       gcol = gdaex_grid_column_new ("Age", "age", G_TYPE_INT, TRUE, TRUE, TRUE, TRUE, 0);
+       gcol = gdaex_grid_column_new ("Birthday", "birthday", G_TYPE_DATE, TRUE, TRUE, TRUE, TRUE, -1);
        gdaex_grid_add_column (grid, gcol);
 
-       gcol = gdaex_grid_column_new ("Birthday", "birthday", G_TYPE_DATE, TRUE, TRUE, TRUE, TRUE, 0);
+       gcol = gdaex_grid_column_new ("Incoming", "incoming", G_TYPE_DOUBLE, TRUE, TRUE, TRUE, TRUE, 2);
        gdaex_grid_add_column (grid, gcol);
 
        wgrid = gdaex_grid_get_widget (grid);
-       gtk_container_add (GTK_CONTAINER (w), wgrid);
+       gtk_container_add (GTK_CONTAINER (scrolledw), wgrid);
 
        gdaex_grid_fill_from_sql (grid, gdaex, "SELECT * FROM clients", NULL);
 
index d9dad15c6e045f67553c625c312758684abf33de..fd7f26f57a8b4a933d3ab3ae7167e3402f3768a8 100644 (file)
Binary files a/tests/grid.db and b/tests/grid.db differ