Re: Speedup insert into treestore




On Oct 9, 2005, at 1:59 PM, Florian Schaefer wrote:

OK, how do I do this? I tried to do

$tree_view->set_model(undef)

but that resulted in unusable TreeIters to insert the data into the
TreeStore. I read that in C one can add a reference to the object so that
the model doesn't get destroyed, but how is it done in Perl?

Iters are good for the duration of a signal handler or function call, and are invalidated by changes to the model. What you've said suggests that you're storing iters, and that's not a valid thing to do.

This is the basic idiom; i've written it for a list, but you can expand that to a tree without much difficulty.

   sub repopulate_list {
       my $view = shift;

       my $model = $view->get_model ();

       # unset the model, so that the view doesn't waste time updating
       # itself on every change to the model.  we'll restore it below.
       # typically the main loop won't run between now and then,
       # so there should be no chance for the idle to run and paint
       # an empty list (i.e., typically will not flicker).
       $view->set_model (undef);

       # if the model is sorted, you'd do well to disable sorting, too.
       my $id = $model->get_sort_column_id ();
       $model->set_sort_column_id (-2);


       # now clear and refill the list.
       $model->clear ();
       foreach my $val (@big_list_of_data) {
           $model->append ($model->append, 0, $val);
       }


       # re-enable sorting
       $model->set_sort_column_id ($id);

       # restore the model; this will redraw the whole thing.
       $view->set_model ($model);
   }



--
To me, "hajime" means "the man standing opposite you is about to hit you with a stick".
  -- Ian Malpass, speaking of the Japanese word for "the beginning"




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