[shotwell] map: Cache position markers while on same page



commit ec803d53822110d08a40275b047a241bacfb1154
Author: Andreas Brauchli <a brauchli elementarea net>
Date:   Wed Jun 15 22:39:49 2016 +0200

    map: Cache position markers while on same page
    
    While on the same page, cache all created DataViewPositionMarkers for
    quick retrieval when switching between a selection and no
    selection.
    
    The cache is emptied when the page is switched.

 src/MapWidget.vala | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)
---
diff --git a/src/MapWidget.vala b/src/MapWidget.vala
index a803e4b9..de936d23 100644
--- a/src/MapWidget.vala
+++ b/src/MapWidget.vala
@@ -258,7 +258,9 @@ private class MapWidget : Gtk.Bin {
     private Champlain.MarkerLayer marker_layer = new Champlain.MarkerLayer();
     public bool map_edit_lock { get; set; }
     private MarkerGroupRaster marker_group_raster = null;
-    private weak Page page = null;
+    private Gee.Map<DataView, DataViewPositionMarker> data_view_marker_cache =
+        new Gee.HashMap<DataView, DataViewPositionMarker>();
+    private weak Page? page = null;
     private Clutter.Image? map_edit_locked_image;
     private Clutter.Image? map_edit_unlocked_image;
     private Clutter.Actor map_edit_lock_button = new Clutter.Actor();
@@ -305,7 +307,10 @@ private class MapWidget : Gtk.Bin {
     }
 
     public void set_page(Page page) {
-        this.page = page;
+        if (this.page != page) {
+            this.page = page;
+            data_view_marker_cache.clear();
+        }
     }
 
     public void clear() {
@@ -522,13 +527,17 @@ private class MapWidget : Gtk.Bin {
     }
 
     private DataViewPositionMarker create_position_marker(DataView view) {
-        // TODO: store markers in map to only create them once
+        var position_marker = data_view_marker_cache.get(view);
+        if (position_marker != null)
+            return position_marker;
         DataSource data_source = view.get_source();
         Positionable p = (Positionable) data_source;
         GpsCoords gps_coords = p.get_gps_coords();
         Champlain.Marker champlain_marker = create_champlain_marker(gps_coords, marker_image,
             marker_selected_image, marker_image_width, marker_image_height);
-        return new DataViewPositionMarker(this, view, champlain_marker);
+        position_marker = new DataViewPositionMarker(this, view, champlain_marker);
+        data_view_marker_cache.set(view, position_marker);
+        return position_marker;
     }
 
     internal MarkerGroup create_marker_group(GpsCoords gps_coords) {
@@ -555,13 +564,11 @@ private class MapWidget : Gtk.Bin {
     }
 
     private bool internal_drop_received(Gee.List<MediaSource> media, double lat, double lon) {
-        if (map_edit_lock) {
+        if (map_edit_lock)
             return false;
-        }
-        int i = 0;
         bool success = false;
-        while (i < media.size) {
-            Positionable p = media.get(i) as Positionable;
+        foreach (var m in media) {
+            Positionable p = m as Positionable;
             if (p != null) {
                 GpsCoords gps_coords = GpsCoords() {
                     has_gps = 1,
@@ -571,7 +578,6 @@ private class MapWidget : Gtk.Bin {
                 p.set_gps_coords(gps_coords);
                 success = true;
             }
-            ++i;
         }
         return success;
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]