Skip to content

Commit

Permalink
Fix duplicate signals in resolution filter widget, fix logic and add
Browse files Browse the repository at this point in the history
tests
  • Loading branch information
nyalldawson committed Dec 14, 2023
1 parent f9d27cf commit fab4c74
Show file tree
Hide file tree
Showing 3 changed files with 353 additions and 27 deletions.
12 changes: 9 additions & 3 deletions koordinates/gui/filter_widgets/data_type_filter_widget.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from typing import Set
from typing import (
Optional,
Set
)

from qgis.PyQt.QtWidgets import (
QWidget,
Expand Down Expand Up @@ -27,7 +30,7 @@ class DataTypeFilterWidget(FilterWidgetComboBase):

WITH_SETS = False

def __init__(self, parent):
def __init__(self, parent: Optional[QWidget] = None):
super().__init__(parent)

self._block_geometry_type_constraint_update = 0
Expand Down Expand Up @@ -194,7 +197,7 @@ def __init__(self, parent):
self.has_z_elevation_checkbox.toggled.connect(self._update_value)
self.vector_has_primary_key_checkbox.toggled.connect(self._update_value)

self.clear()
self._update_value()

def _type_group_member_clicked(self, clicked_button):
self._block_changes += 1
Expand Down Expand Up @@ -258,6 +261,9 @@ def _enforce_geometry_type_constraints(self):
self._block_geometry_type_constraint_update -= 1

def clear(self):
if self.layers_radio.isChecked():
return

self._block_changes += 1
self.layers_radio.setChecked(True)
self.raster_radio.setChecked(False)
Expand Down
63 changes: 45 additions & 18 deletions koordinates/gui/filter_widgets/resolution_filter_widget.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import Optional
import math

from qgis.PyQt.QtWidgets import (
Expand All @@ -17,7 +18,7 @@ class ResolutionFilterWidget(FilterWidgetComboBase):
Custom widget for resolution selection
"""

def __init__(self, parent):
def __init__(self, parent: Optional[QWidget] = None):
super().__init__(parent)

self.drop_down_widget = QWidget()
Expand All @@ -44,7 +45,8 @@ def __init__(self, parent):

self._range = (0.03, 2000)
self.slider.setRangeLimits(0, 100000)
self.clear()
self.slider.setRange(self.slider.minimum(), self.slider.maximum())
self._update_labels()

@staticmethod
def scale(value, domain, range):
Expand Down Expand Up @@ -99,7 +101,13 @@ def _update_labels(self):
self.changed.emit()

def clear(self):
if self.slider.lowerValue() == self.slider.minimum() and \
self.slider.upperValue() == self.slider.maximum():
return

self._block_changes += 1
self.slider.setRange(self.slider.minimum(), self.slider.maximum())
self._block_changes -= 1
self._update_labels()

def should_show_clear(self):
Expand All @@ -110,26 +118,31 @@ def should_show_clear(self):
return super().should_show_clear()

def apply_constraints_to_query(self, query: DataBrowserQuery):
if self.map_slider_value_to_resolution(self.slider.lowerValue()) \
!= self.map_slider_value_to_resolution(self.slider.minimum()):
query.minimum_resolution = self.map_slider_value_to_resolution(
self.slider.lowerValue()
)
if self.map_slider_value_to_resolution(self.slider.upperValue()) != \
self.map_slider_value_to_resolution(self.slider.maximum()):
query.maximum_resolution = self.map_slider_value_to_resolution(
self.slider.upperValue()
)
mapped_lower_value =self.map_slider_value_to_resolution(self.slider.lowerValue())
mapped_minimum = self.map_slider_value_to_resolution(self.slider.minimum())
if mapped_lower_value != mapped_minimum:
query.minimum_resolution = mapped_lower_value
else:
query.minimum_resolution = None
mapped_upper_value = self.map_slider_value_to_resolution(self.slider.upperValue())
mapped_maximum = self.map_slider_value_to_resolution(self.slider.maximum())
if mapped_upper_value != mapped_maximum:
query.maximum_resolution = mapped_upper_value
else:
query.maximum_resolution = None

def set_from_query(self, query: DataBrowserQuery):
self._block_changes += 1

if query.minimum_resolution is not None:
self.slider.setLowerValue(int(query.minimum_resolution))
self.slider.setLowerValue(
self.map_value_to_slider(query.minimum_resolution)
)
else:
self.slider.setLowerValue(self.slider.minimum())
if query.maximum_resolution is not None:
self.slider.setUpperValue(int(query.maximum_resolution))
self.slider.setUpperValue(
self.map_value_to_slider(query.maximum_resolution))
else:
self.slider.setUpperValue(self.slider.maximum())

Expand All @@ -140,17 +153,31 @@ def set_facets(self, facets: dict):
min_res = facets.get('raster_resolution', {}).get('min')
max_res = facets.get('raster_resolution', {}).get('max')

prev_range = self.current_range()
prev_range = list(self.current_range())
if prev_range[0] == self._range[0]:
prev_range[0] = None
if prev_range[1] == self._range[1]:
prev_range[1] = None

if min_res is not None and max_res is not None:
self._range = (min_res, max_res)
new_range = (max(prev_range[0], min_res), min(prev_range[1], max_res))
new_range = prev_range[:]
if prev_range[0] is not None:
new_range[0] = max(prev_range[0], min_res)
else:
new_range[0] = min_res
if prev_range[1] is not None:
new_range[1] = min(prev_range[1], max_res)
else:
new_range[1] = max_res
else:
self._range = (0.03, 2000)
new_range = self._range

self._block_changes += 1
self.slider.setRange(self.map_value_to_slider(new_range[0]),
self.map_value_to_slider(new_range[1]))
slider_min = self.map_value_to_slider(new_range[0])
slider_max = self.map_value_to_slider(new_range[1])
self.slider.setRange(slider_min, slider_max)

self._update_labels()
self._block_changes -= 1
Loading

0 comments on commit fab4c74

Please sign in to comment.