From: Andrea Zagli Date: Sat, 21 Dec 2019 10:28:06 +0000 (+0100) Subject: Migrato il form aggregazione_territoriale a zakform. X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=1d945e1630ead15e1e6dacc6f22377a7741b48db;p=solipa%2Fterritorio Migrato il form aggregazione_territoriale a zakform. Utilizzo di ZakGtkDecoder. --- diff --git a/data/territorio/form/aggregazione_territoriale.form b/data/territorio/form/aggregazione_territoriale.form index 823d6a1..299ec15 100644 --- a/data/territorio/form/aggregazione_territoriale.form +++ b/data/territorio/form/aggregazione_territoriale.form @@ -1,29 +1,25 @@ - - - aggregazioni_territoriali
- - - - t - t - - - - - 0 - - SELECT id, nome FROM tipi_aggregazione_territoriale WHERE status <> 'E' ORDER BY nome - - - t - - - - - - t - - - -
+ + + id + integer + + TRUE + label32 + + + + id_tipi_aggregazione_territoriale + integer + + zakgtkdecoder1 + + + + nome + string + + entry14 + + + diff --git a/data/territorio/gui/territorio.gui b/data/territorio/gui/territorio.gui index 46b0e00..9ad998d 100644 --- a/data/territorio/gui/territorio.gui +++ b/data/territorio/gui/territorio.gui @@ -3,6 +3,7 @@ + False 5 @@ -264,176 +265,6 @@ - - False - Aggregazione territoriale - Territorio - True - center-on-parent - True - - - - - - True - False - 5 - vertical - 5 - - - True - False - 5 - 5 - - - True - False - ID - 0 - - - 0 - 0 - - - - - True - False - lbl_id - 0 - - - 1 - 0 - - - - - True - True - True - 150 - ● - True - False - False - - - 1 - 2 - - - - - True - False - lstore_tipi_aggregazione_territoriale - - - - 1 - - - - - 1 - 1 - - - - - True - False - Tipo - 0 - - - 0 - 1 - - - - - True - False - Nome - 0 - - - 0 - 2 - - - - - True - True - 0 - - - - - True - False - 5 - end - - - gtk-cancel - False - True - True - True - True - - - False - False - 0 - - - - - gtk-save - False - True - True - True - True - - - False - False - 1 - - - - - Salva e _chiudi - True - True - True - True - - - True - True - 2 - - - - - False - True - 1 - - - - - @@ -683,6 +514,169 @@ + + False + Aggregazione territoriale - Territorio + True + center-on-parent + True + + + + + + True + False + 5 + vertical + 5 + + + True + False + 5 + 5 + + + True + False + ID + 0 + + + 0 + 0 + + + + + True + False + lbl_id + 0 + + + 1 + 0 + + + + + True + True + True + 150 + ● + True + False + False + + + 1 + 2 + + + + + True + False + Tipo + 0 + + + 0 + 1 + + + + + True + False + Nome + 0 + + + 0 + 2 + + + + + True + False + + + 1 + 1 + + + + + True + True + 0 + + + + + True + False + 5 + end + + + gtk-cancel + False + True + True + True + True + + + False + False + 0 + + + + + gtk-save + False + True + True + True + True + + + False + False + 1 + + + + + Salva e _chiudi + True + True + True + True + + + True + True + 2 + + + + + False + True + 1 + + + + + False Comune - Territorio diff --git a/src/aggregazioneterritoriale.c b/src/aggregazioneterritoriale.c index cdc1168..11ed6a4 100644 --- a/src/aggregazioneterritoriale.c +++ b/src/aggregazioneterritoriale.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2018 Andrea Zagli + * Copyright (C) 2010-2019 Andrea Zagli * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -17,10 +17,15 @@ * */ -#include +#include +#include +#include +#include +#include #include #include +#include "tipiaggregazioneterritoriale.h" #include "aggregazioneterritoriale.h" static void territorio_aggregazione_territoriale_class_init (TerritorioAggregazioneTerritorialeClass *klass); @@ -29,6 +34,9 @@ static void territorio_aggregazione_territoriale_init (TerritorioAggregazioneTer static void territorio_aggregazione_territoriale_carica (TerritorioAggregazioneTerritoriale *territorio_aggregazione_territoriale); static void territorio_aggregazione_territoriale_salva (TerritorioAggregazioneTerritoriale *territorio_aggregazione_territoriale, gboolean chiudi); +static void territorio_aggregazione_territoriale_on_tipo_selezionato (gpointer instance, guint id, gpointer user_data); +static gchar *territorio_aggregazione_territoriale_on_tipo_decode (gpointer instance, gchar *key, gpointer user_data); + static gboolean territorio_aggregazione_territoriale_conferma_chiusura (TerritorioAggregazioneTerritoriale *territorio_aggregazione_territoriale); static void territorio_aggregazione_territoriale_set_property (GObject *object, @@ -44,6 +52,8 @@ static gboolean territorio_aggregazione_territoriale_on_w_aggregazione_territori GdkEvent *event, gpointer user_data); +static void territorio_aggregazione_territoriale_on_btn_ricerca_tipo_clicked (GtkButton *button, + gpointer user_data); static void territorio_aggregazione_territoriale_on_btn_annulla_clicked (GtkButton *button, gpointer user_data); static void territorio_aggregazione_territoriale_on_btn_salva_clicked (GtkButton *button, @@ -63,7 +73,8 @@ struct _TerritorioAggregazioneTerritorialePrivate { TerritorioCommons *commons; - GtkForm *form; + ZakFormGtkForm *form; + ZakFormGdaexProvider *form_provider; GtkWidget *w; @@ -127,8 +138,7 @@ TerritorioAggregazioneTerritoriale error = NULL; gtk_builder_add_objects_from_file (priv->commons->gtkbuilder, priv->commons->guifile, - g_strsplit (g_strconcat ("lstore_tipi_aggregazione_territoriale" - "|w_aggregazione_territoriale", NULL), "|", -1), + g_strsplit (g_strconcat ("w_aggregazione_territoriale", NULL), "|", -1), &error); if (error != NULL) { @@ -136,19 +146,26 @@ TerritorioAggregazioneTerritoriale return NULL; } - priv->form = gtk_form_new (); - g_object_set (G_OBJECT (priv->form), "gdaex", priv->commons->gdaex, NULL); - gtk_form_load_from_file (priv->form, g_build_filename (priv->commons->formdir, "aggregazione_territoriale.form", NULL), priv->commons->gtkbuilder); + priv->form = zak_form_gtk_form_new (); + zak_form_gtk_form_set_gtkbuilder (priv->form, priv->commons->gtkbuilder); + zak_form_form_load_from_file (ZAK_FORM_FORM (priv->form), g_build_filename (priv->commons->formdir, "aggregazione_territoriale.form", NULL)); + + priv->form_provider = zak_form_gdaex_provider_new (priv->commons->gdaex, "aggregazioni_territoriali"); priv->w = GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "w_aggregazione_territoriale")); - priv->objects = gtk_form_get_objects_by_name (priv->form, + priv->objects = zak_form_gtk_form_get_gobjects_by_name (priv->form, "label32", NULL); g_signal_connect (priv->w, "delete-event", G_CALLBACK (territorio_aggregazione_territoriale_on_w_aggregazione_territoriale_delete_event), (gpointer)a); + g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "zakgtkdecoder1"), + "btn-browse-clicked", G_CALLBACK (territorio_aggregazione_territoriale_on_btn_ricerca_tipo_clicked), (gpointer)a); + g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "zakgtkdecoder1"), + "decode", G_CALLBACK (territorio_aggregazione_territoriale_on_tipo_decode), (gpointer)a); + g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button41"), "clicked", G_CALLBACK (territorio_aggregazione_territoriale_on_btn_annulla_clicked), (gpointer)a); g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button42"), @@ -156,13 +173,14 @@ TerritorioAggregazioneTerritoriale g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button76"), "clicked", G_CALLBACK (territorio_aggregazione_territoriale_on_btn_salva_chiudi_clicked), (gpointer)a); - priv->id = id; + zak_form_form_clear (ZAK_FORM_FORM (priv->form)); + priv->id = id; if (priv->id == 0) { gtk_label_set_text (GTK_LABEL (priv->objects[LBL_ID]), ""); - gtk_form_set_as_origin (priv->form); + zak_form_form_set_as_original (ZAK_FORM_FORM (priv->form)); } else { @@ -198,7 +216,7 @@ territorio_aggregazione_territoriale_carica (TerritorioAggregazioneTerritoriale { TerritorioAggregazioneTerritorialePrivate *priv = TERRITORIO_AGGREGAZIONE_TERRITORIALE_GET_PRIVATE (territorio_aggregazione_territoriale); - if (gtk_form_fill_from_table (priv->form)) + if (zak_form_form_load (ZAK_FORM_FORM (priv->form), ZAK_FORM_IPROVIDER (priv->form_provider))) { } } @@ -206,31 +224,42 @@ territorio_aggregazione_territoriale_carica (TerritorioAggregazioneTerritoriale static void territorio_aggregazione_territoriale_salva (TerritorioAggregazioneTerritoriale *territorio_aggregazione_territoriale, gboolean chiudi) { - gchar *sql; + gboolean success;; TerritorioAggregazioneTerritorialeClass *klass = TERRITORIO_AGGREGAZIONE_TERRITORIALE_GET_CLASS (territorio_aggregazione_territoriale); TerritorioAggregazioneTerritorialePrivate *priv = TERRITORIO_AGGREGAZIONE_TERRITORIALE_GET_PRIVATE (territorio_aggregazione_territoriale); - if (!gtk_form_check (priv->form, (priv->id != 0), NULL, TRUE, priv->w, TRUE)) + if (!zak_form_gtk_form_is_valid (priv->form, priv->w)) { return; } + success = FALSE; + if (priv->id == 0) { - sql = gtk_form_get_sql (priv->form, GTK_FORM_SQL_INSERT); + guint new_id; + + new_id = gdaex_get_new_id (priv->commons->gdaex, + "aggregazioni_territoriali", + "id", + NULL); + + gtk_label_set_text (GTK_LABEL (priv->objects[LBL_ID]), g_strdup_printf ("%d", new_id)); + + success = zak_form_form_insert (ZAK_FORM_FORM (priv->form), ZAK_FORM_IPROVIDER (priv->form_provider)); } else { - sql = gtk_form_get_sql (priv->form, GTK_FORM_SQL_UPDATE); + success = zak_form_form_update (ZAK_FORM_FORM (priv->form), ZAK_FORM_IPROVIDER (priv->form_provider)); } - if (gdaex_execute (priv->commons->gdaex, sql) == 1) + if (success) { g_signal_emit (territorio_aggregazione_territoriale, klass->aggiornato_signal_id, 0); - gtk_form_set_as_origin (priv->form); + zak_form_form_set_as_original (ZAK_FORM_FORM (priv->form)); if (priv->id == 0) { @@ -301,7 +330,7 @@ territorio_aggregazione_territoriale_conferma_chiusura (TerritorioAggregazioneTe ret = TRUE; if (gtk_widget_get_sensitive (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "button42"))) - && gtk_form_is_changed (priv->form)) + && zak_form_form_is_changed (ZAK_FORM_FORM (priv->form))) { if (solipa_message_dialog (priv->w, GTK_MESSAGE_QUESTION, @@ -324,6 +353,61 @@ territorio_aggregazione_territoriale_on_w_aggregazione_territoriale_delete_event return !territorio_aggregazione_territoriale_conferma_chiusura ((TerritorioAggregazioneTerritoriale *)user_data); } +static void +territorio_aggregazione_territoriale_on_tipo_selezionato (gpointer instance, guint id, gpointer user_data) +{ + TerritorioAggregazioneTerritoriale *f = (TerritorioAggregazioneTerritoriale *)user_data; + TerritorioAggregazioneTerritorialePrivate *priv = TERRITORIO_AGGREGAZIONE_TERRITORIALE_GET_PRIVATE (f); + + zak_gtk_decoder_set_key (ZAK_GTK_DECODER (gtk_builder_get_object (priv->commons->gtkbuilder, "zakgtkdecoder1")), + g_strdup_printf ("%d", id)); +} + +static gchar +*territorio_aggregazione_territoriale_on_tipo_decode (gpointer instance, gchar *key, gpointer user_data) +{ + GString *ret; + gchar *sql; + GdaDataModel *dm; + + TerritorioAggregazioneTerritoriale *f = (TerritorioAggregazioneTerritoriale *)user_data; + TerritorioAggregazioneTerritorialePrivate *priv = TERRITORIO_AGGREGAZIONE_TERRITORIALE_GET_PRIVATE (f); + + ret = g_string_new (""); + + sql = g_strdup_printf ("SELECT nome" + " FROM tipi_aggregazione_territoriale" + " WHERE id = %d", + strtol (key, NULL, 10)); + dm = gdaex_query (priv->commons->gdaex, sql); + g_free (sql); + if (!gdaex_data_model_is_empty (dm)) + { + g_string_append (ret, gdaex_data_model_get_value_stringify_at (dm, 0, 0)); + } + + return ret->str; +} + +static void +territorio_aggregazione_territoriale_on_btn_ricerca_tipo_clicked (GtkButton *button, + gpointer user_data) +{ + GtkWidget *w; + + TerritorioAggregazioneTerritoriale *f = (TerritorioAggregazioneTerritoriale *)user_data; + TerritorioAggregazioneTerritorialePrivate *priv = TERRITORIO_AGGREGAZIONE_TERRITORIALE_GET_PRIVATE (f); + + TerritorioTipiAggregazioneTerritoriale *c = territorio_tipi_aggregazione_territoriale_new (priv->commons, TRUE); + + g_signal_connect (G_OBJECT (c), "selezionato", + G_CALLBACK (territorio_aggregazione_territoriale_on_tipo_selezionato), user_data); + + w = territorio_tipi_aggregazione_territoriale_get_widget (c); + gtk_window_set_transient_for (GTK_WINDOW (w), GTK_WINDOW (priv->w)); + gtk_widget_show (w); +} + static void territorio_aggregazione_territoriale_on_btn_annulla_clicked (GtkButton *button, gpointer user_data) diff --git a/src/tipiaggregazioneterritoriale.c b/src/tipiaggregazioneterritoriale.c index b8b0192..b210d6a 100644 --- a/src/tipiaggregazioneterritoriale.c +++ b/src/tipiaggregazioneterritoriale.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2016 Andrea Zagli + * Copyright (C) 2010-2019 Andrea Zagli * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -286,7 +286,7 @@ static void territorio_tipi_aggregazione_territoriale_selezionato (TerritorioTipiAggregazioneTerritoriale *territorio_tipi_aggregazione_territoriale) { GtkTreeIter iter; - gchar *id; + guint id; TerritorioTipiAggregazioneTerritorialeClass *klass = TERRITORIO_TIPI_AGGREGAZIONE_TERRITORIALE_GET_CLASS (territorio_tipi_aggregazione_territoriale); TerritorioTipiAggregazioneTerritorialePrivate *priv = TERRITORIO_TIPI_AGGREGAZIONE_TERRITORIALE_GET_PRIVATE (territorio_tipi_aggregazione_territoriale); @@ -297,7 +297,7 @@ territorio_tipi_aggregazione_territoriale_selezionato (TerritorioTipiAggregazion COL_ID, &id, -1); - g_signal_emit (G_OBJECT (territorio_tipi_aggregazione_territoriale), klass->selezionato_signal_id, 0, strtol (id, NULL, 10)); + g_signal_emit (G_OBJECT (territorio_tipi_aggregazione_territoriale), klass->selezionato_signal_id, 0, id); gtk_widget_destroy (priv->widget); g_object_unref (G_OBJECT (territorio_tipi_aggregazione_territoriale));