Change type of filter to Optional[ConnectionType]

It's a bit more semantic this way.

Contributes to issue CURA-8609.
This commit is contained in:
Ghostkeeper 2021-10-15 14:35:07 +02:00
parent a399bacab3
commit 2b4a31c9de
No known key found for this signature in database
GPG key ID: D2A8871EE34EC59A

View file

@ -2,6 +2,7 @@
# Cura is released under the terms of the LGPLv3 or higher. # Cura is released under the terms of the LGPLv3 or higher.
from PyQt5.QtCore import Qt, QTimer, pyqtProperty, pyqtSignal from PyQt5.QtCore import Qt, QTimer, pyqtProperty, pyqtSignal
from typing import Optional
from UM.Qt.ListModel import ListModel from UM.Qt.ListModel import ListModel
from UM.i18n import i18nCatalog from UM.i18n import i18nCatalog
@ -39,7 +40,7 @@ class GlobalStacksModel(ListModel):
self._change_timer.setSingleShot(True) self._change_timer.setSingleShot(True)
self._change_timer.timeout.connect(self._update) self._change_timer.timeout.connect(self._update)
self._filter_connection_type = -1 self._filter_connection_type = None # type: Optional[ConnectionType]
self._filter_online_only = False self._filter_online_only = False
# Listen to changes # Listen to changes
@ -49,7 +50,7 @@ class GlobalStacksModel(ListModel):
self._updateDelayed() self._updateDelayed()
filterConnectionTypeChanged = pyqtSignal() filterConnectionTypeChanged = pyqtSignal()
def setFilterConnectionType(self, new_filter: int) -> None: def setFilterConnectionType(self, new_filter: Optional[ConnectionType]) -> None:
self._filter_connection_type = new_filter self._filter_connection_type = new_filter
@pyqtProperty(int, fset = setFilterConnectionType, notify = filterConnectionTypeChanged) @pyqtProperty(int, fset = setFilterConnectionType, notify = filterConnectionTypeChanged)
@ -60,7 +61,7 @@ class GlobalStacksModel(ListModel):
Only printers that match this connection type will be listed in the Only printers that match this connection type will be listed in the
model. model.
""" """
return self._filter_connection_type return int(self._filter_connection_type)
filterOnlineOnlyChanged = pyqtSignal() filterOnlineOnlyChanged = pyqtSignal()
def setFilterOnlineOnly(self, new_filter: bool) -> None: def setFilterOnlineOnly(self, new_filter: bool) -> None:
@ -88,7 +89,7 @@ class GlobalStacksModel(ListModel):
container_stacks = CuraContainerRegistry.getInstance().findContainerStacks(type = "machine") container_stacks = CuraContainerRegistry.getInstance().findContainerStacks(type = "machine")
for container_stack in container_stacks: for container_stack in container_stacks:
if self._filter_connection_type != -1: # We want to filter on connection types. if self._filter_connection_type is not None: # We want to filter on connection types.
if not any((connection_type == self._filter_connection_type for connection_type in container_stack.configuredConnectionTypes)): if not any((connection_type == self._filter_connection_type for connection_type in container_stack.configuredConnectionTypes)):
continue # No connection type on this printer matches the filter. continue # No connection type on this printer matches the filter.