]> saetta.ns0.it Git - libgdaex/commitdiff
Added properties for_show, always_showed and for_where to GdaExQueryEditorField.
authorAndrea Zagli <azagli@libero.it>
Sat, 5 Mar 2011 09:50:30 +0000 (10:50 +0100)
committerAndrea Zagli <azagli@libero.it>
Sat, 5 Mar 2011 09:50:30 +0000 (10:50 +0100)
data/libgdaex/gui/libgdaex.ui
src/queryeditor.c
src/queryeditor.h
tests/query_editor.c

index 11eedfd8b75ae3a9039be59151ded79e60854dca..083287334e276a0e0e02825bf5ec384d06a4d128 100644 (file)
@@ -2,18 +2,6 @@
 <interface>
   <requires lib="gtk+" version="2.16"/>
   <!-- interface-naming-policy project-wide -->
-  <object class="GtkTreeStore" id="tstore_fields">
-    <columns>
-      <!-- column-name table_name -->
-      <column type="gchararray"/>
-      <!-- column-name name -->
-      <column type="gchararray"/>
-      <!-- column-name name_visible -->
-      <column type="gchararray"/>
-      <!-- column-name description -->
-      <column type="gchararray"/>
-    </columns>
-  </object>
   <object class="GtkListStore" id="lstore_show">
     <columns>
       <!-- column-name table_name -->
       <column type="gchararray"/>
     </columns>
   </object>
+  <object class="GtkTreeStore" id="tstore_fields">
+    <columns>
+      <!-- column-name table_name -->
+      <column type="gchararray"/>
+      <!-- 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>
index 845949f0dd6ed09505307657326dd943258c3d14..a39dc96c4339042eeecef8c2fdd039bcafa09b74 100644 (file)
@@ -86,6 +86,8 @@ static void gdaex_query_editor_on_btn_save_clicked (GtkButton *button,
 static void gdaex_query_editor_on_sel_fields_changed (GtkTreeSelection *treeselection,
                                                     gpointer user_data);
 
+static void gdaex_query_editor_show_add_iter (GdaExQueryEditor *qe, GtkTreeIter *iter);
+
 static void gdaex_query_editor_on_btn_show_add_clicked (GtkButton *button,
                                     gpointer user_data);
 static void gdaex_query_editor_on_btn_show_remove_clicked (GtkButton *button,
@@ -94,6 +96,8 @@ static void gdaex_query_editor_on_btn_show_up_clicked (GtkButton *button,
                                     gpointer user_data);
 static void gdaex_query_editor_on_btn_show_down_clicked (GtkButton *button,
                                     gpointer user_data);
+static void gdaex_query_editor_on_sel_show_changed (GtkTreeSelection *treeselection,
+                                                    gpointer user_data);
 
 static void gdaex_query_editor_on_btn_where_add_clicked (GtkButton *button,
                                     gpointer user_data);
@@ -294,6 +298,8 @@ GdaExQueryEditor
                          G_CALLBACK (gdaex_query_editor_on_btn_show_up_clicked), (gpointer)gdaex_query_editor);
        g_signal_connect (gtk_builder_get_object (priv->gtkbuilder, "button6"), "clicked",
                          G_CALLBACK (gdaex_query_editor_on_btn_show_down_clicked), (gpointer)gdaex_query_editor);
+       g_signal_connect (priv->sel_show, "changed",
+                         G_CALLBACK (gdaex_query_editor_on_sel_show_changed), (gpointer)gdaex_query_editor);
 
        g_signal_connect (gtk_builder_get_object (priv->gtkbuilder, "button7"), "clicked",
                          G_CALLBACK (gdaex_query_editor_on_btn_where_add_clicked), (gpointer)gdaex_query_editor);
@@ -693,6 +699,11 @@ gdaex_query_editor_refresh_gui_add_fields (GdaExQueryEditor *qe,
                                            COL_FIELDS_VISIBLE_NAME, field->name_visible,
                                            COL_FIELDS_DESCRIPTION, field->description,
                                            -1);
+
+                       if (field->always_showed)
+                               {
+                                       gdaex_query_editor_show_add_iter (qe, &iter);
+                               }
                }
 }
 
