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

Loader tools: Fix sorting of versions in comboboxes #559

Merged
merged 2 commits into from
Jun 4, 2024
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
28 changes: 23 additions & 5 deletions client/ayon_core/tools/loader/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion client/ayon_core/tools/loader/ui/products_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,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
Expand Down