Re: New list/tree model questions



Havoc Pennington <hp redhat com> writes:

  if (!gtk_tree_model_get_iter_first (model, &tmp))
     return FALSE;

  do
  {
     gtk_tree_model_get (model, &tmp, column, &this_data, -1);
     if (this_data == data)
       {
           *iter = tmp;
           return TRUE;
       }
   } while (gtk_tree_model_iter_next (model, &tmp));

   return FALSE; /* FALSE return means not found */
}

As a side note, my current favorite idiom for iterating over
all rows in a model is:

  gboolean valid;

  for (valid = gtk_tree_model_get_iter_first (model, &iter);
       valid;
       valid = gtk_tree_model_iter_next (model, &iter))
    {
      [ Do something with &iter ]
    }

The extra boolean variable lets you avoid having separate start
and termination conditions.

Regards,
                                        Owen

P.S. - or, in avoid-for()-loops style:

 gboolean valid = gtk_tree_model_get_iter_first (model, &iter);
 while (valid)
  {
    [ Do something with iter ]
     valid = gtk_tree_model_iter_next (model, &iter);
  }
 



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