diff --git a/res/ui/currency_tab.ui b/res/ui/currency_tab.ui index 8218af48ed277e794265950b98bfee2f45e6fd16..dc8998410d10c7f7f000d68c4d02b2baa49dd7f1 100644 --- a/res/ui/currency_tab.ui +++ b/res/ui/currency_tab.ui @@ -33,7 +33,7 @@ <bool>false</bool> </property> <property name="currentIndex"> - <number>0</number> + <number>1</number> </property> <widget class="QWidget" name="tab_wallets"> <attribute name="icon"> @@ -70,27 +70,17 @@ <item> <widget class="QLabel" name="label"> <property name="text"> - <string>Sent</string> + <string>History</string> </property> </widget> </item> <item> - <widget class="QListView" name="list_transactions_sent"/> - </item> - </layout> - </item> - <item> - <layout class="QVBoxLayout" name="verticalLayout_2"> - <item> - <widget class="QLabel" name="label_2"> - <property name="text"> - <string>Received</string> - </property> + <widget class="QTableView" name="table_history"> + <attribute name="verticalHeaderVisible"> + <bool>false</bool> + </attribute> </widget> </item> - <item> - <widget class="QListView" name="list_transactions_received"/> - </item> </layout> </item> </layout> diff --git a/src/cutecoin/__init__.py b/src/cutecoin/__init__.py index 5bdc6645502fb5f55054de8deddbcf778967b770..d939c5ffcc80f629372e682b63181ef35cfb12b5 100644 --- a/src/cutecoin/__init__.py +++ b/src/cutecoin/__init__.py @@ -1,2 +1,2 @@ -__version_info__ = ('0', '7', '5') +__version_info__ = ('0', '8', '0') __version__ = '.'.join(__version_info__) diff --git a/src/cutecoin/gui/currency_tab.py b/src/cutecoin/gui/currency_tab.py index ac552f8acba2ce8a0d347e1d9f464c14eb460b8d..0e1c66ddffc84439b1e98210fce0a4be06a81823 100644 --- a/src/cutecoin/gui/currency_tab.py +++ b/src/cutecoin/gui/currency_tab.py @@ -13,8 +13,7 @@ from PyQt5.QtCore import QModelIndex, Qt, pyqtSlot, QObject, QThread, pyqtSignal from PyQt5.QtGui import QIcon from ..gen_resources.currency_tab_uic import Ui_CurrencyTabWidget from .community_tab import CommunityTabWidget -from ..models.sent import SentListModel -from ..models.received import ReceivedListModel +from ..models.txhistory import HistoryTableModel from ..models.wallets import WalletsListModel from ..models.wallet import WalletListModel from ..tools.exceptions import NoPeerAvailable @@ -87,10 +86,8 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): self.tabs_account.setEnabled(True) self.refresh_wallets() - self.list_transactions_sent.setModel( - SentListModel(self.app.current_account, self.community)) - self.list_transactions_received.setModel( - ReceivedListModel(self.app.current_account, self.community)) + self.table_history.setModel( + HistoryTableModel(self.app.current_account, self.community)) self.tab_community = CommunityTabWidget(self.app.current_account, self.community, self.password_asker) @@ -115,18 +112,12 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): QModelIndex(), QModelIndex(), []) - if self.list_transactions_sent.model(): - self.list_transactions_sent.model().dataChanged.emit( + if self.table_history.model(): + self.table_history.model().dataChanged.emit( QModelIndex(), QModelIndex(), []) - if self.list_transactions_received.model(): - self.list_transactions_received.model().dataChanged.emit( - QModelIndex(), - QModelIndex(), - []) - if self.tab_community.list_community_members.model(): self.tab_community.list_community_members.model().dataChanged.emit( QModelIndex(), diff --git a/src/cutecoin/models/txhistory.py b/src/cutecoin/models/txhistory.py new file mode 100644 index 0000000000000000000000000000000000000000..0207b191c351fe965fbd8cffda1848375769c1b4 --- /dev/null +++ b/src/cutecoin/models/txhistory.py @@ -0,0 +1,107 @@ +''' +Created on 5 févr. 2014 + +@author: inso +''' + +import logging +from ..core.person import Person +from ..tools.exceptions import PersonNotFoundError +from PyQt5.QtCore import QAbstractTableModel, Qt, QVariant +from PyQt5.QtGui import QFont + + +class HistoryTableModel(QAbstractTableModel): + + ''' + A Qt abstract item model to display communities in a tree + ''' + + def __init__(self, account, community, parent=None): + ''' + Constructor + ''' + super().__init__(parent) + self.account = account + self.community = community + self.columns = ('date', 'uid', 'pubkey', 'output', 'input') + + def rowCount(self, parent): + transactions = self.account.transactions_sent(self.community) + \ + self.account.transactions_awaiting(self.community) + \ + self.account.transactions_received(self.community) + logging.debug("rowcount: {0}:{1}".format(parent.row(), len(transactions))) + return len(transactions) + + def columnCount(self, parent): + return len(self.columns) + + def headerData(self, section, orientation, role): + if role == Qt.DisplayRole: + return self.columns[section] + + def data_received(self, tx): + outputs = [] + amount = 0 + for o in tx.outputs: + pubkeys = [w.pubkey for w in self.account.wallets] + if o.pubkey not in pubkeys: + outputs.append(o) + amount += o.amount + + pubkey = tx.issuers[0] + sender = "" + try: + sender = Person.lookup(pubkey, self.community) + except PersonNotFoundError: + sender = "" + + return ("", sender.name, pubkey, "", "{0}".format(amount)) + + def data_sent(self, tx): + amount = 0 + outputs = [] + for o in tx.outputs: + pubkeys = [w.pubkey for w in self.account.wallets] + if o.pubkey not in pubkeys: + outputs.append(o) + amount += o.amount + + pubkey = outputs[0].pubkey + receiver = "" + try: + receiver = Person.lookup(pubkey, self.community) + except PersonNotFoundError: + receiver = "" + + return ("", receiver.name, pubkey, "-{0}".format(amount), "") + + def data(self, index, role): + row = index.row() + col = index.column() + transactions = self.account.transactions_sent(self.community) + \ + self.account.transactions_awaiting(self.community) + \ + self.account.transactions_received(self.community) + + if not index.isValid(): + return QVariant() + + if role == Qt.DisplayRole: + logging.debug("{0}/{1}".format(row, len(transactions))) + if transactions[row] in self.account.transactions_sent(self.community) \ + or transactions[row] in self.account.transactions_awaiting(self.community): + return self.data_sent(transactions[row])[col] + + if transactions[row] in self.account.transactions_received(self.community): + return self.data_received(transactions[row])[col] + + if role == Qt.FontRole: + font = QFont() + if transactions[row] in self.account.transactions_awaiting(self.community): + font.setItalic(True) + else: + font.setItalic(False) + return font + + def flags(self, index): + return Qt.ItemIsSelectable | Qt.ItemIsEnabled