From: Andrea Zagli Date: Sat, 5 Mar 2011 09:50:30 +0000 (+0100) Subject: Added properties for_show, always_showed and for_where to GdaExQueryEditorField. X-Git-Tag: 0.5.0~57 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=5d80eba40fcbaf836769dcaa3f1542d741d2f7cc;p=libgdaex Added properties for_show, always_showed and for_where to GdaExQueryEditorField. --- diff --git a/data/libgdaex/gui/libgdaex.ui b/data/libgdaex/gui/libgdaex.ui index 11eedfd..0832873 100644 --- a/data/libgdaex/gui/libgdaex.ui +++ b/data/libgdaex/gui/libgdaex.ui @@ -2,18 +2,6 @@ - - - - - - - - - - - - @@ -56,6 +44,18 @@ + + + + + + + + + + + + 5 Query Editor diff --git a/src/queryeditor.c b/src/queryeditor.c index 845949f..a39dc96 100644 --- a/src/queryeditor.c +++ b/src/queryeditor.c @@ -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) diff --git a/src/queryeditor.h b/src/queryeditor.h index 85f35d5..0568948 100644 --- a/src/queryeditor.h +++ b/src/queryeditor.h @@ -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; diff --git a/tests/query_editor.c b/tests/query_editor.c index f56152d..f15a852 100644 --- a/tests/query_editor.c +++ b/tests/query_editor.c @@ -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");*/