From e0443c4909cd2a33c67d570de19d85ec25fdfd5e Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sun, 27 Feb 2011 10:43:01 +0100 Subject: [PATCH] Start filling tables/fields store. --- data/libgdaex/gui/libgdaex.ui | 19 ++++---- src/queryeditor.c | 89 +++++++++++++++++++++++++++++++---- src/queryeditor.h | 1 + tests/query_editor.c | 37 ++++++++++++++- 4 files changed, 128 insertions(+), 18 deletions(-) diff --git a/data/libgdaex/gui/libgdaex.ui b/data/libgdaex/gui/libgdaex.ui index 43599b9..bac8475 100644 --- a/data/libgdaex/gui/libgdaex.ui +++ b/data/libgdaex/gui/libgdaex.ui @@ -2,14 +2,6 @@ - - - - - - - - @@ -46,6 +38,16 @@ + + + + + + + + + + 5 Query Editor @@ -77,6 +79,7 @@ True True tstore_fields + 2 Fields diff --git a/src/queryeditor.c b/src/queryeditor.c index d37e65b..eed4f21 100644 --- a/src/queryeditor.c +++ b/src/queryeditor.c @@ -22,6 +22,13 @@ #include "queryeditor.h" +typedef struct + { + gchar *name; + gchar *name_visible; + GHashTable *fields; /* GdaExQueryEditorField */ + } GdaExQueryEditorTable; + static void gdaex_query_editor_class_init (GdaExQueryEditorClass *class); static void gdaex_query_editor_init (GdaExQueryEditor *gdaex_query_editor); @@ -34,17 +41,13 @@ static void gdaex_query_editor_get_property (GObject *object, GValue *value, GParamSpec *pspec); -static void gdaex_query_editor_build_ui (GdaExQueryEditor *qe); +static void gdaex_query_editor_refresh_gui (GdaExQueryEditor *qe); +static void gdaex_query_editor_refresh_gui_add_fields (GdaExQueryEditor *qe, + GdaExQueryEditorTable *table, + GtkTreeIter *iter_parent); #define GDAEX_QUERY_EDITOR_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_GDAEX_QUERY_EDITOR, GdaExQueryEditorPrivate)) -typedef struct - { - gchar *name; - gchar *name_visible; - GHashTable *fields; /* GdaExQueryEditorField */ - } GdaExQueryEditorTable; - typedef struct _GdaExQueryEditorPrivate GdaExQueryEditorPrivate; struct _GdaExQueryEditorPrivate { @@ -55,6 +58,8 @@ struct _GdaExQueryEditorPrivate GtkWidget *dialog; GtkWidget *hpaned_main; + GtkTreeStore *tstore_fields; + GHashTable *tables; /* GdaExQueryEditorTable */ }; @@ -75,7 +80,8 @@ enum enum { COL_FIELDS_NAME, - COL_FIELDS_VISIBLE_NAME + COL_FIELDS_VISIBLE_NAME, + COL_FIELDS_DESCRIPTION }; enum @@ -164,6 +170,8 @@ GdaExQueryEditor return NULL; } + priv->tstore_fields = GTK_TREE_STORE (gtk_builder_get_object (priv->gtkbuilder, "tstore_fields")); + return gdaex_query_editor; } @@ -181,6 +189,8 @@ GtkWidget priv->dialog = GTK_WIDGET (gtk_builder_get_object (priv->gtkbuilder, "diag_query_editor")); } + gdaex_query_editor_refresh_gui (gdaex_query_editor); + return priv->dialog; } @@ -198,6 +208,8 @@ GtkWidget priv->hpaned_main = GTK_WIDGET (gtk_builder_get_object (priv->gtkbuilder, "hpaned1")); } + gdaex_query_editor_refresh_gui (gdaex_query_editor); + return priv->hpaned_main; } @@ -291,3 +303,62 @@ gdaex_query_editor_get_property (GObject *object, break; } } + +static void +gdaex_query_editor_refresh_gui (GdaExQueryEditor *qe) +{ + GdaExQueryEditorPrivate *priv; + + GtkTreeIter iter; + GHashTableIter hiter; + gpointer key, value; + GdaExQueryEditorTable *table; + + g_return_if_fail (GDAEX_IS_QUERY_EDITOR (qe)); + + priv = GDAEX_QUERY_EDITOR_GET_PRIVATE (qe); + + gtk_tree_store_clear (priv->tstore_fields); + + g_hash_table_iter_init (&hiter, priv->tables); + while (g_hash_table_iter_next (&hiter, &key, &value)) + { + table = (GdaExQueryEditorTable *)value; + + gtk_tree_store_append (priv->tstore_fields, &iter, NULL); + gtk_tree_store_set (priv->tstore_fields, &iter, + COL_FIELDS_NAME, table->name, + COL_FIELDS_VISIBLE_NAME, table->name_visible, + -1); + + gdaex_query_editor_refresh_gui_add_fields (qe, table, &iter); + } +} + +static void +gdaex_query_editor_refresh_gui_add_fields (GdaExQueryEditor *qe, + GdaExQueryEditorTable *table, + GtkTreeIter *iter_parent) +{ + GdaExQueryEditorPrivate *priv; + + GtkTreeIter iter; + GHashTableIter hiter; + gpointer key, value; + GdaExQueryEditorField *field; + + priv = GDAEX_QUERY_EDITOR_GET_PRIVATE (qe); + + g_hash_table_iter_init (&hiter, table->fields); + while (g_hash_table_iter_next (&hiter, &key, &value)) + { + field = (GdaExQueryEditorField *)value; + + gtk_tree_store_append (priv->tstore_fields, &iter, iter_parent); + gtk_tree_store_set (priv->tstore_fields, &iter, + COL_FIELDS_NAME, field->name, + COL_FIELDS_VISIBLE_NAME, field->name_visible, + COL_FIELDS_DESCRIPTION, field->description, + -1); + } +} diff --git a/src/queryeditor.h b/src/queryeditor.h index 1bdb554..f163a31 100644 --- a/src/queryeditor.h +++ b/src/queryeditor.h @@ -62,6 +62,7 @@ typedef struct { gchar *name; gchar *name_visible; + gchar *description; /* - tipo di campo (stringa, interno, double, date, datetime) */ /* - sempre presente nelle query, quindi non sceglibile per la parte show */ /* - sceglibile per la parte where */ diff --git a/tests/query_editor.c b/tests/query_editor.c index c4cc731..9ec4393 100644 --- a/tests/query_editor.c +++ b/tests/query_editor.c @@ -29,6 +29,10 @@ main (int argc, char *argv[]) GdaEx *gdaex; GdaExQueryEditor *qe; + GdaExQueryEditorField *field; + + GtkWidget *dialog; + gtk_init (&argc, &argv); gdaex = gdaex = gdaex_new_from_string (g_strdup_printf ("SQLite://DB_DIR=%s;DB_NAME=test_prefix.db", TESTSDIR)); @@ -49,7 +53,38 @@ main (int argc, char *argv[]) qe = gdaex_query_editor_new (gdaex); - gtk_dialog_run (GTK_DIALOG (gdaex_query_editor_get_dialog (qe))); + gdaex_query_editor_add_table (qe, "clients", "Clients"); + + field = g_new0 (GdaExQueryEditorField, 1); + field->name = g_strdup ("id"); + field->name_visible = g_strdup ("ID"); + gdaex_query_editor_table_add_field (qe, "clients", *field); + g_free (field); + + field = g_new0 (GdaExQueryEditorField, 1); + field->name = g_strdup ("name"); + field->name_visible = g_strdup ("Name"); + field->description = g_strdup ("The client's name"); + gdaex_query_editor_table_add_field (qe, "clients", *field); + g_free (field); + + field = g_new0 (GdaExQueryEditorField, 1); + field->name = g_strdup ("surname"); + field->name_visible = g_strdup ("Surname"); + field->description = g_strdup ("The client's surname"); + gdaex_query_editor_table_add_field (qe, "clients", *field); + g_free (field); + + field = g_new0 (GdaExQueryEditorField, 1); + field->name = g_strdup ("age"); + field->name_visible = g_strdup ("Age"); + field->description = g_strdup ("The client's age"); + gdaex_query_editor_table_add_field (qe, "clients", *field); + g_free (field); + + dialog = gdaex_query_editor_get_dialog (qe); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); gtk_main (); -- 2.49.0