diff --git a/res/ui/currency_tab.ui b/res/ui/currency_tab.ui index 35f6249b12eab281d4aef6d019225bee48f7342d..93e11120b99ba9ce81f6acf8b0b65eb2aee30600 100644 --- a/res/ui/currency_tab.ui +++ b/res/ui/currency_tab.ui @@ -67,6 +67,33 @@ <layout class="QHBoxLayout" name="horizontalLayout_3"> <item> <layout class="QVBoxLayout" name="verticalLayout_3"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <property name="topMargin"> + <number>5</number> + </property> + <item> + <widget class="QDateTimeEdit" name="date_from"> + <property name="displayFormat"> + <string>dd/MM/yyyy</string> + </property> + <property name="calendarPopup"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <widget class="QDateTimeEdit" name="date_to"> + <property name="displayFormat"> + <string>dd/MM/yyyy</string> + </property> + <property name="calendarPopup"> + <bool>true</bool> + </property> + </widget> + </item> + </layout> + </item> <item> <widget class="QTableView" name="table_history"> <attribute name="horizontalHeaderShowSortIndicator" stdset="0"> @@ -127,9 +154,42 @@ </hint> </hints> </connection> + <connection> + <sender>date_from</sender> + <signal>dateTimeChanged(QDateTime)</signal> + <receiver>CurrencyTabWidget</receiver> + <slot>dates_changed(QDateTime)</slot> + <hints> + <hint type="sourcelabel"> + <x>114</x> + <y>73</y> + </hint> + <hint type="destinationlabel"> + <x>199</x> + <y>149</y> + </hint> + </hints> + </connection> + <connection> + <sender>date_to</sender> + <signal>dateTimeChanged(QDateTime)</signal> + <receiver>CurrencyTabWidget</receiver> + <slot>dates_changed(QDateTime)</slot> + <hints> + <hint type="sourcelabel"> + <x>285</x> + <y>73</y> + </hint> + <hint type="destinationlabel"> + <x>199</x> + <y>149</y> + </hint> + </hints> + </connection> </connections> <slots> <slot>refresh_wallet_content(QModelIndex)</slot> <slot>wallet_context_menu(QPoint)</slot> + <slot>dates_changed(QDateTime)</slot> </slots> </ui> diff --git a/src/cutecoin/gui/currency_tab.py b/src/cutecoin/gui/currency_tab.py index 8fe38a858d4422f3667096b1d49c84458084b834..3458ff4f88d4a570a632059a375799c449f46f18 100644 --- a/src/cutecoin/gui/currency_tab.py +++ b/src/cutecoin/gui/currency_tab.py @@ -9,8 +9,8 @@ import time import requests from ucoinpy.api import bma -from PyQt5.QtWidgets import QWidget, QMenu, QAction, QApplication, QMessageBox -from PyQt5.QtCore import QModelIndex, Qt, pyqtSlot, QObject, QThread, pyqtSignal +from PyQt5.QtWidgets import QWidget, QMenu, QAction, QApplication +from PyQt5.QtCore import QModelIndex, Qt, pyqtSlot, QObject, QThread, pyqtSignal, QDateTime from PyQt5.QtGui import QIcon from ..gen_resources.currency_tab_uic import Ui_CurrencyTabWidget from .community_tab import CommunityTabWidget @@ -90,6 +90,19 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): else: self.tabs_account.setEnabled(True) self.refresh_wallets() + blockchain_init = QDateTime() + blockchain_init.setTime_t(self.community.get_block(1).mediantime) + + blockchain_lastblock = QDateTime() + blockchain_lastblock.setTime_t(self.community.get_block().mediantime) + + self.date_from.setMinimumDateTime(blockchain_init) + self.date_from.setDateTime(blockchain_init) + self.date_from.setMaximumDateTime(blockchain_lastblock) + + self.date_to.setMinimumDateTime(blockchain_init) + self.date_to.setDateTime(blockchain_lastblock) + self.date_to.setMaximumDateTime(blockchain_lastblock) self.table_history.setModel( HistoryTableModel(self.app.current_account, self.community)) @@ -192,3 +205,9 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): def closeEvent(self, event): self.bc_watcher.deleteLater() self.watcher_thread.deleteLater() + + def dates_changed(self, datetime): + ts_from = self.date_from.dateTime().toTime_t() + ts_to = self.date_to.dateTime().toTime_t() + if self.table_history.model(): + self.table_history.model().set_period(ts_from, ts_to) diff --git a/src/cutecoin/models/txhistory.py b/src/cutecoin/models/txhistory.py index 934a8c8bc4eb878b2c685e90d03fbab5f76bf220..7a8942b95e35104e70faa6d18f01985a6945d4cb 100644 --- a/src/cutecoin/models/txhistory.py +++ b/src/cutecoin/models/txhistory.py @@ -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, QSortFilterProxyModel +from PyQt5.QtCore import QAbstractTableModel, Qt, QVariant, QAbstractProxyModel from PyQt5.QtGui import QFont from operator import itemgetter import datetime @@ -27,8 +27,7 @@ class HistoryTableModel(QAbstractTableModel): self.account = account self.community = community self.columns = ('Date', 'UID/Public key', 'Payment', 'Deposit', 'Comment') - self.section_sorting = 0 - self.reversed = True + self.sorting = lambda self.transactions = self.account.transactions_sent(self.community) + \ self.account.transactions_awaiting(self.community) + \ self.account.transactions_received(self.community) @@ -151,11 +150,34 @@ class HistoryTableModel(QAbstractTableModel): 3: amount_received, 4: comment} + self.transactions = self.account.transactions_sent(self.community) + \ + self.account.transactions_awaiting(self.community) + \ + self.account.transactions_received(self.community) + self.transactions = sorted(self.transactions, reverse=(order == Qt.DescendingOrder), key=key_getter[section]) self.layoutChanged.emit() + def set_period(self, ts_from, ts_to): + """ + Filter table by given timestamps + """ + self.layoutAboutToBeChanged.emit() + logging.debug("Filtering from {0} to {1}".format(ts_from, ts_to)) + + def in_period(tx): + block = self.community.get_block(tx[0]) + return (block.mediantime in range(ts_from, ts_to)) + + self.transactions = self.account.transactions_sent(self.community) + \ + self.account.transactions_awaiting(self.community) + \ + self.account.transactions_received(self.community) + + self.transactions = [tx for tx in filter(in_period, self.transactions)] + + self.layoutChanged.emit() + def flags(self, index): return Qt.ItemIsSelectable | Qt.ItemIsEnabled