]> saetta.ns0.it Git - libgdaex/commitdiff
Start filling tables/fields store.
authorAndrea Zagli <azagli@libero.it>
Sun, 27 Feb 2011 09:43:01 +0000 (10:43 +0100)
committerAndrea Zagli <azagli@libero.it>
Sun, 27 Feb 2011 09:43:01 +0000 (10:43 +0100)
data/libgdaex/gui/libgdaex.ui
src/queryeditor.c
src/queryeditor.h
tests/query_editor.c

index 43599b90e396b64eb485edad2f07ef2e4aa76d24..bac847578219a0d6ebeda1051d7df39bdce62452 100644 (file)
@@ -2,14 +2,6 @@
 <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>
@@ -77,6 +79,7 @@
                     <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>
index d37e65b5ad644c58758cb16f688a6575a593c72e..eed4f2198276f2c997cfb956d332c865cb33a174 100644 (file)
 
 #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);
+               }
+}
index 1bdb55409ed16895660416f68164baa1fce320c0..f163a311c33757cd82b4f54ddd017a484bd58ad2 100644 (file)
@@ -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 */
index c4cc7315b4e9500ff8964162bb114aaa810c0b8f..9ec4393aa0e0f140ad6a038171c49400f037b449 100644 (file)
@@ -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 ();