From c33284fa8cddf8301c3320822df25c03ccdb46f4 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 27 Feb 2019 15:14:38 +0800 Subject: [PATCH 1/6] Add compile flag to show Qt deprecation warnings --- src/CMakeLists.txt | 3 ++- src/src.pro | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 51b81e60c..7ad732815 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -53,9 +53,10 @@ endif () include_directories(${CMAKE_CURRENT_SOURCE_DIR}) # defines +add_definitions(-DQT_DEPRECATED_WARNINGS) add_definitions(-DQT_NO_CAST_TO_ASCII) -# Efficient construction for QString & QByteArray (Qt >= 4.8) add_definitions(-DQT_USE_QSTRINGBUILDER) +add_definitions(-DQT_STRICT_ITERATORS) if (CMAKE_BUILD_TYPE MATCHES "Debug") message(STATUS "Project is built in DEBUG mode.") diff --git a/src/src.pro b/src/src.pro index 65b343ce5..b8e970e57 100644 --- a/src/src.pro +++ b/src/src.pro @@ -54,8 +54,9 @@ CONFIG(release, debug|release) { # VERSION DEFINES include(../version.pri) +# Qt defines +DEFINES += QT_DEPRECATED_WARNINGS DEFINES += QT_NO_CAST_TO_ASCII -# Efficient construction for QString & QByteArray (Qt >= 4.8) DEFINES += QT_USE_QSTRINGBUILDER DEFINES += QT_STRICT_ITERATORS From 168d3fbdac8e92e42747487d63110328a19d1339 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 27 Feb 2019 15:22:12 +0800 Subject: [PATCH 2/6] Replace deprecated trUtf8() --- src/base/bittorrent/session.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 62603750f..95d5d2708 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -4012,7 +4012,7 @@ void Session::handlePeerBlockedAlert(const libt::peer_blocked_alert *p) reason = tr("because it has a low port.", "this peer was blocked because it has a low port."); break; case libt::peer_blocked_alert::utp_disabled: - reason = trUtf8("because %1 is disabled.", "this peer was blocked because uTP is disabled.").arg(QString::fromUtf8(C_UTP)); // don't translate μTP + reason = tr("because %1 is disabled.", "this peer was blocked because uTP is disabled.").arg(QString::fromUtf8(C_UTP)); // don't translate μTP break; case libt::peer_blocked_alert::tcp_disabled: reason = tr("because %1 is disabled.", "this peer was blocked because TCP is disabled.").arg("TCP"); // don't translate TCP From c657134344813846af80108d6ce2400561a76b1d Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 27 Feb 2019 15:23:56 +0800 Subject: [PATCH 3/6] Replace deprecated QSslSocket::setDefaultCiphers() --- src/base/http/server.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/base/http/server.cpp b/src/base/http/server.cpp index 50a7c1407..04d7aff62 100644 --- a/src/base/http/server.cpp +++ b/src/base/http/server.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -51,7 +52,7 @@ namespace QList safeCipherList() { const QStringList badCiphers {"idea", "rc4"}; - const QList allCiphers {QSslSocket::supportedCiphers()}; + const QList allCiphers {QSslConfiguration::supportedCiphers()}; QList safeCiphers; std::copy_if(allCiphers.cbegin(), allCiphers.cend(), std::back_inserter(safeCiphers), [&badCiphers](const QSslCipher &cipher) { @@ -72,7 +73,10 @@ Server::Server(IRequestHandler *requestHandler, QObject *parent) , m_https(false) { setProxy(QNetworkProxy::NoProxy); - QSslSocket::setDefaultCiphers(safeCipherList()); + + QSslConfiguration sslConf {QSslConfiguration::defaultConfiguration()}; + sslConf.setCiphers(safeCipherList()); + QSslConfiguration::setDefaultConfiguration(sslConf); auto *dropConnectionTimer = new QTimer(this); connect(dropConnectionTimer, &QTimer::timeout, this, &Server::dropTimedOutConnection); From 6dab93f7fdd211ce91d831e0c4b159628c197362 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 27 Feb 2019 15:59:44 +0800 Subject: [PATCH 4/6] Replace deprecated QDesktopWidget class --- src/base/utils/misc.cpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/base/utils/misc.cpp b/src/base/utils/misc.cpp index 259151fec..f9d93fc12 100644 --- a/src/base/utils/misc.cpp +++ b/src/base/utils/misc.cpp @@ -59,8 +59,10 @@ #else #include #include -#include +#include #include +#include +#include #if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) && defined(QT_DBUS_LIB) #include #include @@ -252,11 +254,26 @@ QPoint Utils::Misc::screenCenter(const QWidget *w) { // Returns the QPoint which the widget will be placed center on screen (where parent resides) + if (!w) + return {}; + + QRect r = QGuiApplication::primaryScreen()->availableGeometry(); + const QPoint primaryScreenCenter {(r.x() + (r.width() - w->frameSize().width()) / 2), (r.y() + (r.height() - w->frameSize().height()) / 2)}; + const QWidget *parent = w->parentWidget(); - const QDesktopWidget *desktop = QApplication::desktop(); - const int scrn = desktop->screenNumber(parent); // fallback to `primaryScreen` when parent is invalid - const QRect r = desktop->availableGeometry(scrn); - return {r.x() + (r.width() - w->frameSize().width()) / 2, r.y() + (r.height() - w->frameSize().height()) / 2}; + if (!parent) + return primaryScreenCenter; + + const QWindow *window = parent->window()->windowHandle(); + if (!window) + return primaryScreenCenter; + + const QScreen *screen = window->screen(); + if (!screen) + return primaryScreenCenter; + + r = screen->availableGeometry(); + return {(r.x() + (r.width() - w->frameSize().width()) / 2), (r.y() + (r.height() - w->frameSize().height()) / 2)}; } #endif From c6ae1aa9d9085aa0b804f385e06492fb31b857b2 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 27 Feb 2019 16:06:05 +0800 Subject: [PATCH 5/6] Replace deprecated QString::null --- src/gui/advancedsettings.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/advancedsettings.cpp b/src/gui/advancedsettings.cpp index b66f2ed39..64fb4cfae 100644 --- a/src/gui/advancedsettings.cpp +++ b/src/gui/advancedsettings.cpp @@ -199,11 +199,11 @@ void AdvancedSettings::saveAdvancedSettings() // Interface address if (comboBoxInterfaceAddress.currentIndex() == 0) { // All addresses (default) - session->setNetworkInterfaceAddress(QString::null); + session->setNetworkInterfaceAddress({}); } else { QHostAddress ifaceAddr(comboBoxInterfaceAddress.currentText().trimmed()); - ifaceAddr.isNull() ? session->setNetworkInterfaceAddress(QString::null) : session->setNetworkInterfaceAddress(ifaceAddr.toString()); + ifaceAddr.isNull() ? session->setNetworkInterfaceAddress({}) : session->setNetworkInterfaceAddress(ifaceAddr.toString()); } session->setIPv6Enabled(checkBoxListenIPv6.isChecked()); // Announce IP From 3dd969df643f68b465e10f29a4c8611607ca9968 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 27 Feb 2019 16:16:02 +0800 Subject: [PATCH 6/6] Replace deprecated QSignalMapper class --- src/gui/properties/speedwidget.cpp | 8 +------- src/gui/properties/speedwidget.h | 2 -- src/gui/search/searchwidget.cpp | 9 +-------- src/gui/search/searchwidget.h | 2 -- 4 files changed, 2 insertions(+), 19 deletions(-) diff --git a/src/gui/properties/speedwidget.cpp b/src/gui/properties/speedwidget.cpp index 754211569..56012f7b6 100644 --- a/src/gui/properties/speedwidget.cpp +++ b/src/gui/properties/speedwidget.cpp @@ -32,7 +32,6 @@ #include #include #include -#include #include #include @@ -89,18 +88,13 @@ SpeedWidget::SpeedWidget(PropertiesWidget *parent) m_graphsMenu->addAction(tr("Tracker Download")); m_graphsMenuActions = m_graphsMenu->actions(); - m_graphsSignalMapper = new QSignalMapper(this); for (int id = SpeedPlotView::UP; id < SpeedPlotView::NB_GRAPHS; ++id) { QAction *action = m_graphsMenuActions.at(id); action->setCheckable(true); action->setChecked(true); - connect(action, &QAction::changed, m_graphsSignalMapper - , static_cast(&QSignalMapper::map)); - m_graphsSignalMapper->setMapping(action, id); + connect(action, &QAction::changed, this, [this, id]() { onGraphChange(id); }); } - connect(m_graphsSignalMapper, static_cast(&QSignalMapper::mapped) - , this, &SpeedWidget::onGraphChange); m_graphsButton = new ComboBoxMenuButton(this, m_graphsMenu); m_graphsButton->addItem(tr("Select Graphs")); diff --git a/src/gui/properties/speedwidget.h b/src/gui/properties/speedwidget.h index bcfa68f9b..148e40f55 100644 --- a/src/gui/properties/speedwidget.h +++ b/src/gui/properties/speedwidget.h @@ -38,7 +38,6 @@ class QVBoxLayout; class QHBoxLayout; class QLabel; class QMenu; -class QSignalMapper; class PropertiesWidget; class ComboBoxMenuButton : public QComboBox @@ -80,7 +79,6 @@ private: ComboBoxMenuButton *m_graphsButton; QMenu *m_graphsMenu; QList m_graphsMenuActions; - QSignalMapper *m_graphsSignalMapper; }; #endif // SPEEDWIDGET_H diff --git a/src/gui/search/searchwidget.cpp b/src/gui/search/searchwidget.cpp index 748a501fe..fec6cd1c1 100644 --- a/src/gui/search/searchwidget.cpp +++ b/src/gui/search/searchwidget.cpp @@ -42,7 +42,6 @@ #include #include #include -#include #include #include #include @@ -91,7 +90,6 @@ namespace SearchWidget::SearchWidget(MainWindow *mainWindow) : QWidget(mainWindow) , m_ui(new Ui::SearchWidget()) - , m_tabStatusChangedMapper(new QSignalMapper(this)) , m_mainWindow(mainWindow) , m_isNewQueryString(false) { @@ -131,9 +129,6 @@ SearchWidget::SearchWidget(MainWindow *mainWindow) connect(m_ui->tabWidget, &QTabWidget::tabCloseRequested, this, &SearchWidget::closeTab); connect(m_ui->tabWidget, &QTabWidget::currentChanged, this, &SearchWidget::tabChanged); - connect(m_tabStatusChangedMapper, static_cast(&QSignalMapper::mapped) - , this, &SearchWidget::tabStatusChanged); - const auto *searchManager = SearchPluginManager::instance(); const auto onPluginChanged = [this]() { @@ -342,9 +337,7 @@ void SearchWidget::on_searchButton_clicked() m_ui->tabWidget->setCurrentWidget(newTab); connect(newTab, &SearchJobWidget::resultsCountUpdated, this, &SearchWidget::resultsCountUpdated); - connect(newTab, &SearchJobWidget::statusChanged - , m_tabStatusChangedMapper, static_cast(&QSignalMapper::map)); - m_tabStatusChangedMapper->setMapping(newTab, newTab); + connect(newTab, &SearchJobWidget::statusChanged, this, [this, &newTab]() { tabStatusChanged(newTab); }); m_ui->searchButton->setText(tr("Stop")); m_activeSearchTab = newTab; diff --git a/src/gui/search/searchwidget.h b/src/gui/search/searchwidget.h index e303b569d..46a8315a7 100644 --- a/src/gui/search/searchwidget.h +++ b/src/gui/search/searchwidget.h @@ -34,7 +34,6 @@ #include class QShortcut; -class QSignalMapper; class QTabWidget; class MainWindow; @@ -81,7 +80,6 @@ private: QString selectedPlugin() const; Ui::SearchWidget *m_ui; - QSignalMapper *m_tabStatusChangedMapper; QPointer m_currentSearchTab; // Selected tab QPointer m_activeSearchTab; // Tab with running search QList m_allTabs; // To store all tabs