Skip to content
Snippets Groups Projects
Commit 86205315 authored by inso's avatar inso
Browse files

Introducing tableview for transactions like bank accounts

parent d7f03fb0
Branches
Tags
No related merge requests found
......@@ -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>
......
__version_info__ = ('0', '7', '5')
__version_info__ = ('0', '8', '0')
__version__ = '.'.join(__version_info__)
......@@ -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,14 +112,8 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget):
QModelIndex(),
QModelIndex(),
[])
if self.list_transactions_sent.model():
self.list_transactions_sent.model().dataChanged.emit(
QModelIndex(),
QModelIndex(),
[])
if self.list_transactions_received.model():
self.list_transactions_received.model().dataChanged.emit(
if self.table_history.model():
self.table_history.model().dataChanged.emit(
QModelIndex(),
QModelIndex(),
[])
......
'''
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment