Skip to content

Commit

Permalink
Resolve #1215 (#1278)
Browse files Browse the repository at this point in the history
  • Loading branch information
marc-vdm authored May 30, 2024
1 parent fefdff5 commit cb64dca
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions activity_browser/ui/tables/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,24 @@ def setup_model_data(self) -> None:
def sync(self, *args, **kwargs) -> None:
pass


class ABSortProxyModel(QSortFilterProxyModel):
"""Reimplementation to allow for sorting on the actual data in cells instead of the visible data.
See this for context: https://github.com/LCA-ActivityBrowser/activity-browser/pull/1151
"""
def lessThan(self, left, right):
def lessThan(self, left, right) -> bool:
"""Override to sort actual data, expects `left` and `right` are comparable.
If `left` and `right` are not the same type, we check if numerical and empty string are compared, if that is the
case, we assume empty string == 0.
Added this case for: https://github.com/LCA-ActivityBrowser/activity-browser/issues/1215"""
left_data = self.sourceModel().data(left, 'sorting')
right_data = self.sourceModel().data(right, 'sorting')
return left_data < right_data
if type(left_data) is type(right_data):
return left_data < right_data
elif type(left_data) in (int, float) and type(right_data) is str and right_data == "":
return left_data < 0
elif type(right_data) in (int, float) and type(left_data) is str and left_data == "":
return 0 < right_data
raise ValueError(f"Cannot compare {left_data} and {right_data}, incompatible types.")

0 comments on commit cb64dca

Please sign in to comment.