From bb976499bfeccdc5184564fef878c4a0ffbd7f7f Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Thu, 19 Nov 2020 19:04:11 +0100 Subject: [PATCH] Merge bitcoin-core/gui#46: refactor: Fix deprecation warnings when building against Qt 5.15 705c1f0648c72aa97e0ee699ff9a3da23fc9bd61 qt, refactor: Fix 'buttonClicked is deprecated' warnings (Hennadii Stepanov) c2f4e5ea1d6f01713ac69aaf6018884028aa55bd qt, refactor: Fix 'split is deprecated' warnings (Hennadii Stepanov) 8e12d6996116e786e928077b22d9f47cee27319e qt, refactor: Fix 'QFlags is deprecated' warnings (Hennadii Stepanov) fa5749c805878304c107bcae0ae5ffa401dc7c4d qt, refactor: Fix 'pixmap is deprecated' warnings (Hennadii Stepanov) b02264cb5dfcef50eec8a6346471cbaa25370e00 qt, refactor: Fix 'QDateTime is deprecated' warnings (Hennadii Stepanov) Pull request description: [What's New in Qt 5.15](https://doc.qt.io/qt-5/whatsnew515.html#deprecated-modules): > To help preparing for the transition to Qt 6, numerous classes and member functions that will be removed from Qt 6.0 have been marked as deprecated in the Qt 5.15 release. Fixes #36 ACKs for top commit: jonasschnelli: utACK 705c1f0648c72aa97e0ee699ff9a3da23fc9bd61 promag: Tested ACK 705c1f0648c72aa97e0ee699ff9a3da23fc9bd61 on macos with Apple clang version 11.0.3 (clang-1103.0.32.62) and brew qt 5.15.1. Tree-SHA512: 29e00535b4583ceec0dfb29612e86ee29bdea13651b548c6d22167917a4a10464af49160a12b05151030699f690f437ebb9c4ae9f130f66a722415222165b44f --- src/qt/bitcoin.cpp | 2 +- src/qt/bitcoingui.cpp | 2 +- src/qt/bitcoingui.h | 1 + src/qt/guiutil.cpp | 31 +++++++++++++++++++++++ src/qt/guiutil.h | 40 +++++++++++++++++++++++++++++- src/qt/optionsdialog.cpp | 4 +++ src/qt/optionsmodel.cpp | 2 +- src/qt/overviewpage.cpp | 1 + src/qt/paymentserver.cpp | 1 - src/qt/qrimagewidget.cpp | 13 ++++------ src/qt/rpcconsole.cpp | 5 ++++ src/qt/rpcconsole.h | 1 + src/qt/sendcoinsdialog.cpp | 7 ++++++ src/qt/signverifymessagedialog.cpp | 4 +++ src/qt/splashscreen.cpp | 4 +-- src/qt/splashscreen.h | 2 +- src/qt/transactionview.cpp | 18 +++++++------- 17 files changed, 113 insertions(+), 25 deletions(-) diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index 54a2e1160acde..ea773505eab3c 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -254,7 +254,7 @@ void BitcoinApplication::createWindow(const NetworkStyle *networkStyle) void BitcoinApplication::createSplashScreen(const NetworkStyle *networkStyle) { - SplashScreen *splash = new SplashScreen(m_node, nullptr, networkStyle); + SplashScreen *splash = new SplashScreen(m_node, networkStyle); // We don't hold a direct pointer to the splash screen after creation, but the splash // screen will take care of deleting itself when finish() happens. splash->show(); diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 641f0b25db166..5da6234d34e73 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -1858,7 +1858,7 @@ void BitcoinGUI::updateProxyIcon() bool proxy_enabled = clientModel->getProxyInfo(ip_port); if (proxy_enabled) { - if (labelProxyIcon->pixmap() == nullptr) { + if (!GUIUtil::HasPixmap(labelProxyIcon)) { QString ip_port_q = QString::fromStdString(ip_port); labelProxyIcon->setPixmap(GUIUtil::getIcon("proxy", GUIUtil::ThemedColor::GREEN).pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE)); labelProxyIcon->setToolTip(tr("Proxy is enabled: %1").arg(ip_port_q)); diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 372e0a7e4e4b0..7439c9774734c 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -49,6 +49,7 @@ QT_BEGIN_NAMESPACE class QAction; class QButtonGroup; class QComboBox; +class QDateTime; class QMenu; class QProgressBar; class QProgressDialog; diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index f436773ff9f94..f7aca14f0c509 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -1901,4 +1901,35 @@ void LogQtInfo() } } +QDateTime StartOfDay(const QDate& date) +{ +#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) + return date.startOfDay(); +#else + return QDateTime(date); +#endif +} + +bool HasPixmap(const QLabel* label) +{ +#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) + return !label->pixmap(Qt::ReturnByValue).isNull(); +#else + return label->pixmap() != nullptr; +#endif +} + +QImage GetImage(const QLabel* label) +{ + if (!HasPixmap(label)) { + return QImage(); + } + +#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) + return label->pixmap(Qt::ReturnByValue).toImage(); +#else + return label->pixmap()->toImage(); +#endif +} + } // namespace GUIUtil diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h index 5ef5b96a0cc59..d5c7b45a866ff 100644 --- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -473,7 +473,7 @@ namespace GUIUtil /** * Returns the distance in pixels appropriate for drawing a subsequent character after text. * - * In Qt 5.12 and before the QFontMetrics::width() is used and it is deprecated since Qt 13.0. + * In Qt 5.12 and before the QFontMetrics::width() is used and it is deprecated since Qt 5.13. * In Qt 5.11 the QFontMetrics::horizontalAdvance() was introduced. */ int TextWidth(const QFontMetrics& fm, const QString& text); @@ -482,6 +482,44 @@ namespace GUIUtil * Writes to debug.log short info about the used Qt and the host system. */ void LogQtInfo(); + + /** + * Returns the start-moment of the day in local time. + * + * QDateTime::QDateTime(const QDate& date) is deprecated since Qt 5.15. + * QDate::startOfDay() was introduced in Qt 5.14. + */ + QDateTime StartOfDay(const QDate& date); + + /** + * Returns true if pixmap has been set. + * + * QPixmap* QLabel::pixmap() is deprecated since Qt 5.15. + */ + bool HasPixmap(const QLabel* label); + QImage GetImage(const QLabel* label); + + /** + * Splits the string into substrings wherever separator occurs, and returns + * the list of those strings. Empty strings do not appear in the result. + * + * QString::split() signature differs in different Qt versions: + * - QString::SplitBehavior is deprecated since Qt 5.15 + * - Qt::SplitBehavior was introduced in Qt 5.14 + * If {QString|Qt}::SkipEmptyParts behavior is required, use this + * function instead of QString::split(). + */ + template + QStringList SplitSkipEmptyParts(const QString& string, const SeparatorType& separator) + { + #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) + return string.split(separator, Qt::SkipEmptyParts); + #else + return string.split(separator, QString::SkipEmptyParts); + #endif + } + + } // namespace GUIUtil #endif // BITCOIN_QT_GUIUTIL_H diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp index b74646a95ead7..9524d682baf99 100644 --- a/src/qt/optionsdialog.cpp +++ b/src/qt/optionsdialog.cpp @@ -125,7 +125,11 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) : pageButtons->addButton(ui->btnDisplay, pageButtons->buttons().size()); pageButtons->addButton(ui->btnAppearance, pageButtons->buttons().size()); +#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) + connect(pageButtons, &QButtonGroup::idClicked, this, &OptionsDialog::showPage); +#else connect(pageButtons, QOverload::of(&QButtonGroup::buttonClicked), this, &OptionsDialog::showPage); +#endif showPage(0); diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index 5266c83ee4804..d5b092ea5bf50 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -367,7 +367,7 @@ static ProxySetting GetProxySetting(QSettings &settings, const QString &name) return default_val; } // contains IP at index 0 and port at index 1 - QStringList ip_port = settings.value(name).toString().split(":", QString::SkipEmptyParts); + QStringList ip_port = GUIUtil::SplitSkipEmptyParts(settings.value(name).toString(), ":"); if (ip_port.size() == 2) { return {true, ip_port.at(0), ip_port.at(1)}; } else { // Invalid: return default diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index 0a8966fa1c08c..1808fd8d7f994 100644 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include #include diff --git a/src/qt/paymentserver.cpp b/src/qt/paymentserver.cpp index ee784f12f82b8..55a92ebe00919 100644 --- a/src/qt/paymentserver.cpp +++ b/src/qt/paymentserver.cpp @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include diff --git a/src/qt/qrimagewidget.cpp b/src/qt/qrimagewidget.cpp index 531cccc5a73e2..7f6d5312727b5 100644 --- a/src/qt/qrimagewidget.cpp +++ b/src/qt/qrimagewidget.cpp @@ -105,15 +105,12 @@ bool QRImageWidget::setQR(const QString& data, const QString& text) QImage QRImageWidget::exportImage() { - if(!pixmap()) - return QImage(); - return pixmap()->toImage(); + return GUIUtil::GetImage(this); } void QRImageWidget::mousePressEvent(QMouseEvent *event) { - if(event->button() == Qt::LeftButton && pixmap()) - { + if (event->button() == Qt::LeftButton && GUIUtil::HasPixmap(this)) { event->accept(); QMimeData *mimeData = new QMimeData; mimeData->setImageData(exportImage()); @@ -128,7 +125,7 @@ void QRImageWidget::mousePressEvent(QMouseEvent *event) void QRImageWidget::saveImage() { - if(!pixmap()) + if (!GUIUtil::HasPixmap(this)) return; QString fn = GUIUtil::getSaveFileName(this, tr("Save QR Code"), QString(), tr("PNG Image (*.png)"), nullptr); if (!fn.isEmpty()) @@ -139,14 +136,14 @@ void QRImageWidget::saveImage() void QRImageWidget::copyImage() { - if(!pixmap()) + if (!GUIUtil::HasPixmap(this)) return; QApplication::clipboard()->setImage(exportImage()); } void QRImageWidget::contextMenuEvent(QContextMenuEvent *event) { - if(!pixmap()) + if (!GUIUtil::HasPixmap(this)) return; contextMenu->exec(event->globalPos()); } diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 7eab9f8457b3c..7c423b51639ef 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -515,7 +516,11 @@ RPCConsole::RPCConsole(interfaces::Node& node, QWidget* parent, Qt::WindowFlags pageButtons->addButton(ui->btnNetTraffic, pageButtons->buttons().size()); pageButtons->addButton(ui->btnPeers, pageButtons->buttons().size()); pageButtons->addButton(ui->btnRepair, pageButtons->buttons().size()); +#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) + connect(pageButtons, &QButtonGroup::idClicked, this, &RPCConsole::showPage); +#else connect(pageButtons, QOverload::of(&QButtonGroup::buttonClicked), this, &RPCConsole::showPage); +#endif showPage(ToUnderlying(TabTypes::INFO)); diff --git a/src/qt/rpcconsole.h b/src/qt/rpcconsole.h index a3019d528dca5..febc46c9b17eb 100644 --- a/src/qt/rpcconsole.h +++ b/src/qt/rpcconsole.h @@ -30,6 +30,7 @@ namespace Ui { QT_BEGIN_NAMESPACE class QButtonGroup; +class QDateTime; class QMenu; class QItemSelection; QT_END_NAMESPACE diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp index 27b631de700d5..c5f14b5506a2d 100644 --- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -205,8 +205,15 @@ void SendCoinsDialog::setModel(WalletModel *_model) } connect(ui->confTargetSelector, static_cast(&QComboBox::currentIndexChanged), this, &SendCoinsDialog::updateSmartFeeLabel); connect(ui->confTargetSelector, static_cast(&QComboBox::currentIndexChanged), this, &SendCoinsDialog::coinControlUpdateLabels); + +#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) + connect(ui->groupFee, &QButtonGroup::idClicked, this, &SendCoinsDialog::updateFeeSectionControls); + connect(ui->groupFee, &QButtonGroup::idClicked, this, &SendCoinsDialog::coinControlUpdateLabels); +#else connect(ui->groupFee, static_cast(&QButtonGroup::buttonClicked), this, &SendCoinsDialog::updateFeeSectionControls); connect(ui->groupFee, static_cast(&QButtonGroup::buttonClicked), this, &SendCoinsDialog::coinControlUpdateLabels); +#endif + connect(ui->customFee, &BitcoinAmountField::valueChanged, this, &SendCoinsDialog::coinControlUpdateLabels); CAmount requiredFee = model->wallet().getRequiredFee(1000); ui->customFee->SetMinValue(requiredFee); diff --git a/src/qt/signverifymessagedialog.cpp b/src/qt/signverifymessagedialog.cpp index 6b0fd0fbea9c2..3b7d0ef801471 100644 --- a/src/qt/signverifymessagedialog.cpp +++ b/src/qt/signverifymessagedialog.cpp @@ -31,7 +31,11 @@ SignVerifyMessageDialog::SignVerifyMessageDialog(QWidget* parent) : pageButtons = new QButtonGroup(this); pageButtons->addButton(ui->btnSignMessage, pageButtons->buttons().size()); pageButtons->addButton(ui->btnVerifyMessage, pageButtons->buttons().size()); +#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) + connect(pageButtons, &QButtonGroup::idClicked, this, &SignVerifyMessageDialog::showPage); +#else connect(pageButtons, QOverload::of(&QButtonGroup::buttonClicked), this, &SignVerifyMessageDialog::showPage); +#endif // These icons are needed on Mac also GUIUtil::setIcon(ui->addressBookButton_SM, "address-book"); diff --git a/src/qt/splashscreen.cpp b/src/qt/splashscreen.cpp index 1e56981a08ce6..43f84f79e5097 100644 --- a/src/qt/splashscreen.cpp +++ b/src/qt/splashscreen.cpp @@ -28,8 +28,8 @@ #include -SplashScreen::SplashScreen(interfaces::Node& node, Qt::WindowFlags f, const NetworkStyle *networkStyle) : - QWidget(nullptr, f), curAlignment(0), m_node(node) +SplashScreen::SplashScreen(interfaces::Node& node, const NetworkStyle *networkStyle) : + QWidget(), curAlignment(0), m_node(node) { // transparent background diff --git a/src/qt/splashscreen.h b/src/qt/splashscreen.h index ad6019a4304b2..86858dd84825a 100644 --- a/src/qt/splashscreen.h +++ b/src/qt/splashscreen.h @@ -28,7 +28,7 @@ class SplashScreen : public QWidget Q_OBJECT public: - explicit SplashScreen(interfaces::Node& node, Qt::WindowFlags f, const NetworkStyle *networkStyle); + explicit SplashScreen(interfaces::Node& node, const NetworkStyle *networkStyle); ~SplashScreen(); protected: diff --git a/src/qt/transactionview.cpp b/src/qt/transactionview.cpp index 00a86857c76ec..c4fa4a24ebf80 100644 --- a/src/qt/transactionview.cpp +++ b/src/qt/transactionview.cpp @@ -241,7 +241,7 @@ void TransactionView::setModel(WalletModel *_model) if (_model->getOptionsModel()) { // Add third party transaction URLs to context menu - QStringList listUrls = _model->getOptionsModel()->getThirdPartyTxUrls().split("|", QString::SkipEmptyParts); + QStringList listUrls = GUIUtil::SplitSkipEmptyParts(_model->getOptionsModel()->getThirdPartyTxUrls(), "|"); for (int i = 0; i < listUrls.size(); ++i) { QString url = listUrls[i].trimmed(); @@ -289,30 +289,30 @@ void TransactionView::chooseDate(int idx) break; case Today: transactionProxyModel->setDateRange( - QDateTime(current), + GUIUtil::StartOfDay(current), TransactionFilterProxy::MAX_DATE); break; case ThisWeek: { // Find last Monday QDate startOfWeek = current.addDays(-(current.dayOfWeek()-1)); transactionProxyModel->setDateRange( - QDateTime(startOfWeek), + GUIUtil::StartOfDay(startOfWeek), TransactionFilterProxy::MAX_DATE); } break; case ThisMonth: transactionProxyModel->setDateRange( - QDateTime(QDate(current.year(), current.month(), 1)), + GUIUtil::StartOfDay(QDate(current.year(), current.month(), 1)), TransactionFilterProxy::MAX_DATE); break; case LastMonth: transactionProxyModel->setDateRange( - QDateTime(QDate(current.year(), current.month(), 1).addMonths(-1)), - QDateTime(QDate(current.year(), current.month(), 1))); + GUIUtil::StartOfDay(QDate(current.year(), current.month(), 1).addMonths(-1)), + GUIUtil::StartOfDay(QDate(current.year(), current.month(), 1))); break; case ThisYear: transactionProxyModel->setDateRange( - QDateTime(QDate(current.year(), 1, 1)), + GUIUtil::StartOfDay(QDate(current.year(), 1, 1)), TransactionFilterProxy::MAX_DATE); break; case Range: @@ -666,8 +666,8 @@ void TransactionView::dateRangeChanged() settings.setValue("transactionDateTo", dateTo->date().toString(PERSISTENCE_DATE_FORMAT)); transactionProxyModel->setDateRange( - QDateTime(dateFrom->date()), - QDateTime(dateTo->date())); + GUIUtil::StartOfDay(dateFrom->date()), + GUIUtil::StartOfDay(dateTo->date())); } void TransactionView::focusTransaction(const QModelIndex &idx)