Re: Speedup insert into treestore



Hi,

On Sun, 2005-10-09 at 19:59 +0200, Florian Schaefer wrote:
Hi Emmanuele!

On Sun, 09 Oct 2005 19:39:11 +0200, Emmanuele Bassi said:

[...]
Strategy 1) is always the best one when updating the contents of a
TreeModel implementation; the TreeView is constantly listening for
changes in the model - so disconnecting it yields the better results.

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.

TreeIters are object created on the fly; you shouldn't have persistent a
TreeIter unless you know what you are doing - typically because you have
implemented a TreeModel by yourself.

 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?

You should keep a reference to the model inside your Perl program; it
works by simply creating a model and then keeping the variable storing
it:

        my $model = Gtk2::TreeStore->new('Gtk2::Gdk::Pixbuf', 'Glib::String');
        fill_model_with_data($model);

        my $treeview = Gtk2::TreeView->new($model);

Before rebuilding your data, you "disconnect" the model from the viewer:

        $treeview->set_model(undef);

        $model->clear;
        fill_model_with_data($model);
        
        $treeview->set_model($model);

Sadly, I don't know how to do either of those options (set_sort_column_id
does not accept undef).

Disabling sorting is done by passing -1 as the column id.

Hmm, -1 or -2, anyone with another number? ;-) SCNR

It was -2; I really should check constants instead of using my (faulty)
memory... :-)

Ciao,
 Emmanuele.

-- 
Emmanuele Bassi - <ebassi gmail com>
Log: http://log.emmanuelebassi.net




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