Struggling with TreeModelFilter

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view

Struggling with TreeModelFilter

Mike Martin-5
I have a small (3 columns including filter column) treeview with a treemodel filter.

Editing works fine if no filter is applied, but if a filter is applied I cant get the edit to apply to the correct row in the underlying model.

I assume its something to do with setting an iter_to_child_iter mapping , but where?


###setup  model###

my $tag_model=Gtk3::ListStore->new('Glib::String','Glib::String','Glib::Boolean')
my $filter=Gtk3::TreeModelFilter->new($widget_table{tag_model});

my $tag_view=Gtk3::TreeView->new();

the editing setup code is

my @tvctrl=(

sub tv_cols {
 my ($cols,$list,$liststore)=@_;

foreach my $col (@{$cols}){
my $column;   
my $r;
my $id=$col->[0];
if ($col->[1] eq 'text'){
$r->set( editable => $col->[3] );

$column = Gtk3::TreeViewColumn->new_with_attributes(
                   'text' => $col->[0]
                my $model1=[$liststore,$id];
$r->signal_connect (edited => \&cell_edited, $model1);

sub cell_edited {
  my ($cell, $path_string, $new_text, $model1) = @_;
my ($model,$column)=@{$model1};
  my $path = Gtk3::TreePath->new_from_string ($path_string);
        my $iter = $model->get_iter ($path);
my $gvalue = Glib::Object::Introspection::GValueWrapper->new (
    'Glib::String', $new_text);
  #$self->{stack}->child_set_property ($child, 'needs-attention', $gvalue);
  $model->set_value ($iter, $column, $gvalue);


gtk-perl-list mailing list
[hidden email]
Reply | Threaded
Open this post in threaded view

Re: Struggling with TreeModelFilter

"Torsten Schönfeld"
"Mike Martin" <[hidden email]>:
> sub cell_edited {
> my ($cell, $path_string, $new_text, $model1) = @_;

You're example code is not complete, but $path_string here most probably refers to the filtered model.

> my ($model,$column)=@{$model1};

And $model is most likely the unfiltered model.

>   my $path = Gtk3::TreePath->new_from_string ($path_string);

Hence you probably need this here:

$path = $filter->convert_path_to_child_path ($path);

>   my $iter = $model->get_iter ($path);
> my $gvalue = Glib::Object::Introspection::GValueWrapper->new (
>   'Glib::String', $new_text);
>   #$self->{stack}->child_set_property ($child, 'needs-attention', $gvalue);
>   $model->set_value ($iter, $column, $gvalue);

This should work as well:

$model->set ($iter, $column, $new_text)

> }

gtk-perl-list mailing list
[hidden email]