<interface>
<requires lib="gtk+" version="2.16"/>
<!-- interface-naming-policy project-wide -->
- <object class="GtkTreeStore" id="tstore_fields">
- <columns>
- <!-- column-name name -->
- <column type="gchararray"/>
- <!-- column-name name_visible -->
- <column type="gchararray"/>
- </columns>
- </object>
<object class="GtkListStore" id="lstore_show">
<columns>
<!-- column-name name -->
<column type="gchararray"/>
</columns>
</object>
+ <object class="GtkTreeStore" id="tstore_fields">
+ <columns>
+ <!-- column-name name -->
+ <column type="gchararray"/>
+ <!-- column-name name_visible -->
+ <column type="gchararray"/>
+ <!-- column-name description -->
+ <column type="gchararray"/>
+ </columns>
+ </object>
<object class="GtkDialog" id="diag_query_editor">
<property name="border_width">5</property>
<property name="title" translatable="yes">Query Editor</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="model">tstore_fields</property>
+ <property name="tooltip_column">2</property>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn1">
<property name="title">Fields</property>
#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);
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
{
GtkWidget *dialog;
GtkWidget *hpaned_main;
+ GtkTreeStore *tstore_fields;
+
GHashTable *tables; /* GdaExQueryEditorTable */
};
enum
{
COL_FIELDS_NAME,
- COL_FIELDS_VISIBLE_NAME
+ COL_FIELDS_VISIBLE_NAME,
+ COL_FIELDS_DESCRIPTION
};
enum
return NULL;
}
+ priv->tstore_fields = GTK_TREE_STORE (gtk_builder_get_object (priv->gtkbuilder, "tstore_fields"));
+
return gdaex_query_editor;
}
priv->dialog = GTK_WIDGET (gtk_builder_get_object (priv->gtkbuilder, "diag_query_editor"));
}
+ gdaex_query_editor_refresh_gui (gdaex_query_editor);
+
return priv->dialog;
}
priv->hpaned_main = GTK_WIDGET (gtk_builder_get_object (priv->gtkbuilder, "hpaned1"));
}
+ gdaex_query_editor_refresh_gui (gdaex_query_editor);
+
return priv->hpaned_main;
}
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);
+ }
+}
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));
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 ();