From c32700c40c49410636d81d771b3323cf93b1ce68 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Tue, 28 May 2024 13:32:56 +0200 Subject: [PATCH] fix sorting of versions in loader comboboxes --- client/ayon_core/tools/loader/abstract.py | 28 +++++++++++++++---- .../tools/loader/ui/products_model.py | 4 ++- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/client/ayon_core/tools/loader/abstract.py b/client/ayon_core/tools/loader/abstract.py index 509db4d037..a1c1e6a062 100644 --- a/client/ayon_core/tools/loader/abstract.py +++ b/client/ayon_core/tools/loader/abstract.py @@ -172,12 +172,30 @@ def __ne__(self, other): def __gt__(self, other): if not isinstance(other, VersionItem): return False - if ( - other.version == self.version - and self.is_hero - ): + # Make sure hero versions are positive + version = abs(self.version) + other_version = abs(other.version) + # Hero version is greater than non-hero + if version == other_version: + return self.is_hero + return version > other_version + + def __lt__(self, other): + if not isinstance(other, VersionItem): return True - return other.version < self.version + # Make sure hero versions are positive + version = abs(self.version) + other_version = abs(other.version) + # Non-hero version is lesser than hero + if version == other_version: + return not self.is_hero + return version < other_version + + def __ge__(self, other): + return self.__eq__(other) or self.__gt__(other) + + def __le__(self, other): + return self.__eq__(other) or self.__lt__(other) def to_data(self): return { diff --git a/client/ayon_core/tools/loader/ui/products_model.py b/client/ayon_core/tools/loader/ui/products_model.py index f309473d10..fc7375d8c1 100644 --- a/client/ayon_core/tools/loader/ui/products_model.py +++ b/client/ayon_core/tools/loader/ui/products_model.py @@ -198,7 +198,9 @@ def data(self, index, role=None): product_item = self._product_items_by_id.get(product_id) if product_item is None: return None - return list(product_item.version_items.values()) + product_items = list(product_item.version_items.values()) + product_items.sort(reverse=True) + return product_items if role == QtCore.Qt.EditRole: return None