[libchamplain] Iterate through container using clutter_group_get_nth_child() when the container is not modified
- From: Pierre-Luc Beaudoin <plbeaudoin src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libchamplain] Iterate through container using clutter_group_get_nth_child() when the container is not modified
- Date: Tue, 23 Mar 2010 14:41:30 +0000 (UTC)
commit 20f473ac0ed555c914aa302d2f26fadee5917e5f
Author: JiÅ?Ã Techet <techet gmail com>
Date: Sun Mar 14 19:35:20 2010 +0100
Iterate through container using clutter_group_get_nth_child() when the container is not modified
Use of clutter_group_get_nth_child() is slightly simpler than using
clutter_container_get_children() [no forgotten free() at the end] and
there is no danger when the container is not modified inside the loop.
Signed-off-by: JiÅ?Ã Techet <techet gmail com>
champlain/champlain-layer.c | 59 ++++++++++++++++--------------------------
champlain/champlain-view.c | 14 ++++------
2 files changed, 29 insertions(+), 44 deletions(-)
---
diff --git a/champlain/champlain-layer.c b/champlain/champlain-layer.c
index 48e5f47..59928a4 100644
--- a/champlain/champlain-layer.c
+++ b/champlain/champlain-layer.c
@@ -117,8 +117,7 @@ static void
reorder_marker (ClutterGroup *layer,
ChamplainBaseMarker *marker)
{
- GList* markers = clutter_container_get_children (CLUTTER_CONTAINER(layer));
- GList* it;
+ guint i;
gdouble y, tmp_y, low_y;
ChamplainBaseMarker *lowest = NULL;
@@ -126,9 +125,9 @@ reorder_marker (ClutterGroup *layer,
y = 90 - y;
low_y = G_MAXDOUBLE;
- for (it = markers; it != NULL; it = it->next)
+ for (i = 0; i < clutter_group_get_n_children (layer); i++)
{
- ChamplainBaseMarker *prev_marker = (ChamplainBaseMarker*) it->data;
+ ChamplainBaseMarker *prev_marker = CHAMPLAIN_BASE_MARKER (clutter_group_get_nth_child (layer, i));
if (prev_marker == (ChamplainBaseMarker*) marker)
continue;
@@ -146,8 +145,6 @@ reorder_marker (ClutterGroup *layer,
if (lowest)
clutter_container_lower_child (CLUTTER_CONTAINER(layer),
CLUTTER_ACTOR (marker), CLUTTER_ACTOR (lowest));
-
- g_list_free (markers);
}
static void
@@ -273,21 +270,18 @@ champlain_layer_hide (ChamplainLayer *layer)
void
champlain_layer_animate_in_all_markers (ChamplainLayer *layer)
{
- GList *children, *child;
+ guint i;
guint delay = 0;
g_return_if_fail (CHAMPLAIN_IS_LAYER (layer));
- children = clutter_container_get_children (CLUTTER_CONTAINER (layer));
-
- for (child = children; child != NULL; child = g_list_next (child))
+ for (i = 0; i < clutter_group_get_n_children (CLUTTER_GROUP (layer)); i++)
{
- champlain_base_marker_animate_in_with_delay (CHAMPLAIN_BASE_MARKER (child->data),
- delay);
+ ChamplainBaseMarker *marker = CHAMPLAIN_BASE_MARKER (clutter_group_get_nth_child (CLUTTER_GROUP (layer), i));
+
+ champlain_base_marker_animate_in_with_delay (marker, delay);
delay += 50;
}
-
- g_list_free (children);
}
/**
@@ -301,21 +295,18 @@ champlain_layer_animate_in_all_markers (ChamplainLayer *layer)
void
champlain_layer_animate_out_all_markers (ChamplainLayer *layer)
{
- GList *children, *child;
+ guint i;
guint delay = 0;
g_return_if_fail (CHAMPLAIN_IS_LAYER (layer));
- children = clutter_container_get_children (CLUTTER_CONTAINER (layer));
-
- for (child = children; child != NULL; child = g_list_next (child))
+ for (i = 0; i < clutter_group_get_n_children (CLUTTER_GROUP (layer)); i++)
{
- champlain_base_marker_animate_out_with_delay (CHAMPLAIN_BASE_MARKER (child->data),
- delay);
+ ChamplainBaseMarker *marker = CHAMPLAIN_BASE_MARKER (clutter_group_get_nth_child (CLUTTER_GROUP (layer), i));
+
+ champlain_base_marker_animate_out_with_delay (marker, delay);
delay += 50;
}
-
- g_list_free (children);
}
/**
@@ -329,18 +320,16 @@ champlain_layer_animate_out_all_markers (ChamplainLayer *layer)
void
champlain_layer_show_all_markers (ChamplainLayer *layer)
{
- GList *children, *child;
+ guint i;
g_return_if_fail (CHAMPLAIN_IS_LAYER (layer));
- children = clutter_container_get_children (CLUTTER_CONTAINER (layer));
-
- for (child = children; child != NULL; child = g_list_next (child))
+ for (i = 0; i < clutter_group_get_n_children (CLUTTER_GROUP (layer)); i++)
{
- clutter_actor_show (CLUTTER_ACTOR (child->data));
- }
+ ClutterActor *marker = CLUTTER_ACTOR (clutter_group_get_nth_child (CLUTTER_GROUP (layer), i));
- g_list_free (children);
+ clutter_actor_show (marker);
+ }
}
/**
@@ -354,16 +343,14 @@ champlain_layer_show_all_markers (ChamplainLayer *layer)
void
champlain_layer_hide_all_markers (ChamplainLayer *layer)
{
- GList *children, *child;
+ guint i;
g_return_if_fail (CHAMPLAIN_IS_LAYER (layer));
- children = clutter_container_get_children (CLUTTER_CONTAINER (layer));
-
- for (child = children; child != NULL; child = g_list_next (child))
+ for (i = 0; i < clutter_group_get_n_children (CLUTTER_GROUP (layer)); i++)
{
- clutter_actor_hide (CLUTTER_ACTOR (child->data));
- }
+ ClutterActor *marker = CLUTTER_ACTOR (clutter_group_get_nth_child (CLUTTER_GROUP (layer), i));
- g_list_free (children);
+ clutter_actor_hide (marker);
+ }
}
diff --git a/champlain/champlain-view.c b/champlain/champlain-view.c
index 2d71016..c370f80 100644
--- a/champlain/champlain-view.c
+++ b/champlain/champlain-view.c
@@ -1145,26 +1145,24 @@ button_release_cb (ClutterActor *actor,
ClutterEvent *event,
ChamplainView *view)
{
- GList *children = NULL;
+ guint i;
gboolean found = FALSE;
ChamplainViewPrivate *priv = GET_PRIVATE (view);
if (clutter_event_get_button (event) != 1)
return FALSE;
- children = clutter_container_get_children (CLUTTER_CONTAINER (priv->user_layers));
- for (;children != NULL; children = g_list_next (children))
+ for (i = 0; i < clutter_group_get_n_children (CLUTTER_GROUP (priv->user_layers)); i++)
{
- if (CHAMPLAIN_IS_SELECTION_LAYER (children->data) &&
- champlain_selection_layer_count_selected_markers (CHAMPLAIN_SELECTION_LAYER (children->data)) > 0)
+ ChamplainSelectionLayer *layer = CHAMPLAIN_SELECTION_LAYER (clutter_group_get_nth_child (CLUTTER_GROUP (priv->user_layers), i));
+
+ if (layer && champlain_selection_layer_count_selected_markers (layer ) > 0)
{
- champlain_selection_layer_unselect_all (CHAMPLAIN_SELECTION_LAYER (children->data));
+ champlain_selection_layer_unselect_all (layer);
found = TRUE;
}
}
- g_list_free (children);
-
return found;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]