2015-12-13 14:51:43 +01:00
|
|
|
// Copyright (c) 2011-2015 The Bitcoin Core developers
|
2014-12-13 05:09:33 +01:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2013-11-04 16:20:43 +01:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <qt/transactionview.h>
|
2011-06-28 21:41:56 +02:00
|
|
|
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <qt/addresstablemodel.h>
|
|
|
|
#include <qt/bitcoinunits.h>
|
|
|
|
#include <qt/csvmodelwriter.h>
|
|
|
|
#include <qt/editaddressdialog.h>
|
|
|
|
#include <qt/optionsmodel.h>
|
|
|
|
#include <qt/qrdialog.h>
|
|
|
|
#include <qt/transactiondescdialog.h>
|
|
|
|
#include <qt/transactionfilterproxy.h>
|
|
|
|
#include <qt/transactionrecord.h>
|
|
|
|
#include <qt/transactiontablemodel.h>
|
|
|
|
#include <qt/walletmodel.h>
|
2013-04-13 07:13:08 +02:00
|
|
|
|
2020-10-01 16:05:57 +02:00
|
|
|
#include <interfaces/node.h>
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <ui_interface.h>
|
2011-06-28 21:41:56 +02:00
|
|
|
|
2020-07-20 17:01:11 +02:00
|
|
|
#include <QCalendarWidget>
|
2011-06-28 21:41:56 +02:00
|
|
|
#include <QComboBox>
|
2013-04-13 07:13:08 +02:00
|
|
|
#include <QDateTimeEdit>
|
2014-04-24 22:21:45 +02:00
|
|
|
#include <QDesktopServices>
|
2011-06-28 21:41:56 +02:00
|
|
|
#include <QDoubleValidator>
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QHeaderView>
|
2011-07-22 18:30:25 +02:00
|
|
|
#include <QLabel>
|
2013-04-13 07:13:08 +02:00
|
|
|
#include <QLineEdit>
|
2020-09-18 12:15:55 +02:00
|
|
|
#include <QListView>
|
2013-04-13 07:13:08 +02:00
|
|
|
#include <QMenu>
|
|
|
|
#include <QPoint>
|
|
|
|
#include <QScrollBar>
|
2015-07-04 15:27:37 +02:00
|
|
|
#include <QSettings>
|
2013-04-13 07:13:08 +02:00
|
|
|
#include <QTableView>
|
2020-07-20 17:01:11 +02:00
|
|
|
#include <QTextCharFormat>
|
2017-09-26 23:59:01 +02:00
|
|
|
#include <QTimer>
|
2014-04-24 22:21:45 +02:00
|
|
|
#include <QUrl>
|
2013-04-13 07:13:08 +02:00
|
|
|
#include <QVBoxLayout>
|
2011-06-28 21:41:56 +02:00
|
|
|
|
2016-06-13 14:11:26 +02:00
|
|
|
/** Date format for persistence */
|
|
|
|
static const char* PERSISTENCE_DATE_FORMAT = "yyyy-MM-dd";
|
|
|
|
|
2020-07-26 13:20:19 +02:00
|
|
|
TransactionView::TransactionView(QWidget* parent) :
|
2019-01-14 15:20:45 +01:00
|
|
|
QWidget(parent), model(nullptr), transactionProxyModel(nullptr),
|
|
|
|
transactionView(nullptr), abandonAction(nullptr), columnResizingFixer(nullptr)
|
2011-06-28 21:41:56 +02:00
|
|
|
{
|
2015-07-04 15:27:37 +02:00
|
|
|
QSettings settings;
|
2011-06-28 21:41:56 +02:00
|
|
|
// Build filter row
|
2011-07-03 20:59:56 +02:00
|
|
|
setContentsMargins(0,0,0,0);
|
|
|
|
|
2011-06-28 21:41:56 +02:00
|
|
|
QHBoxLayout *hlayout = new QHBoxLayout();
|
2011-07-03 20:59:56 +02:00
|
|
|
hlayout->setContentsMargins(0,0,0,0);
|
2020-07-26 13:20:19 +02:00
|
|
|
hlayout->setSpacing(1);
|
|
|
|
hlayout->addSpacing(STATUS_COLUMN_WIDTH - 2);
|
|
|
|
|
2014-08-10 02:26:04 +02:00
|
|
|
watchOnlyWidget = new QComboBox(this);
|
|
|
|
watchOnlyWidget->setFixedWidth(24);
|
|
|
|
watchOnlyWidget->addItem("", TransactionFilterProxy::WatchOnlyFilter_All);
|
2020-09-10 18:28:05 +02:00
|
|
|
watchOnlyWidget->addItem(GUIUtil::getIcon("eye_plus"), "", TransactionFilterProxy::WatchOnlyFilter_Yes);
|
|
|
|
watchOnlyWidget->addItem(GUIUtil::getIcon("eye_minus"), "", TransactionFilterProxy::WatchOnlyFilter_No);
|
2014-08-10 02:26:04 +02:00
|
|
|
hlayout->addWidget(watchOnlyWidget);
|
|
|
|
|
2011-06-28 21:41:56 +02:00
|
|
|
dateWidget = new QComboBox(this);
|
2020-07-26 13:20:19 +02:00
|
|
|
dateWidget->setFixedWidth(120);
|
2011-06-28 21:41:56 +02:00
|
|
|
dateWidget->addItem(tr("All"), All);
|
|
|
|
dateWidget->addItem(tr("Today"), Today);
|
|
|
|
dateWidget->addItem(tr("This week"), ThisWeek);
|
|
|
|
dateWidget->addItem(tr("This month"), ThisMonth);
|
2011-07-01 20:28:11 +02:00
|
|
|
dateWidget->addItem(tr("Last month"), LastMonth);
|
2011-06-28 21:41:56 +02:00
|
|
|
dateWidget->addItem(tr("This year"), ThisYear);
|
|
|
|
dateWidget->addItem(tr("Range..."), Range);
|
2015-07-04 15:27:37 +02:00
|
|
|
dateWidget->setCurrentIndex(settings.value("transactionDate").toInt());
|
2011-06-28 21:41:56 +02:00
|
|
|
hlayout->addWidget(dateWidget);
|
|
|
|
|
2021-07-11 11:28:50 +02:00
|
|
|
QString strCoinJoinName = QString::fromStdString(gCoinJoinName);
|
2011-06-28 21:41:56 +02:00
|
|
|
typeWidget = new QComboBox(this);
|
2020-07-26 13:20:19 +02:00
|
|
|
typeWidget->setFixedWidth(TYPE_COLUMN_WIDTH - 1);
|
2011-06-28 21:41:56 +02:00
|
|
|
typeWidget->addItem(tr("All"), TransactionFilterProxy::ALL_TYPES);
|
2015-07-04 15:27:37 +02:00
|
|
|
typeWidget->addItem(tr("Most Common"), TransactionFilterProxy::COMMON_TYPES);
|
2011-06-28 21:41:56 +02:00
|
|
|
typeWidget->addItem(tr("Received with"), TransactionFilterProxy::TYPE(TransactionRecord::RecvWithAddress) |
|
2011-12-28 11:14:05 +01:00
|
|
|
TransactionFilterProxy::TYPE(TransactionRecord::RecvFromOther));
|
2011-06-28 21:41:56 +02:00
|
|
|
typeWidget->addItem(tr("Sent to"), TransactionFilterProxy::TYPE(TransactionRecord::SendToAddress) |
|
2011-12-28 11:14:05 +01:00
|
|
|
TransactionFilterProxy::TYPE(TransactionRecord::SendToOther));
|
2021-07-11 11:28:50 +02:00
|
|
|
typeWidget->addItem(tr("%1 Send").arg(strCoinJoinName), TransactionFilterProxy::TYPE(TransactionRecord::CoinJoinSend));
|
|
|
|
typeWidget->addItem(tr("%1 Make Collateral Inputs").arg(strCoinJoinName), TransactionFilterProxy::TYPE(TransactionRecord::CoinJoinMakeCollaterals));
|
|
|
|
typeWidget->addItem(tr("%1 Create Denominations").arg(strCoinJoinName), TransactionFilterProxy::TYPE(TransactionRecord::CoinJoinCreateDenominations));
|
|
|
|
typeWidget->addItem(tr("%1 Mixing").arg(strCoinJoinName), TransactionFilterProxy::TYPE(TransactionRecord::CoinJoinMixing));
|
|
|
|
typeWidget->addItem(tr("%1 Collateral Payment").arg(strCoinJoinName), TransactionFilterProxy::TYPE(TransactionRecord::CoinJoinCollateralPayment));
|
2011-06-28 21:41:56 +02:00
|
|
|
typeWidget->addItem(tr("To yourself"), TransactionFilterProxy::TYPE(TransactionRecord::SendToSelf));
|
2011-07-07 10:43:04 +02:00
|
|
|
typeWidget->addItem(tr("Mined"), TransactionFilterProxy::TYPE(TransactionRecord::Generated));
|
2011-06-28 21:41:56 +02:00
|
|
|
typeWidget->addItem(tr("Other"), TransactionFilterProxy::TYPE(TransactionRecord::Other));
|
2015-07-04 15:27:37 +02:00
|
|
|
typeWidget->setCurrentIndex(settings.value("transactionType").toInt());
|
2011-06-28 21:41:56 +02:00
|
|
|
|
|
|
|
hlayout->addWidget(typeWidget);
|
|
|
|
|
2017-11-30 00:50:30 +01:00
|
|
|
search_widget = new QLineEdit(this);
|
|
|
|
search_widget->setPlaceholderText(tr("Enter address, transaction id, or label to search"));
|
2020-01-17 17:49:24 +01:00
|
|
|
search_widget->setObjectName("search_widget");
|
2017-11-30 00:50:30 +01:00
|
|
|
hlayout->addWidget(search_widget);
|
2011-06-28 21:41:56 +02:00
|
|
|
|
|
|
|
amountWidget = new QLineEdit(this);
|
2011-08-28 14:12:26 +02:00
|
|
|
amountWidget->setPlaceholderText(tr("Min amount"));
|
2020-07-26 13:20:19 +02:00
|
|
|
amountWidget->setFixedWidth(125);
|
2018-10-18 12:25:53 +02:00
|
|
|
QDoubleValidator *amountValidator = new QDoubleValidator(0, 1e20, 8, this);
|
|
|
|
QLocale amountLocale(QLocale::C);
|
|
|
|
amountLocale.setNumberOptions(QLocale::RejectGroupSeparator);
|
|
|
|
amountValidator->setLocale(amountLocale);
|
|
|
|
amountWidget->setValidator(amountValidator);
|
2016-06-06 07:44:59 +02:00
|
|
|
amountWidget->setObjectName("amountWidget");
|
2011-06-28 21:41:56 +02:00
|
|
|
hlayout->addWidget(amountWidget);
|
|
|
|
|
2017-09-26 23:59:01 +02:00
|
|
|
// Delay before filtering transactions in ms
|
|
|
|
static const int input_filter_delay = 200;
|
|
|
|
|
|
|
|
QTimer* amount_typing_delay = new QTimer(this);
|
|
|
|
amount_typing_delay->setSingleShot(true);
|
|
|
|
amount_typing_delay->setInterval(input_filter_delay);
|
|
|
|
|
|
|
|
QTimer* prefix_typing_delay = new QTimer(this);
|
|
|
|
prefix_typing_delay->setSingleShot(true);
|
|
|
|
prefix_typing_delay->setInterval(input_filter_delay);
|
|
|
|
|
2011-06-28 21:41:56 +02:00
|
|
|
QVBoxLayout *vlayout = new QVBoxLayout(this);
|
2011-07-03 20:59:56 +02:00
|
|
|
vlayout->setContentsMargins(0,0,0,0);
|
|
|
|
vlayout->setSpacing(0);
|
2011-06-28 21:41:56 +02:00
|
|
|
|
|
|
|
QTableView *view = new QTableView(this);
|
|
|
|
vlayout->addLayout(hlayout);
|
2011-07-22 18:30:25 +02:00
|
|
|
vlayout->addWidget(createDateRangeWidget());
|
2011-06-28 21:41:56 +02:00
|
|
|
vlayout->addWidget(view);
|
|
|
|
vlayout->setSpacing(0);
|
2019-10-31 18:30:57 +01:00
|
|
|
#ifndef Q_OS_MAC
|
2011-06-28 21:41:56 +02:00
|
|
|
int width = view->verticalScrollBar()->sizeHint().width();
|
|
|
|
// Cover scroll bar width with spacing
|
2020-07-26 13:20:19 +02:00
|
|
|
hlayout->addSpacing(width);
|
2011-06-28 21:41:56 +02:00
|
|
|
// Always show scroll bar
|
|
|
|
view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
2019-10-31 18:30:57 +01:00
|
|
|
#endif
|
2011-07-07 18:25:27 +02:00
|
|
|
view->setTabKeyNavigation(false);
|
2011-07-08 22:27:36 +02:00
|
|
|
view->setContextMenuPolicy(Qt::CustomContextMenu);
|
2011-06-28 21:41:56 +02:00
|
|
|
|
2014-05-10 00:50:09 +02:00
|
|
|
view->installEventFilter(this);
|
|
|
|
|
2011-06-28 21:41:56 +02:00
|
|
|
transactionView = view;
|
2020-02-12 14:48:02 +01:00
|
|
|
transactionView->setObjectName("transactionView");
|
2011-06-28 21:41:56 +02:00
|
|
|
|
2011-07-08 22:27:36 +02:00
|
|
|
// Actions
|
2017-09-09 09:04:02 +02:00
|
|
|
abandonAction = new QAction(tr("Abandon transaction"), this);
|
2022-06-07 23:07:27 +02:00
|
|
|
resendAction = new QAction(tr("Resend transaction"), this);
|
2011-08-28 14:12:26 +02:00
|
|
|
QAction *copyAddressAction = new QAction(tr("Copy address"), this);
|
|
|
|
QAction *copyLabelAction = new QAction(tr("Copy label"), this);
|
2011-12-04 14:14:10 +01:00
|
|
|
QAction *copyAmountAction = new QAction(tr("Copy amount"), this);
|
2013-03-21 10:33:36 +01:00
|
|
|
QAction *copyTxIDAction = new QAction(tr("Copy transaction ID"), this);
|
2015-11-17 11:17:09 +01:00
|
|
|
QAction *copyTxHexAction = new QAction(tr("Copy raw transaction"), this);
|
2017-09-07 17:59:00 +02:00
|
|
|
QAction *copyTxPlainText = new QAction(tr("Copy full transaction details"), this);
|
2021-02-25 09:09:29 +01:00
|
|
|
QAction *editLabelAction = new QAction(tr("Edit address label"), this);
|
2012-05-06 16:24:15 +02:00
|
|
|
QAction *showDetailsAction = new QAction(tr("Show transaction details"), this);
|
2019-03-06 20:45:22 +01:00
|
|
|
QAction *showAddressQRCodeAction = new QAction(tr("Show address QR code"), this);
|
2022-05-29 22:42:18 +02:00
|
|
|
#ifndef USE_QRCODE
|
|
|
|
showAddressQRCodeAction->setEnabled(false);
|
|
|
|
#endif
|
2011-07-08 22:27:36 +02:00
|
|
|
|
2017-09-11 15:38:14 +02:00
|
|
|
contextMenu = new QMenu(this);
|
2020-02-12 14:48:02 +01:00
|
|
|
contextMenu->setObjectName("contextMenu");
|
2011-07-08 22:27:36 +02:00
|
|
|
contextMenu->addAction(copyAddressAction);
|
|
|
|
contextMenu->addAction(copyLabelAction);
|
2011-12-04 14:14:10 +01:00
|
|
|
contextMenu->addAction(copyAmountAction);
|
2013-03-21 10:33:36 +01:00
|
|
|
contextMenu->addAction(copyTxIDAction);
|
2015-11-17 11:17:09 +01:00
|
|
|
contextMenu->addAction(copyTxHexAction);
|
2017-09-07 17:59:00 +02:00
|
|
|
contextMenu->addAction(copyTxPlainText);
|
2011-07-08 22:27:36 +02:00
|
|
|
contextMenu->addAction(showDetailsAction);
|
2019-03-06 20:45:22 +01:00
|
|
|
contextMenu->addAction(showAddressQRCodeAction);
|
2017-09-09 09:04:02 +02:00
|
|
|
contextMenu->addSeparator();
|
|
|
|
contextMenu->addAction(abandonAction);
|
2022-06-07 23:07:27 +02:00
|
|
|
contextMenu->addAction(resendAction);
|
2021-02-25 09:09:29 +01:00
|
|
|
contextMenu->addAction(editLabelAction);
|
2011-07-08 22:27:36 +02:00
|
|
|
|
2018-08-21 10:54:43 +02:00
|
|
|
connect(dateWidget, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, &TransactionView::chooseDate);
|
|
|
|
connect(typeWidget, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, &TransactionView::chooseType);
|
|
|
|
connect(watchOnlyWidget, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, &TransactionView::chooseWatchonly);
|
|
|
|
connect(amountWidget, &QLineEdit::textChanged, amount_typing_delay, static_cast<void (QTimer::*)()>(&QTimer::start));
|
|
|
|
connect(amount_typing_delay, &QTimer::timeout, this, &TransactionView::changedAmount);
|
|
|
|
connect(search_widget, &QLineEdit::textChanged, prefix_typing_delay, static_cast<void (QTimer::*)()>(&QTimer::start));
|
|
|
|
connect(prefix_typing_delay, &QTimer::timeout, this, &TransactionView::changedSearch);
|
2011-06-30 21:34:00 +02:00
|
|
|
|
2018-08-21 10:54:43 +02:00
|
|
|
connect(view, &QTableView::doubleClicked, this, &TransactionView::doubleClicked);
|
2021-08-17 17:55:26 +02:00
|
|
|
connect(view, &QTableView::clicked, this, &TransactionView::computeSum);
|
2018-08-21 10:54:43 +02:00
|
|
|
connect(view, &QTableView::customContextMenuRequested, this, &TransactionView::contextualMenu);
|
|
|
|
|
|
|
|
connect(abandonAction, &QAction::triggered, this, &TransactionView::abandonTx);
|
2022-06-07 23:07:27 +02:00
|
|
|
connect(resendAction, &QAction::triggered, this, &TransactionView::resendTx);
|
2018-08-21 10:54:43 +02:00
|
|
|
connect(copyAddressAction, &QAction::triggered, this, &TransactionView::copyAddress);
|
|
|
|
connect(copyLabelAction, &QAction::triggered, this, &TransactionView::copyLabel);
|
|
|
|
connect(copyAmountAction, &QAction::triggered, this, &TransactionView::copyAmount);
|
|
|
|
connect(copyTxIDAction, &QAction::triggered, this, &TransactionView::copyTxID);
|
|
|
|
connect(copyTxHexAction, &QAction::triggered, this, &TransactionView::copyTxHex);
|
|
|
|
connect(copyTxPlainText, &QAction::triggered, this, &TransactionView::copyTxPlainText);
|
2021-02-25 09:09:29 +01:00
|
|
|
connect(editLabelAction, &QAction::triggered, this, &TransactionView::editLabel);
|
2018-08-21 10:54:43 +02:00
|
|
|
connect(showDetailsAction, &QAction::triggered, this, &TransactionView::showDetails);
|
2021-08-17 17:55:26 +02:00
|
|
|
connect(showAddressQRCodeAction, &QAction::triggered, this, &TransactionView::showAddressQRCode);
|
|
|
|
// Double-clicking on a transaction on the transaction history page shows details
|
|
|
|
connect(this, &TransactionView::doubleClicked, this, &TransactionView::showDetails);
|
2011-06-28 21:41:56 +02:00
|
|
|
}
|
|
|
|
|
2016-09-23 12:44:09 +02:00
|
|
|
void TransactionView::setModel(WalletModel *_model)
|
2011-06-28 21:41:56 +02:00
|
|
|
{
|
2015-07-04 15:27:37 +02:00
|
|
|
QSettings settings;
|
2016-09-23 12:44:09 +02:00
|
|
|
this->model = _model;
|
|
|
|
if(_model)
|
2011-11-08 21:18:36 +01:00
|
|
|
{
|
|
|
|
transactionProxyModel = new TransactionFilterProxy(this);
|
2016-09-23 12:44:09 +02:00
|
|
|
transactionProxyModel->setSourceModel(_model->getTransactionTableModel());
|
2011-11-08 21:18:36 +01:00
|
|
|
transactionProxyModel->setDynamicSortFilter(true);
|
2012-07-17 11:38:18 +02:00
|
|
|
transactionProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
|
|
|
|
transactionProxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
2011-11-08 21:18:36 +01:00
|
|
|
|
|
|
|
transactionProxyModel->setSortRole(Qt::EditRole);
|
|
|
|
|
2014-03-21 06:45:47 +01:00
|
|
|
transactionView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
2011-11-08 21:18:36 +01:00
|
|
|
transactionView->setModel(transactionProxyModel);
|
|
|
|
transactionView->setAlternatingRowColors(true);
|
|
|
|
transactionView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
|
|
transactionView->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
2019-02-05 22:39:16 +01:00
|
|
|
transactionView->horizontalHeader()->setSortIndicator(TransactionTableModel::Date, Qt::DescendingOrder);
|
2011-11-08 21:18:36 +01:00
|
|
|
transactionView->setSortingEnabled(true);
|
|
|
|
transactionView->verticalHeader()->hide();
|
|
|
|
|
2014-03-21 06:45:47 +01:00
|
|
|
transactionView->setColumnWidth(TransactionTableModel::Status, STATUS_COLUMN_WIDTH);
|
2014-08-10 02:26:04 +02:00
|
|
|
transactionView->setColumnWidth(TransactionTableModel::Watchonly, WATCHONLY_COLUMN_WIDTH);
|
2014-03-21 06:45:47 +01:00
|
|
|
transactionView->setColumnWidth(TransactionTableModel::Date, DATE_COLUMN_WIDTH);
|
|
|
|
transactionView->setColumnWidth(TransactionTableModel::Type, TYPE_COLUMN_WIDTH);
|
|
|
|
transactionView->setColumnWidth(TransactionTableModel::Amount, AMOUNT_MINIMUM_COLUMN_WIDTH);
|
|
|
|
|
2015-05-14 08:31:40 +02:00
|
|
|
// Note: it's a good idea to connect this signal AFTER the model is set
|
2021-08-17 17:55:26 +02:00
|
|
|
connect(transactionView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &TransactionView::computeSum);
|
2015-05-14 08:31:40 +02:00
|
|
|
|
2017-09-11 15:38:14 +02:00
|
|
|
columnResizingFixer = new GUIUtil::TableViewLastColumnResizingFixer(transactionView, AMOUNT_MINIMUM_COLUMN_WIDTH, MINIMUM_COLUMN_WIDTH, this);
|
2014-04-24 22:21:45 +02:00
|
|
|
|
2016-09-23 12:44:09 +02:00
|
|
|
if (_model->getOptionsModel())
|
2014-04-24 22:21:45 +02:00
|
|
|
{
|
|
|
|
// Add third party transaction URLs to context menu
|
2016-09-23 12:44:09 +02:00
|
|
|
QStringList listUrls = _model->getOptionsModel()->getThirdPartyTxUrls().split("|", QString::SkipEmptyParts);
|
2014-04-24 22:21:45 +02:00
|
|
|
for (int i = 0; i < listUrls.size(); ++i)
|
|
|
|
{
|
2019-03-17 19:55:56 +01:00
|
|
|
QString url = listUrls[i].trimmed();
|
|
|
|
QString host = QUrl(url, QUrl::StrictMode).host();
|
2014-04-24 22:21:45 +02:00
|
|
|
if (!host.isEmpty())
|
|
|
|
{
|
|
|
|
QAction *thirdPartyTxUrlAction = new QAction(host, this); // use host as menu item label
|
|
|
|
if (i == 0)
|
|
|
|
contextMenu->addSeparator();
|
|
|
|
contextMenu->addAction(thirdPartyTxUrlAction);
|
2019-03-17 19:55:56 +01:00
|
|
|
connect(thirdPartyTxUrlAction, &QAction::triggered, [this, url] { openThirdPartyTxUrl(url); });
|
2014-04-24 22:21:45 +02:00
|
|
|
}
|
|
|
|
}
|
2020-09-28 09:41:19 +02:00
|
|
|
|
2021-08-17 17:55:26 +02:00
|
|
|
connect(_model->getOptionsModel(), &OptionsModel::coinJoinEnabledChanged, this, &TransactionView::updateCoinJoinVisibility);
|
2014-04-24 22:21:45 +02:00
|
|
|
}
|
2014-08-10 02:26:04 +02:00
|
|
|
|
|
|
|
// show/hide column Watch-only
|
2017-04-18 00:56:44 +02:00
|
|
|
updateWatchOnlyColumn(_model->wallet().haveWatchOnly());
|
2014-08-10 02:26:04 +02:00
|
|
|
|
|
|
|
// Watch-only signal
|
2018-08-21 10:54:43 +02:00
|
|
|
connect(_model, &WalletModel::notifyWatchonlyChanged, this, &TransactionView::updateWatchOnlyColumn);
|
2017-11-30 00:50:30 +01:00
|
|
|
|
2015-07-04 15:27:37 +02:00
|
|
|
// Update transaction list with persisted settings
|
|
|
|
chooseType(settings.value("transactionType").toInt());
|
|
|
|
chooseDate(settings.value("transactionDate").toInt());
|
2020-08-28 11:52:00 +02:00
|
|
|
|
2021-03-17 23:36:11 +01:00
|
|
|
updateCoinJoinVisibility();
|
2011-11-08 21:18:36 +01:00
|
|
|
}
|
2011-06-28 21:41:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void TransactionView::chooseDate(int idx)
|
|
|
|
{
|
2018-03-01 12:18:25 +01:00
|
|
|
if (!transactionProxyModel) return;
|
2017-11-30 00:50:30 +01:00
|
|
|
|
2016-06-13 14:11:26 +02:00
|
|
|
QSettings settings;
|
2011-06-28 21:41:56 +02:00
|
|
|
QDate current = QDate::currentDate();
|
2011-07-22 18:30:25 +02:00
|
|
|
dateRangeWidget->setVisible(false);
|
2011-06-28 21:41:56 +02:00
|
|
|
switch(dateWidget->itemData(idx).toInt())
|
|
|
|
{
|
|
|
|
case All:
|
|
|
|
transactionProxyModel->setDateRange(
|
|
|
|
TransactionFilterProxy::MIN_DATE,
|
|
|
|
TransactionFilterProxy::MAX_DATE);
|
|
|
|
break;
|
|
|
|
case Today:
|
|
|
|
transactionProxyModel->setDateRange(
|
|
|
|
QDateTime(current),
|
|
|
|
TransactionFilterProxy::MAX_DATE);
|
|
|
|
break;
|
|
|
|
case ThisWeek: {
|
2012-07-26 02:48:39 +02:00
|
|
|
// Find last Monday
|
2011-06-28 21:41:56 +02:00
|
|
|
QDate startOfWeek = current.addDays(-(current.dayOfWeek()-1));
|
|
|
|
transactionProxyModel->setDateRange(
|
|
|
|
QDateTime(startOfWeek),
|
|
|
|
TransactionFilterProxy::MAX_DATE);
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case ThisMonth:
|
|
|
|
transactionProxyModel->setDateRange(
|
|
|
|
QDateTime(QDate(current.year(), current.month(), 1)),
|
|
|
|
TransactionFilterProxy::MAX_DATE);
|
|
|
|
break;
|
2011-07-01 20:28:11 +02:00
|
|
|
case LastMonth:
|
2016-06-05 07:11:22 +02:00
|
|
|
transactionProxyModel->setDateRange(
|
2016-01-13 21:17:08 +01:00
|
|
|
QDateTime(QDate(current.year(), current.month(), 1).addMonths(-1)),
|
2011-07-01 20:28:11 +02:00
|
|
|
QDateTime(QDate(current.year(), current.month(), 1)));
|
|
|
|
break;
|
2011-06-28 21:41:56 +02:00
|
|
|
case ThisYear:
|
|
|
|
transactionProxyModel->setDateRange(
|
|
|
|
QDateTime(QDate(current.year(), 1, 1)),
|
|
|
|
TransactionFilterProxy::MAX_DATE);
|
|
|
|
break;
|
|
|
|
case Range:
|
2011-07-22 18:30:25 +02:00
|
|
|
dateRangeWidget->setVisible(true);
|
|
|
|
dateRangeChanged();
|
2011-06-28 21:41:56 +02:00
|
|
|
break;
|
|
|
|
}
|
2016-06-13 14:11:26 +02:00
|
|
|
// Persist new date settings
|
|
|
|
settings.setValue("transactionDate", idx);
|
|
|
|
if (dateWidget->itemData(idx).toInt() == Range){
|
|
|
|
settings.setValue("transactionDateFrom", dateFrom->date().toString(PERSISTENCE_DATE_FORMAT));
|
|
|
|
settings.setValue("transactionDateTo", dateTo->date().toString(PERSISTENCE_DATE_FORMAT));
|
2015-07-04 15:27:37 +02:00
|
|
|
}
|
2011-06-28 21:41:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void TransactionView::chooseType(int idx)
|
|
|
|
{
|
2011-11-08 21:18:36 +01:00
|
|
|
if(!transactionProxyModel)
|
|
|
|
return;
|
2011-06-28 21:41:56 +02:00
|
|
|
transactionProxyModel->setTypeFilter(
|
|
|
|
typeWidget->itemData(idx).toInt());
|
2015-07-04 15:27:37 +02:00
|
|
|
// Persist settings
|
|
|
|
QSettings settings;
|
|
|
|
settings.setValue("transactionType", idx);
|
2011-06-28 21:41:56 +02:00
|
|
|
}
|
|
|
|
|
2014-08-10 02:26:04 +02:00
|
|
|
void TransactionView::chooseWatchonly(int idx)
|
|
|
|
{
|
|
|
|
if(!transactionProxyModel)
|
|
|
|
return;
|
|
|
|
transactionProxyModel->setWatchOnlyFilter(
|
2018-02-07 22:15:16 +01:00
|
|
|
static_cast<TransactionFilterProxy::WatchOnlyFilter>(watchOnlyWidget->itemData(idx).toInt()));
|
2014-08-10 02:26:04 +02:00
|
|
|
}
|
|
|
|
|
2017-11-30 00:50:30 +01:00
|
|
|
void TransactionView::changedSearch()
|
2011-06-28 21:41:56 +02:00
|
|
|
{
|
2011-11-08 21:18:36 +01:00
|
|
|
if(!transactionProxyModel)
|
|
|
|
return;
|
2017-11-30 00:50:30 +01:00
|
|
|
transactionProxyModel->setSearchString(search_widget->text());
|
2011-06-28 21:41:56 +02:00
|
|
|
}
|
|
|
|
|
2017-09-26 23:59:01 +02:00
|
|
|
void TransactionView::changedAmount()
|
2011-06-28 21:41:56 +02:00
|
|
|
{
|
2011-11-08 21:18:36 +01:00
|
|
|
if(!transactionProxyModel)
|
|
|
|
return;
|
2014-04-23 00:46:19 +02:00
|
|
|
CAmount amount_parsed = 0;
|
2015-07-20 18:28:49 +02:00
|
|
|
|
|
|
|
// Replace "," by "." so BitcoinUnits::parse will not fail for users entering "," as decimal separator
|
2017-09-26 23:59:01 +02:00
|
|
|
QString newAmount = amountWidget->text();
|
2015-07-20 18:28:49 +02:00
|
|
|
newAmount.replace(QString(","), QString("."));
|
|
|
|
|
2017-09-26 23:59:01 +02:00
|
|
|
if (BitcoinUnits::parse(model->getOptionsModel()->getDisplayUnit(), newAmount, &amount_parsed)) {
|
2011-06-28 21:41:56 +02:00
|
|
|
transactionProxyModel->setMinAmount(amount_parsed);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
transactionProxyModel->setMinAmount(0);
|
|
|
|
}
|
|
|
|
}
|
2011-07-07 14:27:16 +02:00
|
|
|
|
|
|
|
void TransactionView::exportClicked()
|
|
|
|
{
|
2017-06-29 14:44:07 +02:00
|
|
|
if (!model || !model->getOptionsModel()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-07 14:27:16 +02:00
|
|
|
// CSV is currently the only supported format
|
2013-10-26 19:21:10 +02:00
|
|
|
QString filename = GUIUtil::getSaveFileName(this,
|
|
|
|
tr("Export Transaction History"), QString(),
|
2019-08-06 05:08:33 +02:00
|
|
|
tr("Comma separated file (*.csv)"), nullptr);
|
2011-07-07 14:27:16 +02:00
|
|
|
|
2013-10-26 19:21:10 +02:00
|
|
|
if (filename.isNull())
|
|
|
|
return;
|
2011-07-15 02:11:11 +02:00
|
|
|
|
2011-07-07 14:27:16 +02:00
|
|
|
CSVModelWriter writer(filename);
|
|
|
|
|
|
|
|
// name, column, role
|
|
|
|
writer.setModel(transactionProxyModel);
|
2011-08-28 14:12:26 +02:00
|
|
|
writer.addColumn(tr("Confirmed"), 0, TransactionTableModel::ConfirmedRole);
|
2017-04-18 00:56:44 +02:00
|
|
|
if (model->wallet().haveWatchOnly())
|
2014-08-28 23:20:46 +02:00
|
|
|
writer.addColumn(tr("Watch-only"), TransactionTableModel::Watchonly);
|
2011-08-28 14:12:26 +02:00
|
|
|
writer.addColumn(tr("Date"), 0, TransactionTableModel::DateRole);
|
|
|
|
writer.addColumn(tr("Type"), TransactionTableModel::Type, Qt::EditRole);
|
|
|
|
writer.addColumn(tr("Label"), 0, TransactionTableModel::LabelRole);
|
|
|
|
writer.addColumn(tr("Address"), 0, TransactionTableModel::AddressRole);
|
2014-06-07 08:20:22 +02:00
|
|
|
writer.addColumn(BitcoinUnits::getAmountColumnTitle(model->getOptionsModel()->getDisplayUnit()), 0, TransactionTableModel::FormattedAmountRole);
|
2018-03-07 16:48:09 +01:00
|
|
|
writer.addColumn(tr("ID"), 0, TransactionTableModel::TxHashRole);
|
2011-07-07 14:27:16 +02:00
|
|
|
|
2013-10-26 19:21:10 +02:00
|
|
|
if(!writer.write()) {
|
2015-07-14 13:59:05 +02:00
|
|
|
Q_EMIT message(tr("Exporting Failed"), tr("There was an error trying to save the transaction history to %1.").arg(filename),
|
2013-10-26 19:21:10 +02:00
|
|
|
CClientUIInterface::MSG_ERROR);
|
|
|
|
}
|
|
|
|
else {
|
2015-07-14 13:59:05 +02:00
|
|
|
Q_EMIT message(tr("Exporting Successful"), tr("The transaction history was successfully saved to %1.").arg(filename),
|
2013-10-26 19:21:10 +02:00
|
|
|
CClientUIInterface::MSG_INFORMATION);
|
2011-07-07 14:27:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-08 22:27:36 +02:00
|
|
|
void TransactionView::contextualMenu(const QPoint &point)
|
|
|
|
{
|
2019-04-30 14:48:21 +02:00
|
|
|
if (!transactionView || !transactionView->selectionModel())
|
|
|
|
return;
|
2011-07-08 22:27:36 +02:00
|
|
|
QModelIndex index = transactionView->indexAt(point);
|
2017-09-09 09:04:02 +02:00
|
|
|
QModelIndexList selection = transactionView->selectionModel()->selectedRows(0);
|
2016-06-24 13:47:54 +02:00
|
|
|
if (selection.empty())
|
|
|
|
return;
|
2017-09-09 09:04:02 +02:00
|
|
|
|
|
|
|
// check if transaction can be abandoned, disable context menu action in case it doesn't
|
|
|
|
uint256 hash;
|
|
|
|
hash.SetHex(selection.at(0).data(TransactionTableModel::TxHashRole).toString().toStdString());
|
2017-04-18 00:56:44 +02:00
|
|
|
abandonAction->setEnabled(model->wallet().transactionCanBeAbandoned(hash));
|
2022-06-07 23:07:27 +02:00
|
|
|
resendAction->setEnabled(selection.size() == 1 && model->wallet().transactionCanBeResent(hash));
|
2017-09-09 09:04:02 +02:00
|
|
|
|
2011-07-08 22:27:36 +02:00
|
|
|
if(index.isValid())
|
|
|
|
{
|
2020-02-12 14:48:02 +01:00
|
|
|
contextMenu->popup(transactionView->viewport()->mapToGlobal(point));
|
2011-07-08 22:27:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-09 09:04:02 +02:00
|
|
|
void TransactionView::abandonTx()
|
|
|
|
{
|
|
|
|
if(!transactionView || !transactionView->selectionModel())
|
|
|
|
return;
|
|
|
|
QModelIndexList selection = transactionView->selectionModel()->selectedRows(0);
|
|
|
|
|
|
|
|
// get the hash from the TxHashRole (QVariant / QString)
|
|
|
|
uint256 hash;
|
|
|
|
QString hashQStr = selection.at(0).data(TransactionTableModel::TxHashRole).toString();
|
|
|
|
hash.SetHex(hashQStr.toStdString());
|
|
|
|
|
|
|
|
// Abandon the wallet transaction over the walletModel
|
2017-04-18 00:56:44 +02:00
|
|
|
model->wallet().abandonTransaction(hash);
|
2017-09-09 09:04:02 +02:00
|
|
|
|
|
|
|
// Update the table
|
|
|
|
model->getTransactionTableModel()->updateTransaction(hashQStr, CT_UPDATED, false);
|
|
|
|
}
|
|
|
|
|
2022-06-07 23:07:27 +02:00
|
|
|
void TransactionView::resendTx()
|
|
|
|
{
|
|
|
|
if(!transactionView || !transactionView->selectionModel()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QModelIndexList selection = transactionView->selectionModel()->selectedRows(0);
|
|
|
|
|
|
|
|
// get the hash from the TxHashRole (QVariant / QString)
|
|
|
|
uint256 hash;
|
|
|
|
QString hashQStr = selection.at(0).data(TransactionTableModel::TxHashRole).toString();
|
|
|
|
hash.SetHex(hashQStr.toStdString());
|
|
|
|
|
|
|
|
// Abandon the wallet transaction over the walletModel
|
|
|
|
model->wallet().resendTransaction(hash);
|
|
|
|
}
|
|
|
|
|
2011-07-08 22:27:36 +02:00
|
|
|
void TransactionView::copyAddress()
|
|
|
|
{
|
2011-12-04 14:14:10 +01:00
|
|
|
GUIUtil::copyEntryData(transactionView, 0, TransactionTableModel::AddressRole);
|
2011-07-08 22:27:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void TransactionView::copyLabel()
|
|
|
|
{
|
2011-12-04 14:14:10 +01:00
|
|
|
GUIUtil::copyEntryData(transactionView, 0, TransactionTableModel::LabelRole);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransactionView::copyAmount()
|
|
|
|
{
|
|
|
|
GUIUtil::copyEntryData(transactionView, 0, TransactionTableModel::FormattedAmountRole);
|
2011-07-08 22:27:36 +02:00
|
|
|
}
|
|
|
|
|
2013-03-21 10:33:36 +01:00
|
|
|
void TransactionView::copyTxID()
|
|
|
|
{
|
2018-03-07 16:48:09 +01:00
|
|
|
GUIUtil::copyEntryData(transactionView, 0, TransactionTableModel::TxHashRole);
|
2013-03-21 10:33:36 +01:00
|
|
|
}
|
|
|
|
|
2015-11-17 11:17:09 +01:00
|
|
|
void TransactionView::copyTxHex()
|
|
|
|
{
|
|
|
|
GUIUtil::copyEntryData(transactionView, 0, TransactionTableModel::TxHexRole);
|
|
|
|
}
|
|
|
|
|
2017-09-07 17:59:00 +02:00
|
|
|
void TransactionView::copyTxPlainText()
|
|
|
|
{
|
|
|
|
GUIUtil::copyEntryData(transactionView, 0, TransactionTableModel::TxPlainTextRole);
|
|
|
|
}
|
|
|
|
|
2021-02-25 09:09:29 +01:00
|
|
|
void TransactionView::editLabel()
|
|
|
|
{
|
|
|
|
if(!transactionView->selectionModel() ||!model)
|
|
|
|
return;
|
|
|
|
QModelIndexList selection = transactionView->selectionModel()->selectedRows();
|
|
|
|
if(!selection.isEmpty())
|
|
|
|
{
|
|
|
|
AddressTableModel *addressBook = model->getAddressTableModel();
|
|
|
|
if(!addressBook)
|
|
|
|
return;
|
|
|
|
QString address = selection.at(0).data(TransactionTableModel::AddressRole).toString();
|
|
|
|
if(address.isEmpty())
|
|
|
|
{
|
|
|
|
// If this transaction has no associated address, exit
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Is address in address book? Address book can miss address when a transaction is
|
|
|
|
// sent from outside the UI.
|
|
|
|
int idx = addressBook->lookupAddress(address);
|
|
|
|
if(idx != -1)
|
|
|
|
{
|
|
|
|
// Edit sending / receiving address
|
|
|
|
QModelIndex modelIdx = addressBook->index(idx, 0, QModelIndex());
|
|
|
|
// Determine type of address, launch appropriate editor dialog type
|
|
|
|
QString type = modelIdx.data(AddressTableModel::TypeRole).toString();
|
|
|
|
|
|
|
|
EditAddressDialog dlg(
|
|
|
|
type == AddressTableModel::Receive
|
|
|
|
? EditAddressDialog::EditReceivingAddress
|
|
|
|
: EditAddressDialog::EditSendingAddress, this);
|
|
|
|
dlg.setModel(addressBook);
|
|
|
|
dlg.loadRow(idx);
|
|
|
|
dlg.exec();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Add sending address
|
|
|
|
EditAddressDialog dlg(EditAddressDialog::NewSendingAddress,
|
|
|
|
this);
|
|
|
|
dlg.setModel(addressBook);
|
|
|
|
dlg.setAddress(address);
|
|
|
|
dlg.exec();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-08 22:27:36 +02:00
|
|
|
void TransactionView::showDetails()
|
|
|
|
{
|
2011-11-08 21:18:36 +01:00
|
|
|
if(!transactionView->selectionModel())
|
|
|
|
return;
|
2011-07-08 22:27:36 +02:00
|
|
|
QModelIndexList selection = transactionView->selectionModel()->selectedRows();
|
|
|
|
if(!selection.isEmpty())
|
|
|
|
{
|
2020-07-14 22:16:38 +02:00
|
|
|
TransactionDescDialog* dlg = new TransactionDescDialog(selection.at(0), this);
|
2016-04-28 12:15:33 +02:00
|
|
|
dlg->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
dlg->show();
|
2011-07-08 22:27:36 +02:00
|
|
|
}
|
|
|
|
}
|
2011-07-22 18:30:25 +02:00
|
|
|
|
2019-03-06 20:45:22 +01:00
|
|
|
void TransactionView::showAddressQRCode()
|
|
|
|
{
|
|
|
|
QList<QModelIndex> entries = GUIUtil::getEntryData(transactionView, 0);
|
|
|
|
if (entries.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString strAddress = entries.at(0).data(TransactionTableModel::AddressRole).toString();
|
|
|
|
QRDialog* dialog = new QRDialog(this);
|
|
|
|
|
|
|
|
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
dialog->setInfo(tr("QR code"), "dash:"+strAddress, "", strAddress);
|
|
|
|
dialog->show();
|
|
|
|
}
|
|
|
|
|
2015-05-10 01:22:35 +02:00
|
|
|
/** Compute sum of all selected transactions */
|
|
|
|
void TransactionView::computeSum()
|
|
|
|
{
|
|
|
|
qint64 amount = 0;
|
|
|
|
int nDisplayUnit = model->getOptionsModel()->getDisplayUnit();
|
|
|
|
if(!transactionView->selectionModel())
|
|
|
|
return;
|
|
|
|
QModelIndexList selection = transactionView->selectionModel()->selectedRows();
|
2015-05-16 01:34:25 +02:00
|
|
|
|
2019-07-05 09:07:45 +02:00
|
|
|
for (QModelIndex index : selection){
|
2015-07-12 18:00:48 +02:00
|
|
|
amount += index.data(TransactionTableModel::AmountRole).toLongLong();
|
2015-05-16 01:34:25 +02:00
|
|
|
}
|
2015-07-12 18:00:48 +02:00
|
|
|
QString strAmount(BitcoinUnits::formatWithUnit(nDisplayUnit, amount, true, BitcoinUnits::separatorAlways));
|
2019-11-22 19:13:47 +01:00
|
|
|
if (amount < 0) strAmount = "<span style='" + GUIUtil::getThemedStyleQString(GUIUtil::ThemedStyle::TS_ERROR) + "'>" + strAmount + "</span>";
|
2016-02-02 16:28:56 +01:00
|
|
|
Q_EMIT trxAmount(strAmount);
|
2015-05-10 01:22:35 +02:00
|
|
|
}
|
|
|
|
|
2014-04-24 22:21:45 +02:00
|
|
|
void TransactionView::openThirdPartyTxUrl(QString url)
|
|
|
|
{
|
|
|
|
if(!transactionView || !transactionView->selectionModel())
|
|
|
|
return;
|
|
|
|
QModelIndexList selection = transactionView->selectionModel()->selectedRows(0);
|
|
|
|
if(!selection.isEmpty())
|
|
|
|
QDesktopServices::openUrl(QUrl::fromUserInput(url.replace("%s", selection.at(0).data(TransactionTableModel::TxHashRole).toString())));
|
|
|
|
}
|
|
|
|
|
2011-07-22 18:30:25 +02:00
|
|
|
QWidget *TransactionView::createDateRangeWidget()
|
|
|
|
{
|
2016-06-13 14:11:26 +02:00
|
|
|
// Create default dates in case nothing is persisted
|
|
|
|
QString defaultDateFrom = QDate::currentDate().toString(PERSISTENCE_DATE_FORMAT);
|
|
|
|
QString defaultDateTo = QDate::currentDate().addDays(1).toString(PERSISTENCE_DATE_FORMAT);
|
|
|
|
QSettings settings;
|
2017-11-30 00:50:30 +01:00
|
|
|
|
2011-07-22 18:30:25 +02:00
|
|
|
dateRangeWidget = new QFrame();
|
|
|
|
dateRangeWidget->setFrameStyle(QFrame::Panel | QFrame::Raised);
|
|
|
|
dateRangeWidget->setContentsMargins(1,1,1,1);
|
|
|
|
QHBoxLayout *layout = new QHBoxLayout(dateRangeWidget);
|
|
|
|
layout->setContentsMargins(0,0,0,0);
|
|
|
|
layout->addSpacing(23);
|
2011-08-28 14:12:26 +02:00
|
|
|
layout->addWidget(new QLabel(tr("Range:")));
|
2011-07-22 18:30:25 +02:00
|
|
|
|
|
|
|
dateFrom = new QDateTimeEdit(this);
|
|
|
|
dateFrom->setCalendarPopup(true);
|
|
|
|
dateFrom->setMinimumWidth(100);
|
2016-06-13 14:11:26 +02:00
|
|
|
// Load persisted FROM date
|
|
|
|
dateFrom->setDate(QDate::fromString(settings.value("transactionDateFrom", defaultDateFrom).toString(), PERSISTENCE_DATE_FORMAT));
|
|
|
|
|
2011-07-22 18:30:25 +02:00
|
|
|
layout->addWidget(dateFrom);
|
2011-08-28 14:12:26 +02:00
|
|
|
layout->addWidget(new QLabel(tr("to")));
|
2011-07-22 18:30:25 +02:00
|
|
|
|
|
|
|
dateTo = new QDateTimeEdit(this);
|
|
|
|
dateTo->setCalendarPopup(true);
|
|
|
|
dateTo->setMinimumWidth(100);
|
2016-06-13 14:11:26 +02:00
|
|
|
// Load persisted TO date
|
|
|
|
dateTo->setDate(QDate::fromString(settings.value("transactionDateTo", defaultDateTo).toString(), PERSISTENCE_DATE_FORMAT));
|
|
|
|
|
2011-07-22 18:30:25 +02:00
|
|
|
layout->addWidget(dateTo);
|
|
|
|
layout->addStretch();
|
|
|
|
|
|
|
|
// Hide by default
|
|
|
|
dateRangeWidget->setVisible(false);
|
|
|
|
|
|
|
|
// Notify on change
|
2018-08-21 10:54:43 +02:00
|
|
|
connect(dateFrom, &QDateTimeEdit::dateChanged, this, &TransactionView::dateRangeChanged);
|
|
|
|
connect(dateTo, &QDateTimeEdit::dateChanged, this, &TransactionView::dateRangeChanged);
|
2011-07-22 18:30:25 +02:00
|
|
|
|
2020-07-20 17:01:11 +02:00
|
|
|
updateCalendarWidgets();
|
|
|
|
|
2011-07-22 18:30:25 +02:00
|
|
|
return dateRangeWidget;
|
|
|
|
}
|
|
|
|
|
2020-07-20 17:01:11 +02:00
|
|
|
void TransactionView::updateCalendarWidgets()
|
|
|
|
{
|
|
|
|
auto adjustWeekEndColors = [](QCalendarWidget* w) {
|
|
|
|
QTextCharFormat format = w->weekdayTextFormat(Qt::Saturday);
|
|
|
|
format.setForeground(QBrush(GUIUtil::getThemedQColor(GUIUtil::ThemedColor::DEFAULT), Qt::SolidPattern));
|
|
|
|
|
|
|
|
w->setWeekdayTextFormat(Qt::Saturday, format);
|
|
|
|
w->setWeekdayTextFormat(Qt::Sunday, format);
|
|
|
|
};
|
|
|
|
|
|
|
|
adjustWeekEndColors(dateFrom->calendarWidget());
|
|
|
|
adjustWeekEndColors(dateTo->calendarWidget());
|
|
|
|
}
|
|
|
|
|
2011-07-22 18:30:25 +02:00
|
|
|
void TransactionView::dateRangeChanged()
|
|
|
|
{
|
2011-11-08 21:18:36 +01:00
|
|
|
if(!transactionProxyModel)
|
|
|
|
return;
|
2017-11-30 00:50:30 +01:00
|
|
|
|
2016-06-13 14:11:26 +02:00
|
|
|
// Persist new date range
|
|
|
|
QSettings settings;
|
|
|
|
settings.setValue("transactionDateFrom", dateFrom->date().toString(PERSISTENCE_DATE_FORMAT));
|
|
|
|
settings.setValue("transactionDateTo", dateTo->date().toString(PERSISTENCE_DATE_FORMAT));
|
2017-11-30 00:50:30 +01:00
|
|
|
|
2011-07-22 18:30:25 +02:00
|
|
|
transactionProxyModel->setDateRange(
|
|
|
|
QDateTime(dateFrom->date()),
|
2016-06-13 14:11:26 +02:00
|
|
|
QDateTime(dateTo->date()));
|
2011-07-22 18:30:25 +02:00
|
|
|
}
|
2012-05-12 13:19:44 +02:00
|
|
|
|
|
|
|
void TransactionView::focusTransaction(const QModelIndex &idx)
|
|
|
|
{
|
|
|
|
if(!transactionProxyModel)
|
|
|
|
return;
|
|
|
|
QModelIndex targetIdx = transactionProxyModel->mapFromSource(idx);
|
2015-05-10 01:22:35 +02:00
|
|
|
transactionView->selectRow(targetIdx.row());
|
|
|
|
computeSum();
|
2012-05-12 13:19:44 +02:00
|
|
|
transactionView->scrollTo(targetIdx);
|
|
|
|
transactionView->setCurrentIndex(targetIdx);
|
|
|
|
transactionView->setFocus();
|
|
|
|
}
|
2014-03-21 06:45:47 +01:00
|
|
|
|
2018-03-01 12:18:25 +01:00
|
|
|
void TransactionView::focusTransaction(const uint256& txid)
|
|
|
|
{
|
|
|
|
if (!transactionProxyModel)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const QModelIndexList results = this->model->getTransactionTableModel()->match(
|
|
|
|
this->model->getTransactionTableModel()->index(0,0),
|
|
|
|
TransactionTableModel::TxHashRole,
|
|
|
|
QString::fromStdString(txid.ToString()), -1);
|
|
|
|
|
|
|
|
transactionView->setFocus();
|
|
|
|
transactionView->selectionModel()->clearSelection();
|
|
|
|
for (const QModelIndex& index : results) {
|
|
|
|
const QModelIndex targetIndex = transactionProxyModel->mapFromSource(index);
|
|
|
|
transactionView->selectionModel()->select(
|
|
|
|
targetIndex,
|
|
|
|
QItemSelectionModel::Rows | QItemSelectionModel::Select);
|
|
|
|
// Called once per destination to ensure all results are in view, unless
|
|
|
|
// transactions are not ordered by (ascending or descending) date.
|
|
|
|
transactionView->scrollTo(targetIndex);
|
|
|
|
// scrollTo() does not scroll far enough the first time when transactions
|
|
|
|
// are ordered by ascending date.
|
|
|
|
if (index == results[0]) transactionView->scrollTo(targetIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-21 09:12:01 +01:00
|
|
|
// We override the virtual resizeEvent of the QWidget to adjust tables column
|
|
|
|
// sizes as the tables width is proportional to the dialogs width.
|
|
|
|
void TransactionView::resizeEvent(QResizeEvent* event)
|
|
|
|
{
|
|
|
|
QWidget::resizeEvent(event);
|
|
|
|
columnResizingFixer->stretchColumnWidth(TransactionTableModel::ToAddress);
|
2014-03-21 06:45:47 +01:00
|
|
|
}
|
2014-05-10 00:50:09 +02:00
|
|
|
|
2020-07-20 17:01:11 +02:00
|
|
|
void TransactionView::changeEvent(QEvent* e)
|
|
|
|
{
|
2020-09-23 08:33:46 +02:00
|
|
|
QWidget::changeEvent(e);
|
2020-07-20 17:01:11 +02:00
|
|
|
if (e->type() == QEvent::StyleChange) {
|
|
|
|
updateCalendarWidgets();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-10 00:50:09 +02:00
|
|
|
// Need to override default Ctrl+C action for amount as default behaviour is just to copy DisplayRole text
|
|
|
|
bool TransactionView::eventFilter(QObject *obj, QEvent *event)
|
|
|
|
{
|
|
|
|
if (event->type() == QEvent::KeyPress)
|
|
|
|
{
|
|
|
|
QKeyEvent *ke = static_cast<QKeyEvent *>(event);
|
|
|
|
if (ke->key() == Qt::Key_C && ke->modifiers().testFlag(Qt::ControlModifier))
|
|
|
|
{
|
2017-09-07 17:59:00 +02:00
|
|
|
GUIUtil::copyEntryData(transactionView, 0, TransactionTableModel::TxPlainTextRole);
|
|
|
|
return true;
|
2014-05-10 00:50:09 +02:00
|
|
|
}
|
|
|
|
}
|
2020-07-20 17:01:11 +02:00
|
|
|
if (event->type() == QEvent::Show) {
|
|
|
|
// Give the search field the first focus on startup
|
|
|
|
static bool fGotFirstFocus = false;
|
|
|
|
if (!fGotFirstFocus) {
|
|
|
|
search_widget->setFocus();
|
|
|
|
fGotFirstFocus = true;
|
|
|
|
}
|
|
|
|
}
|
2014-05-10 00:50:09 +02:00
|
|
|
return QWidget::eventFilter(obj, event);
|
|
|
|
}
|
2014-08-10 02:26:04 +02:00
|
|
|
|
|
|
|
// show/hide column Watch-only
|
|
|
|
void TransactionView::updateWatchOnlyColumn(bool fHaveWatchOnly)
|
|
|
|
{
|
2018-11-23 16:23:15 +01:00
|
|
|
watchOnlyWidget->setVisible(fHaveWatchOnly);
|
2014-08-10 02:26:04 +02:00
|
|
|
transactionView->setColumnHidden(TransactionTableModel::Watchonly, !fHaveWatchOnly);
|
|
|
|
}
|
2020-09-18 12:15:55 +02:00
|
|
|
|
2021-03-17 23:36:11 +01:00
|
|
|
void TransactionView::updateCoinJoinVisibility()
|
2020-09-18 12:15:55 +02:00
|
|
|
{
|
2020-08-28 11:52:00 +02:00
|
|
|
if (model == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
2021-03-17 23:36:11 +01:00
|
|
|
bool fEnabled = model->node().coinJoinOptions().isEnabled();
|
|
|
|
// If CoinJoin gets enabled use "All" else "Most common"
|
2021-06-25 10:49:22 +02:00
|
|
|
int idx = fEnabled ? 0 : 1;
|
|
|
|
chooseType(idx);
|
|
|
|
typeWidget->setCurrentIndex(idx);
|
2021-03-17 23:36:11 +01:00
|
|
|
// Hide all CoinJoin related filters
|
2020-09-18 12:15:55 +02:00
|
|
|
QListView* typeList = qobject_cast<QListView*>(typeWidget->view());
|
|
|
|
std::vector<int> vecRows{4, 5, 6, 7, 8};
|
|
|
|
for (auto nRow : vecRows) {
|
|
|
|
typeList->setRowHidden(nRow, !fEnabled);
|
|
|
|
}
|
|
|
|
}
|