GtkTreeModel *model;
GdaExGridColumn *gcolumn;
+ GtkTreeViewColumn *vcolumn;
+
+ GList *cells;
guint col;
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);
+ }
}
}
#include <config.h>
#endif
+#include <libgda/libgda.h>
+
#include "gridcolumn.h"
static void gdaex_grid_column_class_init (GdaExGridColumnClass *klass);
gboolean sortable;
gboolean reorderable;
guint decimals;
+
+ GtkTreeViewColumn *vcolumn;
};
G_DEFINE_TYPE (GdaExGridColumn, gdaex_grid_column, G_TYPE_OBJECT)
priv->resizable = FALSE;
priv->sortable = FALSE;
priv->reorderable = FALSE;
- priv->decimals = 0;
+ priv->decimals = -1;
}
GdaExGridColumn
}
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;
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 */
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)
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)
int
main (int argc, char **argv)
{
+ GdaEx *gdaex;
+ GdaDataModel *dm;
+
GtkWidget *w;
GdaExGrid *grid;
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 ();
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 ();