App-Chart

 view release on metacpan or  search on metacpan

lib/App/Chart/Gtk2/Ex/ListOfListsModel.pm  view on Meta::CPAN

  my ($self, $pspec, $newval) = @_;
  my $pname = $pspec->get_name;
  if (DEBUG) { print "ListOfListsModel set '$pname'\n"; }

  if ($pname eq 'list_model') {
    if (! $newval->isa('Gtk2::TreeModel')) {
      croak 'ListOfListsModel.list-model object must implement GtkTreeModel interface';
    }
  }
  $self->{$pname} = $newval;  # per default GET_PROPERTY

  if ($pname eq 'list_model') {
    _update_models ($self);
  }
}

sub _update_models {
  my ($self) = @_;
  if (DEBUG) { print "ListOfListsModel _update_models\n"; }

  my $list_model = $self->{'list_model'};
  my $ref_weak_self = App::Chart::Glib::Ex::MoreUtils::ref_weak($self);

  $self->{'list_model_ids'} = $list_model &&
    Glib::Ex::SignalIds->new
        ($list_model,
         $list_model->signal_connect
         (row_changed   =>\&_do_toplevel_row_changed, $ref_weak_self),
         $list_model->signal_connect
         (row_deleted   =>\&_do_toplevel_row_deleted, $ref_weak_self),
         $list_model->signal_connect
         (row_inserted  =>\&_do_toplevel_row_inserted, $ref_weak_self),
         $list_model->signal_connect
         (rows_reordered=>\&_do_toplevel_rows_reordered, $ref_weak_self));

  my @mlist;
  my $n_columns = 0;
  my @column_types;

  if ($list_model) {
    if (DEBUG) { print "  list_model $list_model\n"; }
    $n_columns = $self->{'list_model_n_columns'} = $list_model->get_n_columns;
    @column_types = map {$list_model->get_column_type($_)} (0..$n_columns-1);
    my $submodel;

    #     for (my $iter = $list_model->get_iter_first, my $mnum = 0;
    #          $iter;
    #          $iter = $list_model->iter_next ($iter), $mnum++) {

    for (my $mnum = 0; ; $mnum++) {
      if (DEBUG) { print "  mnum $mnum\n"; }
      my $iter = $list_model->iter_nth_child (undef, $mnum) || last;
      my $model = $list_model->get_value ($iter, 0);
      $submodel ||= $model;

      my $has_child = ($model && $model->iter_n_children(undef) != 0 ? 1 : 0);
      my $minfo = { model     => $model,
                    mnum      => $mnum,
                    self      => $self,
                    has_child => $has_child };
      Scalar::Util::weaken ($minfo->{'self'});
      push @mlist, $minfo;

      if ($model) {
        $minfo->{'ids'} = Glib::Ex::SignalIds->new
          ($model,
           $model->signal_connect
           (row_changed    => \&_do_sublist_row_changed, $minfo),
           $model->signal_connect
           (row_deleted    => \&_do_sublist_row_deleted, $minfo),
           $model->signal_connect
           (row_inserted   => \&_do_sublist_row_inserted, $minfo),
           $model->signal_connect
           (rows_reordered => \&_do_sublist_rows_reordered, $minfo));
      }
    }

    if ($submodel) {
      my $sub_columns = $submodel->get_n_columns;
      $n_columns += $sub_columns;
      push @column_types,
        map {$submodel->get_column_type($_)} (0 .. $sub_columns-1);
    }
  }

  $self->{'mlist'} = \@mlist;
  $self->{'n_columns'} = $n_columns;
  $self->{'column_types'} = \@column_types;

  if (DEBUG) {
    local $, = ' ';
    print "  column_types",@column_types,"\n";
  }
}

# gtk_tree_model_get_flags
#
sub GET_FLAGS {
  return [];
}

# gtk_tree_model_get_n_columns
#
sub GET_N_COLUMNS {
  my ($self) = @_;
  if (DEBUG >= 2) { print "ListOfListsModel get_n_columns\n"; }
  return $self->{'n_columns'};
}

# gtk_tree_model_get_column_type
#
sub GET_COLUMN_TYPE {
  return $_[0]->{'column_types'}->[$_[1]];
}

# gtk_tree_model_get_iter
#
sub GET_ITER {
  my ($self, $path) = @_;
  if (DEBUG >= 2) { print "ListOfListsModel get_iter, path='",
                      $path->to_string,"'\n"; }



( run in 0.501 second using v1.01-cache-2.11-cpan-39bf76dae61 )