@@ -891,8 +902,15 @@ gdaex_query_editor_on_sel_fields_changed (GtkTreeSelection *treeselection,
                        table = g_hash_table_lookup (priv->tables, table_name);
                        field = g_hash_table_lookup (table->fields, field_name);
 
-                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (priv->gtkbuilder, "button3")), TRUE);
-                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (priv->gtkbuilder, "button7")), TRUE);
+                       if (!field->always_showed && field->for_show)
+                               {
+                                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (priv->gtkbuilder, "button3")), TRUE);
+                               }
+
+                       if (field->for_where)
+                               {
+                                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (priv->gtkbuilder, "button7")),  TRUE);
+                               }
 
                        table_field = g_strconcat (table->name_visible, " - ", field->name_visible, NULL);
                        v_table_field = gda_value_new (G_TYPE_STRING);
@@ -952,6 +970,34 @@ gdaex_query_editor_on_btn_save_clicked (GtkButton *button,
        gtk_widget_hide (priv->vbx_values_container);
 }
 
+static void
+gdaex_query_editor_show_add_iter (GdaExQueryEditor *qe, GtkTreeIter *iter)
+{
+       GdaExQueryEditorPrivate *priv;
+
+       gchar *table_name;
+       gchar *field_name;
+       GdaExQueryEditorTable *table;
+       GdaExQueryEditorField *field;
+
+       priv = GDAEX_QUERY_EDITOR_GET_PRIVATE (qe);
+
+       gtk_tree_model_get (GTK_TREE_MODEL (priv->tstore_fields), iter,
+                           COL_FIELDS_TABLE_NAME, &table_name,
+                           COL_FIELDS_NAME, &field_name,
+                           -1);
+
+       table = g_hash_table_lookup (priv->tables, table_name);
+       field = g_hash_table_lookup (table->fields, field_name);
+
+       gtk_list_store_append (priv->lstore_show, iter);
+       gtk_list_store_set (priv->lstore_show, iter,
+                           COL_SHOW_TABLE_NAME, field->table_name,
+                           COL_SHOW_NAME, field_name,
+                           COL_SHOW_VISIBLE_NAME, g_strconcat (table->name_visible, " - ", field->name_visible, NULL),
+                           -1);
+}
+
 static void
 gdaex_query_editor_on_btn_show_add_clicked (GtkButton *button,
                                     gpointer user_data)
@@ -962,30 +1008,12 @@ gdaex_query_editor_on_btn_show_add_clicked (GtkButton *button,
        GtkTreeIter iter;
        GtkWidget *dialog;
 
-       gchar *table_name;
-       gchar *field_name;
-       GdaExQueryEditorTable *table;
-       GdaExQueryEditorField *field;
-
        qe = (GdaExQueryEditor *)user_data;
        priv = GDAEX_QUERY_EDITOR_GET_PRIVATE (qe);
 
        if (gtk_tree_selection_get_selected (priv->sel_fields, NULL, &iter))
                {
-                       gtk_tree_model_get (GTK_TREE_MODEL (priv->tstore_fields), &iter,
-                                           COL_FIELDS_TABLE_NAME, &table_name,
-                                           COL_FIELDS_NAME, &field_name,
-                                           -1);
-
-                       table = g_hash_table_lookup (priv->tables, table_name);
-                       field = g_hash_table_lookup (table->fields, field_name);
-
-                       gtk_list_store_append (priv->lstore_show, &iter);
-                       gtk_list_store_set (priv->lstore_show, &iter,
-                                           COL_SHOW_TABLE_NAME, field->table_name,
-                                           COL_SHOW_NAME, field_name,
-                                           COL_SHOW_VISIBLE_NAME, g_strconcat (table->name_visible, " - ", field->name_visible, NULL),
-                                           -1);
+                       gdaex_query_editor_show_add_iter (qe, &iter);
                }
        else
                {
@@ -1038,6 +1066,34 @@ gdaex_query_editor_on_btn_show_down_clicked (GtkButton *button,
                                              FALSE);
 }
 
+static void
+gdaex_query_editor_on_sel_show_changed (GtkTreeSelection *treeselection,
+                                          gpointer user_data)
+{
+       GtkTreeIter iter;
+
+       gchar *table_name;
+       gchar *field_name;
+       GdaExQueryEditorTable *table;
+       GdaExQueryEditorField *field;
+
+       GdaExQueryEditor *qe = (GdaExQueryEditor *)user_data;
+       GdaExQueryEditorPrivate *priv = GDAEX_QUERY_EDITOR_GET_PRIVATE (qe);
+
+       if (gtk_tree_selection_get_selected (priv->sel_show, NULL, &iter))
+               {
+                       gtk_tree_model_get (GTK_TREE_MODEL (priv->lstore_show), &iter,
+                                           COL_SHOW_TABLE_NAME, &table_name,
+                                           COL_SHOW_NAME, &field_name,
+                                           -1);
+
+                       table = g_hash_table_lookup (priv->tables, table_name);
+                       field = g_hash_table_lookup (table->fields, field_name);
+
+                       gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (priv->gtkbuilder, "button4")), !field->always_showed);
+               }
+}
+
 static void
 gdaex_query_editor_on_btn_where_add_clicked (GtkButton *button,
                                     gpointer user_data)
