From d8515bf4290bfece33fd41d356e86e74c0728067 Mon Sep 17 00:00:00 2001 From: Jussi Kukkonen Date: Thu, 2 Dec 2010 16:27:36 +0200 Subject: [PATCH] Fix clutter_list_model_get_iter_at_row() when filtered Currently clutter_list_model_get_iter_at_row() always returns an iterator to the last non-filtered row when asking for row [1-N]. Patch makes the function return an iterator to the Nth non-filtered row or NULL. http://bugzilla.clutter-project.org/show_bug.cgi?id=2460 --- clutter/clutter-list-model.c | 60 +++++++++++------------------------- 1 file changed, 18 insertions(+), 42 deletions(-) diff --git a/clutter/clutter-list-model.c b/clutter/clutter-list-model.c index 49d1ad779..5548c52d5 100644 --- a/clutter/clutter-list-model.c +++ b/clutter/clutter-list-model.c @@ -440,8 +440,10 @@ clutter_list_model_get_iter_at_row (ClutterModel *model, { ClutterListModel *model_default = CLUTTER_LIST_MODEL (model); GSequence *sequence = model_default->priv->sequence; + GSequenceIter *filter_next; gint seq_length = g_sequence_get_length (sequence); ClutterListModelIter *retval; + gint count = -1; if (row >= seq_length) return NULL; @@ -459,55 +461,29 @@ clutter_list_model_get_iter_at_row (ClutterModel *model, return CLUTTER_MODEL_ITER (retval); } - if (row == 0) + filter_next = g_sequence_get_begin_iter (sequence); + g_assert (filter_next != NULL); + + while (!g_sequence_iter_is_end (filter_next)) { - GSequenceIter *filter_next; - gboolean row_found = FALSE; + retval->seq_iter = filter_next; - filter_next = g_sequence_get_begin_iter (sequence); - g_assert (filter_next != NULL); - - while (!g_sequence_iter_is_end (filter_next)) + if (clutter_model_filter_iter (model, CLUTTER_MODEL_ITER (retval))) { - retval->seq_iter = filter_next; - - if (clutter_model_filter_iter (model, CLUTTER_MODEL_ITER (retval))) - { - /* We've found a row that is valid under the filter */ - row_found = TRUE; - break; - } - - filter_next = g_sequence_iter_next (filter_next); - } - - /* Everything has been filtered -> there is no first row */ - if (!row_found) - { - g_object_unref (retval); - return NULL; - } - } - else - { - GSequenceIter *filter_prev; - - filter_prev = g_sequence_get_end_iter (sequence); - g_assert (filter_prev != NULL); - - filter_prev = g_sequence_iter_prev (filter_prev); - - while (!g_sequence_iter_is_begin (filter_prev)) - { - retval->seq_iter = filter_prev; - - if (clutter_model_filter_iter (model, CLUTTER_MODEL_ITER (retval))) + /* We've found a row that is valid under the filter */ + count++; + if (count == row) break; - - filter_prev = g_sequence_iter_prev (filter_prev); } + + filter_next = g_sequence_iter_next (filter_next); } + if (count != row) + { + g_object_unref (retval); + return NULL; + } return CLUTTER_MODEL_ITER (retval); }