From 1541dc32bd4cfbb84d35778131d6513a289ec173 Mon Sep 17 00:00:00 2001 From: fdov Date: Sat, 15 May 2021 23:46:42 +0200 Subject: [PATCH] qt: Fix deprecation warnings when building against Qt 5.15 bitcoin-core/gui#46 + some adjustments for Raven qt, refactor: Fix 'QDateTime is Deprecated' warnings. qt, refactor: Fix 'QFlags is deprecated' warnings qt, refactor: Fix 'split is deprecated' warnings qt, refactor: Fix 'buttonClicked is deprecated' warnings --- src/qt/assetsdialog.cpp | 5 ++++- src/qt/createassetdialog.cpp | 6 ++++++ src/qt/guiutil.cpp | 10 ++++++++++ src/qt/guiutil.h | 29 +++++++++++++++++++++++++++++ src/qt/optionsmodel.cpp | 8 ++++---- src/qt/overviewpage.cpp | 1 + src/qt/paymentserver.cpp | 1 - src/qt/raven.cpp | 2 +- src/qt/ravengui.h | 1 + src/qt/reissueassetdialog.cpp | 6 ++++++ src/qt/rpcconsole.cpp | 1 + src/qt/rpcconsole.h | 1 + src/qt/sendcoinsdialog.cpp | 6 ++++++ src/qt/splashscreen.cpp | 4 ++-- src/qt/splashscreen.h | 2 +- src/qt/transactionview.cpp | 18 +++++++++--------- 16 files changed, 82 insertions(+), 19 deletions(-) diff --git a/src/qt/assetsdialog.cpp b/src/qt/assetsdialog.cpp index c731a3ceac..3961eef7ed 100644 --- a/src/qt/assetsdialog.cpp +++ b/src/qt/assetsdialog.cpp @@ -178,8 +178,11 @@ void AssetsDialog::setModel(WalletModel *_model) } connect(ui->confTargetSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(updateSmartFeeLabel())); connect(ui->confTargetSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(assetControlUpdateLabels())); +#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) + connect(ui->groupFee, &QButtonGroup::idClicked, this, &AssetsDialog::updateFeeSectionControls); +#else connect(ui->groupFee, SIGNAL(buttonClicked(int)), this, SLOT(updateFeeSectionControls())); - connect(ui->groupFee, SIGNAL(buttonClicked(int)), this, SLOT(assetControlUpdateLabels())); +#endif connect(ui->customFee, SIGNAL(valueChanged()), this, SLOT(assetControlUpdateLabels())); connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(setMinimumFee())); connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(updateFeeSectionControls())); diff --git a/src/qt/createassetdialog.cpp b/src/qt/createassetdialog.cpp index 8e432bf3d8..ba30207cfc 100644 --- a/src/qt/createassetdialog.cpp +++ b/src/qt/createassetdialog.cpp @@ -180,8 +180,14 @@ void CreateAssetDialog::setModel(WalletModel *_model) } connect(ui->confTargetSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(updateSmartFeeLabel())); connect(ui->confTargetSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(coinControlUpdateLabels())); + +#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) + connect(ui->groupFee, &QButtonGroup::idClicked, this, &CreateAssetDialog::updateFeeSectionControls); + connect(ui->groupFee, &QButtonGroup::idClicked, this, &CreateAssetDialog::coinControlUpdateLabels); +#else connect(ui->groupFee, SIGNAL(buttonClicked(int)), this, SLOT(updateFeeSectionControls())); connect(ui->groupFee, SIGNAL(buttonClicked(int)), this, SLOT(coinControlUpdateLabels())); +#endif connect(ui->customFee, SIGNAL(valueChanged()), this, SLOT(coinControlUpdateLabels())); connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(setMinimumFee())); connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(updateFeeSectionControls())); diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index 1d33809856..bb48982eeb 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -1156,4 +1156,14 @@ void concatenate(QPainter* painter, QString& catString, int static_width, int le catString.append("..."); } +QDateTime StartOfDay(const QDate& date) +{ +#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) + return date.startOfDay(); +#else + return QDateTime(date); +#endif +} + + } // namespace GUIUtil diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h index f029b282de..3a8e0abbeb 100644 --- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -270,6 +270,35 @@ namespace GUIUtil typedef ClickableProgressBar ProgressBar; #endif + /** + * 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); + + + /** + * 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 // RAVEN_QT_GUIUTIL_H diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index 07a2059cae..3ab692e883 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -246,12 +246,12 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const return settings.value("fUseProxy", false); case ProxyIP: { // contains IP at index 0 and port at index 1 - QStringList strlIpPort = settings.value("addrProxy").toString().split(":", QString::SkipEmptyParts); + QStringList strlIpPort = GUIUtil::SplitSkipEmptyParts(settings.value("addrProxy").toString(), ":"); return strlIpPort.at(0); } case ProxyPort: { // contains IP at index 0 and port at index 1 - QStringList strlIpPort = settings.value("addrProxy").toString().split(":", QString::SkipEmptyParts); + QStringList strlIpPort = GUIUtil::SplitSkipEmptyParts(settings.value("addrProxy").toString(), ":"); return strlIpPort.at(1); } @@ -260,12 +260,12 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const return settings.value("fUseSeparateProxyTor", false); case ProxyIPTor: { // contains IP at index 0 and port at index 1 - QStringList strlIpPort = settings.value("addrSeparateProxyTor").toString().split(":", QString::SkipEmptyParts); + QStringList strlIpPort = GUIUtil::SplitSkipEmptyParts(settings.value("addrSeparateProxyTor").toString(), ":"); return strlIpPort.at(0); } case ProxyPortTor: { // contains IP at index 0 and port at index 1 - QStringList strlIpPort = settings.value("addrSeparateProxyTor").toString().split(":", QString::SkipEmptyParts); + QStringList strlIpPort = GUIUtil::SplitSkipEmptyParts(settings.value("addrSeparateProxyTor").toString(), ":"); return strlIpPort.at(1); } diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index 45f055f72a..a543db7c76 100644 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -20,6 +20,7 @@ #include "assetrecord.h" #include +#include #include #include #include diff --git a/src/qt/paymentserver.cpp b/src/qt/paymentserver.cpp index 6109ed4a93..d343a7541e 100644 --- a/src/qt/paymentserver.cpp +++ b/src/qt/paymentserver.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include diff --git a/src/qt/raven.cpp b/src/qt/raven.cpp index 7b18a0c20c..86f3711b39 100644 --- a/src/qt/raven.cpp +++ b/src/qt/raven.cpp @@ -437,7 +437,7 @@ void RavenApplication::createWindow(const NetworkStyle *networkStyle) void RavenApplication::createSplashScreen(const NetworkStyle *networkStyle) { - SplashScreen *splash = new SplashScreen(0, networkStyle); + SplashScreen *splash = new SplashScreen(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 slotFinish happens. splash->show(); diff --git a/src/qt/ravengui.h b/src/qt/ravengui.h index 35e7099bdf..f44de3706a 100644 --- a/src/qt/ravengui.h +++ b/src/qt/ravengui.h @@ -20,6 +20,7 @@ #include #include #include +#include class ClientModel; class NetworkStyle; diff --git a/src/qt/reissueassetdialog.cpp b/src/qt/reissueassetdialog.cpp index c0071e5a2a..cfb557177c 100644 --- a/src/qt/reissueassetdialog.cpp +++ b/src/qt/reissueassetdialog.cpp @@ -189,8 +189,14 @@ void ReissueAssetDialog::setModel(WalletModel *_model) } connect(ui->confTargetSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(updateSmartFeeLabel())); connect(ui->confTargetSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(coinControlUpdateLabels())); + +#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) + connect(ui->groupFee, &QButtonGroup::idClicked, this, &ReissueAssetDialog::updateFeeSectionControls); + connect(ui->groupFee, &QButtonGroup::idClicked, this, &ReissueAssetDialog::coinControlUpdateLabels); +#else connect(ui->groupFee, SIGNAL(buttonClicked(int)), this, SLOT(updateFeeSectionControls())); connect(ui->groupFee, SIGNAL(buttonClicked(int)), this, SLOT(coinControlUpdateLabels())); +#endif connect(ui->customFee, SIGNAL(valueChanged()), this, SLOT(coinControlUpdateLabels())); connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(setMinimumFee())); connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(updateFeeSectionControls())); diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 246dbd055f..5de94300e7 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -30,6 +30,7 @@ #include #endif +#include #include #include #include diff --git a/src/qt/rpcconsole.h b/src/qt/rpcconsole.h index 29684cc9cf..9d472df1b3 100644 --- a/src/qt/rpcconsole.h +++ b/src/qt/rpcconsole.h @@ -24,6 +24,7 @@ namespace Ui { } QT_BEGIN_NAMESPACE +class QDateTime; class QMenu; class QItemSelection; QT_END_NAMESPACE diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp index 7a5b446c4e..da14667b3d 100644 --- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -163,8 +163,14 @@ void SendCoinsDialog::setModel(WalletModel *_model) } connect(ui->confTargetSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(updateSmartFeeLabel())); connect(ui->confTargetSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(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, SIGNAL(buttonClicked(int)), this, SLOT(updateFeeSectionControls())); connect(ui->groupFee, SIGNAL(buttonClicked(int)), this, SLOT(coinControlUpdateLabels())); +#endif connect(ui->customFee, SIGNAL(valueChanged()), this, SLOT(coinControlUpdateLabels())); connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(setMinimumFee())); connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(updateFeeSectionControls())); diff --git a/src/qt/splashscreen.cpp b/src/qt/splashscreen.cpp index c90fdcff1c..2c3a7a070f 100644 --- a/src/qt/splashscreen.cpp +++ b/src/qt/splashscreen.cpp @@ -35,8 +35,8 @@ #include using namespace boost::placeholders; -SplashScreen::SplashScreen(Qt::WindowFlags f, const NetworkStyle *networkStyle) : - QWidget(0, f), curAlignment(0) +SplashScreen::SplashScreen(const NetworkStyle* networkStyle) + : QWidget(), curAlignment(0) { // set reference point, paddings int paddingRight = 50; diff --git a/src/qt/splashscreen.h b/src/qt/splashscreen.h index c9e9392616..ded482f2e2 100644 --- a/src/qt/splashscreen.h +++ b/src/qt/splashscreen.h @@ -23,7 +23,7 @@ class SplashScreen : public QWidget Q_OBJECT public: - explicit SplashScreen(Qt::WindowFlags f, const NetworkStyle *networkStyle); + explicit SplashScreen(const NetworkStyle *networkStyle); ~SplashScreen(); protected: diff --git a/src/qt/transactionview.cpp b/src/qt/transactionview.cpp index 5b217975d8..9d2a962679 100644 --- a/src/qt/transactionview.cpp +++ b/src/qt/transactionview.cpp @@ -274,7 +274,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 host = QUrl(listUrls[i].trimmed(), QUrl::StrictMode).host(); @@ -313,30 +313,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: @@ -653,8 +653,8 @@ void TransactionView::dateRangeChanged() if(!transactionProxyModel) return; transactionProxyModel->setDateRange( - QDateTime(dateFrom->date()), - QDateTime(dateTo->date()).addDays(1)); + GUIUtil::StartOfDay(dateFrom->date()), + GUIUtil::StartOfDay(dateTo->date()).addDays(1)); } void TransactionView::focusTransaction(const QModelIndex &idx)