Skip to content

Commit

Permalink
Fixed a division by zero bug and guaranteed a minimum zoom value of 0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
XavierCLL committed Sep 26, 2024
1 parent 3e7163a commit ef20d17
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
16 changes: 12 additions & 4 deletions gui/response_design_view_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def render_layer(self, layer):
def set_extents_and_scalefactor(self, extent):
with block_signals_to(self.canvas):
self.canvas.setExtent(extent)
self.canvas.zoomByFactor(self.parent_view.scaleFactor.value())
self.canvas.zoomByFactor(round(self.parent_view.scaleFactor.value(), 1))
if self.marker.marker:
self.marker.marker.updatePosition()

Expand Down Expand Up @@ -250,7 +250,11 @@ def canvas_changed(self):
if self.is_active:
from AcATaMa.gui.response_design_window import ResponseDesignWindow
view_extent = self.render_widget.canvas.extent()
view_extent.scale(1/self.current_scale_factor)
try:
view_extent.scale(1/self.current_scale_factor)
except ZeroDivisionError:
self.current_scale_factor = self.scaleFactor.minimum()
view_extent.scale(1 / self.current_scale_factor)

# set extent and scale factor for all view activated except this view
for view_widget in ResponseDesignWindow.view_widgets:
Expand All @@ -262,7 +266,11 @@ def scalefactor_changed(self):
# adjust view with the original extent (scale factor=1)
# and with the new scale factor
view_extent = self.render_widget.canvas.extent()
view_extent.scale(1 / self.current_scale_factor)
try:
view_extent.scale(1 / self.current_scale_factor)
except ZeroDivisionError:
self.current_scale_factor = self.scaleFactor.minimum()
view_extent.scale(1 / self.current_scale_factor)
self.render_widget.set_extents_and_scalefactor(view_extent)
# save the new scale factor
self.current_scale_factor = self.scaleFactor.value()
self.current_scale_factor = round(self.scaleFactor.value(), 1)
5 changes: 4 additions & 1 deletion ui/response_design_view_widget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,17 @@
<number>1</number>
</property>
<property name="minimum">
<double>0.000000000000000</double>
<double>0.100000000000000</double>
</property>
<property name="maximum">
<double>1000.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
<property name="stepType">
<enum>QAbstractSpinBox::AdaptiveDecimalStepType</enum>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
Expand Down

0 comments on commit ef20d17

Please sign in to comment.