mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-31 09:21:39 +00:00
qt addresses list: custom sort order for "Type" and "fiat balance" cols
fixes #4920 fixes #5641
This commit is contained in:
parent
93c90a30f0
commit
efc5deb06e
1 changed files with 20 additions and 9 deletions
|
@ -35,7 +35,7 @@ from electrum.plugin import run_hook
|
|||
from electrum.bitcoin import is_address
|
||||
from electrum.wallet import InternalAddressCorruption
|
||||
|
||||
from .util import MyTreeView, MONOSPACE_FONT, ColorScheme, webopen
|
||||
from .util import MyTreeView, MONOSPACE_FONT, ColorScheme, webopen, MySortModel
|
||||
|
||||
|
||||
class AddressUsageStateFilter(IntEnum):
|
||||
|
@ -78,6 +78,8 @@ class AddressList(MyTreeView):
|
|||
|
||||
filter_columns = [Columns.TYPE, Columns.ADDRESS, Columns.LABEL, Columns.COIN_BALANCE]
|
||||
|
||||
ROLE_SORT_ORDER = Qt.UserRole + 1000
|
||||
|
||||
def __init__(self, parent):
|
||||
super().__init__(parent, self.create_menu, stretch_column=self.Columns.LABEL)
|
||||
self.wallet = self.parent.wallet
|
||||
|
@ -93,8 +95,12 @@ class AddressList(MyTreeView):
|
|||
self.used_button.currentIndexChanged.connect(self.toggle_used)
|
||||
for addr_usage_state in AddressUsageStateFilter.__members__.values(): # type: AddressUsageStateFilter
|
||||
self.used_button.addItem(addr_usage_state.ui_text())
|
||||
self.setModel(QStandardItemModel(self))
|
||||
self.std_model = QStandardItemModel(self)
|
||||
self.proxy = MySortModel(self, sort_role=self.ROLE_SORT_ORDER)
|
||||
self.proxy.setSourceModel(self.std_model)
|
||||
self.setModel(self.proxy)
|
||||
self.update()
|
||||
self.sortByColumn(self.Columns.TYPE, Qt.AscendingOrder)
|
||||
|
||||
def get_toolbar_buttons(self):
|
||||
return QLabel(_("Filter:")), self.change_button, self.used_button
|
||||
|
@ -146,7 +152,8 @@ class AddressList(MyTreeView):
|
|||
addr_list = self.wallet.get_change_addresses()
|
||||
else:
|
||||
addr_list = self.wallet.get_addresses()
|
||||
self.model().clear()
|
||||
self.proxy.setDynamicSortFilter(False) # temp. disable re-sorting after every change
|
||||
self.std_model.clear()
|
||||
self.refresh_headers()
|
||||
fx = self.parent.fx
|
||||
set_address = None
|
||||
|
@ -187,18 +194,21 @@ class AddressList(MyTreeView):
|
|||
address_item[self.Columns.TYPE].setText(_('receiving'))
|
||||
address_item[self.Columns.TYPE].setBackground(ColorScheme.GREEN.as_color(True))
|
||||
address_item[self.Columns.LABEL].setData(address, Qt.UserRole)
|
||||
address_path = self.wallet.get_address_index(address)
|
||||
address_item[self.Columns.TYPE].setData(address_path, self.ROLE_SORT_ORDER)
|
||||
address_path_str = self.wallet.get_address_path_str(address)
|
||||
if address_path_str is not None:
|
||||
address_item[self.Columns.TYPE].setToolTip(address_path_str)
|
||||
address_item[self.Columns.FIAT_BALANCE].setData(balance, self.ROLE_SORT_ORDER)
|
||||
# setup column 1
|
||||
if self.wallet.is_frozen_address(address):
|
||||
address_item[self.Columns.ADDRESS].setBackground(ColorScheme.BLUE.as_color(True))
|
||||
if address in addresses_beyond_gap_limit:
|
||||
address_item[self.Columns.ADDRESS].setBackground(ColorScheme.RED.as_color(True))
|
||||
# add item
|
||||
count = self.model().rowCount()
|
||||
self.model().insertRow(count, address_item)
|
||||
address_idx = self.model().index(count, self.Columns.LABEL)
|
||||
count = self.std_model.rowCount()
|
||||
self.std_model.insertRow(count, address_item)
|
||||
address_idx = self.std_model.index(count, self.Columns.LABEL)
|
||||
if address == current_address:
|
||||
set_address = QPersistentModelIndex(address_idx)
|
||||
self.set_current_idx(set_address)
|
||||
|
@ -208,6 +218,7 @@ class AddressList(MyTreeView):
|
|||
else:
|
||||
self.hideColumn(self.Columns.FIAT_BALANCE)
|
||||
self.filter()
|
||||
self.proxy.setDynamicSortFilter(True)
|
||||
|
||||
def create_menu(self, position):
|
||||
from electrum.wallet import Multisig_Wallet
|
||||
|
@ -217,17 +228,17 @@ class AddressList(MyTreeView):
|
|||
if not selected:
|
||||
return
|
||||
multi_select = len(selected) > 1
|
||||
addrs = [self.model().itemFromIndex(item).text() for item in selected]
|
||||
addrs = [self.item_from_index(item).text() for item in selected]
|
||||
menu = QMenu()
|
||||
if not multi_select:
|
||||
idx = self.indexAt(position)
|
||||
if not idx.isValid():
|
||||
return
|
||||
item = self.model().itemFromIndex(idx)
|
||||
item = self.item_from_index(idx)
|
||||
if not item:
|
||||
return
|
||||
addr = addrs[0]
|
||||
addr_column_title = self.model().horizontalHeaderItem(self.Columns.LABEL).text()
|
||||
addr_column_title = self.std_model.horizontalHeaderItem(self.Columns.LABEL).text()
|
||||
addr_idx = idx.sibling(idx.row(), self.Columns.LABEL)
|
||||
self.add_copy_menu(menu, idx)
|
||||
menu.addAction(_('Details'), lambda: self.parent.show_address(addr))
|
||||
|
|
Loading…
Add table
Reference in a new issue