index 85f35d554caa48c348cced400e90f8756b119ae6..05689487cdd9df9530f478512dc8756925ab0977 100644 (file)
@@ -68,8 +68,11 @@ typedef struct
                gchar *alias;
                /* - tipo di campo (string, integer, double, date, datetime) */
                /* - sceglibile per la parte show (es. le chiavi esterne non ha senno che lo siano) */
+               gboolean for_show;
                /* - sempre presente nelle query, quindi non sceglibile per la parte show */
+               gboolean always_showed;
                /* - sceglibile per la parte where */
+               gboolean for_where;
                /* - condizioni where che è possibile applicare (es. i campi id_* non ha senso che abbiano un between, */
                /*                                             ma ci deve essere la possibilità di fare ricerche anche sulle decodifiche) */
                gchar *decode_table2;
index f56152dafd58fe78347ac479c4abeb950ae8fc01..f15a852b4f3b99bacead6279ed4464db7b57a5df 100644 (file)
@@ -58,6 +58,9 @@ main (int argc, char *argv[])
        field = g_new0 (GdaExQueryEditorField, 1);
        field->name = g_strdup ("id");
        field->name_visible = g_strdup ("ID");
+       field->for_show = TRUE;
+       field->always_showed = TRUE;
+       field->for_where = TRUE;
        gdaex_query_editor_table_add_field (qe, "clients", *field);
        g_free (field);
 
@@ -65,6 +68,8 @@ main (int argc, char *argv[])
        field->name = g_strdup ("name");
        field->name_visible = g_strdup ("Name");
        field->description = g_strdup ("The client's name");
+       field->for_show = TRUE;
+       field->for_where = TRUE;
        gdaex_query_editor_table_add_field (qe, "clients", *field);
        g_free (field);
 
@@ -72,6 +77,8 @@ main (int argc, char *argv[])
        field->name = g_strdup ("surname");
        field->name_visible = g_strdup ("Surname");
        field->description = g_strdup ("The client's surname");
+       field->for_show = TRUE;
+       field->for_where = TRUE;
        gdaex_query_editor_table_add_field (qe, "clients", *field);
        g_free (field);
 
@@ -79,6 +86,8 @@ main (int argc, char *argv[])
        field->name = g_strdup ("age");
        field->name_visible = g_strdup ("Age");
        field->description = g_strdup ("The client's age");
+       field->for_show = TRUE;
+       field->for_where = FALSE;
        gdaex_query_editor_table_add_field (qe, "clients", *field);
        g_free (field);
 
@@ -86,6 +95,8 @@ main (int argc, char *argv[])
        field->name = g_strdup ("id_cities");
        field->name_visible = g_strdup ("City");
        field->description = g_strdup ("The client's city");
+       field->for_show = TRUE;
+       field->for_where = TRUE;
        field->decode_table2 = g_strdup ("cities");
        /*field->decode_fields1 = g_slist_append (field->decode_fields1, "id_cities");
        field->decode_fields2 = g_slist_append (field->decode_fields2, "id");*/