Skip to content

Commit

Permalink
Fix sort order issue
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanw-chartis committed May 10, 2022
1 parent 758dc2e commit 4623ee6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/roam/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
NUM_VERSION = (3, 0, 6)
NUM_VERSION = (3, 0, 7)

import os
import sys
Expand Down
28 changes: 15 additions & 13 deletions src/roam/editorwidgets/listwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,32 +142,34 @@ def _buildfromlayer(self, widget, layerconfig):
if iconfieldindex > -1:
fields.append("icon")

if not filterexp and valuefieldindex == keyfieldindex and iconfieldindex == -1:
values = layer.uniqueValues(keyfieldindex)
values = sorted(values)
for value in values:
value = nullconvert(value)
item = QStandardItem(value)
item.setData(value, Qt.UserRole)
self.listmodel.appendRow(item)
return

features = roam.api.utils.search_layer(layer, filterexp, fields, with_geometry=False)
# if not filterexp and valuefieldindex == keyfieldindex and iconfieldindex == -1:
# values = layer.uniqueValues(keyfieldindex)
# values = sorted(values)
# for value in values:
# value = nullconvert(value)
# item = QStandardItem(value)
# item.setData(value, Qt.UserRole)
# self.listmodel.appendRow(item)
# return

features = roam.api.utils.search_layer(layer, filterexp, field_list=None, with_geometry=False)
# Sort the fields based on config
sortBy = layerconfig.get('sort_by', 'default')
sortAsNumber = layerconfig.get('sort_by_as_number', False)
if sortBy == "default":
sortBy = valuefield

roam.utils.log("SORT BY" + sortBy)

def custom_sort(feature):
value = feature[sortBy]
if sortAsNumber:
try:
value = float(str(value))
return False, value
except ValueError:
return True,
return False, value
return True, value
return (nullconvert(value) is None), value

features = sorted(features, key=custom_sort)

Expand Down

0 comments on commit 4623ee6

Please sign in to comment.