From 50cf4ad9fdab39e3c56dc8d517078be9a21a2265 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sat, 26 Dec 2015 14:16:22 +0100 Subject: [PATCH] Utilizzo di GdaExGrid in stati. --- configure.ac | 1 + data/territorio/gui/territorio.gui | 324 +++++++++++++---------------- libreria/Makefile.am | 3 +- src/Makefile.am | 3 +- src/stati.c | 73 ++++--- 5 files changed, 194 insertions(+), 210 deletions(-) diff --git a/configure.ac b/configure.ac index f58eeb0..89790df 100644 --- a/configure.ac +++ b/configure.ac @@ -27,6 +27,7 @@ AC_PROG_RANLIB PKG_CHECK_MODULES(TERRITORIO, [gio-2.0 >= 2.36 libgda-ui-5.0 >= 5.0.0 libgdaex >= 0.5.0 + libgdaexgrid libgtkform >= 0.5.0 libgtkformui >= 0.5.0 libzakauthe >= 0.2.0 diff --git a/data/territorio/gui/territorio.gui b/data/territorio/gui/territorio.gui index e933588..2dcc61a 100644 --- a/data/territorio/gui/territorio.gui +++ b/data/territorio/gui/territorio.gui @@ -832,182 +832,6 @@ - - - - - - - - - - False - Stati - Territorio - True - center-on-parent - 550 - 400 - True - - - True - False - 5 - 5 - - - True - False - <b>Stati</b> - True - - - False - True - 0 - - - - - True - True - etched-in - - - True - True - lstore_stati - True - 1 - - - - - - Nome - - - - 1 - - - - - - - - - True - True - 1 - - - - - True - False - 5 - end - - - E_sporta - False - True - True - True - True - - - False - False - 0 - - - - - gtk-new - False - True - True - True - True - - - False - False - 1 - - - - - gtk-edit - False - True - True - True - True - - - False - False - 2 - - - - - gtk-delete - 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 - - - - - @@ -2996,6 +2820,154 @@ + + False + Stati - Territorio + True + center-on-parent + 550 + 400 + True + + + True + False + 5 + 5 + + + True + False + <b>Stati</b> + True + + + False + True + 0 + + + + + True + True + etched-in + + + + + + True + True + 1 + + + + + True + False + 5 + end + + + E_sporta + False + True + True + True + True + + + False + False + 0 + + + + + gtk-new + False + True + True + True + True + + + False + False + 1 + + + + + gtk-edit + False + True + True + True + True + + + False + False + 2 + + + + + gtk-delete + 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 Stato - Territorio diff --git a/libreria/Makefile.am b/libreria/Makefile.am index 64ee5b1..784461c 100644 --- a/libreria/Makefile.am +++ b/libreria/Makefile.am @@ -4,7 +4,8 @@ formdir = $(datadir)/$(PACKAGE)/form AM_CPPFLAGS = $(TERRITORIO_CFLAGS) \ -DGUIDIR=\""$(guidir)"\" \ -DFORMDIR=\""$(formdir)"\" \ - -DG_LOG_DOMAIN=\"Territorio\" + -DG_LOG_DOMAIN=\"Territorio\" \ + -DSOLIPA_FOUND=1 LIBS = $(TERRITORIO_LIBS) \ -export-dynamic diff --git a/src/Makefile.am b/src/Makefile.am index 8ae956d..b15e4f8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3,7 +3,8 @@ formdir = $(datadir)/$(PACKAGE)/form AM_CPPFLAGS = $(TERRITORIO_CFLAGS) \ -DGUIDIR=\""$(guidir)"\" \ - -DFORMDIR=\""$(formdir)"\" + -DFORMDIR=\""$(formdir)"\" \ + -DSOLIPA_FOUND=1 LIBS = $(TERRITORIO_LIBS) \ -export-dynamic diff --git a/src/stati.c b/src/stati.c index 57f01c7..71db18c 100644 --- a/src/stati.c +++ b/src/stati.c @@ -21,6 +21,7 @@ #include #include +#include #include "stati.h" #include "stato.h" @@ -79,6 +80,9 @@ struct _TerritorioStatiPrivate TerritorioCommons *commons; GtkWidget *widget; + + GdaExGrid *grid; + GtkWidget *wgrid; GtkTreeSelection *selection; GtkListStore *lstore_stati; @@ -133,6 +137,8 @@ TerritorioStati GError *error; ZakAuthoIResource *ires1; + GdaExGridColumn *gcol; + TerritorioStati *a = TERRITORIO_STATI (g_object_new (territorio_stati_get_type (), NULL)); TerritorioStatiPrivate *priv = TERRITORIO_STATI_GET_PRIVATE (a); @@ -142,9 +148,9 @@ TerritorioStati error = NULL; gtk_builder_add_objects_from_file (priv->commons->gtkbuilder, priv->commons->guifile, - g_strsplit (g_strconcat ("lstore_stati|", - (selezione ? "w_stati" : "vbox2"), - NULL), "|", -1), + g_strsplit (g_strconcat ((selezione ? "w_stati" : "vbox2"), + NULL), + "|", -1), &error); if (error != NULL) { @@ -153,8 +159,24 @@ TerritorioStati } priv->widget = GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, (selezione ? "w_stati" : "vbox2"))); - priv->selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (gtk_builder_get_object (priv->commons->gtkbuilder, "treeview1"))); - priv->lstore_stati = GTK_LIST_STORE (gtk_builder_get_object (priv->commons->gtkbuilder, "lstore_stati")); + + /* 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, "label1")))); + + gcol = gdaex_grid_column_new_defaults ("ID", "id", G_TYPE_INT); + 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_container_add (GTK_CONTAINER (gtk_builder_get_object (priv->commons->gtkbuilder, "scrolledwindow1")), priv->wgrid); + gtk_widget_show (priv->wgrid); + + priv->selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->wgrid)); + priv->lstore_stati = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (priv->wgrid))); if (priv->selezione) { @@ -176,7 +198,7 @@ TerritorioStati "clicked", G_CALLBACK (territorio_stati_on_btn_modifica_clicked), (gpointer)a); g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button3"), "clicked", G_CALLBACK (territorio_stati_on_btn_elimina_clicked), (gpointer)a); - g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "treeview1"), + g_signal_connect (priv->wgrid, "row-activated", G_CALLBACK (territorio_stati_on_trv_stati_row_activated), (gpointer)a); if (priv->selezione) @@ -222,42 +244,29 @@ GtkWidget static void territorio_stati_carica (TerritorioStati *territorio_stati) { - GtkTreeIter iter; - GdaDataModel *dm; - - gint rows; - gint row; + gchar *sql; TerritorioStatiPrivate *priv = TERRITORIO_STATI_GET_PRIVATE (territorio_stati); gtk_list_store_clear (priv->lstore_stati); - dm = gdaex_query (priv->commons->gdaex, - "SELECT c.id, c.nome" + sql = g_strdup ("SELECT c.id, c.nome" " FROM stati AS c" " WHERE c.status <> 'E'" " ORDER BY c.nome"); - if (dm != NULL) - { - rows = gda_data_model_get_n_rows (dm); - for (row = 0; row < rows; row++) - { - gtk_list_store_append (priv->lstore_stati, &iter); - gtk_list_store_set (priv->lstore_stati, &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"), - -1); - } - g_object_unref (dm); - } + gdaex_grid_fill_from_sql (priv->grid, priv->commons->gdaex, + sql, + NULL); + + g_free (sql); } static void territorio_stati_modifica (TerritorioStati *territorio_stati) { GtkTreeIter iter; - guint id; + gchar *id; TerritorioStatiPrivate *priv = TERRITORIO_STATI_GET_PRIVATE (territorio_stati); @@ -269,7 +278,7 @@ territorio_stati_modifica (TerritorioStati *territorio_stati) COL_ID, &id, -1); - TerritorioStato *c = territorio_stato_new (priv->commons, id); + TerritorioStato *c = territorio_stato_new (priv->commons, strtol (id, NULL, 10)); g_signal_connect (G_OBJECT (c), "aggiornato", G_CALLBACK (territorio_stati_on_stato_aggiornato), (gpointer)territorio_stati); @@ -291,7 +300,7 @@ static void territorio_stati_selezionato (TerritorioStati *territorio_stati) { GtkTreeIter iter; - guint *id; + gchar *id; TerritorioStatiClass *klass = TERRITORIO_STATI_GET_CLASS (territorio_stati); TerritorioStatiPrivate *priv = TERRITORIO_STATI_GET_PRIVATE (territorio_stati); @@ -302,7 +311,7 @@ territorio_stati_selezionato (TerritorioStati *territorio_stati) COL_ID, &id, -1); - g_signal_emit (G_OBJECT (territorio_stati), klass->selezionato_signal_id, 0, id); + g_signal_emit (G_OBJECT (territorio_stati), klass->selezionato_signal_id, 0, strtol (id, NULL, 10)); gtk_widget_destroy (priv->widget); g_object_unref (G_OBJECT (territorio_stati)); @@ -457,7 +466,7 @@ territorio_stati_on_btn_elimina_clicked (GtkButton *button, ZakAuthoIResource *ires1; GtkTreeIter iter; - guint id; + gchar *id; TerritorioStati *territorio_stati = (TerritorioStati *)user_data; TerritorioStatiPrivate *priv = TERRITORIO_STATI_GET_PRIVATE (territorio_stati); @@ -484,7 +493,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", id)); + g_strdup_printf ("UPDATE stati SET status = 'E' WHERE id = %d", strtol (id, NULL, 10))); territorio_stati_carica (territorio_stati); } -- 2.49.0