Struggling with TreeModelFilter

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

Struggling with TreeModelFilter

Mike Martin-5
Hi
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?

Code

###setup  model###

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

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

the editing setup code is

my @tvctrl=(
[0,'text','tag',0],
[1,'text','value',1],
[2,'bool','vis',1]
);

&tv_cols(\@tvctrl,$tag_view,$tag_model);
  
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=Gtk3::CellRendererText->new;
$r->set( editable => $col->[3] );

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

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]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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)

> }

-Torsten
_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Loading...