From 4b36ab3a6a0a8659a5dbbc62d7554902b26ea396 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Wed, 2 Apr 2025 20:48:11 +0100 Subject: [PATCH 1/3] qt, refactor: Remove outdated Qt version-specific code Since bitcoin/bitcoin#30997, the minimum supported Qt version is 6.2. --- src/qt/addressbookpage.cpp | 8 -------- src/qt/bitcoin.cpp | 15 --------------- src/qt/guiutil.cpp | 12 ------------ src/qt/guiutil.h | 4 ---- src/qt/optionsdialog.cpp | 4 ---- src/qt/sendcoinsdialog.cpp | 5 ----- src/qt/winshutdownmonitor.cpp | 4 ---- src/qt/winshutdownmonitor.h | 4 ---- 8 files changed, 56 deletions(-) diff --git a/src/qt/addressbookpage.cpp b/src/qt/addressbookpage.cpp index f2f9371c650..26e93bf2acf 100644 --- a/src/qt/addressbookpage.cpp +++ b/src/qt/addressbookpage.cpp @@ -15,11 +15,7 @@ #include #include #include -#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) #include -#else -#include -#endif class AddressBookSortFilterProxyModel final : public QSortFilterProxyModel { @@ -47,11 +43,7 @@ protected: auto address = model->index(row, AddressTableModel::Address, parent); -#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) const auto pattern = filterRegularExpression(); -#else - const auto pattern = filterRegExp(); -#endif return (model->data(address).toString().contains(pattern) || model->data(label).toString().contains(pattern)); } diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index eaaa9fc6fd5..d28bcca470f 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -90,12 +90,7 @@ static void RegisterMetaTypes() qRegisterMetaType>("std::function"); qRegisterMetaType("QMessageBox::Icon"); qRegisterMetaType("interfaces::BlockAndHeaderTipInfo"); - -#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) - qRegisterMetaTypeStreamOperators("BitcoinUnit"); -#else qRegisterMetaType("BitcoinUnit"); -#endif } static QString GetLangTerritory() @@ -134,11 +129,7 @@ static void initTranslations(QTranslator &qtTranslatorBase, QTranslator &qtTrans // - First load the translator for the base language, without territory // - Then load the more specific locale translator -#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) - const QString translation_path{QLibraryInfo::location(QLibraryInfo::TranslationsPath)}; -#else const QString translation_path{QLibraryInfo::path(QLibraryInfo::TranslationsPath)}; -#endif // Load e.g. qt_de.qm if (qtTranslatorBase.load("qt_" + lang, translation_path)) { QApplication::installTranslator(&qtTranslatorBase); @@ -508,12 +499,6 @@ int GuiMain(int argc, char* argv[]) Q_INIT_RESOURCE(bitcoin); Q_INIT_RESOURCE(bitcoin_locale); -#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) - // Generate high-dpi pixmaps - QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); - QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); -#endif - #if defined(QT_QPA_PLATFORM_ANDROID) QApplication::setAttribute(Qt::AA_DontUseNativeMenuBar); QApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index 2369f6b6312..91f566ce1fc 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -954,20 +954,12 @@ void PopupMenu(QMenu* menu, const QPoint& point, QAction* at_action) 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) @@ -976,11 +968,7 @@ QImage GetImage(const QLabel* label) return QImage(); } -#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) return label->pixmap(Qt::ReturnByValue).toImage(); -#else - return label->pixmap()->toImage(); -#endif } QString MakeHtmlLink(const QString& source, const QString& link) diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h index 45251987943..cc94054d237 100644 --- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -362,11 +362,7 @@ namespace GUIUtil 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 } diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp index 2cea1bf6ab4..fd81abb49dc 100644 --- a/src/qt/optionsdialog.cpp +++ b/src/qt/optionsdialog.cpp @@ -164,11 +164,7 @@ OptionsDialog::OptionsDialog(QWidget* parent, bool enableWallet) { /** display language strings as "native language - native country/territory (locale name)", e.g. "Deutsch - Deutschland (de)" */ ui->lang->addItem(locale.nativeLanguageName() + QString(" - ") + -#if (QT_VERSION >= QT_VERSION_CHECK(6, 2, 0)) locale.nativeTerritoryName() + -#else - locale.nativeCountryName() + -#endif QString(" (") + langStr + QString(")"), QVariant(langStr)); } diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp index 48496c51355..8a4dd3abb73 100644 --- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -178,13 +178,8 @@ void SendCoinsDialog::setModel(WalletModel *_model) connect(ui->confTargetSelector, qOverload(&QComboBox::currentIndexChanged), this, &SendCoinsDialog::updateSmartFeeLabel); connect(ui->confTargetSelector, qOverload(&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, qOverload(&QButtonGroup::buttonClicked), this, &SendCoinsDialog::updateFeeSectionControls); - connect(ui->groupFee, qOverload(&QButtonGroup::buttonClicked), this, &SendCoinsDialog::coinControlUpdateLabels); -#endif connect(ui->customFee, &BitcoinAmountField::valueChanged, this, &SendCoinsDialog::coinControlUpdateLabels); #if (QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)) diff --git a/src/qt/winshutdownmonitor.cpp b/src/qt/winshutdownmonitor.cpp index 9ccd7028dac..3f835a7ad84 100644 --- a/src/qt/winshutdownmonitor.cpp +++ b/src/qt/winshutdownmonitor.cpp @@ -12,11 +12,7 @@ // If we don't want a message to be processed by Qt, return true and set result to // the value that the window procedure should return. Otherwise return false. -#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) bool WinShutdownMonitor::nativeEventFilter(const QByteArray &eventType, void *pMessage, qintptr *pnResult) -#else -bool WinShutdownMonitor::nativeEventFilter(const QByteArray &eventType, void *pMessage, long *pnResult) -#endif { Q_UNUSED(eventType); diff --git a/src/qt/winshutdownmonitor.h b/src/qt/winshutdownmonitor.h index a8b626065d7..42c8da75992 100644 --- a/src/qt/winshutdownmonitor.h +++ b/src/qt/winshutdownmonitor.h @@ -20,11 +20,7 @@ public: WinShutdownMonitor(std::function shutdown_fn) : m_shutdown_fn{std::move(shutdown_fn)} {} /** Implements QAbstractNativeEventFilter interface for processing Windows messages */ -#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) bool nativeEventFilter(const QByteArray &eventType, void *pMessage, qintptr *pnResult) override; -#else - bool nativeEventFilter(const QByteArray &eventType, void *pMessage, long *pnResult) override; -#endif /** Register the reason for blocking shutdown on Windows to allow clean client exit */ static void registerShutdownBlockReason(const QString& strReason, const HWND& mainWinId); From d1ec6db24934b9cb0f2f51609b83406d577eb69f Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Wed, 2 Apr 2025 20:48:36 +0100 Subject: [PATCH 2/3] qt, refactor: Inline `GUIUtil::GetImage` function --- src/qt/guiutil.cpp | 9 --------- src/qt/guiutil.h | 1 - src/qt/qrimagewidget.cpp | 6 +++++- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index 91f566ce1fc..c1bf5a56032 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -962,15 +962,6 @@ bool HasPixmap(const QLabel* label) return !label->pixmap(Qt::ReturnByValue).isNull(); } -QImage GetImage(const QLabel* label) -{ - if (!HasPixmap(label)) { - return QImage(); - } - - return label->pixmap(Qt::ReturnByValue).toImage(); -} - QString MakeHtmlLink(const QString& source, const QString& link) { return QString(source).replace( diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h index cc94054d237..3561c313740 100644 --- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -347,7 +347,6 @@ namespace GUIUtil * 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 diff --git a/src/qt/qrimagewidget.cpp b/src/qt/qrimagewidget.cpp index e912dafa607..79b5cde9ab7 100644 --- a/src/qt/qrimagewidget.cpp +++ b/src/qt/qrimagewidget.cpp @@ -92,7 +92,11 @@ bool QRImageWidget::setQR(const QString& data, const QString& text) QImage QRImageWidget::exportImage() { - return GUIUtil::GetImage(this); + if (!GUIUtil::HasPixmap(this)) { + return QImage(); + } + + return this->pixmap(Qt::ReturnByValue).toImage(); } void QRImageWidget::mousePressEvent(QMouseEvent *event) From 3aa58bea8e703e33a1eb8e2f9fdf887aca8d03c1 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Wed, 2 Apr 2025 20:49:18 +0100 Subject: [PATCH 3/3] qt, refactor: Inline `GUIUtil::SplitSkipEmptyParts` function --- src/qt/guiutil.h | 17 ----------------- src/qt/transactionview.cpp | 2 +- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h index 3561c313740..1b493430731 100644 --- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -348,23 +348,6 @@ namespace GUIUtil */ bool HasPixmap(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) - { - return string.split(separator, Qt::SkipEmptyParts); - } - - /** * Replaces a plain text link with an HTML tagged one. */ diff --git a/src/qt/transactionview.cpp b/src/qt/transactionview.cpp index 2aaa65c6f73..90a53fb2bbd 100644 --- a/src/qt/transactionview.cpp +++ b/src/qt/transactionview.cpp @@ -221,7 +221,7 @@ void TransactionView::setModel(WalletModel *_model) if (_model->getOptionsModel()) { // Add third party transaction URLs to context menu - QStringList listUrls = GUIUtil::SplitSkipEmptyParts(_model->getOptionsModel()->getThirdPartyTxUrls(), "|"); + QStringList listUrls = _model->getOptionsModel()->getThirdPartyTxUrls().split("|", Qt::SkipEmptyParts); bool actions_created = false; for (int i = 0; i < listUrls.size(); ++i) {