qt, refactor: Use better QMenu::addAction overloaded function

This overloaded function was introduced in Qt 5.6 and makes code more
concise.
pull/826/head
Hennadii Stepanov 4 years ago
parent 79311750b5
commit 16c157de3c
No known key found for this signature in database
GPG Key ID: 410108112E7EA81F

@ -112,27 +112,16 @@ AddressBookPage::AddressBookPage(const PlatformStyle *platformStyle, Mode _mode,
break; break;
} }
// Context menu actions
QAction* copyAddressAction = new QAction(tr("Copy Address"), this);
QAction* copyLabelAction = new QAction(tr("Copy Label"), this);
QAction* editAction = new QAction(tr("Edit"), this);
// Build context menu // Build context menu
contextMenu = new QMenu(this); contextMenu = new QMenu(this);
contextMenu->addAction(copyAddressAction); contextMenu->addAction(tr("Copy Address"), this, &AddressBookPage::on_copyAddress_clicked);
contextMenu->addAction(copyLabelAction); contextMenu->addAction(tr("Copy Label"), this, &AddressBookPage::onCopyLabelAction);
contextMenu->addAction(editAction); contextMenu->addAction(tr("Edit"), this, &AddressBookPage::onEditAction);
if (tab == SendingTab) { if (tab == SendingTab) {
QAction* deleteAction = new QAction(tr("Delete"), this); contextMenu->addAction(tr("Delete"), this, &AddressBookPage::on_deleteAddress_clicked);
contextMenu->addAction(deleteAction);
connect(deleteAction, &QAction::triggered, this, &AddressBookPage::on_deleteAddress_clicked);
} }
// Connect signals for context menu actions
connect(copyAddressAction, &QAction::triggered, this, &AddressBookPage::on_copyAddress_clicked);
connect(copyLabelAction, &QAction::triggered, this, &AddressBookPage::onCopyLabelAction);
connect(editAction, &QAction::triggered, this, &AddressBookPage::onEditAction);
connect(ui->tableView, &QWidget::customContextMenuRequested, this, &AddressBookPage::contextualMenu); connect(ui->tableView, &QWidget::customContextMenuRequested, this, &AddressBookPage::contextualMenu);
connect(ui->closeButton, &QPushButton::clicked, this, &QDialog::accept); connect(ui->closeButton, &QPushButton::clicked, this, &QDialog::accept);

@ -1468,11 +1468,8 @@ void UnitDisplayStatusBarControl::mousePressEvent(QMouseEvent *event)
void UnitDisplayStatusBarControl::createContextMenu() void UnitDisplayStatusBarControl::createContextMenu()
{ {
menu = new QMenu(this); menu = new QMenu(this);
for (const BitcoinUnits::Unit u : BitcoinUnits::availableUnits()) for (const BitcoinUnits::Unit u : BitcoinUnits::availableUnits()) {
{ menu->addAction(BitcoinUnits::longName(u))->setData(QVariant(u));
QAction *menuAction = new QAction(QString(BitcoinUnits::longName(u)), this);
menuAction->setData(QVariant(u));
menu->addAction(menuAction);
} }
connect(menu, &QMenu::triggered, this, &UnitDisplayStatusBarControl::onMenuSelection); connect(menu, &QMenu::triggered, this, &UnitDisplayStatusBarControl::onMenuSelection);
} }

