]> git.street.me.uk Git - andy/viking.git/blobdiff - src/vikaggregatelayer.c
[QA] Remove unusable constructor
[andy/viking.git] / src / vikaggregatelayer.c
index 7a8c9635cc6636bd10f4001a0828aa8d3b113db0..7f209567c3b0f744e43a75ae0140fd29d26bcf91 100644 (file)
@@ -23,6 +23,7 @@
 #include "icons/icons.h"
 
 #include <string.h>
+#include <glib/gi18n.h>
 
 #define DISCONNECT_UPDATE_SIGNAL(vl, val) g_signal_handlers_disconnect_matched(vl, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, val)
 
@@ -33,6 +34,8 @@ static void aggregate_layer_drag_drop_request ( VikAggregateLayer *val_src, VikA
 
 VikLayerInterface vik_aggregate_layer_interface = {
   "Aggregate",
+  N_("Aggregate"),
+  "<control><shift>A",
   &vikaggregatelayer_pixbuf,
 
   NULL,
@@ -64,6 +67,7 @@ VikLayerInterface vik_aggregate_layer_interface = {
   (VikLayerFuncSublayerToggleVisible)   NULL,
   (VikLayerFuncSublayerTooltip)         NULL,
   (VikLayerFuncLayerTooltip)            NULL,
+  (VikLayerFuncLayerSelected)           NULL,
 
   (VikLayerFuncMarshall)               aggregate_layer_marshall,
   (VikLayerFuncUnmarshall)             aggregate_layer_unmarshall,
@@ -80,6 +84,11 @@ VikLayerInterface vik_aggregate_layer_interface = {
   (VikLayerFuncPasteItem)               NULL,
   (VikLayerFuncFreeCopiedItem)          NULL,
   (VikLayerFuncDragDropRequest)                aggregate_layer_drag_drop_request,
+
+  (VikLayerFuncSelectClick)             NULL,
+  (VikLayerFuncSelectMove)              NULL,
+  (VikLayerFuncSelectRelease)           NULL,
+  (VikLayerFuncSelectedViewportMenu)    NULL,
 };
 
 struct _VikAggregateLayer {
@@ -181,7 +190,7 @@ static VikAggregateLayer *aggregate_layer_unmarshall( guint8 *data, gint len, Vi
 VikAggregateLayer *vik_aggregate_layer_new ()
 {
   VikAggregateLayer *val = VIK_AGGREGATE_LAYER ( g_object_new ( VIK_AGGREGATE_LAYER_TYPE, NULL ) );
-  vik_layer_init ( VIK_LAYER(val), VIK_LAYER_AGGREGATE );
+  vik_layer_set_type ( VIK_LAYER(val), VIK_LAYER_AGGREGATE );
   val->children = NULL;
   return val;
 }
@@ -206,7 +215,12 @@ void vik_aggregate_layer_insert_layer ( VikAggregateLayer *val, VikLayer *l, Gtk
     GList *theone = g_list_find ( val->children, vik_treeview_item_get_pointer ( vl->vt, replace_iter ) );
     val->children = g_list_insert ( val->children, l, g_list_position(val->children,theone)+1 );
   } else {
-    val->children = g_list_append ( val->children, l );
+    // Effectively insert at 'end' of the list to match how displayed in the treeview
+    //  - but since it is drawn from 'bottom first' it is actually the first in the child list
+    // This ordering is especially important if it is a map or similar type,
+    //  which needs be drawn first for the layering draw method to work properly.
+    // ATM this only happens when a layer is drag/dropped to the end of an aggregate layer
+    val->children = g_list_prepend ( val->children, l );
   }
   g_signal_connect_swapped ( G_OBJECT(l), "update", G_CALLBACK(vik_layer_emit_update_secondary), val );
 }
@@ -414,19 +428,48 @@ VikLayer *vik_aggregate_layer_get_top_visible_layer_of_type ( VikAggregateLayer
   return NULL;
 }
 
-GList *vik_aggregate_layer_get_all_layers_of_type(VikAggregateLayer *val, GList *layers, gint type)
+GList *vik_aggregate_layer_get_all_layers_of_type(VikAggregateLayer *val, GList *layers, gint type, gboolean include_invisible)
 {
   GList *l = layers;
   GList *children = val->children;
   VikLayer *vl;
   if (!children)
     return layers;
+
+  // Where appropriate *don't* include non-visible layers
   while (children) {
     vl = VIK_LAYER(children->data);
-    if (vl->type == VIK_LAYER_AGGREGATE)
-      l = vik_aggregate_layer_get_all_layers_of_type(VIK_AGGREGATE_LAYER(children->data), l, type); 
-    else if (vl->type == type)
-      l = g_list_prepend(l, children->data); /* now in top down order */
+    if (vl->type == VIK_LAYER_AGGREGATE ) {
+      // Don't even consider invisible aggregrates, unless told to
+      if (vl->visible || include_invisible)
+       l = vik_aggregate_layer_get_all_layers_of_type(VIK_AGGREGATE_LAYER(children->data), l, type, include_invisible);
+    }
+    else if (vl->type == type) {
+      if (vl->visible || include_invisible)
+       l = g_list_prepend(l, children->data); /* now in top down order */
+    }
+    else if (type == VIK_LAYER_TRW) {
+      /* GPS layers contain TRW layers. cf with usage in file.c */
+      if (VIK_LAYER(children->data)->type == VIK_LAYER_GPS) {
+       if (VIK_LAYER(children->data)->visible || include_invisible) {
+         if (!vik_gps_layer_is_empty(VIK_GPS_LAYER(children->data))) {
+           /*
+             can not use g_list_concat due to wrong copy method - crashes if used a couple times !!
+             l = g_list_concat (l, vik_gps_layer_get_children (VIK_GPS_LAYER(children->data)));
+           */
+           /* create own copy method instead :( */
+           GList *gps_trw_layers = (GList *)vik_gps_layer_get_children (VIK_GPS_LAYER(children->data));
+           int n_layers = g_list_length (gps_trw_layers);
+           int layer = 0;
+           for ( layer = 0; layer < n_layers; layer++) {
+             l = g_list_prepend(l, gps_trw_layers->data);
+             gps_trw_layers = gps_trw_layers->next;
+           }
+           g_list_free(gps_trw_layers);
+         }
+       }
+      }
+    }
     children = children->next;
   }
   return l;