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
This commit is contained in:
Jussi Kukkonen 2010-12-02 16:27:36 +02:00 committed by Emmanuele Bassi
parent e7f62bc936
commit d8515bf429

View File

@ -440,8 +440,10 @@ clutter_list_model_get_iter_at_row (ClutterModel *model,
{ {
ClutterListModel *model_default = CLUTTER_LIST_MODEL (model); ClutterListModel *model_default = CLUTTER_LIST_MODEL (model);
GSequence *sequence = model_default->priv->sequence; GSequence *sequence = model_default->priv->sequence;
GSequenceIter *filter_next;
gint seq_length = g_sequence_get_length (sequence); gint seq_length = g_sequence_get_length (sequence);
ClutterListModelIter *retval; ClutterListModelIter *retval;
gint count = -1;
if (row >= seq_length) if (row >= seq_length)
return NULL; return NULL;
@ -459,11 +461,6 @@ clutter_list_model_get_iter_at_row (ClutterModel *model,
return CLUTTER_MODEL_ITER (retval); return CLUTTER_MODEL_ITER (retval);
} }
if (row == 0)
{
GSequenceIter *filter_next;
gboolean row_found = FALSE;
filter_next = g_sequence_get_begin_iter (sequence); filter_next = g_sequence_get_begin_iter (sequence);
g_assert (filter_next != NULL); g_assert (filter_next != NULL);
@ -474,40 +471,19 @@ clutter_list_model_get_iter_at_row (ClutterModel *model,
if (clutter_model_filter_iter (model, CLUTTER_MODEL_ITER (retval))) if (clutter_model_filter_iter (model, CLUTTER_MODEL_ITER (retval)))
{ {
/* We've found a row that is valid under the filter */ /* We've found a row that is valid under the filter */
row_found = TRUE; count++;
if (count == row)
break; break;
} }
filter_next = g_sequence_iter_next (filter_next); filter_next = g_sequence_iter_next (filter_next);
} }
/* Everything has been filtered -> there is no first row */ if (count != row)
if (!row_found)
{ {
g_object_unref (retval); g_object_unref (retval);
return NULL; 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)))
break;
filter_prev = g_sequence_iter_prev (filter_prev);
}
}
return CLUTTER_MODEL_ITER (retval); return CLUTTER_MODEL_ITER (retval);
} }