Gtk2-Ex-ListModelConcat
view release on metacpan or search on metacpan
t/ListModelConcat.t view on Meta::CPAN
&$subr();
$model->signal_handler_disconnect ($id);
return $ret;
}
sub listen_inserted {
my ($model, $subr) = @_;
my $ret = { count => 0 };
my $id = $model->signal_connect
(row_inserted => sub {
my ($model, $path, $iter) = @_;
if (VERBOSE) { diag "listen_inserted() signal received"; }
$ret->{'count'}++;
$ret->{'path'} = [ $path->get_indices ];
$ret->{'iter'} = $iter && [ $model->get_path($iter)->get_indices ];
$ret->{'value'} = $iter && $model->get_value($iter,0);
});
&$subr();
$model->signal_handler_disconnect ($id);
return $ret;
}
sub listen_reorder {
my ($model, $subr) = @_;
my $ret = { count => 0 };
my $id = $model->signal_connect
(rows_reordered => sub {
my ($model, $path, $iter, $aref) = @_;
if (VERBOSE) { diag "listen_reorder() signal received"; }
$ret->{'count'}++;
# buggy in gtk2-perl 1.183
$path = Gtk2::TreePath->new;
$ret->{'path'} = [ $path->get_indices ];
$ret->{'iter'} = $iter && [ $model->get_path($iter)->get_indices ];
$ret->{'order'} = $aref;
if (VERBOSE) { diag " order ",join(' ',@$aref); }
});
&$subr();
$model->signal_handler_disconnect ($id);
return $ret;
}
#------------------------------------------------------------------------------
{ my $concat = Gtk2::Ex::ListModelConcat->new;
is_deeply ([@{$concat->get_flags}], ['list-only']);
is ($concat->get_n_columns, 0);
is ($concat->iter_n_children(undef), 0);
is ($concat->get_iter_first, undef);
is ($concat->iter_children(undef), undef);
is ($concat->get_iter(Gtk2::TreePath->new_from_indices(0)), undef);
is ($concat->get_iter(Gtk2::TreePath->new_from_indices(1)), undef);
is ($concat->get_iter(Gtk2::TreePath->new_from_indices(999)), undef);
ok (! $concat->iter_nth_child(undef,0));
ok (! $concat->iter_nth_child(undef,1));
ok (! $concat->iter_nth_child(undef,999));
require Scalar::Util;
Scalar::Util::weaken ($concat);
is ($concat, undef, 'empty garbage collected when weakened');
}
{ my $store = Gtk2::ListStore->new ('Glib::String');
my $concat = Gtk2::Ex::ListModelConcat->new;
$concat->set_property (models => [ $store ]);
is ($concat->get_n_columns, 1);
is ($concat->iter_n_children(undef), 0);
is ($concat->iter_children(undef), undef);
is ($concat->get_iter_first, undef);
Scalar::Util::weaken ($concat);
is ($concat, undef, 'garbage collected when weakened');
}
{ my $s1 = Gtk2::ListStore->new ('Glib::String');
my $s2 = Gtk2::ListStore->new ('Glib::String');
my $concat = Gtk2::Ex::ListModelConcat->new (models => [ $s1, $s2 ]);
is ($concat->get_n_columns, 1);
is ($concat->iter_n_children(undef), 0);
is ($concat->iter_children(undef), undef);
is ($concat->get_iter_first, undef);
Scalar::Util::weaken ($concat);
is ($concat, undef, 'garbage collected when weakened');
}
{ my $store = Gtk2::ListStore->new ('Glib::String');
$store->set_value ($store->insert(0), 0=>'zero');
my $concat = Gtk2::Ex::ListModelConcat->new (models => [ $store ]);
is ($concat->iter_n_children(undef), 1);
ok ($concat->iter_children(undef));
ok ($concat->get_iter(Gtk2::TreePath->new_from_indices(0)));
is ($concat->get_iter(Gtk2::TreePath->new_from_indices(1)), undef);
is ($concat->get_iter(Gtk2::TreePath->new_from_indices(999)), undef);
ok ($concat->iter_nth_child(undef,0));
ok (! $concat->iter_nth_child(undef,1));
ok (! $concat->iter_nth_child(undef,999));
my $iter = $concat->get_iter_first;
ok ($iter);
is ($concat->get_path($iter)->to_string, '0');
is ($concat->get_value($iter,0), 'zero');
is ($concat->iter_children($iter), undef);
is ($concat->iter_parent($iter), undef);
$iter = $concat->iter_next ($iter);
is ($iter, undef);
}
{ my $store = Gtk2::ListStore->new ('Glib::String');
$store->set_value ($store->insert(0), 0=>'zero');
my $concat = Gtk2::Ex::ListModelConcat->new (models => [ $store, $store ]);
is ($concat->iter_n_children(undef), 2);
my $iter = $concat->get_iter_first;
ok ($iter);
is ($concat->get_path($iter)->to_string, '0');
is ($concat->get_value($iter,0), 'zero');
is ($concat->iter_children($iter), undef);
ok (! $concat->iter_has_child($iter));
is ($concat->iter_parent($iter), undef);
$iter = $concat->iter_next ($iter);
ok ($iter);
is ($concat->get_path($iter)->to_string, '1');
is ($concat->get_value($iter,0), 'zero');
is ($concat->iter_children($iter), undef);
is ($concat->iter_parent($iter), undef);
ok (! $concat->iter_has_child($iter));
$iter = $concat->iter_next ($iter);
is ($iter, undef);
$store->set_value ($store->insert(0), 0=>'one');
}
{
my $s1 = Gtk2::ListStore->new ('Glib::String');
my $s2 = Gtk2::ListStore->new ('Glib::String');
$s1->set_value ($s1->insert(0), 0=>'zero');
$s2->set_value ($s2->insert(0), 0=>'one');
my $concat = Gtk2::Ex::ListModelConcat->new (models => [ $s1, $s2 ]);
is ($concat->iter_n_children(undef), 2);
{ my $iter = $concat->iter_nth_child(undef,0);
( run in 1.805 second using v1.01-cache-2.11-cpan-5837b0d9d2c )