From: Andrea Zagli Date: Mon, 28 Dec 2015 12:18:42 +0000 (+0100) Subject: Inizio utilizzo GdaExQueryEditor. X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=02346e44f2ded388a5d6d0f64a5043b8bae55bf9;p=solipa%2Fterritorio Inizio utilizzo GdaExQueryEditor. --- diff --git a/configure.ac b/configure.ac index 89790df..4ed27ef 100644 --- a/configure.ac +++ b/configure.ac @@ -52,6 +52,7 @@ AC_CONFIG_FILES([ data/territorio/Makefile data/territorio/form/Makefile data/territorio/gui/Makefile + data/territorio/queryeditor/Makefile docs/Makefile docs/territorio/Makefile docs/territorio/examples/Makefile diff --git a/data/territorio/Makefile.am b/data/territorio/Makefile.am index 93b52d7..5045181 100644 --- a/data/territorio/Makefile.am +++ b/data/territorio/Makefile.am @@ -1 +1 @@ -SUBDIRS = form gui +SUBDIRS = form gui queryeditor diff --git a/data/territorio/gui/territorio.gui b/data/territorio/gui/territorio.gui index 2dcc61a..680f68b 100644 --- a/data/territorio/gui/territorio.gui +++ b/data/territorio/gui/territorio.gui @@ -2928,6 +2928,20 @@ 3 + + + gtk-find + True + True + True + True + + + True + True + 4 + + gtk-cancel @@ -2940,7 +2954,7 @@ False False - 4 + 5 @@ -2955,7 +2969,80 @@ False False - 5 + 6 + + + + + False + True + 2 + + + + + + + False + Ricerca fornitori - Gestione ordini cancelleria + True + center-on-parent + 550 + True + + + True + False + 5 + vertical + 5 + + + + + + True + False + + + False + True + 1 + + + + + True + False + True + 5 + end + + + gtk-cancel + True + True + True + True + + + False + False + 0 + + + + + gtk-ok + True + True + True + True + + + False + False + 1 diff --git a/data/territorio/queryeditor/Makefile.am b/data/territorio/queryeditor/Makefile.am new file mode 100644 index 0000000..dc71303 --- /dev/null +++ b/data/territorio/queryeditor/Makefile.am @@ -0,0 +1,6 @@ +queryeditordir = $(datadir)/$(PACKAGE)/queryeditor + +queryeditor_DATA = \ + stati.xml + +EXTRA_DIST = $(queryeditor_DATA) diff --git a/data/territorio/queryeditor/stati.xml b/data/territorio/queryeditor/stati.xml new file mode 100644 index 0000000..5c0f93d --- /dev/null +++ b/data/territorio/queryeditor/stati.xml @@ -0,0 +1,51 @@ + + + + + stati + Stati +
+
+ + + + id + ID + integer + true + equal + + + nome + Nome + text + true + string + + + nazionalita + Nazionalità + text + string + + + sigla + Partita Sigla + text + string + + + cod_istat + Codice ISTAT + text + string + + + comunita_europea + In Comunità Europea + boolean + equal + + + +
diff --git a/libreria/Makefile.am b/libreria/Makefile.am index 784461c..a44251a 100644 --- a/libreria/Makefile.am +++ b/libreria/Makefile.am @@ -26,6 +26,7 @@ libterritorio_la_SOURCES = \ ../src/ricercaprovince.c \ ../src/ricercavie.c \ ../src/stati.c \ + ../src/statiqe.c \ ../src/stato.c \ ../src/tipiaggregazioneterritoriale.c \ ../src/tipoaggregazioneterritoriale.c \ @@ -49,6 +50,7 @@ libterritorio_include_HEADERS = \ ../src/regione.h \ ../src/regioni.h \ ../src/stati.h \ + ../src/statiqe.h \ ../src/stato.h \ ../src/tipiaggregazioneterritoriale.h \ ../src/tipoaggregazioneterritoriale.h \ diff --git a/src/Makefile.am b/src/Makefile.am index b15e4f8..b14787f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,9 +1,11 @@ guidir = $(datadir)/$(PACKAGE)/gui formdir = $(datadir)/$(PACKAGE)/form +queryeditordir = $(datadir)/$(PACKAGE)/queryeditor AM_CPPFLAGS = $(TERRITORIO_CFLAGS) \ -DGUIDIR=\""$(guidir)"\" \ -DFORMDIR=\""$(formdir)"\" \ + -DQUERYEDITORDIR=\""$(queryeditordir)"\" \ -DSOLIPA_FOUND=1 LIBS = $(TERRITORIO_LIBS) \ @@ -47,6 +49,8 @@ territorio_SOURCES = \ ricercavie.h \ stati.c \ stati.h \ + statiqe.c \ + statiqe.h \ stato.c \ stato.h \ tipiaggregazioneterritoriale.c \ diff --git a/src/commons.h b/src/commons.h index ac0d7f4..b49e782 100644 --- a/src/commons.h +++ b/src/commons.h @@ -42,6 +42,7 @@ typedef struct { gchar *guidir; gchar *formdir; + gchar *queryeditordir; GtkBuilder *gtkbuilder; diff --git a/src/main.c b/src/main.c index 93a396c..edb15e7 100644 --- a/src/main.c +++ b/src/main.c @@ -298,7 +298,7 @@ main (int argc, char *argv[]) commons->utente = g_strdup (utente); - /* leggo i parametri per libzak_autho */ + /* leggo i parametri per libzakautho */ error = NULL; cnc_string = g_key_file_get_value (config, "AUTOZ", "cnc_string", &error); if (cnc_string == NULL) @@ -350,17 +350,20 @@ main (int argc, char *argv[]) { commons->guidir = g_strdup (GUIDIR); commons->formdir = g_strdup (FORMDIR); + commons->queryeditordir = g_strdup (QUERYEDITORDIR); } else { commons->guidir = g_build_filename (moddir, "share", PACKAGE, "gui", NULL); commons->formdir = g_build_filename (moddir, "share", PACKAGE, "form", NULL); + commons->queryeditordir = g_build_filename (moddir, "share", PACKAGE, "queryeditor", NULL); } #else commons->guidir = g_strdup (GUIDIR); commons->formdir = g_strdup (FORMDIR); + commons->queryeditordir = g_strdup (QUERYEDITORDIR); #endif diff --git a/src/stati.c b/src/stati.c index 71db18c..120a566 100644 --- a/src/stati.c +++ b/src/stati.c @@ -12,7 +12,7 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software + * License along with this library; if not, writ!e to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ @@ -25,6 +25,7 @@ #include "stati.h" #include "stato.h" +#include "statiqe.h" static void territorio_stati_class_init (TerritorioStatiClass *klass); static void territorio_stati_init (TerritorioStati *territorio_stati); @@ -34,6 +35,7 @@ static void territorio_stati_modifica (TerritorioStati *territorio_stati); static void territorio_stati_selezionato (TerritorioStati *territorio_stati); static void territorio_stati_on_stato_aggiornato (gpointer instance, gpointer user_data); +static void territorio_stati_on_stati_qe_selezionato (gpointer instance, gpointer parametri, gpointer user_data); static void territorio_stati_set_property (GObject *object, guint property_id, @@ -61,6 +63,9 @@ static void territorio_stati_on_trv_stati_row_activated (GtkTreeView *tree_view, GtkTreeViewColumn *column, gpointer user_data); +static void territorio_stati_on_btn_trova_clicked (GtkButton *button, + gpointer user_data); + static void territorio_stati_on_btn_annulla_clicked (GtkButton *button, gpointer user_data); static void territorio_stati_on_btn_seleziona_clicked (GtkButton *button, @@ -88,6 +93,8 @@ struct _TerritorioStatiPrivate gboolean selezione; GtkWindow *wtransient; + + GdaExQueryEditor *qe; }; G_DEFINE_TYPE (TerritorioStati, territorio_stati, G_TYPE_OBJECT) @@ -201,6 +208,9 @@ TerritorioStati g_signal_connect (priv->wgrid, "row-activated", G_CALLBACK (territorio_stati_on_trv_stati_row_activated), (gpointer)a); + g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button69"), + "clicked", G_CALLBACK (territorio_stati_on_btn_trova_clicked), (gpointer)a); + if (priv->selezione) { gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "label1"))); @@ -250,12 +260,31 @@ territorio_stati_carica (TerritorioStati *territorio_stati) gtk_list_store_clear (priv->lstore_stati); - sql = g_strdup ("SELECT c.id, c.nome" + if (!GDAEX_IS_QUERY_EDITOR (priv->qe) + || gdaex_query_editor_get_sql_where (priv->qe) == NULL + || g_strcmp0 (gdaex_query_editor_get_sql_where (priv->qe), "") == 0) + { + sql = g_strdup ("SELECT c.id, c.nome" " FROM stati AS c" " WHERE c.status <> 'E'" " ORDER BY c.nome"); + } + else + { + sql = g_strconcat ("SELECT ", + gdaex_query_editor_get_sql_select (priv->qe), + " FROM ", + gdaex_query_editor_get_sql_from (priv->qe), + " WHERE ", + gdaex_query_editor_get_sql_where (priv->qe), + " AND stati.status <> 'E'" + " ORDER BY stati.nome", + NULL); + + } - gdaex_grid_fill_from_sql (priv->grid, priv->commons->gdaex, + gdaex_grid_fill_from_sql (priv->grid, + priv->commons->gdaex, sql, NULL); @@ -331,6 +360,16 @@ territorio_stati_on_stato_aggiornato (gpointer instance, gpointer user_data) territorio_stati_carica ((TerritorioStati *)user_data); } +static void +territorio_stati_on_stati_qe_selezionato (gpointer instance, gpointer parametri, gpointer user_data) +{ + TerritorioStati *territorio_stati = TERRITORIO_STATI (user_data); + TerritorioStatiPrivate *priv = TERRITORIO_STATI_GET_PRIVATE (territorio_stati); + + priv->qe = (GdaExQueryEditor *)parametri; + territorio_stati_carica (territorio_stati); +} + static void territorio_stati_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { @@ -526,6 +565,20 @@ territorio_stati_on_trv_stati_row_activated (GtkTreeView *tree_view, } +static void +territorio_stati_on_btn_trova_clicked (GtkButton *button, + gpointer user_data) +{ + TerritorioStatiPrivate *priv = TERRITORIO_STATI_GET_PRIVATE ((TerritorioStati *)user_data); + + TerritorioStatiQe *c = territorio_stati_qe_new (priv->commons, priv->qe); + + g_signal_connect (G_OBJECT (c), "selezionato", + G_CALLBACK (territorio_stati_on_stati_qe_selezionato), user_data); + + territorio_stati_qe_show (c, GTK_WINDOW (priv->wtransient)); +} + static void territorio_stati_on_btn_annulla_clicked (GtkButton *button, gpointer user_data) diff --git a/src/statiqe.c b/src/statiqe.c new file mode 100644 index 0000000..9f97d30 --- /dev/null +++ b/src/statiqe.c @@ -0,0 +1,274 @@ +/* + * Copyright (C) 2015 Andrea Zagli + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifdef HAVE_CONFIG_H + #include +#endif + +#include + +#include +#include + +#include "statiqe.h" + +static void territorio_stati_qe_class_init (TerritorioStatiQeClass *klass); +static void territorio_stati_qe_init (TerritorioStatiQe *territorio_stati_qe); + +static void territorio_stati_qe_selezionato (TerritorioStatiQe *territorio_stati_qe); + +static void territorio_stati_qe_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void territorio_stati_qe_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +static gboolean territorio_stati_qe_on_key_release_event (GtkWidget *widget, + GdkEventKey *event, + gpointer user_data); + +static void territorio_stati_qe_on_btn_annulla_clicked (GtkButton *button, + gpointer user_data); +static void territorio_stati_qe_on_btn_seleziona_clicked (GtkButton *button, + gpointer user_data); + +#define TERRITORIO_STATI_QE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_TERRITORIO_STATI_QE, TerritorioStatiQePrivate)) + +typedef struct _TerritorioStatiQePrivate TerritorioStatiQePrivate; +struct _TerritorioStatiQePrivate + { + TerritorioCommons *commons; + + GtkWidget *widget; + + GdaExQueryEditor *qe; + GtkWidget *wqe; + }; + +G_DEFINE_TYPE (TerritorioStatiQe, territorio_stati_qe, G_TYPE_OBJECT) + +static void +territorio_stati_qe_class_init (TerritorioStatiQeClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (object_class, sizeof (TerritorioStatiQePrivate)); + + object_class->set_property = territorio_stati_qe_set_property; + object_class->get_property = territorio_stati_qe_get_property; + + /** + * TerritorioStatiQe::selezionato: + * @territorio_stati_qe: + * + */ + klass->selezionato_signal_id = g_signal_new ("selezionato", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + 0, + NULL, + NULL, + g_cclosure_marshal_VOID__UINT, + G_TYPE_NONE, + 1, G_TYPE_UINT); +} + +static void +territorio_stati_qe_init (TerritorioStatiQe *territorio_stati_qe) +{ + TerritorioStatiQePrivate *priv = TERRITORIO_STATI_QE_GET_PRIVATE (territorio_stati_qe); +} + +/** + * territorio_stati_qe_new: + * @commons: + * @qe: + * + * Returns: the newly created #TerritorioStatiQe object. + */ +TerritorioStatiQe +*territorio_stati_qe_new (TerritorioCommons *commons, GdaExQueryEditor *qe) +{ + GError *error; + + TerritorioStatiQe *a = TERRITORIO_STATI_QE (g_object_new (territorio_stati_qe_get_type (), NULL)); + + TerritorioStatiQePrivate *priv = TERRITORIO_STATI_QE_GET_PRIVATE (a); + + priv->commons = commons; + + error = NULL; + gtk_builder_add_objects_from_file (priv->commons->gtkbuilder, priv->commons->guifile, + g_strsplit ("w_stati_qe", + "|", -1), + &error); + if (error != NULL) + { + g_warning ("Errore: %s.", error->message); + return NULL; + } + + priv->widget = GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "w_stati_qe")); + + g_signal_connect (priv->widget, + "key-release-event", G_CALLBACK (territorio_stati_qe_on_key_release_event), (gpointer)a); + + g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button65"), + "clicked", G_CALLBACK (territorio_stati_qe_on_btn_annulla_clicked), (gpointer)a); + g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button66"), + "clicked", G_CALLBACK (territorio_stati_qe_on_btn_seleziona_clicked), (gpointer)a); + + priv->qe = gdaex_query_editor_new (priv->commons->gdaex); + gdaex_query_editor_load_tables_from_file (priv->qe, g_build_filename (priv->commons->queryeditordir, "stati.xml", NULL), TRUE); + gdaex_query_editor_set_show_visible (priv->qe, FALSE); + gdaex_query_editor_set_order_visible (priv->qe, FALSE); + + priv->wqe = gdaex_query_editor_get_widget (priv->qe); + gtk_box_pack_start (GTK_BOX (gtk_builder_get_object (priv->commons->gtkbuilder, "vbox19")), + priv->wqe, + TRUE, TRUE, 0); + gtk_box_reorder_child (GTK_BOX (gtk_builder_get_object (priv->commons->gtkbuilder, "vbox19")), + priv->wqe, + 0); + + if (GDAEX_IS_QUERY_EDITOR (qe)) + { + gdaex_query_editor_load_choices_from_xml (priv->qe, + gdaex_query_editor_get_sql_as_xml (qe), + TRUE); + } + + return a; +} + +/** + * territorio_stati_qe_get_widget: + * @territorio_stati_qe: + * + */ +GtkWidget +*territorio_stati_qe_get_widget (TerritorioStatiQe *territorio_stati_qe) +{ + TerritorioStatiQePrivate *priv = TERRITORIO_STATI_QE_GET_PRIVATE (territorio_stati_qe); + + return priv->widget; +} + +/** + * territorio_stati_qe_show: + * @territorio_stati_qe: + * @parent: + */ +GtkWidget +*territorio_stati_qe_show (TerritorioStatiQe *territorio_stati_qe, GtkWindow *parent) +{ + GtkWidget *w; + + TerritorioStatiQePrivate *priv = TERRITORIO_STATI_QE_GET_PRIVATE (territorio_stati_qe); + + w = territorio_stati_qe_get_widget (territorio_stati_qe); + if (parent != NULL) + { + gtk_window_set_transient_for (GTK_WINDOW (w), parent); + } + gtk_widget_show_all (w); + + return w; +} + +/* PRIVATE */ +static void +territorio_stati_qe_selezionato (TerritorioStatiQe *territorio_stati_qe) +{ + TerritorioStatiQeClass *klass = TERRITORIO_STATI_QE_GET_CLASS (territorio_stati_qe); + TerritorioStatiQePrivate *priv = TERRITORIO_STATI_QE_GET_PRIVATE (territorio_stati_qe); + + g_signal_emit (G_OBJECT (territorio_stati_qe), klass->selezionato_signal_id, 0, (gpointer)priv->qe); + + gtk_widget_destroy (priv->widget); + g_object_unref (G_OBJECT (territorio_stati_qe)); +} + +static void +territorio_stati_qe_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) +{ + TerritorioStatiQe *territorio_stati_qe = TERRITORIO_STATI_QE (object); + TerritorioStatiQePrivate *priv = TERRITORIO_STATI_QE_GET_PRIVATE (territorio_stati_qe); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +territorio_stati_qe_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) +{ + TerritorioStatiQe *territorio_stati_qe = TERRITORIO_STATI_QE (object); + TerritorioStatiQePrivate *priv = TERRITORIO_STATI_QE_GET_PRIVATE (territorio_stati_qe); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +/* CALLBACK */ +static gboolean +territorio_stati_qe_on_key_release_event (GtkWidget *widget, + GdkEventKey *event, + gpointer user_data) +{ + switch (event->keyval) + { + case GDK_KEY_Escape: + { + TerritorioStatiQePrivate *priv = TERRITORIO_STATI_QE_GET_PRIVATE ((TerritorioStatiQe *)user_data); + + gtk_button_clicked (GTK_BUTTON (gtk_builder_get_object (priv->commons->gtkbuilder, "button65"))); + return TRUE; + } + } + + return FALSE; +} + +static void +territorio_stati_qe_on_btn_annulla_clicked (GtkButton *button, + gpointer user_data) +{ + TerritorioStatiQePrivate *priv = TERRITORIO_STATI_QE_GET_PRIVATE ((TerritorioStatiQe *)user_data); + + gtk_widget_destroy (priv->widget); + g_object_unref (G_OBJECT (user_data)); +} + +static void +territorio_stati_qe_on_btn_seleziona_clicked (GtkButton *button, + gpointer user_data) +{ + territorio_stati_qe_selezionato ((TerritorioStatiQe *)user_data); +} diff --git a/src/statiqe.h b/src/statiqe.h new file mode 100644 index 0000000..a780021 --- /dev/null +++ b/src/statiqe.h @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2015 Andrea Zagli + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __TERRITORIO_STATI_QE_H__ +#define __TERRITORIO_STATI_QE_H__ + +#include +#include + +#include + +#include "commons.h" + +G_BEGIN_DECLS + + +#define TYPE_TERRITORIO_STATI_QE (territorio_stati_qe_get_type ()) +#define TERRITORIO_STATI_QE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TERRITORIO_STATI_QE, TerritorioStatiQe)) +#define TERRITORIO_STATI_QE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TERRITORIO_STATI_QE, TerritorioStatiQeClass)) +#define IS_TERRITORIO_STATI_QE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TERRITORIO_STATI_QE)) +#define IS_TERRITORIO_STATI_QE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TERRITORIO_STATI_QE)) +#define TERRITORIO_STATI_QE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TERRITORIO_STATI_QE, TerritorioStatiQeClass)) + + +typedef struct _TerritorioStatiQe TerritorioStatiQe; +typedef struct _TerritorioStatiQeClass TerritorioStatiQeClass; + +struct _TerritorioStatiQe + { + GObject parent; + }; + +struct _TerritorioStatiQeClass + { + GObjectClass parent_class; + + guint selezionato_signal_id; + }; + +GType territorio_stati_qe_get_type (void) G_GNUC_CONST; + +TerritorioStatiQe *territorio_stati_qe_new (TerritorioCommons *commons, GdaExQueryEditor *qe); + +GtkWidget *territorio_stati_qe_get_widget (TerritorioStatiQe *territorio_stati_qe); +GtkWidget *territorio_stati_qe_show (TerritorioStatiQe *territorio_stati_qe, GtkWindow *parent); + + +G_END_DECLS + +#endif /* __TERRITORIO_STATI_QE_H__ */