From 2679728dbe65315f30073efc75ed04b73456475d Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Mon, 25 Jan 2016 16:50:52 +0100 Subject: [PATCH] Utilizzo di GdaExGrid in comuni. Aggiustamenti. --- data/territorio/gui/territorio.gui | 352 ++++++++++++----------------- src/comuni.c | 75 +++--- src/province.c | 15 +- src/regioni.c | 15 +- src/stati.c | 15 +- 5 files changed, 216 insertions(+), 256 deletions(-) diff --git a/data/territorio/gui/territorio.gui b/data/territorio/gui/territorio.gui index d3a8b3d..821fd3f 100644 --- a/data/territorio/gui/territorio.gui +++ b/data/territorio/gui/territorio.gui @@ -238,209 +238,6 @@ - - - - - - - - - - - - - - False - Comuni - Territorio - True - center-on-parent - 550 - 400 - True - - - True - False - 5 - vertical - 5 - - - True - False - <b>Comuni</b> - True - - - False - True - 0 - - - - - True - True - etched-in - - - True - True - lstore_comuni - True - 1 - - - - - - Nome - - - - 1 - - - - - - - Provincia - - - - 2 - - - - - - - Regione - - - - 3 - - - - - - - - - True - True - 1 - - - - - True - False - 5 - end - - - gtk-new - False - True - True - True - True - - - False - False - 0 - - - - - gtk-edit - False - True - True - True - True - - - False - False - 1 - - - - - gtk-delete - False - True - True - True - True - - - False - False - 2 - - - - - gtk-find - False - True - True - True - True - - - False - False - 3 - - - - - gtk-cancel - False - True - True - True - True - - - False - False - 4 - - - - - gtk-ok - False - True - True - True - True - - - False - False - 5 - - - - - False - True - 2 - - - - - @@ -1260,6 +1057,155 @@ + + False + Comuni - Territorio + True + center-on-parent + 550 + 400 + True + + + True + False + 5 + vertical + 5 + + + True + False + <b>Comuni</b> + True + + + False + True + 0 + + + + + True + True + etched-in + + + + + + True + True + 1 + + + + + True + False + 5 + end + + + gtk-new + False + True + True + True + True + + + False + False + 0 + + + + + gtk-edit + False + True + True + True + True + + + False + False + 1 + + + + + gtk-delete + False + True + True + True + True + + + False + False + 2 + + + + + gtk-find + False + True + True + True + True + + + False + False + 3 + + + + + gtk-cancel + False + True + True + True + True + + + False + False + 4 + + + + + gtk-ok + False + True + True + True + True + + + False + False + 5 + + + + + False + True + 2 + + + + + False Territorio diff --git a/src/comuni.c b/src/comuni.c index 14f63cd..752db75 100644 --- a/src/comuni.c +++ b/src/comuni.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 Andrea Zagli + * Copyright (C) 2010-2016 Andrea Zagli * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -20,6 +20,7 @@ #include #include +#include #include "comuni.h" #include "comune.h" @@ -93,8 +94,11 @@ struct _TerritorioComuniPrivate TerritorioCommons *commons; GtkWidget *widget; + + GdaExGrid *grid; + GtkWidget *wgrid; GtkTreeSelection *selection; - GtkListStore *lstore_comuni; + GtkTreeStore *lstore_comuni; GHashTable *parametri_ricerca; @@ -162,6 +166,8 @@ TerritorioComuni GError *error; ZakAuthoIResource *ires1; + GdaExGridColumn *gcol; + TerritorioComuni *a = TERRITORIO_COMUNI (g_object_new (territorio_comuni_get_type (), NULL)); TerritorioComuniPrivate *priv = TERRITORIO_COMUNI_GET_PRIVATE (a); @@ -182,8 +188,31 @@ TerritorioComuni } priv->widget = GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, (selezione ? "w_comuni" : "vbox8"))); - priv->selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (gtk_builder_get_object (priv->commons->gtkbuilder, "treeview4"))); - priv->lstore_comuni = GTK_LIST_STORE (gtk_builder_get_object (priv->commons->gtkbuilder, "lstore_comuni")); + + /* creo la gdaexgrid */ + priv->grid = gdaex_grid_new (); + gdaex_grid_set_solipa (priv->grid, priv->commons->solipa); + gdaex_grid_set_title (priv->grid, gtk_label_get_text (GTK_LABEL (gtk_builder_get_object (priv->commons->gtkbuilder, "label20")))); + + gcol = gdaex_grid_column_new ("ID", "id", G_TYPE_INT, TRUE, TRUE, TRUE, TRUE, -1); + gdaex_grid_add_column (priv->grid, gcol); + + gcol = gdaex_grid_column_new_defaults ("Nome", "nome", G_TYPE_STRING); + gdaex_grid_add_column (priv->grid, gcol); + + gcol = gdaex_grid_column_new_defaults ("Provincia", "provincia", G_TYPE_STRING); + gdaex_grid_add_column (priv->grid, gcol); + + gcol = gdaex_grid_column_new_defaults ("Regione", "regione", G_TYPE_STRING); + gdaex_grid_add_column (priv->grid, gcol); + + priv->wgrid = gdaex_grid_get_widget (priv->grid); + gtk_tree_view_set_search_column (GTK_TREE_VIEW (priv->wgrid), 1); + gtk_container_add (GTK_CONTAINER (gtk_builder_get_object (priv->commons->gtkbuilder, "scrolledwindow4")), priv->wgrid); + gtk_widget_show (priv->wgrid); + + priv->selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->wgrid)); + priv->lstore_comuni = GTK_TREE_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (priv->wgrid))); if (priv->selezione) { @@ -205,7 +234,7 @@ TerritorioComuni "clicked", G_CALLBACK (territorio_comuni_on_btn_modifica_clicked), (gpointer)a); g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button24"), "clicked", G_CALLBACK (territorio_comuni_on_btn_elimina_clicked), (gpointer)a); - g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "treeview4"), + g_signal_connect (priv->wgrid, "row-activated", G_CALLBACK (territorio_comuni_on_trv_territorio_comuni_row_activated), (gpointer)a); g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button58"), "clicked", G_CALLBACK (territorio_comuni_on_btn_trova_clicked), (gpointer)a); @@ -251,9 +280,6 @@ GtkWidget static void territorio_comuni_carica (TerritorioComuni *territorio_comuni) { - GtkTreeIter iter; - GdaDataModel *dm; - gchar *sql; gchar *sql_where; @@ -261,12 +287,9 @@ territorio_comuni_carica (TerritorioComuni *territorio_comuni) gchar *gcval; gint ival; - gint rows; - gint row; - TerritorioComuniPrivate *priv = TERRITORIO_COMUNI_GET_PRIVATE (territorio_comuni); - gtk_list_store_clear (priv->lstore_comuni); + gtk_tree_store_clear (priv->lstore_comuni); sql_where = g_strdup (""); if (priv->parametri_ricerca != NULL) @@ -314,25 +337,13 @@ territorio_comuni_carica (TerritorioComuni *territorio_comuni) "%s" " ORDER BY c.nome", sql_where); - dm = gdaex_query (priv->commons->gdaex, sql); - g_free (sql); - g_free (sql_where); - if (dm != NULL) - { - rows = gda_data_model_get_n_rows (dm); - for (row = 0; row < rows; row++) - { - gtk_list_store_append (priv->lstore_comuni, &iter); - gtk_list_store_set (priv->lstore_comuni, &iter, - COL_ID, gdaex_data_model_get_field_value_integer_at (dm, row, "id"), - COL_NOME, gdaex_data_model_get_field_value_stringify_at (dm, row, "nome"), - COL_PROVINCIA, gdaex_data_model_get_field_value_stringify_at (dm, row, "provincia"), - COL_REGIONE, gdaex_data_model_get_field_value_stringify_at (dm, row, "regione"), - -1); - } - g_object_unref (dm); - } + gdaex_grid_fill_from_sql (priv->grid, + priv->commons->gdaex, + sql, + NULL); + + g_free (sql); } static void @@ -373,7 +384,7 @@ static void territorio_comuni_selezionato (TerritorioComuni *territorio_comuni) { GtkTreeIter iter; - guint *id; + guint id; TerritorioComuniClass *klass = TERRITORIO_COMUNI_GET_CLASS (territorio_comuni); TerritorioComuniPrivate *priv = TERRITORIO_COMUNI_GET_PRIVATE (territorio_comuni); @@ -581,7 +592,7 @@ territorio_comuni_on_btn_elimina_clicked (GtkButton *button, solipa_message_dialog (GTK_WIDGET (priv->wtransient), GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, - "Occorre prima selezionare un comune"); + "Occorre prima selezionare un comune."); } } diff --git a/src/province.c b/src/province.c index a1fbb84..cddce1d 100644 --- a/src/province.c +++ b/src/province.c @@ -196,7 +196,7 @@ TerritorioProvince gdaex_grid_set_solipa (priv->grid, priv->commons->solipa); gdaex_grid_set_title (priv->grid, gtk_label_get_text (GTK_LABEL (gtk_builder_get_object (priv->commons->gtkbuilder, "label13")))); - gcol = gdaex_grid_column_new_defaults ("ID", "id", G_TYPE_INT); + gcol = gdaex_grid_column_new ("ID", "id", G_TYPE_INT, TRUE, TRUE, TRUE, TRUE, -1); gdaex_grid_add_column (priv->grid, gcol); gcol = gdaex_grid_column_new_defaults ("Nome", "nome", G_TYPE_STRING); @@ -209,6 +209,7 @@ TerritorioProvince gdaex_grid_add_column (priv->grid, gcol); priv->wgrid = gdaex_grid_get_widget (priv->grid); + gtk_tree_view_set_search_column (GTK_TREE_VIEW (priv->wgrid), 1); gtk_container_add (GTK_CONTAINER (gtk_builder_get_object (priv->commons->gtkbuilder, "scrolledwindow3")), priv->wgrid); gtk_widget_show (priv->wgrid); @@ -341,7 +342,7 @@ static void territorio_province_modifica (TerritorioProvince *territorio_province) { GtkTreeIter iter; - gchar *id; + guint id; TerritorioProvincePrivate *priv = TERRITORIO_PROVINCE_GET_PRIVATE (territorio_province); @@ -353,7 +354,7 @@ territorio_province_modifica (TerritorioProvince *territorio_province) COL_ID, &id, -1); - TerritorioProvincia *c = territorio_provincia_new (priv->commons, strtol (id, NULL, 10)); + TerritorioProvincia *c = territorio_provincia_new (priv->commons, id); g_signal_connect (G_OBJECT (c), "aggiornato", G_CALLBACK (territorio_province_on_provincia_aggiornato), (gpointer)territorio_province); @@ -375,7 +376,7 @@ static void territorio_province_selezionato (TerritorioProvince *territorio_province) { GtkTreeIter iter; - gchar *id; + guint id; TerritorioProvinceClass *klass = TERRITORIO_PROVINCE_GET_CLASS (territorio_province); TerritorioProvincePrivate *priv = TERRITORIO_PROVINCE_GET_PRIVATE (territorio_province); @@ -386,7 +387,7 @@ territorio_province_selezionato (TerritorioProvince *territorio_province) COL_ID, &id, -1); - g_signal_emit (G_OBJECT (territorio_province), klass->selezionato_signal_id, 0, strtol (id, NULL, 10)); + g_signal_emit (G_OBJECT (territorio_province), klass->selezionato_signal_id, 0, id); gtk_widget_destroy (priv->widget); g_object_unref (G_OBJECT (territorio_province)); @@ -536,7 +537,7 @@ territorio_province_on_btn_elimina_clicked (GtkButton *button, ZakAuthoIResource *ires1; GtkTreeIter iter; - gchar *id; + guint id; TerritorioProvince *territorio_province = (TerritorioProvince *)user_data; TerritorioProvincePrivate *priv = TERRITORIO_PROVINCE_GET_PRIVATE (territorio_province); @@ -563,7 +564,7 @@ territorio_province_on_btn_elimina_clicked (GtkButton *button, -1); gdaex_execute (priv->commons->gdaex, - g_strdup_printf ("UPDATE province SET status = 'E' WHERE id = %d", strtol (id, NULL, 10))); + g_strdup_printf ("UPDATE province SET status = 'E' WHERE id = %d", id)); territorio_province_carica (territorio_province); } diff --git a/src/regioni.c b/src/regioni.c index 1c61b77..1bc8ab5 100644 --- a/src/regioni.c +++ b/src/regioni.c @@ -164,13 +164,14 @@ TerritorioRegioni gdaex_grid_set_solipa (priv->grid, priv->commons->solipa); gdaex_grid_set_title (priv->grid, gtk_label_get_text (GTK_LABEL (gtk_builder_get_object (priv->commons->gtkbuilder, "label9")))); - gcol = gdaex_grid_column_new_defaults ("ID", "id", G_TYPE_INT); + gcol = gdaex_grid_column_new ("ID", "id", G_TYPE_INT, TRUE, TRUE, TRUE, TRUE, -1); gdaex_grid_add_column (priv->grid, gcol); gcol = gdaex_grid_column_new_defaults ("Nome", "nome", G_TYPE_STRING); gdaex_grid_add_column (priv->grid, gcol); priv->wgrid = gdaex_grid_get_widget (priv->grid); + gtk_tree_view_set_search_column (GTK_TREE_VIEW (priv->wgrid), 1); gtk_container_add (GTK_CONTAINER (gtk_builder_get_object (priv->commons->gtkbuilder, "scrolledwindow2")), priv->wgrid); gtk_widget_show (priv->wgrid); @@ -264,7 +265,7 @@ static void territorio_regioni_modifica (TerritorioRegioni *territorio_regioni) { GtkTreeIter iter; - gchar *id; + guint id; TerritorioRegioniPrivate *priv = TERRITORIO_REGIONI_GET_PRIVATE (territorio_regioni); @@ -276,7 +277,7 @@ territorio_regioni_modifica (TerritorioRegioni *territorio_regioni) COL_ID, &id, -1); - TerritorioRegione *c = territorio_regione_new (priv->commons, strtol (id, NULL, 10)); + TerritorioRegione *c = territorio_regione_new (priv->commons, id); g_signal_connect (G_OBJECT (c), "aggiornato", G_CALLBACK (territorio_regioni_on_regione_aggiornato), (gpointer)territorio_regioni); @@ -298,7 +299,7 @@ static void territorio_regioni_selezionato (TerritorioRegioni *territorio_regioni) { GtkTreeIter iter; - gchar *id; + guint id; TerritorioRegioniClass *klass = TERRITORIO_REGIONI_GET_CLASS (territorio_regioni); TerritorioRegioniPrivate *priv = TERRITORIO_REGIONI_GET_PRIVATE (territorio_regioni); @@ -309,7 +310,7 @@ territorio_regioni_selezionato (TerritorioRegioni *territorio_regioni) COL_ID, &id, -1); - g_signal_emit (G_OBJECT (territorio_regioni), klass->selezionato_signal_id, 0, strtol (id, NULL, 10)); + g_signal_emit (G_OBJECT (territorio_regioni), klass->selezionato_signal_id, 0, id); gtk_widget_destroy (priv->widget); g_object_unref (G_OBJECT (territorio_regioni)); @@ -422,7 +423,7 @@ territorio_regioni_on_btn_elimina_clicked (GtkButton *button, ZakAuthoIResource *ires1; GtkTreeIter iter; - gchar *id; + guint id; TerritorioRegioni *territorio_regioni = (TerritorioRegioni *)user_data; TerritorioRegioniPrivate *priv = TERRITORIO_REGIONI_GET_PRIVATE (territorio_regioni); @@ -449,7 +450,7 @@ territorio_regioni_on_btn_elimina_clicked (GtkButton *button, -1); gdaex_execute (priv->commons->gdaex, - g_strdup_printf ("UPDATE regioni SET status = 'E' WHERE id = %d", strtol (id, NULL, 10))); + g_strdup_printf ("UPDATE regioni SET status = 'E' WHERE id = %d", id)); territorio_regioni_carica (territorio_regioni); } diff --git a/src/stati.c b/src/stati.c index cceaef6..8a96ae7 100644 --- a/src/stati.c +++ b/src/stati.c @@ -172,13 +172,14 @@ TerritorioStati gdaex_grid_set_solipa (priv->grid, priv->commons->solipa); gdaex_grid_set_title (priv->grid, gtk_label_get_text (GTK_LABEL (gtk_builder_get_object (priv->commons->gtkbuilder, "label1")))); - gcol = gdaex_grid_column_new_defaults ("ID", "id", G_TYPE_INT); + gcol = gdaex_grid_column_new ("ID", "id", G_TYPE_INT, TRUE, TRUE, TRUE, TRUE, -1); gdaex_grid_add_column (priv->grid, gcol); gcol = gdaex_grid_column_new_defaults ("Nome", "nome", G_TYPE_STRING); gdaex_grid_add_column (priv->grid, gcol); priv->wgrid = gdaex_grid_get_widget (priv->grid); + gtk_tree_view_set_search_column (GTK_TREE_VIEW (priv->wgrid), 1); gtk_container_add (GTK_CONTAINER (gtk_builder_get_object (priv->commons->gtkbuilder, "scrolledwindow1")), priv->wgrid); gtk_widget_show (priv->wgrid); @@ -295,7 +296,7 @@ static void territorio_stati_modifica (TerritorioStati *territorio_stati) { GtkTreeIter iter; - gchar *id; + guint id; TerritorioStatiPrivate *priv = TERRITORIO_STATI_GET_PRIVATE (territorio_stati); @@ -307,7 +308,7 @@ territorio_stati_modifica (TerritorioStati *territorio_stati) COL_ID, &id, -1); - TerritorioStato *c = territorio_stato_new (priv->commons, strtol (id, NULL, 10)); + TerritorioStato *c = territorio_stato_new (priv->commons, id); g_signal_connect (G_OBJECT (c), "aggiornato", G_CALLBACK (territorio_stati_on_stato_aggiornato), (gpointer)territorio_stati); @@ -329,7 +330,7 @@ static void territorio_stati_selezionato (TerritorioStati *territorio_stati) { GtkTreeIter iter; - gchar *id; + guint id; TerritorioStatiClass *klass = TERRITORIO_STATI_GET_CLASS (territorio_stati); TerritorioStatiPrivate *priv = TERRITORIO_STATI_GET_PRIVATE (territorio_stati); @@ -340,7 +341,7 @@ territorio_stati_selezionato (TerritorioStati *territorio_stati) COL_ID, &id, -1); - g_signal_emit (G_OBJECT (territorio_stati), klass->selezionato_signal_id, 0, strtol (id, NULL, 10)); + g_signal_emit (G_OBJECT (territorio_stati), klass->selezionato_signal_id, 0, id); gtk_widget_destroy (priv->widget); g_object_unref (G_OBJECT (territorio_stati)); @@ -505,7 +506,7 @@ territorio_stati_on_btn_elimina_clicked (GtkButton *button, ZakAuthoIResource *ires1; GtkTreeIter iter; - gchar *id; + guint id; TerritorioStati *territorio_stati = (TerritorioStati *)user_data; TerritorioStatiPrivate *priv = TERRITORIO_STATI_GET_PRIVATE (territorio_stati); @@ -532,7 +533,7 @@ territorio_stati_on_btn_elimina_clicked (GtkButton *button, -1); gdaex_execute (priv->commons->gdaex, - g_strdup_printf ("UPDATE stati SET status = 'E' WHERE id = %d", strtol (id, NULL, 10))); + g_strdup_printf ("UPDATE stati SET status = 'E' WHERE id = %d", id)); territorio_stati_carica (territorio_stati); } -- 2.49.0