App/Chart/Gtk2/SymlistComboBox.pm untested

filter: Statementstmt 0.0% 0 / 57 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 12 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 93 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__
92  
93 =for stopwords combobox symlist symlists ComboBox programmatically
94  
95 =head1 NAME
96  
97 App::Chart::Gtk2::SymlistComboBox -- combobox symlist selector
98  
99 =head1 SYNOPSIS
100  
101 use App::Chart::Gtk2::SymlistComboBox;
102 my $combobox = App::Chart::Gtk2::SymlistComboBox->new;
103  
104 =head1 WIDGET HIERARCHY
105  
106 C<App::Chart::Gtk2::SymlistComboBox> is a subclass of C<Gtk2::ComboBox>,
107  
108 Gtk2::Widget
109 Gtk2::Container
110 Gtk2::Bin
111 Gtk2::ComboBox
112 App::Chart::Gtk2::SymlistComboBox
113  
114 =head1 DESCRIPTION
115  
116 C<App::Chart::Gtk2::SymlistComboBox> displays the available symlists, as a
117 convenient combination of C<Gtk2::ComboBox> and
118 C<App::Chart::Gtk2::SymlistListModel>. The C<symlist> property changes according
119 to the list selected.
120  
121 =head1 FUNCTIONS
122  
123 =over 4
124  
125 =item C<< App::Chart::Gtk2::SymlistComboBox->new (key=>value,...) >>
126  
127 Create and return a new C<App::Chart::Gtk2::SymlistComboBox> object. Optional
128 key/value pairs set initial properties as per C<< Glib::Object->new >>.
129  
130 =back
131  
132 =head1 PROPERTIES
133  
134 =over 4
135  
136 =item C<symlist> (C<App::Chart::Gtk2::Symlist> object, default first symlist)
137  
138 The current symlist selected in the ComboBox. This changes with the user's
139 choice, and can be set programmatically to update the ComboBox display.
140  
141 =back
142  
143 =head1 SEE ALSO
144  
145 L<App::Chart::Gtk2::Symlist>
146  
147 =cut