App/Chart/Gtk2/SymlistComboBox.pm untested

filter: Statementstmt 0.0% 0 / 57 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 100 CC 6 SCAR 24.2
CC
6
Cov
0%
SET_PROPERTY
30.0
_do_changed
6.0
INIT_INSTANCE
2.0
CRAP 11.2
1 # Copyright 2007, 2008, 2009, 2010, 2011 Kevin Ryde
2  
3 # This file is part of Chart.
4 #
5 # Chart is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 3, or (at your option) any later version.
8 #
9 # Chart is distributed in the hope that it will be useful, but WITHOUT ANY
10 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12 # details.
13 #
14 # You should have received a copy of the GNU General Public License along
15 # with Chart. If not, see <http://www.gnu.org/licenses/>.
16  
17 package App::Chart::Gtk2::SymlistComboBox;
18 use 5.010;
19 use strict;
20 use warnings;
21 use Carp;
22 use Gtk2;
23 use App::Chart::Gtk2::Symlist;
24  
25 use Glib::Object::Subclass
26 'Gtk2::ComboBox',
27 signals => { changed => \&_do_changed },
28 properties => [ Glib::ParamSpec->object
29 ('symlist',
30 'symlist',
31 'The symlist selected.',
32 'App::Chart::Gtk2::Symlist',
33 Glib::G_PARAM_READWRITE)
34 ];
35  
36 sub INIT_INSTANCE {
37 my ($self) = @_;
38  
39 require App::Chart::Gtk2::SymlistListModel;
40 my $model = App::Chart::Gtk2::SymlistListModel->instance;
41 $self->set (model => $model,
42 active => 0);
43  
44 my $renderer = Gtk2::CellRendererText->new;
45 $renderer->set (ypad => 0);
46 $self->pack_start ($renderer, 1);
47 $self->set_attributes ($renderer, text => $model->COL_NAME);
48 }
49  
50 sub SET_PROPERTY {
51 my ($self, $pspec, $newval) = @_;
52 my $pname = $pspec->get_name;
53  
54 if ($pname eq 'symlist') {
55 if (defined $newval) {
56 $newval->isa('App::Chart::Gtk2::Symlist') or croak 'Not a App::Chart::Gtk2::Symlist';
57 }
58 }
59  
60 $self->{$pname} = $newval; # per default GET_PROPERTY
61  
62 if ($pname eq 'symlist') {
63 my $symlist = $newval;
64 my $pos = -1;
65 if (defined $symlist) {
66 my $key = $symlist->key;
67 my $model = $self->get_model;
68 $pos = $model->key_to_pos ($key);
69 }
70 $self->set_active ($pos);
71 }
72 }
73  
74 # 'changed' class closure
75 sub _do_changed {
76 my ($self) = @_;
77 ### SymlistComboBox _do_changed()
78 my $model = $self->get_model;
79 my $iter = $self->get_active_iter;
80 my $key = $iter && $model->get_value ($iter, $model->COL_KEY);
81 ### to key: $key
82 my $new_symlist = $key && App::Chart::Gtk2::Symlist->new_from_key ($key);
83 if (($new_symlist//0) != ($self->{'symlist'}//0)) {
84 $self->{'symlist'} = $new_symlist;
85 $self->notify('symlist');
86 }
87 return shift->signal_chain_from_overridden(@_);
88 }
89  
90 1;
91 __END__