Skip to content
Snippets Groups Projects
Commit 81d0dac8 authored by Maeva Pourpoint's avatar Maeva Pourpoint
Browse files

Merge branch 'issue-46-sort-button' into 'master'

Fix for Issue 46: Added a sorting menu for networks, stations and channels

See merge request !28
parents ce0f5e0c fab6749a
No related branches found
No related tags found
1 merge request!28Fix for Issue 46: Added a sorting menu for networks, stations and channels
package: package:
name: nexus-passoft name: nexus-passoft
version: "2023.4.3.0" version: "2023.4.4.0"
source: source:
path: ../ path: ../
......
...@@ -4,4 +4,4 @@ ...@@ -4,4 +4,4 @@
__author__ = """IRIS PASSCAL""" __author__ = """IRIS PASSCAL"""
__email__ = 'software-support@passcal.nmt.edu' __email__ = 'software-support@passcal.nmt.edu'
__version__ = '2023.4.3.0' __version__ = '2023.4.4.0'
...@@ -657,21 +657,27 @@ class InventoryModel(QtCore.QAbstractItemModel): ...@@ -657,21 +657,27 @@ class InventoryModel(QtCore.QAbstractItemModel):
if node is not self._root_node: if node is not self._root_node:
self.remove_row(node, self.parent(self.get_index(node))) self.remove_row(node, self.parent(self.get_index(node)))
def add_inventory(self, inventory): def add_inventory(self, inventory, net_r=False, stat_r=False, chan_r=False):
''' '''
Replaces data model with new inventory. Replaces data model with new inventory.
If you want to add and inventory add before and call. If you want to add and inventory add before and call.
''' '''
self.clear_data() self.clear_data()
# sort networks
inventory.networks.sort(key=lambda x: x.code, reverse=net_r)
for net in inventory.networks: for net in inventory.networks:
# Making a node inserts it so append_node is empty # Making a node inserts it so append_node is empty
net_node = NetworkNode(net.code, net, self._root_node) net_node = NetworkNode(net.code, net, self._root_node)
self.append_node(net_node) self.append_node(net_node)
net_index = self.get_index(net_node) net_index = self.get_index(net_node)
# sort stations
net.stations.sort(key=lambda x: x.code, reverse=stat_r)
for sta in net.stations: for sta in net.stations:
sta_node = StationNode(sta.code, sta, net_node) sta_node = StationNode(sta.code, sta, net_node)
self.append_node(sta_node, net_index) self.append_node(sta_node, net_index)
sta_index = self.get_index(sta_node) sta_index = self.get_index(sta_node)
# sort channels
sta.channels.sort(key=lambda x: x.code, reverse=chan_r)
for chan in sta.channels: for chan in sta.channels:
chan_node = ChannelNode(chan.code, chan, sta_node) chan_node = ChannelNode(chan.code, chan, sta_node)
self.append_node(chan_node, sta_index) self.append_node(chan_node, sta_index)
...@@ -688,6 +694,13 @@ class NexusWindow(*load_ui("NexusWindow.ui")): ...@@ -688,6 +694,13 @@ class NexusWindow(*load_ui("NexusWindow.ui")):
super().__init__(parent) super().__init__(parent)
self.setupUi(self) self.setupUi(self)
# default sort is ascending
self.sorting_dict = {
NetworkNode: False,
StationNode: False,
ChannelNode: False
}
# Quick aliases # Quick aliases
global status_message global status_message
status_message = self.status_message status_message = self.status_message
...@@ -710,6 +723,9 @@ class NexusWindow(*load_ui("NexusWindow.ui")): ...@@ -710,6 +723,9 @@ class NexusWindow(*load_ui("NexusWindow.ui")):
self.uiInventoryTree.selectionModel().currentChanged.connect( self.uiInventoryTree.selectionModel().currentChanged.connect(
self.editor.setSelection) self.editor.setSelection)
self.uiInventoryTree.setContextMenuPolicy(Qt.CustomContextMenu)
self.uiInventoryTree.customContextMenuRequested.connect(
self.sorting_popup)
# Actions # Actions
self.actionScan_MiniSEED.triggered.connect(self.scan_ms_dialog) self.actionScan_MiniSEED.triggered.connect(self.scan_ms_dialog)
...@@ -731,6 +747,47 @@ class NexusWindow(*load_ui("NexusWindow.ui")): ...@@ -731,6 +747,47 @@ class NexusWindow(*load_ui("NexusWindow.ui")):
# test # test
self.actionDebug.triggered.connect(self.debug) self.actionDebug.triggered.connect(self.debug)
def sorting_popup(self, point):
'''
Bring up menu to let user sort
inventory in ascending/descending order
'''
index = self.uiInventoryTree.indexAt(point)
node = self.inv_model.get_node(index)
node_type = ''
if isinstance(node, NetworkNode):
node_type = 'Networks'
elif isinstance(node, StationNode):
node_type = 'Stations'
elif isinstance(node, ChannelNode):
node_type = 'Channels'
menu = QtWidgets.QMenu(self)
sort_asc = QtGui.QAction(f"Sort {node_type} 0-Z")
sort_asc.triggered.connect(lambda: self.set_sorting_order('ascending', type(node)))
sort_desc = QtGui.QAction(f"Sort {node_type} Z-0")
sort_desc.triggered.connect(lambda: self.set_sorting_order('descending', type(node)))
menu.exec([sort_asc, sort_desc], self.uiInventoryTree.mapToGlobal(point))
def set_sorting_order(self, order, node):
'''
Repopulate inventory in ascending or
descending order
'''
sort_value = False if order == 'ascending' else True
self.sorting_dict[node] = sort_value
# keep scroll bar where it was after
# sorting inventory
scroll_value = self.uiInventoryTree.verticalScrollBar().value()
self.status_message('Sorting...')
self.inv_model.add_inventory(
self.inventory,
self.sorting_dict[NetworkNode],
self.sorting_dict[StationNode],
self.sorting_dict[ChannelNode])
self.reshape_tree()
self.uiInventoryTree.verticalScrollBar().setValue(scroll_value)
self.status_message('Sorting... Done.')
def debug(self): def debug(self):
pass pass
......
...@@ -50,6 +50,6 @@ setup( ...@@ -50,6 +50,6 @@ setup(
packages=find_packages(include=['nexus']), packages=find_packages(include=['nexus']),
test_suite='tests', test_suite='tests',
url='https://git.passcal.nmt.edu/software_public/passoft/nexus', url='https://git.passcal.nmt.edu/software_public/passoft/nexus',
version='2023.4.3.0', version='2023.4.4.0',
zip_safe=False, zip_safe=False,
) )
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment