GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 71.2% 42 / 0 / 59
Functions: 81.8% 9 / 0 / 11
Branches: 50.0% 8 / 0 / 16

shumate/shumate-layer.c
Line Branch Exec Source
1 /*
2 * Copyright (C) 2011-2013 Jiri Techet <techet@gmail.com>
3 * Copyright (C) 2019 Marcus Lundblad <ml@update.uu.se>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 /**
21 * ShumateLayer:
22 *
23 * Every layer (overlay that moves together with the map) has to inherit this
24 * class and implement its virtual methods.
25 *
26 * You can use the same layer to display many types of maps. In Shumate they
27 * are called map sources. You can change the [property@MapLayer:map-source]
28 * property at any time to replace the current displayed map.
29 */
30
31 #include "shumate-layer.h"
32
33 enum
34 {
35 PROP_VIEWPORT = 1,
36 N_PROPERTIES
37 };
38
39 static GParamSpec *obj_properties[N_PROPERTIES] = { NULL, };
40
41 typedef struct {
42 ShumateViewport *viewport;
43 } ShumateLayerPrivate;
44
45
4/6
shumate_layer_class_intern_init:
✓ Branch 3 → 4 taken 3 times.
✗ Branch 3 → 5 not taken.
shumate_layer_get_type:
✓ Branch 2 → 3 taken 3 times.
✓ Branch 2 → 7 taken 135 times.
✓ Branch 4 → 5 taken 3 times.
✗ Branch 4 → 7 not taken.
291 G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (ShumateLayer, shumate_layer, GTK_TYPE_WIDGET)
46
47 static void
48 11 shumate_layer_set_property (GObject *object,
49 guint property_id,
50 const GValue *value,
51 GParamSpec *pspec)
52 {
53 11 ShumateLayer *self = SHUMATE_LAYER (object);
54 11 ShumateLayerPrivate *priv = shumate_layer_get_instance_private (self);
55
56
1/2
✓ Branch 2 → 3 taken 11 times.
✗ Branch 2 → 5 not taken.
11 switch (property_id)
57 {
58 11 case PROP_VIEWPORT:
59 11 priv->viewport = g_value_dup_object (value);
60 11 break;
61
62 ✗ default:
63 ✗ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
64 ✗ break;
65 }
66 11 }
67
68 static void
69 ✗ shumate_layer_get_property (GObject *object,
70 guint property_id,
71 GValue *value,
72 GParamSpec *pspec)
73 {
74 ✗ ShumateLayer *self = SHUMATE_LAYER (object);
75 ✗ ShumateLayerPrivate *priv = shumate_layer_get_instance_private (self);
76
77 ✗ switch (property_id)
78 {
79 ✗ case PROP_VIEWPORT:
80 ✗ g_value_set_object (value, priv->viewport);
81 ✗ break;
82
83 ✗ default:
84 ✗ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
85 ✗ break;
86 }
87 ✗ }
88
89 static void
90 5 shumate_layer_dispose (GObject *object)
91 {
92 5 ShumateLayerPrivate *priv = shumate_layer_get_instance_private (SHUMATE_LAYER (object));
93
94
1/2
✓ Branch 2 → 3 taken 5 times.
✗ Branch 2 → 4 not taken.
5 g_clear_object (&priv->viewport);
95
96 5 G_OBJECT_CLASS (shumate_layer_parent_class)->dispose (object);
97 5 }
98
99 static void
100 11 shumate_layer_constructed (GObject *object)
101 {
102 11 ShumateLayerPrivate *priv = shumate_layer_get_instance_private (SHUMATE_LAYER (object));
103
104
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 11 times.
11 if (!priv->viewport)
105 ✗ priv->viewport = shumate_viewport_new ();
106
107 11 G_OBJECT_CLASS (shumate_layer_parent_class)->constructed (object);
108 11 }
109
110 static gboolean
111 ✗ shumate_layer_contains (GtkWidget *widget,
112 double x,
113 double y)
114 {
115 /* This allows mouse events on the empty space between markers in this layer
116 * to fall through to lower layers. */
117 ✗ return FALSE;
118 }
119
120 static void
121 3 shumate_layer_class_init (ShumateLayerClass *klass)
122 {
123 3 GObjectClass *object_class = G_OBJECT_CLASS (klass);
124 3 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
125
126 3 object_class->set_property = shumate_layer_set_property;
127 3 object_class->get_property = shumate_layer_get_property;
128 3 object_class->dispose = shumate_layer_dispose;
129 3 object_class->constructed = shumate_layer_constructed;
130
131 3 widget_class->contains = shumate_layer_contains;
132
133 /**
134 * ShumateLayer:viewport:
135 *
136 * The viewport to use.
137 */
138 6 obj_properties[PROP_VIEWPORT] =
139 3 g_param_spec_object ("viewport", NULL, NULL,
140 SHUMATE_TYPE_VIEWPORT,
141 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
142
143 3 g_object_class_install_properties (object_class,
144 N_PROPERTIES,
145 obj_properties);
146
147 3 gtk_widget_class_set_css_name (widget_class, "map-layer");
148 3 }
149
150 static void
151 11 shumate_layer_init (ShumateLayer *self)
152 {
153 11 g_object_set (G_OBJECT (self),
154 "hexpand", TRUE,
155 "vexpand", TRUE,
156 NULL);
157 11 }
158
159 /**
160 * shumate_layer_get_viewport:
161 * @self: a #ShumateLayer
162 *
163 * Gets the #ShumateViewport used by this layer.
164 *
165 * Returns: (transfer none): The #ShumateViewport.
166 */
167 ShumateViewport *
168 120 shumate_layer_get_viewport (ShumateLayer *self)
169 {
170 120 ShumateLayerPrivate *priv = shumate_layer_get_instance_private (self);
171
172
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 120 times.
120 g_return_val_if_fail (SHUMATE_IS_LAYER (self), NULL);
173
174 120 return priv->viewport;
175 }
176