@ -50,32 +50,16 @@ CoinControlDialog::CoinControlDialog(CCoinControl& coin_control, WalletModel* _m
{ {
ui->setupUi(this); ui->setupUi(this);
// context menu actions
QAction *copyAddressAction = new QAction(tr("Copy address"), this);
QAction *copyLabelAction = new QAction(tr("Copy label"), this);
QAction *copyAmountAction = new QAction(tr("Copy amount"), this);
copyTransactionHashAction = new QAction(tr("Copy transaction ID"), this); // we need to enable/disable this
lockAction = new QAction(tr("Lock unspent"), this); // we need to enable/disable this
unlockAction = new QAction(tr("Unlock unspent"), this); // we need to enable/disable this
// context menu // context menu
contextMenu = new QMenu(this); contextMenu = new QMenu(this);
contextMenu->addAction(copyAddressAction); contextMenu->addAction(tr("Copy address"), this, &CoinControlDialog::copyAddress);
contextMenu->addAction(copyLabelAction); contextMenu->addAction(tr("Copy label"), this, &CoinControlDialog::copyLabel);
contextMenu->addAction(copyAmountAction); contextMenu->addAction(tr("Copy amount"), this, &CoinControlDialog::copyAmount);
contextMenu->addAction(copyTransactionHashAction); copyTransactionHashAction = contextMenu->addAction(tr("Copy transaction ID"), this, &CoinControlDialog::copyTransactionHash);
contextMenu->addSeparator(); contextMenu->addSeparator();
contextMenu->addAction(lockAction); lockAction = contextMenu->addAction(tr("Lock unspent"), this, &CoinControlDialog::lockCoin);
contextMenu->addAction(unlockAction); unlockAction = contextMenu->addAction(tr("Unlock unspent"), this, &CoinControlDialog::unlockCoin);
// context menu signals
connect(ui->treeWidget, &QWidget::customContextMenuRequested, this, &CoinControlDialog::showMenu); connect(ui->treeWidget, &QWidget::customContextMenuRequested, this, &CoinControlDialog::showMenu);
connect(copyAddressAction, &QAction::triggered, this, &CoinControlDialog::copyAddress);
connect(copyLabelAction, &QAction::triggered, this, &CoinControlDialog::copyLabel);
connect(copyAmountAction, &QAction::triggered, this, &CoinControlDialog::copyAmount);
connect(copyTransactionHashAction, &QAction::triggered, this, &CoinControlDialog::copyTransactionHash);
connect(lockAction, &QAction::triggered, this, &CoinControlDialog::lockCoin);
connect(unlockAction, &QAction::triggered, this, &CoinControlDialog::unlockCoin);
// clipboard actions // clipboard actions
QAction *clipboardQuantityAction = new QAction(tr("Copy quantity"), this); QAction *clipboardQuantityAction = new QAction(tr("Copy quantity"), this);

@ -27,12 +27,8 @@ QRImageWidget::QRImageWidget(QWidget *parent):
QLabel(parent), contextMenu(nullptr) QLabel(parent), contextMenu(nullptr)
{ {
contextMenu = new QMenu(this); contextMenu = new QMenu(this);
QAction* saveImageAction = new QAction(tr("Save Image..."), this); contextMenu->addAction(tr("Save Image..."), this, &QRImageWidget::saveImage);
connect(saveImageAction, &QAction::triggered, this, &QRImageWidget::saveImage); contextMenu->addAction(tr("Copy Image"), this, &QRImageWidget::copyImage);
contextMenu->addAction(saveImageAction);
QAction* copyImageAction = new QAction(tr("Copy Image"), this);
connect(copyImageAction, &QAction::triggered, this, &QRImageWidget::copyImage);
contextMenu->addAction(copyImageAction);
} }
bool QRImageWidget::setQR(const QString& data, const QString& text) bool QRImageWidget::setQR(const QString& data, const QString& text)

@ -42,28 +42,14 @@ ReceiveCoinsDialog::ReceiveCoinsDialog(const PlatformStyle *_platformStyle, QWid
ui->removeRequestButton->setIcon(_platformStyle->SingleColorIcon(":/icons/remove")); ui->removeRequestButton->setIcon(_platformStyle->SingleColorIcon(":/icons/remove"));
} }
// context menu actions
QAction *copyURIAction = new QAction(tr("Copy URI"), this);
QAction* copyAddressAction = new QAction(tr("Copy address"), this);
copyLabelAction = new QAction(tr("Copy label"), this);
copyMessageAction = new QAction(tr("Copy message"), this);
copyAmountAction = new QAction(tr("Copy amount"), this);
// context menu // context menu
contextMenu = new QMenu(this); contextMenu = new QMenu(this);
contextMenu->addAction(copyURIAction); contextMenu->addAction(tr("Copy URI"), this, &ReceiveCoinsDialog::copyURI);
contextMenu->addAction(copyAddressAction); contextMenu->addAction(tr("Copy address"), this, &ReceiveCoinsDialog::copyAddress);
contextMenu->addAction(copyLabelAction); copyLabelAction = contextMenu->addAction(tr("Copy label"), this, &ReceiveCoinsDialog::copyLabel);
contextMenu->addAction(copyMessageAction); copyMessageAction = contextMenu->addAction(tr("Copy message"), this, &ReceiveCoinsDialog::copyMessage);
contextMenu->addAction(copyAmountAction); copyAmountAction = contextMenu->addAction(tr("Copy amount"), this, &ReceiveCoinsDialog::copyAmount);
// context menu signals
connect(ui->recentRequestsView, &QWidget::customContextMenuRequested, this, &ReceiveCoinsDialog::showMenu); connect(ui->recentRequestsView, &QWidget::customContextMenuRequested, this, &ReceiveCoinsDialog::showMenu);
connect(copyURIAction, &QAction::triggered, this, &ReceiveCoinsDialog::copyURI);
connect(copyAddressAction, &QAction::triggered, this, &ReceiveCoinsDialog::copyAddress);
connect(copyLabelAction, &QAction::triggered, this, &ReceiveCoinsDialog::copyLabel);
connect(copyMessageAction, &QAction::triggered, this, &ReceiveCoinsDialog::copyMessage);
connect(copyAmountAction, &QAction::triggered, this, &ReceiveCoinsDialog::copyAmount);
connect(ui->clearButton, &QPushButton::clicked, this, &ReceiveCoinsDialog::clear); connect(ui->clearButton, &QPushButton::clicked, this, &ReceiveCoinsDialog::clear);

@ -616,29 +616,14 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_
ui->peerWidget->setColumnWidth(PeerTableModel::Ping, PING_COLUMN_WIDTH); ui->peerWidget->setColumnWidth(PeerTableModel::Ping, PING_COLUMN_WIDTH);
ui->peerWidget->horizontalHeader()->setStretchLastSection(true); ui->peerWidget->horizontalHeader()->setStretchLastSection(true);
// create peer table context menu actions
QAction* disconnectAction = new QAction(tr("Disconnect"), this);
QAction* banAction1h = new QAction(ts.ban_for + " " + tr("1 hour"), this);
QAction* banAction24h = new QAction(ts.ban_for + " " + tr("1 day"), this);
QAction* banAction7d = new QAction(ts.ban_for + " " + tr("1 week"), this);
QAction* banAction365d = new QAction(ts.ban_for + " " + tr("1 year"), this);
// create peer table context menu // create peer table context menu
peersTableContextMenu = new QMenu(this); peersTableContextMenu = new QMenu(this);
peersTableContextMenu->addAction(disconnectAction); peersTableContextMenu->addAction(tr("Disconnect"), this, &RPCConsole::disconnectSelectedNode);
peersTableContextMenu->addAction(banAction1h); peersTableContextMenu->addAction(ts.ban_for + " " + tr("1 hour"), [this] { banSelectedNode(60 * 60); });
peersTableContextMenu->addAction(banAction24h); peersTableContextMenu->addAction(ts.ban_for + " " + tr("1 day"), [this] { banSelectedNode(60 * 60 * 24); });
peersTableContextMenu->addAction(banAction7d); peersTableContextMenu->addAction(ts.ban_for + " " + tr("1 week"), [this] { banSelectedNode(60 * 60 * 24 * 7); });
peersTableContextMenu->addAction(banAction365d); peersTableContextMenu->addAction(ts.ban_for + " " + tr("1 year"), [this] { banSelectedNode(60 * 60 * 24 * 365); });
connect(banAction1h, &QAction::triggered, [this] { banSelectedNode(60 * 60); });
connect(banAction24h, &QAction::triggered, [this] { banSelectedNode(60 * 60 * 24); });
connect(banAction7d, &QAction::triggered, [this] { banSelectedNode(60 * 60 * 24 * 7); });
connect(banAction365d, &QAction::triggered, [this] { banSelectedNode(60 * 60 * 24 * 365); });
// peer table context menu signals
connect(ui->peerWidget, &QTableView::customContextMenuRequested, this, &RPCConsole::showPeersTableContextMenu); connect(ui->peerWidget, &QTableView::customContextMenuRequested, this, &RPCConsole::showPeersTableContextMenu);
connect(disconnectAction, &QAction::triggered, this, &RPCConsole::disconnectSelectedNode);
// peer table signal handling - update peer details when selecting new node // peer table signal handling - update peer details when selecting new node
connect(ui->peerWidget->selectionModel(), &QItemSelectionModel::selectionChanged, this, &RPCConsole::updateDetailWidget); connect(ui->peerWidget->selectionModel(), &QItemSelectionModel::selectionChanged, this, &RPCConsole::updateDetailWidget);
@ -657,16 +642,10 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_
ui->banlistWidget->setColumnWidth(BanTableModel::Bantime, BANTIME_COLUMN_WIDTH); ui->banlistWidget->setColumnWidth(BanTableModel::Bantime, BANTIME_COLUMN_WIDTH);
ui->banlistWidget->horizontalHeader()->setStretchLastSection(true); ui->banlistWidget->horizontalHeader()->setStretchLastSection(true);
// create ban table context menu action
QAction* unbanAction = new QAction(tr("Unban"), this);
// create ban table context menu // create ban table context menu
banTableContextMenu = new QMenu(this); banTableContextMenu = new QMenu(this);
banTableContextMenu->addAction(unbanAction); banTableContextMenu->addAction(tr("Unban"), this, &RPCConsole::unbanSelectedNode);
// ban table context menu signals
connect(ui->banlistWidget, &QTableView::customContextMenuRequested, this, &RPCConsole::showBanTableContextMenu); connect(ui->banlistWidget, &QTableView::customContextMenuRequested, this, &RPCConsole::showBanTableContextMenu);
connect(unbanAction, &QAction::triggered, this, &RPCConsole::unbanSelectedNode);
// ban table signal handling - clear peer details when clicking a peer in the ban table // ban table signal handling - clear peer details when clicking a peer in the ban table
connect(ui->banlistWidget, &QTableView::clicked, this, &RPCConsole::clearSelectedNode); connect(ui->banlistWidget, &QTableView::clicked, this, &RPCConsole::clearSelectedNode);

@ -161,32 +161,21 @@ TransactionView::TransactionView(const PlatformStyle *platformStyle, QWidget *pa
transactionView->horizontalHeader()->setStretchLastSection(true); transactionView->horizontalHeader()->setStretchLastSection(true);
} }
// Actions
abandonAction = new QAction(tr("Abandon transaction"), this);
bumpFeeAction = new QAction(tr("Increase transaction fee"), this);
bumpFeeAction->setObjectName("bumpFeeAction");
copyAddressAction = new QAction(tr("Copy address"), this);
copyLabelAction = new QAction(tr("Copy label"), this);
QAction *copyAmountAction = new QAction(tr("Copy amount"), this);
QAction *copyTxIDAction = new QAction(tr("Copy transaction ID"), this);
QAction *copyTxHexAction = new QAction(tr("Copy raw transaction"), this);
QAction *copyTxPlainText = new QAction(tr("Copy full transaction details"), this);
QAction *editLabelAction = new QAction(tr("Edit address label"), this);
QAction *showDetailsAction = new QAction(tr("Show transaction details"), this);
contextMenu = new QMenu(this); contextMenu = new QMenu(this);
contextMenu->setObjectName("contextMenu"); contextMenu->setObjectName("contextMenu");
contextMenu->addAction(copyAddressAction); copyAddressAction = contextMenu->addAction(tr("Copy address"), this, &TransactionView::copyAddress);
contextMenu->addAction(copyLabelAction); copyLabelAction = contextMenu->addAction(tr("Copy label"), this, &TransactionView::copyLabel);
contextMenu->addAction(copyAmountAction); contextMenu->addAction(tr("Copy amount"), this, &TransactionView::copyAmount);
contextMenu->addAction(copyTxIDAction); contextMenu->addAction(tr("Copy transaction ID"), this, &TransactionView::copyTxID);
contextMenu->addAction(copyTxHexAction); contextMenu->addAction(tr("Copy raw transaction"), this, &TransactionView::copyTxHex);
contextMenu->addAction(copyTxPlainText); contextMenu->addAction(tr("Copy full transaction details"), this, &TransactionView::copyTxPlainText);
contextMenu->addAction(showDetailsAction); contextMenu->addAction(tr("Show transaction details"), this, &TransactionView::showDetails);
contextMenu->addSeparator(); contextMenu->addSeparator();
contextMenu->addAction(bumpFeeAction); bumpFeeAction = contextMenu->addAction(tr("Increase transaction fee"));
contextMenu->addAction(abandonAction); GUIUtil::ExceptionSafeConnect(bumpFeeAction, &QAction::triggered, this, &TransactionView::bumpFee);
contextMenu->addAction(editLabelAction); bumpFeeAction->setObjectName("bumpFeeAction");
abandonAction = contextMenu->addAction(tr("Abandon transaction"), this, &TransactionView::abandonTx);
contextMenu->addAction(tr("Edit address label"), this, &TransactionView::editLabel);
connect(dateWidget, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, &TransactionView::chooseDate); 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(typeWidget, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, &TransactionView::chooseType);
@ -199,16 +188,6 @@ TransactionView::TransactionView(const PlatformStyle *platformStyle, QWidget *pa
connect(transactionView, &QTableView::doubleClicked, this, &TransactionView::doubleClicked); connect(transactionView, &QTableView::doubleClicked, this, &TransactionView::doubleClicked);
connect(transactionView, &QTableView::customContextMenuRequested, this, &TransactionView::contextualMenu); connect(transactionView, &QTableView::customContextMenuRequested, this, &TransactionView::contextualMenu);
GUIUtil::ExceptionSafeConnect(bumpFeeAction, &QAction::triggered, this, &TransactionView::bumpFee);
connect(abandonAction, &QAction::triggered, this, &TransactionView::abandonTx);
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);
connect(editLabelAction, &QAction::triggered, this, &TransactionView::editLabel);
connect(showDetailsAction, &QAction::triggered, this, &TransactionView::showDetails);
// Double-clicking on a transaction on the transaction history page shows details // Double-clicking on a transaction on the transaction history page shows details
connect(this, &TransactionView::doubleClicked, this, &TransactionView::showDetails); connect(this, &TransactionView::doubleClicked, this, &TransactionView::showDetails);
// Highlight transaction after fee bump // Highlight transaction after fee bump

Loading…
Cancel
Save