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

Sorted tableview

parent 12996f29
No related branches found
No related tags found
No related merge requests found
......@@ -69,6 +69,9 @@
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QTableView" name="table_history">
<attribute name="horizontalHeaderShowSortIndicator" stdset="0">
<bool>true</bool>
</attribute>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
......
......@@ -132,6 +132,8 @@ class Community(object):
pass
except TimeoutError:
pass
except ConnectionError:
pass
except ValueError:
pass
......
......@@ -32,8 +32,6 @@ class Person(object):
'''
data = community.request(bma.wot.Lookup, req_args={'search': pubkey},
cached=cached)
results = data['results']
logging.debug(results)
timestamp = 0
for result in data['results']:
......
......@@ -88,6 +88,7 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget):
self.table_history.setModel(
HistoryTableModel(self.app.current_account, self.community))
self.table_history.setSortingEnabled(True)
self.tab_community = CommunityTabWidget(self.app.current_account,
self.community,
self.password_asker)
......
......@@ -7,7 +7,7 @@ Created on 5 févr. 2014
import logging
from ..core.person import Person
from ..tools.exceptions import PersonNotFoundError
from PyQt5.QtCore import QAbstractTableModel, Qt, QVariant
from PyQt5.QtCore import QAbstractTableModel, Qt, QVariant, QSortFilterProxyModel
from PyQt5.QtGui import QFont
from operator import itemgetter
import datetime
......@@ -27,12 +27,14 @@ class HistoryTableModel(QAbstractTableModel):
self.account = account
self.community = community
self.columns = ('Date', 'UID/Public key', 'Payment', 'Deposit', 'Comment')
def rowCount(self, parent):
transactions = self.account.transactions_sent(self.community) + \
self.section_sorting = 0
self.reversed = True
self.transactions = self.account.transactions_sent(self.community) + \
self.account.transactions_awaiting(self.community) + \
self.account.transactions_received(self.community)
return len(transactions)
def rowCount(self, parent):
return len(self.transactions )
def columnCount(self, parent):
return len(self.columns)
......@@ -84,29 +86,76 @@ class HistoryTableModel(QAbstractTableModel):
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)
transactions = sorted(transactions, reverse=True, key=itemgetter(0))
if not index.isValid():
return QVariant()
if role == Qt.DisplayRole:
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 self.transactions[row] in self.account.transactions_sent(self.community) \
or self.transactions[row] in self.account.transactions_awaiting(self.community):
return self.data_sent(self.transactions[row])[col]
if transactions[row] in self.account.transactions_received(self.community):
return self.data_received(transactions[row])[col]
if self.transactions[row] in self.account.transactions_received(self.community):
return self.data_received(self.transactions[row])[col]
if role == Qt.FontRole:
font = QFont()
if transactions[row] in self.account.transactions_awaiting(self.community):
if self.transactions[row] in self.account.transactions_awaiting(self.community):
font.setItalic(True)
else:
font.setItalic(False)
return font
def sort(self, section, order):
"""Sort table by given column number.
"""
self.layoutAboutToBeChanged.emit()
def uid(tx):
if tx in self.account.transactions_received(self.community):
pubkey = tx[1].issuers[0]
else:
pubkey = tx[1].outputs[0].pubkey
try:
receiver = Person.lookup(pubkey, self.community).name
except PersonNotFoundError:
receiver = pubkey
return receiver
def amount_received(tx):
amount = 0
if tx in self.account.transactions_received(self.community):
for o in tx[1].outputs:
pubkeys = [w.pubkey for w in self.account.wallets]
if o.pubkey not in pubkeys:
amount += o.amount
return amount
def amount_sent(tx):
amount = 0
if tx in self.account.transactions_sent(self.community) \
or tx in self.account.transactions_awaiting(self.community):
for o in tx[1].outputs:
pubkeys = [w.pubkey for w in self.account.wallets]
if o.pubkey not in pubkeys:
amount += o.amount
return amount
def comment(tx):
return tx[1].comment
key_getter = {0: itemgetter(0),
1: uid,
2: amount_sent,
3: amount_received,
4: comment}
self.transactions = sorted(self.transactions,
reverse=(order == Qt.DescendingOrder),
key=key_getter[section])
self.layoutChanged.emit()
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.
Finish editing this message first!
Please register or to comment