Issue with iters with cellrenderercombo and sorted columns



I have a wierd issue with iters and and a liststore with a combo cellrender and edited signal.
If I dont sort the column everything is fine the iter points to the right row.
However if I do sort the iter points to a different row

Code is

setup for column renderers

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);
        }
        elsif ($col->[1] eq 'bool') {
            $r=Gtk3::CellRendererToggle->new();
            $column = Gtk3::TreeViewColumn->new_with_attributes(
                $col->[2],$r,'active' => $col->[0]
              );

            my @id=($liststore,$col->[0]);
            $r->signal_connect('toggled'=>\&toggled,\@id);
        }
        elsif ($col->[1] eq 'combo') {
            $r=Gtk3::CellRendererCombo->new();

            #$r->set( activatable => 1 );
            my $model=Gtk3::ListStore->new('Glib::String');
            foreach my $list (@{$col->[4]}){
                $model->set($model->append,0,$list);
            }
            my $model1=[$liststore,$id];
            $r->signal_connect (edited => \&cell_edited, $model1);
            $r->set(model=>$model,text_column=>0,editable=>$col->[3]);
            $column = Gtk3::TreeViewColumn->new_with_attributes(
                $col->[2],$r,'text' => $col->[0]
              );
            my @id=($liststore,$col->[0]);
        }
        $list->append_column($column);
    }
    return 1
}

sub cell_edited {
    my ($cell, $path_string, $new_text, $model1) = @_;
    my ($model2,$column)=@{$model1};
    my $model;
    my $path = Gtk3::TreePath->new_from_string ($path_string);
    my $iter = $model2->get_iter ($path);
    my $iter2;
    if ($model2=~/TreeModelFilter/){
        $model=$model2->get_model;
        $iter2=$model2->convert_iter_to_child_iter($iter);
    }
    else {
        $model=$model2;
         $iter2=$iter
    }
    my $gvalue = Glib::Object::Introspection::GValueWrapper->new (
        'Glib::String', $new_text);
    $model->set_value ($iter2, $column, $gvalue);
    return 1
}

edited sub-routine

$c->[0]->get_cells->signal_connect('edited'=>sub{
            my ($cell, $path_str, $value) = @_;
           my $iter;
            $iter=$list->get_model->get_iter_from_string($path_str) ;
            my @updfiles;
            my @listcols=$list->get_model->get($iter,0,1,5);
            @updfiles= ($value,$listcols[1],$listcols[2])
               }
@updfiles contains the wrong rowid (column 5 is a rowid from a database)
The sort is just
$list->get_column(0)->set_sort_column_id (0);
nothing fancy
seems to only affect a cellrenderercombo
I have another column wihich is cellrenderertext which has no issues

Any ideas why this is happening

thanks

Mike


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