Skip to content

Commit

Permalink
modify all instances using iter_next
Browse files Browse the repository at this point in the history
Gtk3 returns false on last iter,
and directly pdates the iter var
with the new details.

Much of this code could do with a
further audit for loop labels.

Updates #770
  • Loading branch information
shawnlaffan committed Nov 1, 2020
1 parent b441ddb commit 7d9a43e
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 18 deletions.
10 changes: 7 additions & 3 deletions lib/Biodiverse/GUI/BasedataImport.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ sub fill_params {

push( @{ $params{'LABEL_COLUMNS'} }, $info->{id} );

$iter = $labels_model->iter_next($iter);
last if !$labels_model->iter_next($iter);
}

# Do groups
Expand All @@ -1049,7 +1049,7 @@ sub fill_params {
push( @{ $params{'CELL_IS_LAT'} }, $info2->{is_lat} );
push( @{ $params{'CELL_IS_LON'} }, $info2->{is_lon} );

$iter = $groups_model->iter_next($iter);
last if !$groups_model->iter_next($iter);
}

return \%params;
Expand Down Expand Up @@ -1325,7 +1325,11 @@ sub on_up_down {
}
}
elsif ( $btn eq 'down' ) {
$model->move_after( $iter, $model->iter_next($iter) );
# need copy as iter_next updates $iter under Gtk3
my $iter_from = $model->iter_copy($iter);
if ($model->iter_next ($iter)) {
$model->move_after( $iter_from, $iter );
}
}

return;
Expand Down
2 changes: 1 addition & 1 deletion lib/Biodiverse/GUI/DeleteElementProperties.pm
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ sub on_clicked_apply {
my ($text) = $model->get($iter, MODEL_TEXT_COL);
push (@targets, $text);
}
$iter = $model->iter_next($iter);
last if !$model->iter_next($iter);
}
my $sub_delete_count;
foreach my $target (@targets) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Biodiverse/GUI/Popup.pm
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ sub find_selected_source {
my $name = $sources_model->get($iter, SOURCES_MODEL_NAME);
last if ($name eq $search_name);

$iter = $sources_model->iter_next($iter);
last if !$sources_model->iter_next($iter);
}

return $iter;
Expand Down Expand Up @@ -440,7 +440,7 @@ END_HTML_HEADER
elsif ($datatype == TYPE_HTML) {
$text .= "<tr><td>$name</td><td>$value</td></tr>\n";
}
$iter = $model->iter_next($iter);
last if !$model->iter_next($iter);
}

if ($datatype == TYPE_HTML) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Biodiverse/GUI/Project.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1047,11 +1047,11 @@ sub register_in_outputs_model {
; #FIXME: do we have to look at other iter_bases, or does this iterate over entire level?
}

$iter_output = $model->iter_next($iter_output);
last if !$model->iter_next($iter_output);
}

last if $iter; # break if found it
$iter_base = $model->iter_next($iter_base);
last if !$model->iter_next($iter_base);
}

if ($iter) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Biodiverse/GUI/RemapGUI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,7 @@ sub get_comma_separated_complete_treeview_list {
my $this_row = join (",", @column_data);
push @value_list, $this_row;

$iter = $model->iter_next( $iter );
last if !$model->iter_next( $iter );
}

return \@value_list;
Expand Down
8 changes: 4 additions & 4 deletions lib/Biodiverse/GUI/Tabs/CalculationsTree.pm
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,10 @@ sub get_calculations_to_run {
my ($func) = $model->get($child_iter, MODEL_FUNCTION_COL);
push (@to_run, $func);
}
$child_iter = $model->iter_next($child_iter);
last if !$model->iter_next($child_iter);
}

$type_iter = $model->iter_next($type_iter);
last if !$model->iter_next($type_iter);
}
return @to_run;
}
Expand All @@ -309,7 +309,7 @@ sub update_type_checkbox {
last;
}
$prevchecked = $check;
$child_iter = $model->iter_next($child_iter);
last if !$model->iter_next($child_iter);
}

$check = 0 if $gray == 1;
Expand Down Expand Up @@ -342,7 +342,7 @@ sub on_calculation_toggled {
my $child_iter = $model->iter_nth_child($iter, 0);
while ($child_iter) {
$model->set($child_iter, MODEL_CHECKED_COL, $state);
$child_iter = $model->iter_next($child_iter);
last if !$model->iter_next($child_iter);
}

# update state of any parent
Expand Down
4 changes: 2 additions & 2 deletions lib/Biodiverse/GUI/Tabs/Labels.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1264,7 +1264,7 @@ sub on_grid_select {
$hselection->$sel_method($iter);
}

$iter = $hmodel->iter_next($iter);
last if !$hmodel->iter_next($iter);
}
if (not $ignore_change) {
delete $self->{ignore_selection_change};
Expand Down Expand Up @@ -1381,7 +1381,7 @@ sub on_phylogeny_click {
$hselection->$sel_method($iter);
}

$iter = $hmodel->iter_next($iter);
last if !$hmodel->iter_next($iter);
}
delete $self->{ignore_selection_change};
on_selected_labels_changed($hselection, [$self, 'listLabels1']);
Expand Down
4 changes: 2 additions & 2 deletions lib/Biodiverse/GUI/Tabs/Spatial.pm
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ sub update_lists_combo {
$selected = $iter;
last; # break loop
}
$iter = $self->{output_lists_model}->iter_next($iter);
last if !$self->{output_lists_model}->iter_next($iter);
}

if ($selected) {
Expand Down Expand Up @@ -1770,7 +1770,7 @@ sub update_output_indices_combo {
$selected = $iter;
last BY_ITER; # break loop
}
$iter = $self->{output_indices_model}->iter_next($iter);
last if !$self->{output_indices_model}->iter_next($iter);
}

if ($selected) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Biodiverse/GUI/Tabs/SpatialMatrix.pm
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ sub on_cell_selected {
$selected = $iter;
last BY_ITER; # break loop
}
$iter = $self->{output_indices_model}->iter_next($iter);
last if !$self->{output_indices_model}->iter_next($iter);
}

if ($selected) {
Expand Down

0 comments on commit 7d9a43e

Please sign in to comment.