From 3f577c17a784d0fc4da8bd5a72a0f463be181f9c Mon Sep 17 00:00:00 2001 From: Inso <insomniak.fr@gmail.com> Date: Wed, 18 Feb 2015 08:29:19 +0100 Subject: [PATCH] SortProxy for the wallets table --- res/ui/wallets_tab.ui | 4 ++- src/cutecoin/__init__.py | 2 +- src/cutecoin/gui/currency_tab.py | 7 +---- src/cutecoin/gui/wallets_tab.py | 8 +++--- src/cutecoin/models/wallets.py | 44 +++++++++++++++++++++++++++++++- 5 files changed, 53 insertions(+), 12 deletions(-) diff --git a/res/ui/wallets_tab.ui b/res/ui/wallets_tab.ui index 53e10c3b..77685701 100644 --- a/res/ui/wallets_tab.ui +++ b/res/ui/wallets_tab.ui @@ -102,6 +102,8 @@ QGroupBox::title { </item> </layout> </widget> - <resources/> + <resources> + <include location="../icons/icons.qrc"/> + </resources> <connections/> </ui> diff --git a/src/cutecoin/__init__.py b/src/cutecoin/__init__.py index ad18e517..e6ed9679 100644 --- a/src/cutecoin/__init__.py +++ b/src/cutecoin/__init__.py @@ -1,2 +1,2 @@ -__version_info__ = ('0', '8', '1') +__version_info__ = ('0', '9', '0') __version__ = '.'.join(__version_info__) diff --git a/src/cutecoin/gui/currency_tab.py b/src/cutecoin/gui/currency_tab.py index 68c436cc..17c842d7 100644 --- a/src/cutecoin/gui/currency_tab.py +++ b/src/cutecoin/gui/currency_tab.py @@ -154,6 +154,7 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): self.tab_wallets = WalletsTabWidget(self.app.current_account, self.community) self.tabs_account.addTab(self.tab_wallets, + QIcon(':/icons/wallet_icon'), "Wallets") self.tabs_account.addTab(self.tab_community, @@ -212,12 +213,6 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): self.refresh_wallet_content(QModelIndex()) ''' - def refresh_wallet_content(self, index): - if self.app.current_account: - current_wallet = self.app.current_account.wallets[index.row()] - wallet_list_model = WalletListModel(current_wallet, self.community) - self.list_wallet_content.setModel(wallet_list_model) - def wallet_context_menu(self, point): index = self.list_wallets.indexAt(point) model = self.list_wallets.model() diff --git a/src/cutecoin/gui/wallets_tab.py b/src/cutecoin/gui/wallets_tab.py index 9ecd4c3e..59623b3b 100644 --- a/src/cutecoin/gui/wallets_tab.py +++ b/src/cutecoin/gui/wallets_tab.py @@ -8,7 +8,7 @@ import logging from PyQt5.QtWidgets import QWidget from PyQt5.QtCore import QDateTime from ..core.person import Person -from ..models.wallets import WalletsTableModel +from ..models.wallets import WalletsTableModel, WalletsFilterProxyModel from ..tools.exceptions import MembershipNotFoundError from ..gen_resources.wallets_tab_uic import Ui_WalletsTab @@ -63,7 +63,7 @@ class WalletsTabWidget(QWidget, Ui_WalletsTab): "Membership", "Last renewal on {:}, expiration on {:}".format(date_renewal, date_expiration), "Your web of trust :", - "Certified by : {0} ; Certifier of : {0}".format(len(certified), + "Certified by : {0} members; Certifier of : {1} members".format(len(certified), len(certifiers)) ) ) @@ -86,7 +86,9 @@ class WalletsTabWidget(QWidget, Ui_WalletsTab): ) wallets_model = WalletsTableModel(self.account, self.community) - self.table_wallets.setModel(wallets_model) + proxy_model = WalletsFilterProxyModel() + proxy_model.setSourceModel(wallets_model) + self.table_wallets.setModel(proxy_model) def get_referential_value(self, value): return self.account.units_to_ref(value, self.community) diff --git a/src/cutecoin/models/wallets.py b/src/cutecoin/models/wallets.py index 5addfb9b..fe5f20ac 100644 --- a/src/cutecoin/models/wallets.py +++ b/src/cutecoin/models/wallets.py @@ -4,10 +4,52 @@ Created on 8 févr. 2014 @author: inso ''' -from PyQt5.QtCore import QAbstractTableModel, Qt +from PyQt5.QtCore import QAbstractTableModel, QSortFilterProxyModel, Qt import logging +class WalletsFilterProxyModel(QSortFilterProxyModel): + def __init__(self, parent=None): + super().__init__(parent) + + def columnCount(self, parent): + return self.sourceModel().columnCount(None) + + def setSourceModel(self, sourceModel): + self.community = sourceModel.community + self.account = sourceModel.account + super().setSourceModel(sourceModel) + + def lessThan(self, left, right): + """ + Sort table by given column number. + """ + left_data = self.sourceModel().data(left, Qt.DisplayRole) + right_data = self.sourceModel().data(right, Qt.DisplayRole) + return (left_data < right_data) + + def data(self, index, role): + source_index = self.mapToSource(index) + source_data = self.sourceModel().data(source_index, role) + if role == Qt.DisplayRole: + if source_index.column() == self.sourceModel().columns_types.index('pubkey'): + pubkey = "pub:{0}".format(source_data[:5]) + source_data = pubkey + return source_data + if source_index.column() == self.sourceModel().columns_types.index('amount'): + amount_ref = self.account.units_to_ref(source_data, + self.community) + units_ref = self.account.diff_ref_name(self.community.short_currency) + + if type(amount_ref) is int: + formatter = "{0} {1}" + else: + formatter = "{0:.2f} {1}" + + return formatter.format(amount_ref, units_ref) + return source_data + + class WalletsTableModel(QAbstractTableModel): ''' -- GitLab