From 9b2463d256130b92035df7961c15df2de15524af Mon Sep 17 00:00:00 2001 From: Andrea Zagli <azagli@libero.it> Date: Mon, 25 Jan 2016 16:28:22 +0100 Subject: [PATCH] Utilizzo di GdaExGrid in province. --- data/territorio/gui/territorio.gui | 355 ++++++++++++----------------- src/province.c | 127 ++++------- 2 files changed, 194 insertions(+), 288 deletions(-) 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 @@ <column type="gchararray"/> </columns> </object> - <object class="GtkWindow" id="w_province"> - <property name="can_focus">False</property> - <property name="title" translatable="yes">Province - Territorio</property> - <property name="modal">True</property> - <property name="window_position">center-on-parent</property> - <property name="default_width">550</property> - <property name="default_height">400</property> - <property name="destroy_with_parent">True</property> - <child> - <object class="GtkBox" id="vbox6"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="border_width">5</property> - <property name="orientation">vertical</property> - <property name="spacing">5</property> - <child> - <object class="GtkLabel" id="label13"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="label" translatable="yes"><b>Province</b></property> - <property name="use_markup">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkScrolledWindow" id="scrolledwindow3"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="shadow_type">etched-in</property> - <child> - <object class="GtkTreeView" id="treeview3"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="model">lstore_province</property> - <property name="rules_hint">True</property> - <property name="search_column">1</property> - <child internal-child="selection"> - <object class="GtkTreeSelection" id="treeview-selection3"/> - </child> - <child> - <object class="GtkTreeViewColumn" id="treeviewcolumn3"> - <property name="title">Nome</property> - <child> - <object class="GtkCellRendererText" id="cellrenderertext3"/> - <attributes> - <attribute name="text">1</attribute> - </attributes> - </child> - </object> - </child> - <child> - <object class="GtkTreeViewColumn" id="treeviewcolumn11"> - <property name="title">Sigla</property> - <child> - <object class="GtkCellRendererText" id="cellrenderertext12"/> - <attributes> - <attribute name="text">2</attribute> - </attributes> - </child> - </object> - </child> - <child> - <object class="GtkTreeViewColumn" id="treeviewcolumn8"> - <property name="title">Regione</property> - <child> - <object class="GtkCellRendererText" id="cellrenderertext9"/> - <attributes> - <attribute name="text">3</attribute> - </attributes> - </child> - </object> - </child> - </object> - </child> - </object> - <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">1</property> - </packing> - </child> - <child> - <object class="GtkButtonBox" id="hbuttonbox5"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="spacing">5</property> - <property name="layout_style">end</property> - <child> - <object class="GtkButton" id="button59"> - <property name="label" translatable="yes">E_sporta</property> - <property name="use_action_appearance">False</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <property name="use_underline">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkButton" id="button15"> - <property name="label">gtk-new</property> - <property name="use_action_appearance">False</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <property name="use_stock">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">1</property> - </packing> - </child> - <child> - <object class="GtkButton" id="button16"> - <property name="label">gtk-edit</property> - <property name="use_action_appearance">False</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <property name="use_stock">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">2</property> - </packing> - </child> - <child> - <object class="GtkButton" id="button17"> - <property name="label">gtk-delete</property> - <property name="use_action_appearance">False</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <property name="use_stock">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">3</property> - </packing> - </child> - <child> - <object class="GtkButton" id="button53"> - <property name="label">gtk-find</property> - <property name="use_action_appearance">False</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <property name="use_stock">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">4</property> - </packing> - </child> - <child> - <object class="GtkButton" id="button18"> - <property name="label">gtk-cancel</property> - <property name="use_action_appearance">False</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <property name="use_stock">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">5</property> - </packing> - </child> - <child> - <object class="GtkButton" id="button19"> - <property name="label">gtk-ok</property> - <property name="use_action_appearance">False</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <property name="use_stock">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">6</property> - </packing> - </child> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="position">2</property> - </packing> - </child> - </object> - </child> - </object> <object class="GtkListStore" id="lstore_tipi_aggregazione_territoriale"> <columns> <!-- column-name id --> @@ -1740,6 +1534,155 @@ </object> </child> </object> + <object class="GtkWindow" id="w_province"> + <property name="can_focus">False</property> + <property name="title" translatable="yes">Province - Territorio</property> + <property name="modal">True</property> + <property name="window_position">center-on-parent</property> + <property name="default_width">550</property> + <property name="default_height">400</property> + <property name="destroy_with_parent">True</property> + <child> + <object class="GtkBox" id="vbox6"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="border_width">5</property> + <property name="orientation">vertical</property> + <property name="spacing">5</property> + <child> + <object class="GtkLabel" id="label13"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes"><b>Province</b></property> + <property name="use_markup">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkScrolledWindow" id="scrolledwindow3"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="shadow_type">etched-in</property> + <child> + <placeholder/> + </child> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkButtonBox" id="hbuttonbox5"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="spacing">5</property> + <property name="layout_style">end</property> + <child> + <object class="GtkButton" id="button15"> + <property name="label">gtk-new</property> + <property name="use_action_appearance">False</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="use_stock">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkButton" id="button16"> + <property name="label">gtk-edit</property> + <property name="use_action_appearance">False</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="use_stock">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">2</property> + </packing> + </child> + <child> + <object class="GtkButton" id="button17"> + <property name="label">gtk-delete</property> + <property name="use_action_appearance">False</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="use_stock">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">3</property> + </packing> + </child> + <child> + <object class="GtkButton" id="button53"> + <property name="label">gtk-find</property> + <property name="use_action_appearance">False</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="use_stock">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">4</property> + </packing> + </child> + <child> + <object class="GtkButton" id="button18"> + <property name="label">gtk-cancel</property> + <property name="use_action_appearance">False</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="use_stock">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">5</property> + </packing> + </child> + <child> + <object class="GtkButton" id="button19"> + <property name="label">gtk-ok</property> + <property name="use_action_appearance">False</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="use_stock">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">6</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">2</property> + </packing> + </child> + </object> + </child> + </object> <object class="GtkWindow" id="w_provincia"> <property name="can_focus">False</property> <property name="title" translatable="yes">Provincia - Territorio</property> 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 <azagli@libero.it> + * Copyright (C) 2010-2016 Andrea Zagli <azagli@libero.it> * * 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 <libzakautho/autoz.h> #include <libsolipa/libsolipa.h> +#include <libgdaexgrid/libgdaexgrid.h> #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); } -- 2.49.0