Skip to content

Commit 8d7125f

Browse files
committed
Merge #257: refactor: Use template function qOverload in signal-slot connections
cdbc2bd qt: Use template function qOverload in signal-slot connections (Hennadii Stepanov) Pull request description: A nice template function [`qOverload`](https://doc.qt.io/qt-5/qtglobal.html#qOverload) is available for us now (bitcoin/bitcoin#20413, bitcoin/bitcoin#21286). Its usage makes code much more readable. This PR does not change behavior. ACKs for top commit: Talkless: utACK cdbc2bd. promag: Code review ACK cdbc2bd. Tree-SHA512: 72002aa646b1a79bab62d498825b3f245dc7ebdc189280f8bd3b4076e1bb50be8802c02bc872ff6f70c1ea81faec66d3bec36471119dd98c9e70d87b990396ae
2 parents d8ae29e + cdbc2bd commit 8d7125f

9 files changed

+20
-20
lines changed

src/qt/bitcoinamountfield.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ BitcoinAmountField::BitcoinAmountField(QWidget *parent) :
239239

240240
// If one if the widgets changes, the combined content changes as well
241241
connect(amount, &AmountSpinBox::valueChanged, this, &BitcoinAmountField::valueChanged);
242-
connect(unit, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &BitcoinAmountField::unitChanged);
242+
connect(unit, qOverload<int>(&QComboBox::currentIndexChanged), this, &BitcoinAmountField::unitChanged);
243243

244244
// Set default based on configuration
245245
unitChanged(unit->currentIndex());

src/qt/bitcoingui.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ void BitcoinGUI::createToolBars()
561561

562562
m_wallet_selector = new QComboBox();
563563
m_wallet_selector->setSizeAdjustPolicy(QComboBox::AdjustToContents);
564-
connect(m_wallet_selector, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &BitcoinGUI::setCurrentWalletBySelectorIndex);
564+
connect(m_wallet_selector, qOverload<int>(&QComboBox::currentIndexChanged), this, &BitcoinGUI::setCurrentWalletBySelectorIndex);
565565

566566
m_wallet_selector_label = new QLabel();
567567
m_wallet_selector_label->setText(tr("Wallet:") + " ");

src/qt/intro.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ Intro::Intro(QWidget *parent, int64_t blockchain_size_gb, int64_t chain_state_si
155155
UpdatePruneLabels(prune_checked);
156156
UpdateFreeSpaceLabel();
157157
});
158-
connect(ui->pruneGB, QOverload<int>::of(&QSpinBox::valueChanged), [this](int prune_GB) {
158+
connect(ui->pruneGB, qOverload<int>(&QSpinBox::valueChanged), [this](int prune_GB) {
159159
m_prune_target_gb = prune_GB;
160160
UpdatePruneLabels(ui->prune->isChecked());
161161
UpdateFreeSpaceLabel();

src/qt/optionsdialog.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,17 +197,17 @@ void OptionsDialog::setModel(OptionsModel *_model)
197197
/* Main */
198198
connect(ui->prune, &QCheckBox::clicked, this, &OptionsDialog::showRestartWarning);
199199
connect(ui->prune, &QCheckBox::clicked, this, &OptionsDialog::togglePruneWarning);
200-
connect(ui->pruneSize, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &OptionsDialog::showRestartWarning);
201-
connect(ui->databaseCache, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &OptionsDialog::showRestartWarning);
202-
connect(ui->threadsScriptVerif, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &OptionsDialog::showRestartWarning);
200+
connect(ui->pruneSize, qOverload<int>(&QSpinBox::valueChanged), this, &OptionsDialog::showRestartWarning);
201+
connect(ui->databaseCache, qOverload<int>(&QSpinBox::valueChanged), this, &OptionsDialog::showRestartWarning);
202+
connect(ui->threadsScriptVerif, qOverload<int>(&QSpinBox::valueChanged), this, &OptionsDialog::showRestartWarning);
203203
/* Wallet */
204204
connect(ui->spendZeroConfChange, &QCheckBox::clicked, this, &OptionsDialog::showRestartWarning);
205205
/* Network */
206206
connect(ui->allowIncoming, &QCheckBox::clicked, this, &OptionsDialog::showRestartWarning);
207207
connect(ui->connectSocks, &QCheckBox::clicked, this, &OptionsDialog::showRestartWarning);
208208
connect(ui->connectSocksTor, &QCheckBox::clicked, this, &OptionsDialog::showRestartWarning);
209209
/* Display */
210-
connect(ui->lang, static_cast<void (QValueComboBox::*)()>(&QValueComboBox::valueChanged), [this]{ showRestartWarning(); });
210+
connect(ui->lang, qOverload<>(&QValueComboBox::valueChanged), [this]{ showRestartWarning(); });
211211
connect(ui->thirdPartyTxUrls, &QLineEdit::textChanged, [this]{ showRestartWarning(); });
212212
}
213213

src/qt/qvaluecombobox.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
QValueComboBox::QValueComboBox(QWidget *parent) :
88
QComboBox(parent), role(Qt::UserRole)
99
{
10-
connect(this, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &QValueComboBox::handleSelectionChanged);
10+
connect(this, qOverload<int>(&QComboBox::currentIndexChanged), this, &QValueComboBox::handleSelectionChanged);
1111
}
1212

1313
QVariant QValueComboBox::value() const

src/qt/rpcconsole.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,7 @@ void RPCConsole::startExecutor()
959959
executor->moveToThread(&thread);
960960

961961
// Replies from executor object must go to this object
962-
connect(executor, &RPCExecutor::reply, this, static_cast<void (RPCConsole::*)(int, const QString&)>(&RPCConsole::message));
962+
connect(executor, &RPCExecutor::reply, this, qOverload<int, const QString&>(&RPCConsole::message));
963963

964964
// Requests from this object must go to executor
965965
connect(this, &RPCConsole::cmdRequest, executor, &RPCExecutor::request);

src/qt/sendcoinsdialog.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,15 @@ void SendCoinsDialog::setModel(WalletModel *_model)
173173
for (const int n : confTargets) {
174174
ui->confTargetSelector->addItem(tr("%1 (%2 blocks)").arg(GUIUtil::formatNiceTimeOffset(n*Params().GetConsensus().nPowTargetSpacing)).arg(n));
175175
}
176-
connect(ui->confTargetSelector, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &SendCoinsDialog::updateSmartFeeLabel);
177-
connect(ui->confTargetSelector, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &SendCoinsDialog::coinControlUpdateLabels);
176+
connect(ui->confTargetSelector, qOverload<int>(&QComboBox::currentIndexChanged), this, &SendCoinsDialog::updateSmartFeeLabel);
177+
connect(ui->confTargetSelector, qOverload<int>(&QComboBox::currentIndexChanged), this, &SendCoinsDialog::coinControlUpdateLabels);
178178

179179
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
180180
connect(ui->groupFee, &QButtonGroup::idClicked, this, &SendCoinsDialog::updateFeeSectionControls);
181181
connect(ui->groupFee, &QButtonGroup::idClicked, this, &SendCoinsDialog::coinControlUpdateLabels);
182182
#else
183-
connect(ui->groupFee, static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked), this, &SendCoinsDialog::updateFeeSectionControls);
184-
connect(ui->groupFee, static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked), this, &SendCoinsDialog::coinControlUpdateLabels);
183+
connect(ui->groupFee, qOverload<int>(&QButtonGroup::buttonClicked), this, &SendCoinsDialog::updateFeeSectionControls);
184+
connect(ui->groupFee, qOverload<int>(&QButtonGroup::buttonClicked), this, &SendCoinsDialog::coinControlUpdateLabels);
185185
#endif
186186

187187
connect(ui->customFee, &BitcoinAmountField::valueChanged, this, &SendCoinsDialog::coinControlUpdateLabels);

src/qt/transactionview.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,12 @@ TransactionView::TransactionView(const PlatformStyle *platformStyle, QWidget *pa
177177
abandonAction = contextMenu->addAction(tr("Abandon transaction"), this, &TransactionView::abandonTx);
178178
contextMenu->addAction(tr("Edit address label"), this, &TransactionView::editLabel);
179179

180-
connect(dateWidget, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, &TransactionView::chooseDate);
181-
connect(typeWidget, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, &TransactionView::chooseType);
182-
connect(watchOnlyWidget, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, &TransactionView::chooseWatchonly);
183-
connect(amountWidget, &QLineEdit::textChanged, amount_typing_delay, static_cast<void (QTimer::*)()>(&QTimer::start));
180+
connect(dateWidget, qOverload<int>(&QComboBox::activated), this, &TransactionView::chooseDate);
181+
connect(typeWidget, qOverload<int>(&QComboBox::activated), this, &TransactionView::chooseType);
182+
connect(watchOnlyWidget, qOverload<int>(&QComboBox::activated), this, &TransactionView::chooseWatchonly);
183+
connect(amountWidget, &QLineEdit::textChanged, amount_typing_delay, qOverload<>(&QTimer::start));
184184
connect(amount_typing_delay, &QTimer::timeout, this, &TransactionView::changedAmount);
185-
connect(search_widget, &QLineEdit::textChanged, prefix_typing_delay, static_cast<void (QTimer::*)()>(&QTimer::start));
185+
connect(search_widget, &QLineEdit::textChanged, prefix_typing_delay, qOverload<>(&QTimer::start));
186186
connect(prefix_typing_delay, &QTimer::timeout, this, &TransactionView::changedSearch);
187187

188188
connect(transactionView, &QTableView::doubleClicked, this, &TransactionView::doubleClicked);

src/qt/walletview.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent):
7171

7272
connect(overviewPage, &OverviewPage::transactionClicked, this, &WalletView::transactionClicked);
7373
// Clicking on a transaction on the overview pre-selects the transaction on the transaction history page
74-
connect(overviewPage, &OverviewPage::transactionClicked, transactionView, static_cast<void (TransactionView::*)(const QModelIndex&)>(&TransactionView::focusTransaction));
74+
connect(overviewPage, &OverviewPage::transactionClicked, transactionView, qOverload<const QModelIndex&>(&TransactionView::focusTransaction));
7575

7676
connect(overviewPage, &OverviewPage::outOfSyncWarningClicked, this, &WalletView::requestedSyncWarningInfo);
7777

7878
connect(sendCoinsPage, &SendCoinsDialog::coinsSent, this, &WalletView::coinsSent);
7979
// Highlight transaction after send
80-
connect(sendCoinsPage, &SendCoinsDialog::coinsSent, transactionView, static_cast<void (TransactionView::*)(const uint256&)>(&TransactionView::focusTransaction));
80+
connect(sendCoinsPage, &SendCoinsDialog::coinsSent, transactionView, qOverload<const uint256&>(&TransactionView::focusTransaction));
8181

8282
// Clicking on "Export" allows to export the transaction list
8383
connect(exportButton, &QPushButton::clicked, transactionView, &TransactionView::exportClicked);

0 commit comments

Comments
 (0)