Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to avoid "flashing" results widget #308

Merged
merged 8 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion koordinates/gui/filter_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
QgsFilterLineEdit
)

from .advanced_filter_widget import AdvancedFilterWidget
from .filter_widgets import AdvancedFilterWidget
from .enums import (
TabStyle,
FilterWidgetAppearance,
Expand Down
10 changes: 10 additions & 0 deletions koordinates/gui/filter_widgets/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from .access_filter_widget import AccessFilterWidget # NOQA
from .category_filter_widget import CategoryFilterWidget # NOQA
from .data_type_filter_widget import DataTypeFilterWidget # NOQA
from .date_filter_widget import DateFilterWidget # NOQA
from .group_filter_widget import GroupFilterWidget # NOQA
from .license_filter_widget import LicenseFilterWidget # NOQA
from .publisher_filter_widget import PublisherFilterWidget # NOQA
from .publisher_filter_widget import PublisherSelectionWidget # NOQA
from .resolution_filter_widget import ResolutionFilterWidget # NOQA
from .advanced_filter_widget import AdvancedFilterWidget # NOQA
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import Optional
from qgis.PyQt.QtWidgets import (
QWidget,
QVBoxLayout,
Expand All @@ -6,7 +7,7 @@
)

from .filter_widget_combo_base import FilterWidgetComboBase
from ..api import (
from ...api import (
DataBrowserQuery,
AccessType
)
Expand All @@ -17,7 +18,7 @@ class AccessFilterWidget(FilterWidgetComboBase):
Custom widget for access based filtering
"""

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

self.drop_down_widget = QWidget()
Expand All @@ -39,7 +40,10 @@ def __init__(self, parent):

self.set_contents_widget(self.drop_down_widget)

self.clear()
self._update_visible_frames()
self._block_changes += 1
self._update_value()
self._block_changes -= 1

def _access_group_member_clicked(self, clicked_button):
self._block_changes += 1
Expand All @@ -56,6 +60,10 @@ def _update_visible_frames(self):
self._floating_widget.reflow()

def clear(self):
if not any((self.public_radio.isChecked(),
self.private_radio.isChecked())):
return

self.public_radio.setChecked(False)
self.private_radio.setChecked(False)
self._update_visible_frames()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@
)

from .access_filter_widget import AccessFilterWidget
# from .category_filter_widget import CategoryFilterWidget
from .data_type_filter_widget import DataTypeFilterWidget
from .date_filter_widget import DateFilterWidget
from .publisher_filter_widget import PublisherFilterWidget
from .enums import FilterWidgetAppearance
from .flow_layout import FlowLayout
from .group_filter_widget import GroupFilterWidget
from .license_filter_widget import LicenseFilterWidget
from .resolution_filter_widget import ResolutionFilterWidget
from ..api import (
from ..enums import FilterWidgetAppearance
from ..flow_layout import FlowLayout
from ...api import (
DataBrowserQuery,
DataType,
Publisher
Expand All @@ -43,7 +42,7 @@ class AdvancedFilterWidget(QWidget):

CORNER_RADIUS = 4

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

self.should_show = False
Expand Down Expand Up @@ -199,7 +198,7 @@ def apply_constraints_to_query(self, query: DataBrowserQuery):
Updates a query to reflect the current widget state
"""
for w in self.filter_widgets:
if w.isVisible():
if not w.isHidden():
w.apply_constraints_to_query(query)

def set_from_query(self, query: DataBrowserQuery):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
)

from .filter_widget_combo_base import FilterWidgetComboBase
from ..api import (
from ...api import (
DataBrowserQuery
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def __init__(self, parent):
self._show_clear_button = True
self._clear_action = None

self._current_text = ''
self._current_text: str = ''
self._hover_state = None

self._floating_widget = CustomComboBox.ContentsWidget(self)
Expand Down Expand Up @@ -249,10 +249,19 @@ def expand(self):
if self.parent() and self.parent().parent():
self.parent().parent().update()

def set_current_text(self, text):
def set_current_text(self, text: str):
"""
Sets the current text shown in the collapsed combo box
"""
self._current_text = text
self.update()

def current_text(self) -> str:
"""
Returns the current text shown in the collapsed combo box
"""
return self._current_text

def paintEvent(self, event):
super().paintEvent(event)

Expand Down
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 All @@ -9,7 +12,7 @@
)

from .filter_widget_combo_base import FilterWidgetComboBase
from ..api import (
from ...api import (
DataBrowserQuery,
DataType,
RasterFilter,
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
QgsDateEdit
)

from ...api import DataBrowserQuery
from .filter_widget_combo_base import FilterWidgetComboBase
from ..api import DataBrowserQuery
from .range_slider import RangeSlider

DATE_FORMAT = 'dd MMM yyyy'
Expand Down Expand Up @@ -55,7 +55,7 @@ class DateFilterWidget(FilterWidgetComboBase):
Custom widget for date selection
"""

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

self.drop_down_widget = QWidget()
Expand Down Expand Up @@ -393,6 +393,14 @@ def set_created_limits(self, min_date: Optional[QDate], max_date: Optional[QDate
self.set_published_range(prev_min_created, prev_max_created)

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

self._block_changes += 1
self.updated_date_slider.setRange(
self.updated_date_slider.minimum(),
self.updated_date_slider.maximum()
Expand All @@ -401,6 +409,7 @@ def clear(self):
self.published_date_slider.minimum(),
self.published_date_slider.maximum()
)
self._block_changes -= 1
self._update_labels()

def should_show_clear(self):
Expand All @@ -416,12 +425,20 @@ def should_show_clear(self):
def apply_constraints_to_query(self, query: DataBrowserQuery):
if self.min_published_date_edit.date() != self.min_published_date_edit.default_date():
query.created_minimum = QDateTime(self.min_published_date_edit.date())
else:
query.created_minimum = None
if self.max_published_date_edit.date() != self.max_published_date_edit.default_date():
query.created_maximum = QDateTime(self.max_published_date_edit.date())
else:
query.created_maximum = None
if self.min_updated_date_edit.date() != self.min_updated_date_edit.default_date():
query.updated_minimum = QDateTime(self.min_updated_date_edit.date())
else:
query.updated_minimum = None
if self.max_updated_date_edit.date() != self.max_updated_date_edit.default_date():
query.updated_maximum = QDateTime(self.max_updated_date_edit.date())
else:
query.updated_maximum = None

def set_from_query(self, query: DataBrowserQuery):
self._block_changes += 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from qgis.PyQt.QtCore import pyqtSignal

from .custom_combo_box import CustomComboBox
from ..api import DataBrowserQuery
from ...api import DataBrowserQuery


class FilterWidgetComboBase(CustomComboBox):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
)

from .filter_widget_combo_base import FilterWidgetComboBase
from ..api import (
from ...api import (
DataBrowserQuery
)

Expand All @@ -18,7 +18,7 @@ class GroupFilterWidget(FilterWidgetComboBase):
Custom widget for group based filtering
"""

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

Expand All @@ -35,7 +35,7 @@ def __init__(self, parent):

self.set_contents_widget(self.drop_down_widget)

self.clear()
self._update_value()

def _group_member_clicked(self, clicked_button):
self._block_changes += 1
Expand All @@ -51,6 +51,9 @@ def _update_visible_frames(self):
self._floating_widget.reflow()

def clear(self):
if not any(radio.isChecked() for radio in self._radios):
return

for radio in self._radios:
radio.setChecked(False)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import Optional
from qgis.PyQt.QtWidgets import (
QWidget,
QVBoxLayout,
Expand All @@ -7,7 +8,7 @@
)

from .filter_widget_combo_base import FilterWidgetComboBase
from ..api import (
from ...api import (
DataBrowserQuery,
CreativeCommonLicenseVersions
)
Expand All @@ -18,7 +19,7 @@ class LicenseFilterWidget(FilterWidgetComboBase):
Custom widget for license filtering
"""

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

self.drop_down_widget = QWidget()
Expand Down Expand Up @@ -80,7 +81,7 @@ def __init__(self, parent):
self.cc_4_checkbox.toggled.connect(self._update_value)
self.cc_3_checkbox.toggled.connect(self._update_value)

self.clear()
self._update_value()

def _update_visible_frames(self):
self.cc_options_widget.setVisible(self.cc_3_checkbox.isChecked()
Expand All @@ -90,11 +91,16 @@ def _update_visible_frames(self):
self._floating_widget.reflow()

def clear(self):
if not self.cc_4_checkbox.isChecked() and not self.cc_3_checkbox.isChecked():
return

self._block_changes = True
self.cc_4_checkbox.setChecked(False)
self.cc_3_checkbox.setChecked(False)
self.derivatives_allowed_radio.setChecked(True)
self.commercial_use_allowed_radio.setChecked(True)
self.no_changes_need_to_be_shared_radio.setChecked(True)
self._block_changes = False
self._update_visible_frames()
self._update_value()

Expand Down Expand Up @@ -143,8 +149,12 @@ def apply_constraints_to_query(self, query: DataBrowserQuery):

if self.cc_3_checkbox.isChecked():
query.cc_license_versions.add(CreativeCommonLicenseVersions.Version3)
elif CreativeCommonLicenseVersions.Version3 in query.cc_license_versions:
query.cc_license_versions.remove(CreativeCommonLicenseVersions.Version3)
if self.cc_4_checkbox.isChecked():
query.cc_license_versions.add(CreativeCommonLicenseVersions.Version4)
elif CreativeCommonLicenseVersions.Version4 in query.cc_license_versions:
query.cc_license_versions.remove(CreativeCommonLicenseVersions.Version4)

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