ComboBoxBits.pm

filter: Statementstmt 34.0% 15 / 44 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 44.4% 4 / 9 Podpod 100% 4 / 4 totaltotal 25.8% 23 / 89 CC 13 SCAR 29.4
CC
13
Cov
21%
set_active_path
42.0
set_active_text
20.0
get_active_path
12.0
CRAP 18.9
↑ Summary Menu/EnumRadio/Item.pm »
1 # Copyright 2010, 2011 Kevin Ryde
2  
3 # This file is part of Gtk2-Ex-ComboBoxBits.
4 #
5 # Gtk2-Ex-ComboBoxBits is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License as published
7 # by the Free Software Foundation; either version 3, or (at your option) any
8 # later version.
9 #
10 # Gtk2-Ex-ComboBoxBits is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 # for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with Gtk2-Ex-ComboBoxBits. If not, see <http://www.gnu.org/licenses/>.
17  
18 package Gtk2::Ex::ComboBoxBits;
19 3 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 3 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 3 our @ISA = ('Exporter');
25 3 our @EXPORT_OK = qw(get_active_path
26 set_active_path
27 set_active_text
28 find_text_iter);
29  
30 # uncomment this to run the ### lines
31 #use Smart::Comments;
32  
33 3 our $VERSION = 32;
34  
35 #------------------------------------------------------------------------------
36  
37 0 ▶sub get_active_path {
Subroutine get_active_path: not called CC=3 SCAR=24.8
Pod documented
38 0 my ($combobox) = @_;
39 0 my ($model, $iter);
40 0 ▶ return (($model = $combobox->get_model)
Condition0%0/6
($model = $combobox->get_model) && ($iter = $combobox->get_active_iter) && $model->get_path($combobox->get_active_iter)
!ll&&!rl&&r
000
$model = $combobox->get_model and $iter = $combobox->get_active_iter
!ll&&!rl&&r
000
MC/DC0%0/3
($model = $combobox->get_model) && ($iter = $combobox->get_active_iter) && $model->get_path($combobox->get_active_iter)
$model = $combobox->get_model $iter = $combobox->get_active_iter $model->get_path($combobox->get_active_iter)
Truth table0%0/4
A and B && C
A= $model = $combobox->get_modelB= $iter = $combobox->get_active_iterC= $model->get_path($combobox->get_active_iter)
ABCresult
0XX0
10X0
1100
1111
41 && ($iter = $combobox->get_active_iter)
42 && $model->get_path ($combobox->get_active_iter));
43 }
44  
45 0 ▶sub set_active_path {
Subroutine set_active_path: not called CC=6 SCAR=37.4
Pod documented
46 0 my ($combobox, $path) = @_;
47 ### set_active_path()
48  
49 # Non-existent rows go to set_active(-1) since the Perl-Gtk2
50 # set_active_iter() doesn't accept undef (NULL) until 1.240.
51 # If ready to demand that version could
52 # $combobox->set_active_iter ($model && $path && $model->get_iter($path));
53  
54 0 ▶ if ($path) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path) 0 0 0
55 0 ▶ if ($path->get_depth == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path->get_depth == 1) 0 0 0
56 # top-level row using set_active()
57 0 $combobox->set_active ($path->get_indices);
58 0 return;
59 }
60  
61 0 ▶ if (my $model = $combobox->get_model) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $model = $combobox->get_model) 0 0 0
62 0 ▶ if (my $iter = $model->get_iter($path)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $iter = $model->get_iter($path)) 0 0 0
63 0 $combobox->set_active_iter ($iter);
64 0 return;
65 }
66 }
67 }
68 # path=undef, or no model, or path not in model
69 # FIXME: ->set_active(-1) spits a warning in gtk 2.28 if no model,
70 # want Gtk2 1.240 for ->set_active_iter(undef)
71 0 ▶ if ($combobox->get_model) {
Branch: 1 branch
BranchTrueFalseTotal
if ($combobox->get_model) 0 0 0
72 0 $combobox->set_active (-1);
73 }
74 }
75  
76 #------------------------------------------------------------------------------
77  
78 0 ▶sub set_active_text {
Subroutine set_active_text: not called CC=4 SCAR=30.0
Pod documented
79 0 my ($combobox, $str) = @_;
80 ### ComboBoxBits set_active_text(): $str
81  
82 0 ▶ if (defined $str && (my $iter = find_text_iter ($combobox, $str))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $str and my $iter = find_text_iter($combobox, $str)) { } 0 0 0
Condition0%0/3
defined $str and my $iter = find_text_iter($combobox, $str)
!ll&&!rl&&r
000
MC/DC0%0/2
defined $str and my $iter = find_text_iter($combobox, $str)
defined $str my $iter = find_text_iter($combobox, $str)
Truth table0%0/3
A and B
A= defined $strB= my $iter = find_text_iter($combobox, $str)
ABresult
0X0
100
111
83 ### $iter
84 0 $combobox->set_active_iter ($iter);
85 } else {
86 # As of Gtk 2.20 set_active() throws a g_log() warning if there's no
87 # model set. Prefer to quietly do nothing to make no active item when
88 # already no active item.
89 0 ▶ if ($combobox->get_model) {
Branch: 1 branch
BranchTrueFalseTotal
if ($combobox->get_model) 0 0 0
90 # pending perl-gtk 1.240 set_active_iter() accepting undef
91 0 $combobox->set_active (-1);
92 }
93 }
94 ### set_active_text() active num now: $combobox->get_active
95 }
96  
97 0 ▶sub find_text_iter {
Subroutine find_text_iter: not called CC=2 SCAR=17.9
Pod documented
98 0 my ($combobox, $str) = @_;
99 ### ComboBoxBits find_text_iter(): $str
100 0 my $ret;
101 0 ▶ if (my $model = $combobox->get_model) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $model = $combobox->get_model) 0 0 0
102 0 ▶ $model->foreach (sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
103 0 my ($model, $path, $iter) = @_;
104 ### get_value: $model->get_value ($iter, 0)
105 0 ▶ if ($str eq $model->get_value ($iter, 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str eq $model->get_value($iter, 0)) 0 0 0
106 ### found at: $path->to_string
107 0 $ret = $iter->copy;
108 0 return 1; # stop
109 }
110 0 return 0; # continue
111 0 });
112 }
113 ### $ret
114 0 return $ret;
115 }
116  
117 3 1;
118 __END__
↑ Summary Menu/EnumRadio/Item.pm »