From: Andrea Zagli Date: Wed, 15 Jul 2009 16:56:11 +0000 (+0200) Subject: Added GtkGis::get_xml. X-Git-Tag: GTKGIS_0_0_2~6 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=022472c84d4457473911d89adb4233fe88293880;p=libgtkgis Added GtkGis::get_xml. Implemented GtkGis::save_to_xml. Added GtkGisLayer::get_xml. Added GtkGisLayerSource::get_xml. Added GtkGisLayerSourceShp::get_xml. Added GtkGisLayerSourcePostgis::get_xml. Added GtkGisLayerSourceRaster::get_xml. --- diff --git a/.gitignore b/.gitignore index ed7b341..b6d27c4 100644 --- a/.gitignore +++ b/.gitignore @@ -30,6 +30,7 @@ stamp-h1 tests/.deps tests/.libs tests/from_xml +tests/test_comune.gtkgis tests/samples # temporarily diff --git a/src/gtkgis.c b/src/gtkgis.c index 27ceafe..3806401 100644 --- a/src/gtkgis.c +++ b/src/gtkgis.c @@ -39,6 +39,10 @@ static void gtk_gis_destroy (GtkObject *object); static void gtk_gis_add (GtkContainer *container, GtkWidget *widget); + +static gboolean gtk_gis_focus (GtkWidget*widget, + GtkDirectionType direction); + static void gtk_gis_forall (GtkContainer *container, gboolean include_internals, GtkCallback callback, @@ -53,6 +57,9 @@ static void gtk_gis_get_property (GObject *object, GValue *value, GParamSpec *pspec); +static gboolean gtk_gis_scroll_event (GtkWidget *widget, + GdkEventScroll *event); + static void gtk_gis_size_request (GtkWidget *widget, GtkRequisition *requisition); static void gtk_gis_size_allocate (GtkWidget *widget, @@ -93,8 +100,10 @@ gtk_gis_class_init (GtkGisClass *klass) object_class->destroy = gtk_gis_destroy; + widget_class->scroll_event = gtk_gis_scroll_event; widget_class->size_request = gtk_gis_size_request; widget_class->size_allocate = gtk_gis_size_allocate; + widget_class->focus = gtk_gis_focus; container_class->add = gtk_gis_add; container_class->forall = gtk_gis_forall; @@ -105,6 +114,14 @@ gtk_gis_init (GtkGis *gtk_gis) { GtkGisPrivate *priv = GTK_GIS_GET_PRIVATE (gtk_gis); + GTK_WIDGET_SET_FLAGS (gtk_gis, GTK_NO_WINDOW | GTK_CAN_FOCUS); + + gtk_widget_set_events (GTK_WIDGET (gtk_gis), + GDK_BUTTON_PRESS_MASK + | gtk_widget_get_events (GTK_WIDGET (gtk_gis))); + + //g_signal_connect (G_OBJECT (gtk_gis), "scroll-event", G_CALLBACK (gtk_gis_scroll_event), (gpointer)NULL); + priv->scroll_win = gtk_scrolled_window_new (NULL, NULL); gtk_container_add (GTK_CONTAINER (gtk_gis), priv->scroll_win); @@ -122,7 +139,7 @@ gtk_gis_init (GtkGis *gtk_gis) priv->extent = NULL; - priv->scale = g_malloc0 (sizeof (GtkGisScale)); + priv->scale = g_malloc (sizeof (GtkGisScale)); priv->scale->x = 1.0; priv->scale->y = 1.0; priv->scale->xy = 1.0; @@ -319,6 +336,46 @@ GtkWidget return gtkgis; } +/** + * gtk_gis_get_xml: + * @gtkgis: + * + */ +xmlDoc +*gtk_gis_get_xml (GtkGis *gtkgis) +{ + xmlDoc *xdoc = NULL; + xmlNode *xroot; + xmlNode *xreport; + xmlNode *xnode; + + GSList *cur_layer; + + GtkGisPrivate *priv; + + priv = GTK_GIS_GET_PRIVATE (gtkgis); + + xdoc = xmlNewDoc ("1.0"); + + xroot = xmlNewNode (NULL, "gtkgis"); + xmlDocSetRootElement (xdoc, xroot); + + cur_layer = priv->layers; + while (cur_layer != NULL) + { + xnode = gtk_gis_layer_get_xml ((GtkGisLayer *)cur_layer->data); + + if (xnode != NULL) + { + xmlAddChild (xroot, xnode); + } + + cur_layer = g_slist_next (cur_layer); + } + + return xdoc; +} + /** * gtk_gis_save_to_xml: * @gtkgis: @@ -327,6 +384,16 @@ GtkWidget void *gtk_gis_save_to_xml (GtkGis *gtkgis, const gchar *filename) { + xmlDoc *xdoc; + + g_return_if_fail (filename != NULL); + + xdoc = gtk_gis_get_xml (gtkgis); + + if (xdoc != NULL) + { + xmlSaveFormatFile (filename, xdoc, 2); + } } /** @@ -589,6 +656,19 @@ gtk_gis_add (GtkContainer *container, gtk_widget_set_parent (child, GTK_WIDGET (bin)); } +static gboolean +gtk_gis_focus (GtkWidget*widget, + GtkDirectionType direction) +{ + if (GTK_WIDGET_CAN_FOCUS (widget)) + { + gtk_widget_grab_focus (widget); + return TRUE; + } + else + return FALSE; +} + static void gtk_gis_forall (GtkContainer *container, gboolean include_internals, @@ -634,6 +714,41 @@ gtk_gis_get_property (GObject *object, guint property_id, GValue *value, GParamS } } +static gboolean +gtk_gis_scroll_event (GtkWidget *widget, + GdkEventScroll *event) +{ + GtkGisPrivate *priv; + + GtkGis *gtkgis; + GtkGisScale *scale; +g_fprintf(stderr,"dentro scroll event"); + g_return_val_if_fail (IS_GTK_GIS (widget), FALSE); + g_return_val_if_fail (event != NULL, FALSE); + + gtkgis = GTK_GIS (widget); + priv = GTK_GIS_GET_PRIVATE (gtkgis); + + scale = gtk_gis_get_scale (gtkgis); + + if (event->direction == GDK_SCROLL_UP) + {g_fprintf(stderr,"dentro scroll up"); + scale->x = (scale->x * 120) / 100; + scale->y = (scale->y * 120) / 100; + scale->xy = (scale->xy * 120) / 100; + } + else if (event->direction == GDK_SCROLL_DOWN) + {g_fprintf(stderr,"dentro scroll down"); + scale->x = (scale->x * 80) / 100; + scale->y = (scale->y * 80) / 100; + scale->xy = (scale->xy * 80) / 100; + } + + gtk_gis_set_scale (gtkgis, scale); + + return TRUE; +} + static void gtk_gis_size_request (GtkWidget *widget, GtkRequisition *requisition) diff --git a/src/gtkgis.h b/src/gtkgis.h index b3d6fa8..aa90770 100644 --- a/src/gtkgis.h +++ b/src/gtkgis.h @@ -59,6 +59,7 @@ GtkWidget *gtk_gis_new (void); GtkWidget *gtk_gis_new_from_xml (xmlDoc *xdoc); GtkWidget *gtk_gis_new_from_file (const gchar *filename); +xmlDoc *gtk_gis_get_xml (GtkGis *gtkgis); void *gtk_gis_save_to_xml (GtkGis *gtkgis, const gchar *filename); void gtk_gis_add_group (GtkGis *gtkgis, GtkGisLayersGroup *group); diff --git a/src/layer.c b/src/layer.c index f33ce1b..00b8e37 100644 --- a/src/layer.c +++ b/src/layer.c @@ -134,6 +134,38 @@ GtkGisLayer return layer; } +/** + * gtk_gis_layer_get_xml: + * @layer: + * + */ +xmlNode +*gtk_gis_layer_get_xml (GtkGisLayer *layer) +{ + xmlNode *xnode; + + GtkGisLayerPrivate *priv; + + priv = GTK_GIS_LAYER_GET_PRIVATE (layer); + + xnode = xmlNewNode (NULL, "layer"); + + if (priv->name != NULL) + { + xmlSetProp (xnode, "name", priv->name); + } + + if (priv->source != NULL) + { + xmlNode *xnode_source; + + xnode_source = gtk_gis_layer_source_get_xml (priv->source); + xmlAddChild (xnode, xnode_source); + } + + return xnode; +} + /** * gtk_gis_layer_get_name: * @layer: diff --git a/src/layer.h b/src/layer.h index d6763b3..31daa88 100644 --- a/src/layer.h +++ b/src/layer.h @@ -25,6 +25,8 @@ #include +#include + #include "commons.h" #include "geometry.h" #include "layersource.h" @@ -63,6 +65,8 @@ GtkGisLayer *gtk_gis_layer_new (GtkGisLayerSource *source, GtkGisLayer *gtk_gis_layer_new_from_source (GtkGisLayerSource *source, const gchar *name); +xmlNode *gtk_gis_layer_get_xml (GtkGisLayer *layer); + gchar *gtk_gis_layer_get_name (GtkGisLayer *layer); GtkGisLayerSource *gtk_gis_layer_get_source (GtkGisLayer *layer); diff --git a/src/layersource.c b/src/layersource.c index 8847b02..71c679c 100644 --- a/src/layersource.c +++ b/src/layersource.c @@ -87,6 +87,31 @@ gtk_gis_layer_source_init (GtkGisLayerSource *gtk_gis_layer_source) GtkGisLayerSourcePrivate *priv = GTK_GIS_LAYER_SOURCE_GET_PRIVATE (gtk_gis_layer_source); } +/** + * gtk_gis_layer_source_get_xml: + * @source: + * + */ +xmlNode +*gtk_gis_layer_source_get_xml (GtkGisLayerSource *source) +{ + xmlNode *xnode = NULL; + xmlNode *xnode_source = NULL; + + if (IS_GTK_GIS_LAYER_SOURCE (source) && GTK_GIS_LAYER_SOURCE_GET_CLASS (source)->get_xml != NULL) + { + xnode_source = GTK_GIS_LAYER_SOURCE_GET_CLASS (source)->get_xml (source); + } + + if (xnode_source != NULL) + { + xnode = xmlNewNode (NULL, "source"); + xmlAddChild (xnode, xnode_source); + } + + return xnode; +} + /** * gtk_gis_layer_source_get_geometries: * @source: diff --git a/src/layersource.h b/src/layersource.h index 4ab8648..c1508a6 100644 --- a/src/layersource.h +++ b/src/layersource.h @@ -27,6 +27,8 @@ #include #include +#include + #include "commons.h" #include "geometry.h" @@ -53,6 +55,8 @@ struct _GtkGisLayerSourceClass { GObjectClass parent_class; + xmlNode *(*get_xml) (GtkGisLayerSource *source); + void (*set_ogr_datasource) (GtkGisLayerSource *source, OGRDataSourceH datasource); void (*set_gdal_dataset) (GtkGisLayerSource *source, @@ -62,6 +66,8 @@ struct _GtkGisLayerSourceClass GType gtk_gis_layer_source_get_type (void) G_GNUC_CONST; +xmlNode *gtk_gis_layer_source_get_xml (GtkGisLayerSource *source); + GList *gtk_gis_layer_source_get_geometries (GtkGisLayerSource *source, const gchar *name); diff --git a/src/layersourcepostgis.c b/src/layersourcepostgis.c index 398b467..8c97e23 100644 --- a/src/layersourcepostgis.c +++ b/src/layersourcepostgis.c @@ -20,11 +20,15 @@ #include #endif +#include + #include "layersourcepostgis.h" static void gtk_gis_layer_source_postgis_class_init (GtkGisLayerSourcePostgisClass *klass); static void gtk_gis_layer_source_postgis_init (GtkGisLayerSourcePostgis *gtk_gis_layer_source_postgis); +static xmlNode *gtk_gis_layer_source_postgis_get_xml (GtkGisLayerSource *source); + static void gtk_gis_layer_source_postgis_set_property (GObject *object, guint property_id, const GValue *value, @@ -52,11 +56,14 @@ static void gtk_gis_layer_source_postgis_class_init (GtkGisLayerSourcePostgisClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkGisLayerSourceClass *gtkgislayersource_class = GTK_GIS_LAYER_SOURCE_CLASS (klass); g_type_class_add_private (object_class, sizeof (GtkGisLayerSourcePostgisPrivate)); object_class->set_property = gtk_gis_layer_source_postgis_set_property; object_class->get_property = gtk_gis_layer_source_postgis_get_property; + + gtkgislayersource_class->get_xml = gtk_gis_layer_source_postgis_get_xml; } static void @@ -97,6 +104,37 @@ GtkGisLayerSource return source; } +static xmlNode +*gtk_gis_layer_source_postgis_get_xml (GtkGisLayerSource *source) +{ + xmlNode *xnode = NULL; + + GtkGisLayerSourcePostgisPrivate *priv; + + priv = GTK_GIS_LAYER_SOURCE_POSTGIS_GET_PRIVATE (source); + + xnode = xmlNewNode (NULL, "postgis"); + + if (priv->host != NULL) + { + xmlSetProp (xnode, "host", priv->host); + } + if (priv->port != 0) + { + xmlSetProp (xnode, "port", g_strdup_printf ("%d", priv->port)); + } + if (priv->username != NULL) + { + xmlSetProp (xnode, "username", priv->username); + } + if (priv->password != NULL) + { + xmlSetProp (xnode, "password", priv->password); + } + + return xnode; +} + static void gtk_gis_layer_source_postgis_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { diff --git a/src/layersourceraster.c b/src/layersourceraster.c index be73be0..4a3cc2e 100644 --- a/src/layersourceraster.c +++ b/src/layersourceraster.c @@ -20,6 +20,8 @@ #include #endif +#include + #include #include "layersourceraster.h" @@ -27,6 +29,8 @@ static void gtk_gis_layer_source_raster_class_init (GtkGisLayerSourceRasterClass *klass); static void gtk_gis_layer_source_raster_init (GtkGisLayerSourceRaster *gtk_gis_layer_source_raster); +static xmlNode *gtk_gis_layer_source_raster_get_xml (GtkGisLayerSource *source); + static void gtk_gis_layer_source_raster_set_gdal_dataset (GtkGisLayerSource *source, GDALDatasetH hDataset); @@ -61,6 +65,8 @@ gtk_gis_layer_source_raster_class_init (GtkGisLayerSourceRasterClass *klass) object_class->set_property = gtk_gis_layer_source_raster_set_property; object_class->get_property = gtk_gis_layer_source_raster_get_property; + + gtkgislayersource_class->get_xml = gtk_gis_layer_source_raster_get_xml; } static void @@ -113,6 +119,25 @@ gchar return g_strdup (priv->filename); } +static xmlNode +*gtk_gis_layer_source_raster_get_xml (GtkGisLayerSource *source) +{ + xmlNode *xnode = NULL; + + GtkGisLayerSourceRasterPrivate *priv; + + priv = GTK_GIS_LAYER_SOURCE_RASTER_GET_PRIVATE (source); + + xnode = xmlNewNode (NULL, "raster"); + + if (priv->filename != NULL) + { + xmlSetProp (xnode, "filename", priv->filename); + } + + return xnode; +} + static void gtk_gis_layer_source_raster_set_gdal_dataset (GtkGisLayerSource *source, GDALDatasetH hDataset) diff --git a/src/layersourceshp.c b/src/layersourceshp.c index 5edaafb..e557251 100644 --- a/src/layersourceshp.c +++ b/src/layersourceshp.c @@ -23,11 +23,15 @@ #include #include +#include + #include "layersourceshp.h" static void gtk_gis_layer_source_shp_class_init (GtkGisLayerSourceShpClass *klass); static void gtk_gis_layer_source_shp_init (GtkGisLayerSourceShp *gtk_gis_layer_source_shp); +static xmlNode *gtk_gis_layer_source_shp_get_xml (GtkGisLayerSource *source); + static void gtk_gis_layer_source_shp_set_ogr_datasource (GtkGisLayerSource *source, OGRDataSourceH datasource); @@ -62,6 +66,8 @@ gtk_gis_layer_source_shp_class_init (GtkGisLayerSourceShpClass *klass) object_class->set_property = gtk_gis_layer_source_shp_set_property; object_class->get_property = gtk_gis_layer_source_shp_get_property; + + gtkgislayersource_class->get_xml = gtk_gis_layer_source_shp_get_xml; } static void @@ -114,6 +120,25 @@ gchar return g_strdup (priv->filename); } +static xmlNode +*gtk_gis_layer_source_shp_get_xml (GtkGisLayerSource *source) +{ + xmlNode *xnode = NULL; + + GtkGisLayerSourceShpPrivate *priv; + + priv = GTK_GIS_LAYER_SOURCE_SHP_GET_PRIVATE (source); + + xnode = xmlNewNode (NULL, "shape"); + + if (priv->filename != NULL) + { + xmlSetProp (xnode, "filename", priv->filename); + } + + return xnode; +} + static void gtk_gis_layer_source_shp_set_ogr_datasource (GtkGisLayerSource *source, OGRDataSourceH datasource) diff --git a/tests/from_xml.c b/tests/from_xml.c index 610ae64..4272b28 100644 --- a/tests/from_xml.c +++ b/tests/from_xml.c @@ -23,6 +23,8 @@ main (int argc, char *argv[]) gtk_gis_zoom_to_max (GTK_GIS (gtkgis)); gtk_gis_draw (GTK_GIS (gtkgis)); + gtk_gis_save_to_xml (GTK_GIS (gtkgis), "test_saved.gtkgis"); + gtk_main (); return 0; diff --git a/tests/test1.gtkgis b/tests/test1.gtkgis index 3a39de7..090eb87 100644 --- a/tests/test1.gtkgis +++ b/tests/test1.gtkgis @@ -2,25 +2,25 @@ - + - + - + - +