From: Andrea Zagli Date: Mon, 25 Jan 2016 15:28:22 +0000 (+0100) Subject: Utilizzo di GdaExGrid in province. X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=9b2463d256130b92035df7961c15df2de15524af;p=solipa%2Fterritorio Utilizzo di GdaExGrid in province. --- diff --git a/data/territorio/gui/territorio.gui b/data/territorio/gui/territorio.gui index 3950cc5..d3a8b3d 100644 --- a/data/territorio/gui/territorio.gui +++ b/data/territorio/gui/territorio.gui @@ -453,212 +453,6 @@ - - False - Province - Territorio - True - center-on-parent - 550 - 400 - True - - - True - False - 5 - vertical - 5 - - - True - False - <b>Province</b> - True - - - False - True - 0 - - - - - True - True - etched-in - - - True - True - lstore_province - True - 1 - - - - - - Nome - - - - 1 - - - - - - - Sigla - - - - 2 - - - - - - - Regione - - - - 3 - - - - - - - - - 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-find - False - True - True - True - True - - - False - False - 4 - - - - - gtk-cancel - False - True - True - True - True - - - False - False - 5 - - - - - gtk-ok - False - True - True - True - True - - - False - False - 6 - - - - - False - True - 2 - - - - - @@ -1740,6 +1534,155 @@ + + False + Province - Territorio + True + center-on-parent + 550 + 400 + True + + + True + False + 5 + vertical + 5 + + + True + False + <b>Province</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 + 1 + + + + + gtk-edit + False + True + True + True + True + + + False + False + 2 + + + + + gtk-delete + False + True + True + True + True + + + False + False + 3 + + + + + gtk-find + False + True + True + True + True + + + False + False + 4 + + + + + gtk-cancel + False + True + True + True + True + + + False + False + 5 + + + + + gtk-ok + False + True + True + True + True + + + False + False + 6 + + + + + False + True + 2 + + + + + False Provincia - Territorio diff --git a/src/province.c b/src/province.c index d93a5b6..a1fbb84 100644 --- a/src/province.c +++ b/src/province.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 @@ -21,6 +21,7 @@ #include #include +#include #include "province.h" #include "provincia.h" @@ -53,8 +54,6 @@ static gboolean territorio_province_on_key_release_event (GtkWidget *widget, static void territorio_province_on_map (GtkWidget *widget, gpointer user_data); -static void territorio_province_on_btn_esporta_clicked (GtkButton *button, - gpointer user_data); static void territorio_province_on_btn_nuovo_clicked (GtkButton *button, gpointer user_data); static void territorio_province_on_btn_modifica_clicked (GtkButton *button, @@ -96,8 +95,11 @@ struct _TerritorioProvincePrivate TerritorioCommons *commons; GtkWidget *widget; + + GdaExGrid *grid; + GtkWidget *wgrid; GtkTreeSelection *selection; - GtkListStore *lstore_province; + GtkTreeStore *lstore_province; GHashTable *parametri_ricerca; @@ -165,6 +167,8 @@ TerritorioProvince GError *error; ZakAuthoIResource *ires1; + GdaExGridColumn *gcol; + TerritorioProvince *a = TERRITORIO_PROVINCE (g_object_new (territorio_province_get_type (), NULL)); TerritorioProvincePrivate *priv = TERRITORIO_PROVINCE_GET_PRIVATE (a); @@ -186,8 +190,30 @@ TerritorioProvince } priv->widget = GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, (selezione ? "w_province" : "vbox6"))); - priv->selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (gtk_builder_get_object (priv->commons->gtkbuilder, "treeview3"))); - priv->lstore_province = GTK_LIST_STORE (gtk_builder_get_object (priv->commons->gtkbuilder, "lstore_province")); + + /* 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, "label13")))); + + 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); + + gcol = gdaex_grid_column_new_defaults ("Sigla", "sigla", 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_container_add (GTK_CONTAINER (gtk_builder_get_object (priv->commons->gtkbuilder, "scrolledwindow3")), priv->wgrid); + gtk_widget_show (priv->wgrid); + + priv->selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->wgrid)); + priv->lstore_province = GTK_TREE_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (priv->wgrid))); if (priv->selezione) { @@ -203,15 +229,13 @@ TerritorioProvince priv->signal_map = g_signal_connect (priv->widget, "map", G_CALLBACK (territorio_province_on_map), (gpointer)a); - g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button59"), - "clicked", G_CALLBACK (territorio_province_on_btn_esporta_clicked), (gpointer)a); g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button15"), "clicked", G_CALLBACK (territorio_province_on_btn_nuovo_clicked), (gpointer)a); g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button16"), "clicked", G_CALLBACK (territorio_province_on_btn_modifica_clicked), (gpointer)a); g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button17"), "clicked", G_CALLBACK (territorio_province_on_btn_elimina_clicked), (gpointer)a); - g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "treeview3"), + g_signal_connect (priv->wgrid, "row-activated", G_CALLBACK (territorio_province_on_trv_territorio_province_row_activated), (gpointer)a); g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button53"), "clicked", G_CALLBACK (territorio_province_on_btn_trova_clicked), (gpointer)a); @@ -257,9 +281,6 @@ GtkWidget static void territorio_province_carica (TerritorioProvince *territorio_province) { - GtkTreeIter iter; - GdaDataModel *dm; - gchar *sql; gchar *sql_where; @@ -267,12 +288,9 @@ territorio_province_carica (TerritorioProvince *territorio_province) gchar *gcval; gint ival; - gint rows; - gint row; - TerritorioProvincePrivate *priv = TERRITORIO_PROVINCE_GET_PRIVATE (territorio_province); - gtk_list_store_clear (priv->lstore_province); + gtk_tree_store_clear (priv->lstore_province); sql_where = g_strdup (""); if (priv->parametri_ricerca != NULL) @@ -311,32 +329,19 @@ territorio_province_carica (TerritorioProvince *territorio_province) " 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_province, &iter); - gtk_list_store_set (priv->lstore_province, &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_SIGLA, gdaex_data_model_get_field_value_stringify_at (dm, row, "sigla"), - COL_REGIONE, gdaex_data_model_get_field_value_stringify_at (dm, row, "regione"), - -1); - } + gdaex_grid_fill_from_sql (priv->grid, + priv->commons->gdaex, + sql, + NULL); - g_object_unref (dm); - } + g_free (sql); } static void territorio_province_modifica (TerritorioProvince *territorio_province) { GtkTreeIter iter; - guint id; + gchar *id; TerritorioProvincePrivate *priv = TERRITORIO_PROVINCE_GET_PRIVATE (territorio_province); @@ -348,7 +353,7 @@ territorio_province_modifica (TerritorioProvince *territorio_province) COL_ID, &id, -1); - TerritorioProvincia *c = territorio_provincia_new (priv->commons, id); + TerritorioProvincia *c = territorio_provincia_new (priv->commons, strtol (id, NULL, 10)); g_signal_connect (G_OBJECT (c), "aggiornato", G_CALLBACK (territorio_province_on_provincia_aggiornato), (gpointer)territorio_province); @@ -370,7 +375,7 @@ static void territorio_province_selezionato (TerritorioProvince *territorio_province) { GtkTreeIter iter; - guint *id; + gchar *id; TerritorioProvinceClass *klass = TERRITORIO_PROVINCE_GET_CLASS (territorio_province); TerritorioProvincePrivate *priv = TERRITORIO_PROVINCE_GET_PRIVATE (territorio_province); @@ -381,7 +386,7 @@ territorio_province_selezionato (TerritorioProvince *territorio_province) COL_ID, &id, -1); - g_signal_emit (G_OBJECT (territorio_province), klass->selezionato_signal_id, 0, id); + g_signal_emit (G_OBJECT (territorio_province), klass->selezionato_signal_id, 0, strtol (id, NULL, 10)); gtk_widget_destroy (priv->widget); g_object_unref (G_OBJECT (territorio_province)); @@ -486,48 +491,6 @@ territorio_province_on_map (GtkWidget *widget, g_signal_handler_disconnect (G_OBJECT (priv->widget), priv->signal_map); } -static void -territorio_province_on_btn_esporta_clicked (GtkButton *button, - gpointer user_data) -{ - GtkWidget *transient; - - guint ret; - - TerritorioProvince *territorio_province = (TerritorioProvince *)user_data; - TerritorioProvincePrivate *priv = TERRITORIO_PROVINCE_GET_PRIVATE (territorio_province); - - gchar **columns_title = g_strsplit ("ID|Provincia|Sigla|Regione", "|", -1); - - if (priv->selezione) - { - transient = priv->widget; - } - else - { - transient = GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "w_main")); - } - - ret = solipa_gtktreemodel_to_csv_gui (priv->commons->solipa, GTK_WINDOW (transient), GTK_TREE_MODEL (priv->lstore_province), - columns_title, g_strv_length (columns_title)); - if (ret == 1) - { - solipa_message_dialog (transient, - GTK_MESSAGE_INFO, - GTK_BUTTONS_OK, - "Salvataggio eseguito con successo."); - } - else if (ret == 0) - { - solipa_message_dialog (transient, - GTK_MESSAGE_WARNING, - GTK_BUTTONS_OK, - "Errore durante il salvataggio."); - } - - g_strfreev (columns_title); -} - static void territorio_province_on_btn_nuovo_clicked (GtkButton *button, gpointer user_data) @@ -573,7 +536,7 @@ territorio_province_on_btn_elimina_clicked (GtkButton *button, ZakAuthoIResource *ires1; GtkTreeIter iter; - guint id; + gchar *id; TerritorioProvince *territorio_province = (TerritorioProvince *)user_data; TerritorioProvincePrivate *priv = TERRITORIO_PROVINCE_GET_PRIVATE (territorio_province); @@ -600,7 +563,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", id)); + g_strdup_printf ("UPDATE province SET status = 'E' WHERE id = %d", strtol (id, NULL, 10))); territorio_province_carica (territorio_province); }