Skip to content

Commit 16781e1

Browse files
committed
Merge bitcoin-core/gui#517: refactor, qt: Use std::chrono for parameters of QTimer methods
51250b0 refactor, qt: Use std::chrono for input_filter_delay constant (Hennadii Stepanov) f3bdc14 refactor, qt: Add SHUTDOWN_POLLING_DELAY constant (Hennadii Stepanov) 0e193de refactor, qt: Use std::chrono for non-zero arguments in QTimer methods (Hennadii Stepanov) 6f0da95 refactor, qt: Use std::chrono in ConfirmMessage parameter (Hennadii Stepanov) 33d520a refactor, qt: Use std::chrono for MODEL_UPDATE_DELAY constant (Hennadii Stepanov) Pull request description: Since Qt 5.8 `QTimer` methods have overloads that accept `std::chrono::milliseconds` arguments: - [`QTimer::singleShot`](https://doc.qt.io/archives/qt-5.9/qtimer.html#singleShot-8) - [`QTimer::start`](https://doc.qt.io/archives/qt-5.9/qtimer.html#start-2) ACKs for top commit: promag: Code review ACK 51250b0. shaavan: reACK 51250b0 Tree-SHA512: aa843bb2322a84c0c2bb113d3b48d7bf02d7f09a770779dcde312c32887f973ef9445cdef42f39edaa599ff0f3d0457454f6153aa130efadd989e413d39c6062
2 parents e0ae541 + 51250b0 commit 16781e1

11 files changed

+39
-17
lines changed

src/qt/bitcoin.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#endif // ENABLE_WALLET
4242

4343
#include <boost/signals2/connection.hpp>
44+
#include <chrono>
4445
#include <memory>
4546

4647
#include <QApplication>
@@ -412,10 +413,10 @@ void BitcoinApplication::initializeResult(bool success, interfaces::BlockAndHead
412413
connect(paymentServer, &PaymentServer::message, [this](const QString& title, const QString& message, unsigned int style) {
413414
window->message(title, message, style);
414415
});
415-
QTimer::singleShot(100, paymentServer, &PaymentServer::uiReady);
416+
QTimer::singleShot(100ms, paymentServer, &PaymentServer::uiReady);
416417
}
417418
#endif
418-
pollShutdownTimer->start(200);
419+
pollShutdownTimer->start(SHUTDOWN_POLLING_DELAY);
419420
} else {
420421
Q_EMIT splashFinished(); // Make sure splash screen doesn't stick around during shutdown
421422
requestShutdown();

src/qt/clientmodel.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <netbase.h>
1818
#include <util/system.h>
1919
#include <util/threadnames.h>
20+
#include <util/time.h>
2021
#include <validation.h>
2122

2223
#include <stdint.h>
@@ -288,7 +289,7 @@ static void BlockTipChanged(ClientModel* clientmodel, SynchronizationState sync_
288289
const bool throttle = (sync_state != SynchronizationState::POST_INIT && !fHeader) || sync_state == SynchronizationState::INIT_REINDEX;
289290
const int64_t now = throttle ? GetTimeMillis() : 0;
290291
int64_t& nLastUpdateNotification = fHeader ? nLastHeaderTipUpdateNotification : nLastBlockTipUpdateNotification;
291-
if (throttle && now < nLastUpdateNotification + MODEL_UPDATE_DELAY) {
292+
if (throttle && now < nLastUpdateNotification + count_milliseconds(MODEL_UPDATE_DELAY)) {
292293
return;
293294
}
294295

src/qt/guiconstants.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@
55
#ifndef BITCOIN_QT_GUICONSTANTS_H
66
#define BITCOIN_QT_GUICONSTANTS_H
77

8+
#include <chrono>
89
#include <cstdint>
910

10-
/* Milliseconds between model updates */
11-
static const int MODEL_UPDATE_DELAY = 250;
11+
using namespace std::chrono_literals;
12+
13+
/* A delay between model updates */
14+
static constexpr auto MODEL_UPDATE_DELAY{250ms};
15+
16+
/* A delay between shutdown pollings */
17+
static constexpr auto SHUTDOWN_POLLING_DELAY{200ms};
1218

1319
/* AskPassphraseDialog -- Maximum passphrase length */
1420
static const int MAX_PASSPHRASE_SIZE = 1024;

src/qt/optionsdialog.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include <netbase.h>
2020
#include <txdb.h> // for -dbcache defaults
2121

22+
#include <chrono>
23+
2224
#include <QDataWidgetMapper>
2325
#include <QDir>
2426
#include <QIntValidator>
@@ -362,7 +364,7 @@ void OptionsDialog::showRestartWarning(bool fPersistent)
362364
ui->statusLabel->setText(tr("This change would require a client restart."));
363365
// clear non-persistent status label after 10 seconds
364366
// Todo: should perhaps be a class attribute, if we extend the use of statusLabel
365-
QTimer::singleShot(10000, this, &OptionsDialog::clearStatusLabel);
367+
QTimer::singleShot(10s, this, &OptionsDialog::clearStatusLabel);
366368
}
367369
}
368370

src/qt/sendcoinsdialog.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@
2424
#include <node/ui_interface.h>
2525
#include <policy/fees.h>
2626
#include <txmempool.h>
27+
#include <validation.h>
2728
#include <wallet/coincontrol.h>
2829
#include <wallet/fees.h>
2930
#include <wallet/wallet.h>
3031

31-
#include <validation.h>
32+
#include <chrono>
3233

3334
#include <QFontMetrics>
3435
#include <QScrollBar>
@@ -1063,7 +1064,7 @@ SendConfirmationDialog::SendConfirmationDialog(const QString& title, const QStri
10631064
int SendConfirmationDialog::exec()
10641065
{
10651066
updateButtons();
1066-
countDownTimer.start(1000);
1067+
countDownTimer.start(1s);
10671068
return QMessageBox::exec();
10681069
}
10691070

src/qt/test/addressbooktests.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include <wallet/wallet.h>
2121
#include <walletinitinterface.h>
2222

23+
#include <chrono>
24+
2325
#include <QApplication>
2426
#include <QTimer>
2527
#include <QMessageBox>
@@ -47,7 +49,7 @@ void EditAddressAndSubmit(
4749
dialog->findChild<QLineEdit*>("labelEdit")->setText(label);
4850
dialog->findChild<QValidatedLineEdit*>("addressEdit")->setText(address);
4951

50-
ConfirmMessage(&warning_text, 5);
52+
ConfirmMessage(&warning_text, 5ms);
5153
dialog->accept();
5254
QCOMPARE(warning_text, expected_msg);
5355
}

src/qt/test/util.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5+
#include <chrono>
6+
57
#include <QApplication>
68
#include <QMessageBox>
79
#include <QPushButton>
810
#include <QString>
911
#include <QTimer>
1012
#include <QWidget>
1113

12-
void ConfirmMessage(QString* text, int msec)
14+
void ConfirmMessage(QString* text, std::chrono::milliseconds msec)
1315
{
1416
QTimer::singleShot(msec, [text]() {
1517
for (QWidget* widget : QApplication::topLevelWidgets()) {

src/qt/test/util.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@
55
#ifndef BITCOIN_QT_TEST_UTIL_H
66
#define BITCOIN_QT_TEST_UTIL_H
77

8-
#include <QString>
8+
#include <chrono>
9+
10+
QT_BEGIN_NAMESPACE
11+
class QString;
12+
QT_END_NAMESPACE
913

1014
/**
1115
* Press "Ok" button in message box dialog.
1216
*
1317
* @param text - Optionally store dialog text.
1418
* @param msec - Number of milliseconds to pause before triggering the callback.
1519
*/
16-
void ConfirmMessage(QString* text = nullptr, int msec = 0);
20+
void ConfirmMessage(QString* text, std::chrono::milliseconds msec);
1721

1822
#endif // BITCOIN_QT_TEST_UTIL_H

src/qt/test/wallettests.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <qt/recentrequeststablemodel.h>
2727
#include <qt/receiverequestdialog.h>
2828

29+
#include <chrono>
2930
#include <memory>
3031

3132
#include <QAbstractButton>
@@ -121,7 +122,7 @@ void BumpFee(TransactionView& view, const uint256& txid, bool expectDisabled, st
121122
if (expectError.empty()) {
122123
ConfirmSend(&text, cancel);
123124
} else {
124-
ConfirmMessage(&text);
125+
ConfirmMessage(&text, 0ms);
125126
}
126127
action->trigger();
127128
QVERIFY(text.indexOf(QString::fromStdString(expectError)) != -1);

src/qt/transactionview.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include <node/ui_interface.h>
2121

22+
#include <chrono>
2223
#include <optional>
2324

2425
#include <QApplication>
@@ -114,8 +115,8 @@ TransactionView::TransactionView(const PlatformStyle *platformStyle, QWidget *pa
114115
amountWidget->setValidator(amountValidator);
115116
hlayout->addWidget(amountWidget);
116117

117-
// Delay before filtering transactions in ms
118-
static const int input_filter_delay = 200;
118+
// Delay before filtering transactions
119+
static constexpr auto input_filter_delay{200ms};
119120

120121
QTimer* amount_typing_delay = new QTimer(this);
121122
amount_typing_delay->setSingleShot(true);

0 commit comments

Comments
 (0)