Changeset View
Changeset View
Standalone View
Standalone View
src/qt/transactionview.cpp
Show First 20 Lines • Show All 243 Lines • ▼ Show 20 Lines | if (_model) { | ||||
// Add third party transaction URLs to context menu | // Add third party transaction URLs to context menu | ||||
QStringList listUrls = | QStringList listUrls = | ||||
_model->getOptionsModel()->getThirdPartyTxUrls().split( | _model->getOptionsModel()->getThirdPartyTxUrls().split( | ||||
"|", QString::SkipEmptyParts); | "|", QString::SkipEmptyParts); | ||||
for (int i = 0; i < listUrls.size(); ++i) { | for (int i = 0; i < listUrls.size(); ++i) { | ||||
QString host = | QString host = | ||||
QUrl(listUrls[i].trimmed(), QUrl::StrictMode).host(); | QUrl(listUrls[i].trimmed(), QUrl::StrictMode).host(); | ||||
if (!host.isEmpty()) { | if (!host.isEmpty()) { | ||||
QAction *thirdPartyTxUrlAction = | // use host as menu item label | ||||
new QAction(host, this); // use host as menu item label | QAction *thirdPartyTxUrlAction = new QAction(host, this); | ||||
if (i == 0) contextMenu->addSeparator(); | if (i == 0) { | ||||
contextMenu->addSeparator(); | |||||
} | |||||
contextMenu->addAction(thirdPartyTxUrlAction); | contextMenu->addAction(thirdPartyTxUrlAction); | ||||
connect(thirdPartyTxUrlAction, SIGNAL(triggered()), | connect(thirdPartyTxUrlAction, SIGNAL(triggered()), | ||||
mapperThirdPartyTxUrls, SLOT(map())); | mapperThirdPartyTxUrls, SLOT(map())); | ||||
mapperThirdPartyTxUrls->setMapping(thirdPartyTxUrlAction, | mapperThirdPartyTxUrls->setMapping(thirdPartyTxUrlAction, | ||||
listUrls[i].trimmed()); | listUrls[i].trimmed()); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// show/hide column Watch-only | // show/hide column Watch-only | ||||
updateWatchOnlyColumn(_model->haveWatchOnly()); | updateWatchOnlyColumn(_model->haveWatchOnly()); | ||||
// Watch-only signal | // Watch-only signal | ||||
connect(_model, SIGNAL(notifyWatchonlyChanged(bool)), this, | connect(_model, SIGNAL(notifyWatchonlyChanged(bool)), this, | ||||
SLOT(updateWatchOnlyColumn(bool))); | SLOT(updateWatchOnlyColumn(bool))); | ||||
} | } | ||||
} | } | ||||
void TransactionView::chooseDate(int idx) { | void TransactionView::chooseDate(int idx) { | ||||
if (!transactionProxyModel) return; | if (!transactionProxyModel) { | ||||
return; | |||||
} | |||||
QDate current = QDate::currentDate(); | QDate current = QDate::currentDate(); | ||||
dateRangeWidget->setVisible(false); | dateRangeWidget->setVisible(false); | ||||
switch (dateWidget->itemData(idx).toInt()) { | switch (dateWidget->itemData(idx).toInt()) { | ||||
case All: | case All: | ||||
transactionProxyModel->setDateRange( | transactionProxyModel->setDateRange( | ||||
TransactionFilterProxy::MIN_DATE, | TransactionFilterProxy::MIN_DATE, | ||||
TransactionFilterProxy::MAX_DATE); | TransactionFilterProxy::MAX_DATE); | ||||
break; | break; | ||||
Show All 27 Lines | switch (dateWidget->itemData(idx).toInt()) { | ||||
case Range: | case Range: | ||||
dateRangeWidget->setVisible(true); | dateRangeWidget->setVisible(true); | ||||
dateRangeChanged(); | dateRangeChanged(); | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
void TransactionView::chooseType(int idx) { | void TransactionView::chooseType(int idx) { | ||||
if (!transactionProxyModel) return; | if (!transactionProxyModel) { | ||||
return; | |||||
} | |||||
transactionProxyModel->setTypeFilter(typeWidget->itemData(idx).toInt()); | transactionProxyModel->setTypeFilter(typeWidget->itemData(idx).toInt()); | ||||
} | } | ||||
void TransactionView::chooseWatchonly(int idx) { | void TransactionView::chooseWatchonly(int idx) { | ||||
if (!transactionProxyModel) return; | if (!transactionProxyModel) { | ||||
return; | |||||
} | |||||
transactionProxyModel->setWatchOnlyFilter( | transactionProxyModel->setWatchOnlyFilter( | ||||
(TransactionFilterProxy::WatchOnlyFilter)watchOnlyWidget->itemData(idx) | (TransactionFilterProxy::WatchOnlyFilter)watchOnlyWidget->itemData(idx) | ||||
.toInt()); | .toInt()); | ||||
} | } | ||||
void TransactionView::changedPrefix(const QString &prefix) { | void TransactionView::changedPrefix(const QString &prefix) { | ||||
if (!transactionProxyModel) return; | if (!transactionProxyModel) { | ||||
return; | |||||
} | |||||
transactionProxyModel->setAddressPrefix(prefix); | transactionProxyModel->setAddressPrefix(prefix); | ||||
} | } | ||||
void TransactionView::changedAmount(const QString &amount) { | void TransactionView::changedAmount(const QString &amount) { | ||||
if (!transactionProxyModel) return; | if (!transactionProxyModel) { | ||||
return; | |||||
} | |||||
Amount amount_parsed(0); | Amount amount_parsed(0); | ||||
if (BitcoinUnits::parse(model->getOptionsModel()->getDisplayUnit(), amount, | if (BitcoinUnits::parse(model->getOptionsModel()->getDisplayUnit(), amount, | ||||
&amount_parsed)) { | &amount_parsed)) { | ||||
transactionProxyModel->setMinAmount(amount_parsed); | transactionProxyModel->setMinAmount(amount_parsed); | ||||
} else { | } else { | ||||
transactionProxyModel->setMinAmount(Amount::zero()); | transactionProxyModel->setMinAmount(Amount::zero()); | ||||
} | } | ||||
} | } | ||||
void TransactionView::exportClicked() { | void TransactionView::exportClicked() { | ||||
// CSV is currently the only supported format | // CSV is currently the only supported format | ||||
QString filename = GUIUtil::getSaveFileName( | QString filename = GUIUtil::getSaveFileName( | ||||
this, tr("Export Transaction History"), QString(), | this, tr("Export Transaction History"), QString(), | ||||
tr("Comma separated file (*.csv)"), nullptr); | tr("Comma separated file (*.csv)"), nullptr); | ||||
if (filename.isNull()) return; | if (filename.isNull()) { | ||||
return; | |||||
} | |||||
CSVModelWriter writer(filename); | CSVModelWriter writer(filename); | ||||
// name, column, role | // name, column, role | ||||
writer.setModel(transactionProxyModel); | writer.setModel(transactionProxyModel); | ||||
writer.addColumn(tr("Confirmed"), 0, TransactionTableModel::ConfirmedRole); | writer.addColumn(tr("Confirmed"), 0, TransactionTableModel::ConfirmedRole); | ||||
if (model && model->haveWatchOnly()) | if (model && model->haveWatchOnly()) { | ||||
writer.addColumn(tr("Watch-only"), TransactionTableModel::Watchonly); | writer.addColumn(tr("Watch-only"), TransactionTableModel::Watchonly); | ||||
} | |||||
writer.addColumn(tr("Date"), 0, TransactionTableModel::DateRole); | writer.addColumn(tr("Date"), 0, TransactionTableModel::DateRole); | ||||
writer.addColumn(tr("Type"), TransactionTableModel::Type, Qt::EditRole); | writer.addColumn(tr("Type"), TransactionTableModel::Type, Qt::EditRole); | ||||
writer.addColumn(tr("Label"), 0, TransactionTableModel::LabelRole); | writer.addColumn(tr("Label"), 0, TransactionTableModel::LabelRole); | ||||
writer.addColumn(tr("Address"), 0, TransactionTableModel::AddressRole); | writer.addColumn(tr("Address"), 0, TransactionTableModel::AddressRole); | ||||
writer.addColumn(BitcoinUnits::getAmountColumnTitle( | writer.addColumn(BitcoinUnits::getAmountColumnTitle( | ||||
model->getOptionsModel()->getDisplayUnit()), | model->getOptionsModel()->getDisplayUnit()), | ||||
0, TransactionTableModel::FormattedAmountRole); | 0, TransactionTableModel::FormattedAmountRole); | ||||
writer.addColumn(tr("ID"), 0, TransactionTableModel::TxIDRole); | writer.addColumn(tr("ID"), 0, TransactionTableModel::TxIDRole); | ||||
Show All 34 Lines | if (index.isValid()) { | ||||
contextMenu->exec(QCursor::pos()); | contextMenu->exec(QCursor::pos()); | ||||
} | } | ||||
} | } | ||||
void TransactionView::abandonTx() { | void TransactionView::abandonTx() { | ||||
if (!transactionView || !transactionView->selectionModel()) { | if (!transactionView || !transactionView->selectionModel()) { | ||||
return; | return; | ||||
} | } | ||||
QModelIndexList selection = | QModelIndexList selection = | ||||
transactionView->selectionModel()->selectedRows(0); | transactionView->selectionModel()->selectedRows(0); | ||||
// get the hash from the TxHashRole (QVariant / QString) | // get the hash from the TxHashRole (QVariant / QString) | ||||
QString hashQStr = | QString hashQStr = | ||||
selection.at(0).data(TransactionTableModel::TxHashRole).toString(); | selection.at(0).data(TransactionTableModel::TxHashRole).toString(); | ||||
TxId txid; | TxId txid; | ||||
Show All 32 Lines | |||||
} | } | ||||
void TransactionView::copyTxPlainText() { | void TransactionView::copyTxPlainText() { | ||||
GUIUtil::copyEntryData(transactionView, 0, | GUIUtil::copyEntryData(transactionView, 0, | ||||
TransactionTableModel::TxPlainTextRole); | TransactionTableModel::TxPlainTextRole); | ||||
} | } | ||||
void TransactionView::editLabel() { | void TransactionView::editLabel() { | ||||
if (!transactionView->selectionModel() || !model) return; | if (!transactionView->selectionModel() || !model) { | ||||
return; | |||||
} | |||||
QModelIndexList selection = | QModelIndexList selection = | ||||
transactionView->selectionModel()->selectedRows(); | transactionView->selectionModel()->selectedRows(); | ||||
if (!selection.isEmpty()) { | if (!selection.isEmpty()) { | ||||
AddressTableModel *addressBook = model->getAddressTableModel(); | AddressTableModel *addressBook = model->getAddressTableModel(); | ||||
if (!addressBook) return; | if (!addressBook) { | ||||
return; | |||||
} | |||||
QString address = | QString address = | ||||
selection.at(0).data(TransactionTableModel::AddressRole).toString(); | selection.at(0).data(TransactionTableModel::AddressRole).toString(); | ||||
if (address.isEmpty()) { | if (address.isEmpty()) { | ||||
// If this transaction has no associated address, exit | // If this transaction has no associated address, exit | ||||
return; | return; | ||||
} | } | ||||
// Is address in address book? Address book can miss address when a | // Is address in address book? Address book can miss address when a | ||||
// transaction is | // transaction is sent from outside the UI. | ||||
// sent from outside the UI. | |||||
int idx = addressBook->lookupAddress(address); | int idx = addressBook->lookupAddress(address); | ||||
if (idx != -1) { | if (idx != -1) { | ||||
// Edit sending / receiving address | // Edit sending / receiving address | ||||
QModelIndex modelIdx = addressBook->index(idx, 0, QModelIndex()); | QModelIndex modelIdx = addressBook->index(idx, 0, QModelIndex()); | ||||
// Determine type of address, launch appropriate editor dialog type | // Determine type of address, launch appropriate editor dialog type | ||||
QString type = | QString type = | ||||
modelIdx.data(AddressTableModel::TypeRole).toString(); | modelIdx.data(AddressTableModel::TypeRole).toString(); | ||||
Show All 10 Lines | if (!selection.isEmpty()) { | ||||
dlg.setModel(addressBook); | dlg.setModel(addressBook); | ||||
dlg.setAddress(address); | dlg.setAddress(address); | ||||
dlg.exec(); | dlg.exec(); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
void TransactionView::showDetails() { | void TransactionView::showDetails() { | ||||
if (!transactionView->selectionModel()) return; | if (!transactionView->selectionModel()) { | ||||
return; | |||||
} | |||||
QModelIndexList selection = | QModelIndexList selection = | ||||
transactionView->selectionModel()->selectedRows(); | transactionView->selectionModel()->selectedRows(); | ||||
if (!selection.isEmpty()) { | if (!selection.isEmpty()) { | ||||
TransactionDescDialog *dlg = new TransactionDescDialog(selection.at(0)); | TransactionDescDialog *dlg = new TransactionDescDialog(selection.at(0)); | ||||
dlg->setAttribute(Qt::WA_DeleteOnClose); | dlg->setAttribute(Qt::WA_DeleteOnClose); | ||||
dlg->show(); | dlg->show(); | ||||
} | } | ||||
} | } | ||||
void TransactionView::openThirdPartyTxUrl(QString url) { | void TransactionView::openThirdPartyTxUrl(QString url) { | ||||
if (!transactionView || !transactionView->selectionModel()) return; | if (!transactionView || !transactionView->selectionModel()) { | ||||
return; | |||||
} | |||||
QModelIndexList selection = | QModelIndexList selection = | ||||
transactionView->selectionModel()->selectedRows(0); | transactionView->selectionModel()->selectedRows(0); | ||||
if (!selection.isEmpty()) | if (!selection.isEmpty()) { | ||||
QDesktopServices::openUrl(QUrl::fromUserInput( | QDesktopServices::openUrl(QUrl::fromUserInput( | ||||
url.replace("%s", | url.replace("%s", | ||||
selection.at(0) | selection.at(0) | ||||
.data(TransactionTableModel::TxHashRole) | .data(TransactionTableModel::TxHashRole) | ||||
.toString()))); | .toString()))); | ||||
} | } | ||||
} | |||||
QWidget *TransactionView::createDateRangeWidget() { | QWidget *TransactionView::createDateRangeWidget() { | ||||
dateRangeWidget = new QFrame(); | dateRangeWidget = new QFrame(); | ||||
dateRangeWidget->setFrameStyle(QFrame::Panel | QFrame::Raised); | dateRangeWidget->setFrameStyle(QFrame::Panel | QFrame::Raised); | ||||
dateRangeWidget->setContentsMargins(1, 1, 1, 1); | dateRangeWidget->setContentsMargins(1, 1, 1, 1); | ||||
QHBoxLayout *layout = new QHBoxLayout(dateRangeWidget); | QHBoxLayout *layout = new QHBoxLayout(dateRangeWidget); | ||||
layout->setContentsMargins(0, 0, 0, 0); | layout->setContentsMargins(0, 0, 0, 0); | ||||
layout->addSpacing(23); | layout->addSpacing(23); | ||||
Show All 22 Lines | QWidget *TransactionView::createDateRangeWidget() { | ||||
connect(dateFrom, SIGNAL(dateChanged(QDate)), this, | connect(dateFrom, SIGNAL(dateChanged(QDate)), this, | ||||
SLOT(dateRangeChanged())); | SLOT(dateRangeChanged())); | ||||
connect(dateTo, SIGNAL(dateChanged(QDate)), this, SLOT(dateRangeChanged())); | connect(dateTo, SIGNAL(dateChanged(QDate)), this, SLOT(dateRangeChanged())); | ||||
return dateRangeWidget; | return dateRangeWidget; | ||||
} | } | ||||
void TransactionView::dateRangeChanged() { | void TransactionView::dateRangeChanged() { | ||||
if (!transactionProxyModel) return; | if (!transactionProxyModel) { | ||||
return; | |||||
} | |||||
transactionProxyModel->setDateRange(QDateTime(dateFrom->date()), | transactionProxyModel->setDateRange(QDateTime(dateFrom->date()), | ||||
QDateTime(dateTo->date()).addDays(1)); | QDateTime(dateTo->date()).addDays(1)); | ||||
} | } | ||||
void TransactionView::focusTransaction(const QModelIndex &idx) { | void TransactionView::focusTransaction(const QModelIndex &idx) { | ||||
if (!transactionProxyModel) return; | if (!transactionProxyModel) { | ||||
return; | |||||
} | |||||
QModelIndex targetIdx = transactionProxyModel->mapFromSource(idx); | QModelIndex targetIdx = transactionProxyModel->mapFromSource(idx); | ||||
transactionView->scrollTo(targetIdx); | transactionView->scrollTo(targetIdx); | ||||
transactionView->setCurrentIndex(targetIdx); | transactionView->setCurrentIndex(targetIdx); | ||||
transactionView->setFocus(); | transactionView->setFocus(); | ||||
} | } | ||||
// We override the virtual resizeEvent of the QWidget to adjust tables column | // We override the virtual resizeEvent of the QWidget to adjust tables column | ||||
// sizes as the tables width is proportional to the dialogs width. | // sizes as the tables width is proportional to the dialogs width. | ||||
Show All 26 Lines |