Simplify SortFilterProxy init

This commit is contained in:
miruka 2019-05-11 16:40:53 -04:00
parent bbc4c15ad3
commit bb86c39fe7
2 changed files with 8 additions and 8 deletions

View File

@ -5,6 +5,7 @@
- Bug fixes - Bug fixes
- dataclass-like `default_factory` for ListItem - dataclass-like `default_factory` for ListItem
- Dragging SidePane to max size makes messages disappear
- Local echo messages all have the same time - Local echo messages all have the same time
- Prevent briefly seeing login screen if there are accounts to - Prevent briefly seeing login screen if there are accounts to
resumeSession for but they take time to appear resumeSession for but they take time to appear

View File

@ -18,18 +18,16 @@ class SortFilterProxy(QSortFilterProxyModel):
parent: QObject = None) -> None: parent: QObject = None) -> None:
super().__init__(parent) super().__init__(parent)
self.setDynamicSortFilter(False) self.setDynamicSortFilter(False)
self.setFilterCaseSensitivity(Qt.CaseInsensitive)
self.ascending = ascending
self.sortByRoleChanged.connect(self._set_sort_role)
self.setSourceModel(source_model) self.setSourceModel(source_model)
source_model.rolesSet.connect(self._set_sort_role) source_model.rolesSet.connect(self._set_internal_sort_role)
source_model.countChanged.connect(self.countChanged.emit) source_model.countChanged.connect(self.countChanged.emit)
source_model.changed.connect(self._sort) source_model.changed.connect(self._sort)
self._sort_by_role = sort_by_role self._sort_by_role = ""
self._set_sort_role() self.sortByRole = sort_by_role
self.ascending = ascending
@pyqtProperty(str, notify=sortByRoleChanged) @pyqtProperty(str, notify=sortByRoleChanged)
@ -40,10 +38,11 @@ class SortFilterProxy(QSortFilterProxyModel):
@sortByRole.setter # type: ignore @sortByRole.setter # type: ignore
def sortByRole(self, role: str) -> None: def sortByRole(self, role: str) -> None:
self._sort_by_role = role self._sort_by_role = role
self._set_internal_sort_role()
self.sortByRoleChanged.emit() self.sortByRoleChanged.emit()
def _set_sort_role(self) -> None: def _set_internal_sort_role(self) -> None:
numbers = self.sourceModel().roleNumbers() numbers = self.sourceModel().roleNumbers()
try: try:
self.setSortRole(numbers[self._sort_by_role]) self.setSortRole(numbers[self._sort_by_role])