Implementati i filtri da oggetti chimanti per vie, comuni e province.
authorAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Wed, 17 Aug 2011 11:35:44 +0000 (13:35 +0200)
committerAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Wed, 17 Aug 2011 11:35:44 +0000 (13:35 +0200)
src/comuni.c
src/province.c
src/vie.c

index 0046aecf79033bfd29af4c96d1ec136186d98581..8cfb2d01ae73a18e94cb848efdae1377b49bec5f 100644 (file)
@@ -73,6 +73,12 @@ static void territorio_comuni_on_btn_seleziona_clicked (GtkButton *button,
 
 #define TERRITORIO_COMUNI_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_TERRITORIO_COMUNI, TerritorioComuniPrivate))
 
+enum
+{
+       PROP_0,
+       PROP_PROVINCIA
+};
+
 enum
 {
        COL_ID,
@@ -96,6 +102,8 @@ struct _TerritorioComuniPrivate
                GtkWindow *wtransient;
 
                guint signal_map;
+
+               guint id_provincia;
        };
 
 G_DEFINE_TYPE (TerritorioComuni, territorio_comuni, G_TYPE_OBJECT)
@@ -110,6 +118,13 @@ territorio_comuni_class_init (TerritorioComuniClass *klass)
        object_class->set_property = territorio_comuni_set_property;
        object_class->get_property = territorio_comuni_get_property;
 
+       g_object_class_install_property (object_class, PROP_PROVINCIA,
+                                        g_param_spec_uint ("provincia",
+                                                           "ID province",
+                                                           "ID province",
+                                                           0, G_MAXUINT, 0,
+                                                           G_PARAM_READWRITE));
+
        /**
         * TerritorioComuni::selezionato:
         * @territorio_comuni:
@@ -130,6 +145,8 @@ static void
 territorio_comuni_init (TerritorioComuni *territorio_comuni)
 {
        TerritorioComuniPrivate *priv = TERRITORIO_COMUNI_GET_PRIVATE (territorio_comuni);
+
+       priv->id_provincia = 0;
 }
 
 /**
@@ -262,13 +279,22 @@ territorio_comuni_carica (TerritorioComuni *territorio_comuni)
                                                                 "%'",
                                                                 NULL);
                                }
+               }
+
+       ival = 0;
+       if (priv->id_provincia > 0)
+               {
+                       ival = priv->id_provincia;
+               }
+       else if (priv->parametri_ricerca != NULL)
+               {
                        ival = g_value_get_int ((GValue *)g_hash_table_lookup (priv->parametri_ricerca, "id_province"));
-                       if (ival != 0)
-                               {
-                                       sql_where = g_strconcat (sql_where, " AND c.id_province = ",
-                                                                g_strdup_printf ("%d", ival),
-                                                                NULL);
-                               }
+               }
+       if (ival > 0)
+               {
+                       sql_where = g_strconcat (sql_where, " AND c.id_province = ",
+                                                g_strdup_printf ("%d", ival),
+                                                NULL);
                }
 
        sql = g_strdup_printf ("SELECT c.id, c.nome,"
@@ -282,13 +308,14 @@ territorio_comuni_carica (TerritorioComuni *territorio_comuni)
                               " 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"),
@@ -391,11 +418,14 @@ static void
 territorio_comuni_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
 {
        TerritorioComuni *territorio_comuni = TERRITORIO_COMUNI (object);
-
        TerritorioComuniPrivate *priv = TERRITORIO_COMUNI_GET_PRIVATE (territorio_comuni);
 
        switch (property_id)
                {
+                       case PROP_PROVINCIA:
+                               priv->id_provincia = g_value_get_uint (value);
+                               break;
+
                        default:
                                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
                                break;
@@ -406,11 +436,14 @@ static void
 territorio_comuni_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
 {
        TerritorioComuni *territorio_comuni = TERRITORIO_COMUNI (object);
-
        TerritorioComuniPrivate *priv = TERRITORIO_COMUNI_GET_PRIVATE (territorio_comuni);
 
        switch (property_id)
                {
+                       case PROP_PROVINCIA:
+                               g_value_set_uint (value, priv->id_provincia);
+                               break;
+
                        default:
                                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
                                break;
index 233e320bac1b7aa8bcc9cb0397233a02aba40520..2323523610a739d05136701bae7bb00d6e39842a 100644 (file)
@@ -73,6 +73,12 @@ static void territorio_province_on_btn_seleziona_clicked (GtkButton *button,
 
 #define TERRITORIO_PROVINCE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_TERRITORIO_PROVINCE, TerritorioProvincePrivate))
 
+enum
+{
+       PROP_0,
+       PROP_REGIONE
+};
+
 enum
 {
        COL_ID,
@@ -96,6 +102,8 @@ struct _TerritorioProvincePrivate
                GtkWindow *wtransient;
 
                guint signal_map;
+
+               guint id_regioni;
        };
 
 G_DEFINE_TYPE (TerritorioProvince, territorio_province, G_TYPE_OBJECT)
@@ -110,6 +118,13 @@ territorio_province_class_init (TerritorioProvinceClass *klass)
        object_class->set_property = territorio_province_set_property;
        object_class->get_property = territorio_province_get_property;
 
+       g_object_class_install_property (object_class, PROP_REGIONE,
+                                        g_param_spec_uint ("regione",
+                                                           "ID regioni",
+                                                           "ID regioni",
+                                                           0, G_MAXUINT, 0,
+                                                           G_PARAM_READWRITE));
+
        /**
         * TerritorioProvince::selezionato:
         * @territorio_province:
@@ -130,6 +145,8 @@ static void
 territorio_province_init (TerritorioProvince *territorio_province)
 {
        TerritorioProvincePrivate *priv = TERRITORIO_PROVINCE_GET_PRIVATE (territorio_province);
+
+       priv->id_regioni = 0;
 }
 
 /**
@@ -263,13 +280,22 @@ territorio_province_carica (TerritorioProvince *territorio_province)
                                                                 "%'",
                                                                 NULL);
                                }
+               }
+
+       ival = 0;
+       if (priv->id_regioni > 0)
+               {
+                       ival = priv->id_regioni;
+               }
+       else if (priv->parametri_ricerca != NULL)
+               {
                        ival = g_value_get_int ((GValue *)g_hash_table_lookup (priv->parametri_ricerca, "id_regioni"));
-                       if (ival != 0)
-                               {
-                                       sql_where = g_strconcat (sql_where, " AND c.id_regioni = ",
-                                                                g_strdup_printf ("%d", ival),
-                                                                NULL);
-                               }
+               }
+       if (ival > 0)
+               {
+                       sql_where = g_strconcat (sql_where, " AND c.id_regioni = ",
+                                                g_strdup_printf ("%d", ival),
+                                                NULL);
                }
 
        sql = g_strdup_printf ("SELECT c.id, c.nome, c.sigla, r.nome AS regione"
@@ -392,11 +418,14 @@ static void
 territorio_province_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
 {
        TerritorioProvince *territorio_province = TERRITORIO_PROVINCE (object);
-
        TerritorioProvincePrivate *priv = TERRITORIO_PROVINCE_GET_PRIVATE (territorio_province);
 
        switch (property_id)
                {
+                       case PROP_REGIONE:
+                               priv->id_regioni = g_value_get_uint (value);
+                               break;
+
                        default:
                                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
                                break;
@@ -407,11 +436,14 @@ static void
 territorio_province_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
 {
        TerritorioProvince *territorio_province = TERRITORIO_PROVINCE (object);
-
        TerritorioProvincePrivate *priv = TERRITORIO_PROVINCE_GET_PRIVATE (territorio_province);
 
        switch (property_id)
                {
+                       case PROP_REGIONE:
+                               g_value_set_uint (value, priv->id_regioni);
+                               break;
+
                        default:
                                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
                                break;
index 10b03e85dba9d2391cc4ea0963f530ac7f04cb86..1fcc04479d994f3783a25b996ec617a9802a5794 100644 (file)
--- a/src/vie.c
+++ b/src/vie.c
@@ -82,6 +82,12 @@ static gboolean search_func (GtkTreeModel *model,
 
 #define TERRITORIO_VIE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_TERRITORIO_VIE, TerritorioViePrivate))
 
+enum
+{
+       PROP_0,
+       PROP_COMUNE
+};
+
 enum
 {
        COL_ID,
@@ -106,6 +112,8 @@ struct _TerritorioViePrivate
                GtkWindow *wtransient;
 
                guint signal_map;
+
+               guint id_comuni;
        };
 
 G_DEFINE_TYPE (TerritorioVie, territorio_vie, G_TYPE_OBJECT)
@@ -120,6 +128,13 @@ territorio_vie_class_init (TerritorioVieClass *klass)
        object_class->set_property = territorio_vie_set_property;
        object_class->get_property = territorio_vie_get_property;
 
+       g_object_class_install_property (object_class, PROP_COMUNE,
+                                        g_param_spec_uint ("comune",
+                                                           "ID comuni",
+                                                           "ID comuni",
+                                                           0, G_MAXUINT, 0,
+                                                           G_PARAM_READWRITE));
+
        /**
         * TerritorioVie::selezionato:
         * @territorio_vie:
@@ -140,6 +155,8 @@ static void
 territorio_vie_init (TerritorioVie *territorio_vie)
 {
        TerritorioViePrivate *priv = TERRITORIO_VIE_GET_PRIVATE (territorio_vie);
+
+       priv->id_comuni = 0;
 }
 
 /**
@@ -264,6 +281,7 @@ territorio_vie_carica (TerritorioVie *territorio_vie)
        gtk_list_store_clear (priv->lstore_vie);
 
        sql_where = g_strdup ("");
+
        if (priv->parametri_ricerca != NULL)
                {
                        gcval = g_strstrip ((gchar *)g_value_get_string ((GValue *)g_hash_table_lookup (priv->parametri_ricerca, "nome")));
@@ -274,13 +292,22 @@ territorio_vie_carica (TerritorioVie *territorio_vie)
                                                                 "%'",
                                                                 NULL);
                                }
+               }
+
+       ival = 0;
+       if (priv->id_comuni > 0)
+               {
+                       ival = priv->id_comuni;
+               }
+       else if (priv->parametri_ricerca != NULL)
+               {
                        ival = g_value_get_int ((GValue *)g_hash_table_lookup (priv->parametri_ricerca, "id_comuni"));
-                       if (ival != 0)
-                               {
-                                       sql_where = g_strconcat (sql_where, " AND v.id_comuni = ",
-                                                                g_strdup_printf ("%d", ival),
-                                                                NULL);
-                               }
+               }
+       if (ival > 0)
+               {
+                       sql_where = g_strconcat (sql_where, " AND v.id_comuni = ",
+                                                g_strdup_printf ("%d", ival),
+                                                NULL);
                }
 
        sql = g_strdup_printf ("SELECT v.id, v.nome,"
@@ -297,6 +324,8 @@ territorio_vie_carica (TerritorioVie *territorio_vie)
                               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);
@@ -380,7 +409,7 @@ territorio_vie_selezionato (TerritorioVie *territorio_vie)
                                                         GTK_DIALOG_DESTROY_WITH_PARENT,
                                                         GTK_MESSAGE_WARNING,
                                                         GTK_BUTTONS_OK,
-                                                        "Occorre prima selezionare una via");
+                                                        "Occorre prima selezionare una via.");
                        gtk_dialog_run (GTK_DIALOG (dialog));
                        gtk_widget_destroy (dialog);
                }
@@ -407,11 +436,14 @@ static void
 territorio_vie_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
 {
        TerritorioVie *territorio_vie = TERRITORIO_VIE (object);
-
        TerritorioViePrivate *priv = TERRITORIO_VIE_GET_PRIVATE (territorio_vie);
 
        switch (property_id)
                {
+                       case PROP_COMUNE:
+                               priv->id_comuni = g_value_get_uint (value);
+                               break;
+
                        default:
                                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
                                break;
@@ -422,11 +454,14 @@ static void
 territorio_vie_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
 {
        TerritorioVie *territorio_vie = TERRITORIO_VIE (object);
-
        TerritorioViePrivate *priv = TERRITORIO_VIE_GET_PRIVATE (territorio_vie);
 
        switch (property_id)
                {
+                       case PROP_COMUNE:
+                               g_value_set_uint (value, priv->id_comuni);
+                               break;
+
                        default:
                                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
                                break;