From 34d30ed031a756f40a8013c972d5b6dc27d25c62 Mon Sep 17 00:00:00 2001 From: Victor Chernyakin <56512186+LocalSpook@users.noreply.github.com> Date: Thu, 17 Aug 2023 21:09:40 -0700 Subject: [PATCH] Replace `Q_UNUSED` with `[[maybe_unused]]` attribute PR #19471. --- src/app/application.cpp | 4 +--- src/base/bittorrent/sessionimpl.cpp | 3 +-- src/base/bittorrent/torrentimpl.cpp | 17 +++++------------ src/base/net/geoipdatabase.cpp | 5 +---- src/base/rss/rss_autodownloader.cpp | 3 +-- src/base/rss/rss_feed.cpp | 3 +-- src/base/utils/misc.cpp | 5 +---- src/gui/addnewtorrentdialog.cpp | 10 +++------- src/gui/cookiesmodel.cpp | 6 ++---- src/gui/desktopintegration.cpp | 5 +---- src/gui/fspathedit_p.cpp | 5 ++--- src/gui/mainwindow.cpp | 3 +-- src/gui/notifications/dbusnotifier.cpp | 8 ++------ src/gui/search/searchwidget.cpp | 5 ++--- src/gui/torrentcontentmodel.cpp | 3 +-- src/gui/torrentoptionsdialog.cpp | 4 +--- .../categoryfilterwidget.cpp | 4 +--- src/gui/transferlistfilters/tagfilterwidget.cpp | 4 +--- src/gui/watchedfoldersmodel.cpp | 3 +-- test/testalgorithm.cpp | 6 ++---- 20 files changed, 31 insertions(+), 75 deletions(-) diff --git a/src/app/application.cpp b/src/app/application.cpp index 69d8cf698..0cc3ef685 100644 --- a/src/app/application.cpp +++ b/src/app/application.cpp @@ -1110,10 +1110,8 @@ void Application::initializeTranslation() } #if (!defined(DISABLE_GUI) && defined(Q_OS_WIN)) -void Application::shutdownCleanup(QSessionManager &manager) +void Application::shutdownCleanup([[maybe_unused]] QSessionManager &manager) { - Q_UNUSED(manager); - // This is only needed for a special case on Windows XP. // (but is called for every Windows version) // If a process takes too much time to exit during OS diff --git a/src/base/bittorrent/sessionimpl.cpp b/src/base/bittorrent/sessionimpl.cpp index d7347d8d0..3e4c84f4f 100644 --- a/src/base/bittorrent/sessionimpl.cpp +++ b/src/base/bittorrent/sessionimpl.cpp @@ -2541,9 +2541,8 @@ void SessionImpl::handleTorrentSaveResumeDataRequested(const TorrentImpl *torren ++m_numResumeData; } -void SessionImpl::handleTorrentSaveResumeDataFailed(const TorrentImpl *torrent) +void SessionImpl::handleTorrentSaveResumeDataFailed([[maybe_unused]] const TorrentImpl *torrent) { - Q_UNUSED(torrent); --m_numResumeData; } diff --git a/src/base/bittorrent/torrentimpl.cpp b/src/base/bittorrent/torrentimpl.cpp index 2aa85e76a..9bbe9cbc3 100644 --- a/src/base/bittorrent/torrentimpl.cpp +++ b/src/base/bittorrent/torrentimpl.cpp @@ -1866,10 +1866,8 @@ void TorrentImpl::handleMoveStorageJobFinished(const Path &path, const MoveStora } } -void TorrentImpl::handleTorrentCheckedAlert(const lt::torrent_checked_alert *p) +void TorrentImpl::handleTorrentCheckedAlert([[maybe_unused]] const lt::torrent_checked_alert *p) { - Q_UNUSED(p); - if (!hasMetadata()) { // The torrent is checked due to metadata received, but we should not process @@ -1911,10 +1909,8 @@ void TorrentImpl::handleTorrentCheckedAlert(const lt::torrent_checked_alert *p) }); } -void TorrentImpl::handleTorrentFinishedAlert(const lt::torrent_finished_alert *p) +void TorrentImpl::handleTorrentFinishedAlert([[maybe_unused]] const lt::torrent_finished_alert *p) { - Q_UNUSED(p); - m_hasMissingFiles = false; if (m_hasFinishedStatus) return; @@ -1943,14 +1939,12 @@ void TorrentImpl::handleTorrentFinishedAlert(const lt::torrent_finished_alert *p }); } -void TorrentImpl::handleTorrentPausedAlert(const lt::torrent_paused_alert *p) +void TorrentImpl::handleTorrentPausedAlert([[maybe_unused]] const lt::torrent_paused_alert *p) { - Q_UNUSED(p); } -void TorrentImpl::handleTorrentResumedAlert(const lt::torrent_resumed_alert *p) +void TorrentImpl::handleTorrentResumedAlert([[maybe_unused]] const lt::torrent_resumed_alert *p) { - Q_UNUSED(p); } void TorrentImpl::handleSaveResumeDataAlert(const lt::save_resume_data_alert *p) @@ -2165,9 +2159,8 @@ void TorrentImpl::handleFilePrioAlert(const lt::file_prio_alert *) } #endif -void TorrentImpl::handleMetadataReceivedAlert(const lt::metadata_received_alert *p) +void TorrentImpl::handleMetadataReceivedAlert([[maybe_unused]] const lt::metadata_received_alert *p) { - Q_UNUSED(p); qDebug("Metadata received for torrent %s.", qUtf8Printable(name())); #ifdef QBT_USES_LIBTORRENT2 diff --git a/src/base/net/geoipdatabase.cpp b/src/base/net/geoipdatabase.cpp index 12f00efcf..b53178402 100644 --- a/src/base/net/geoipdatabase.cpp +++ b/src/base/net/geoipdatabase.cpp @@ -462,13 +462,10 @@ bool GeoIPDatabase::readDataFieldDescriptor(quint32 &offset, DataFieldDescriptor return true; } -void GeoIPDatabase::fromBigEndian(uchar *buf, const quint32 len) const +void GeoIPDatabase::fromBigEndian([[maybe_unused]] uchar *buf, [[maybe_unused]] const quint32 len) const { #if (Q_BYTE_ORDER == Q_LITTLE_ENDIAN) std::reverse(buf, buf + len); -#else - Q_UNUSED(buf); - Q_UNUSED(len); #endif } diff --git a/src/base/rss/rss_autodownloader.cpp b/src/base/rss/rss_autodownloader.cpp index 3c2c7f2f3..798634d7a 100644 --- a/src/base/rss/rss_autodownloader.cpp +++ b/src/base/rss/rss_autodownloader.cpp @@ -612,8 +612,7 @@ void AutoDownloader::setProcessingEnabled(const bool enabled) } } -void AutoDownloader::timerEvent(QTimerEvent *event) +void AutoDownloader::timerEvent([[maybe_unused]] QTimerEvent *event) { - Q_UNUSED(event); store(); } diff --git a/src/base/rss/rss_feed.cpp b/src/base/rss/rss_feed.cpp index e6b2f9b48..a707851dc 100644 --- a/src/base/rss/rss_feed.cpp +++ b/src/base/rss/rss_feed.cpp @@ -560,8 +560,7 @@ void Feed::cleanup() Utils::Fs::removeFile(m_iconPath); } -void Feed::timerEvent(QTimerEvent *event) +void Feed::timerEvent([[maybe_unused]] QTimerEvent *event) { - Q_UNUSED(event); store(); } diff --git a/src/base/utils/misc.cpp b/src/base/utils/misc.cpp index 95f3da848..303d22b7f 100644 --- a/src/base/utils/misc.cpp +++ b/src/base/utils/misc.cpp @@ -111,7 +111,7 @@ namespace } } -void Utils::Misc::shutdownComputer(const ShutdownDialogAction &action) +void Utils::Misc::shutdownComputer([[maybe_unused]] const ShutdownDialogAction &action) { #if defined(Q_OS_WIN) HANDLE hToken; // handle to process token @@ -247,9 +247,6 @@ void Utils::Misc::shutdownComputer(const ShutdownDialogAction &action) QDBusConnection::systemBus()); halIface.call(u"Shutdown"_s); } - -#else - Q_UNUSED(action); #endif } diff --git a/src/gui/addnewtorrentdialog.cpp b/src/gui/addnewtorrentdialog.cpp index 96ec8b254..122d9ebb1 100644 --- a/src/gui/addnewtorrentdialog.cpp +++ b/src/gui/addnewtorrentdialog.cpp @@ -502,17 +502,15 @@ void AddNewTorrentDialog::updateDiskSpaceLabel() m_ui->labelSizeData->setText(sizeString); } -void AddNewTorrentDialog::onSavePathChanged(const Path &newPath) +void AddNewTorrentDialog::onSavePathChanged([[maybe_unused]] const Path &newPath) { - Q_UNUSED(newPath); // Remember index m_savePathIndex = m_ui->savePath->currentIndex(); updateDiskSpaceLabel(); } -void AddNewTorrentDialog::onDownloadPathChanged(const Path &newPath) +void AddNewTorrentDialog::onDownloadPathChanged([[maybe_unused]] const Path &newPath) { - Q_UNUSED(newPath); // Remember index const int currentPathIndex = m_ui->downloadPath->currentIndex(); if (currentPathIndex >= 0) @@ -525,10 +523,8 @@ void AddNewTorrentDialog::onUseDownloadPathChanged(const bool checked) m_ui->downloadPath->setCurrentIndex(checked ? m_downloadPathIndex : -1); } -void AddNewTorrentDialog::categoryChanged(int index) +void AddNewTorrentDialog::categoryChanged([[maybe_unused]] const int index) { - Q_UNUSED(index); - if (m_ui->comboTTM->currentIndex() == 1) { const auto *btSession = BitTorrent::Session::instance(); diff --git a/src/gui/cookiesmodel.cpp b/src/gui/cookiesmodel.cpp index 348561a0c..a8d658646 100644 --- a/src/gui/cookiesmodel.cpp +++ b/src/gui/cookiesmodel.cpp @@ -73,9 +73,8 @@ QModelIndex CookiesModel::index(int row, int column, const QModelIndex &parent) return createIndex(row, column, &m_cookies[row]); } -QModelIndex CookiesModel::parent(const QModelIndex &index) const +QModelIndex CookiesModel::parent([[maybe_unused]] const QModelIndex &index) const { - Q_UNUSED(index); return {}; } @@ -86,9 +85,8 @@ int CookiesModel::rowCount(const QModelIndex &parent) const return m_cookies.size(); } -int CookiesModel::columnCount(const QModelIndex &parent) const +int CookiesModel::columnCount([[maybe_unused]] const QModelIndex &parent) const { - Q_UNUSED(parent); return NB_COLUMNS; } diff --git a/src/gui/desktopintegration.cpp b/src/gui/desktopintegration.cpp index 2be2bc69d..86c9a961b 100644 --- a/src/gui/desktopintegration.cpp +++ b/src/gui/desktopintegration.cpp @@ -54,11 +54,8 @@ namespace #ifdef Q_OS_MACOS DesktopIntegration *desktopIntegrationInstance = nullptr; - bool handleDockClicked(id self, SEL cmd, ...) + bool handleDockClicked([[maybe_unused]] id self, [[maybe_unused]] SEL cmd, ...) { - Q_UNUSED(self); - Q_UNUSED(cmd); - Q_ASSERT(desktopIntegrationInstance); emit desktopIntegrationInstance->activationRequested(); diff --git a/src/gui/fspathedit_p.cpp b/src/gui/fspathedit_p.cpp index d6f4031c9..83b81269e 100644 --- a/src/gui/fspathedit_p.cpp +++ b/src/gui/fspathedit_p.cpp @@ -146,10 +146,9 @@ QValidator::State Private::FileSystemPathValidator::lastValidationState() const return m_lastValidationState; } -QValidator::State Private::FileSystemPathValidator::validate(QString &input, int &pos) const +QValidator::State Private::FileSystemPathValidator::validate(QString &input, [[maybe_unused]] int &pos) const { - // ignore cursor position and validate the full path anyway - Q_UNUSED(pos); + // we ignore cursor position and validate the full path anyway m_lastTestResult = testPath(Path(input)); m_lastValidationState = (m_lastTestResult == TestResult::OK) diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 9e1bfc86e..83fd19670 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -743,9 +743,8 @@ void MainWindow::on_actionDocumentation_triggered() const QDesktopServices::openUrl(QUrl(u"https://doc.qbittorrent.org"_s)); } -void MainWindow::tabChanged(int newTab) +void MainWindow::tabChanged([[maybe_unused]] const int newTab) { - Q_UNUSED(newTab); // We cannot rely on the index newTab // because the tab order is undetermined now if (m_tabs->currentWidget() == m_splitter) diff --git a/src/gui/notifications/dbusnotifier.cpp b/src/gui/notifications/dbusnotifier.cpp index 2b81fa9cd..e0437a8bd 100644 --- a/src/gui/notifications/dbusnotifier.cpp +++ b/src/gui/notifications/dbusnotifier.cpp @@ -76,19 +76,15 @@ void DBusNotifier::showMessage(const QString &title, const QString &message, con }); } -void DBusNotifier::onActionInvoked(const uint messageID, const QString &action) +void DBusNotifier::onActionInvoked(const uint messageID, [[maybe_unused]] const QString &action) { - Q_UNUSED(action); - // Check whether the notification is sent by qBittorrent // to avoid reacting to unrelated notifications if (m_activeMessages.contains(messageID)) emit messageClicked(); } -void DBusNotifier::onNotificationClosed(const uint messageID, const uint reason) +void DBusNotifier::onNotificationClosed(const uint messageID, [[maybe_unused]] const uint reason) { - Q_UNUSED(reason); - m_activeMessages.remove(messageID); } diff --git a/src/gui/search/searchwidget.cpp b/src/gui/search/searchwidget.cpp index fcf22528f..1128a561e 100644 --- a/src/gui/search/searchwidget.cpp +++ b/src/gui/search/searchwidget.cpp @@ -255,16 +255,15 @@ SearchWidget::~SearchWidget() delete m_ui; } -void SearchWidget::tabChanged(int index) +void SearchWidget::tabChanged(const int index) { // when we switch from a tab that is not empty to another that is empty // the download button doesn't have to be available m_currentSearchTab = ((index < 0) ? nullptr : m_allTabs.at(m_ui->tabWidget->currentIndex())); } -void SearchWidget::selectMultipleBox(int index) +void SearchWidget::selectMultipleBox([[maybe_unused]] const int index) { - Q_UNUSED(index); if (selectedPlugin() == u"multi") on_pluginsButton_clicked(); } diff --git a/src/gui/torrentcontentmodel.cpp b/src/gui/torrentcontentmodel.cpp index 07231ccb6..61c43cebc 100644 --- a/src/gui/torrentcontentmodel.cpp +++ b/src/gui/torrentcontentmodel.cpp @@ -293,9 +293,8 @@ QVector TorrentContentModel::getFilePriorities() c return prio; } -int TorrentContentModel::columnCount(const QModelIndex &parent) const +int TorrentContentModel::columnCount([[maybe_unused]] const QModelIndex &parent) const { - Q_UNUSED(parent); return TorrentContentModelItem::NB_COL; } diff --git a/src/gui/torrentoptionsdialog.cpp b/src/gui/torrentoptionsdialog.cpp index 5d6ae2552..611f1c710 100644 --- a/src/gui/torrentoptionsdialog.cpp +++ b/src/gui/torrentoptionsdialog.cpp @@ -543,10 +543,8 @@ int TorrentOptionsDialog::getInactiveSeedingTime() const return m_ui->spinInactiveTimeLimit->value(); } -void TorrentOptionsDialog::handleCategoryChanged(const int index) +void TorrentOptionsDialog::handleCategoryChanged([[maybe_unused]] const int index) { - Q_UNUSED(index); - if (m_ui->checkAutoTMM->checkState() == Qt::Checked) { if (!m_allSameCategory && (m_ui->comboCategory->currentIndex() == 0)) diff --git a/src/gui/transferlistfilters/categoryfilterwidget.cpp b/src/gui/transferlistfilters/categoryfilterwidget.cpp index b9004c90b..655b5ffbd 100644 --- a/src/gui/transferlistfilters/categoryfilterwidget.cpp +++ b/src/gui/transferlistfilters/categoryfilterwidget.cpp @@ -97,10 +97,8 @@ QString CategoryFilterWidget::currentCategory() const return getCategoryFilter(static_cast(model()), current); } -void CategoryFilterWidget::onCurrentRowChanged(const QModelIndex ¤t, const QModelIndex &previous) +void CategoryFilterWidget::onCurrentRowChanged(const QModelIndex ¤t, [[maybe_unused]] const QModelIndex &previous) { - Q_UNUSED(previous); - emit categoryChanged(getCategoryFilter(static_cast(model()), current)); } diff --git a/src/gui/transferlistfilters/tagfilterwidget.cpp b/src/gui/transferlistfilters/tagfilterwidget.cpp index e50ab50a1..79b8bce2e 100644 --- a/src/gui/transferlistfilters/tagfilterwidget.cpp +++ b/src/gui/transferlistfilters/tagfilterwidget.cpp @@ -95,10 +95,8 @@ QString TagFilterWidget::currentTag() const return getTagFilter(static_cast(model()), current); } -void TagFilterWidget::onCurrentRowChanged(const QModelIndex ¤t, const QModelIndex &previous) +void TagFilterWidget::onCurrentRowChanged(const QModelIndex ¤t, [[maybe_unused]] const QModelIndex &previous) { - Q_UNUSED(previous); - emit tagChanged(getTagFilter(static_cast(model()), current)); } diff --git a/src/gui/watchedfoldersmodel.cpp b/src/gui/watchedfoldersmodel.cpp index ebd867f58..0bb4e4c75 100644 --- a/src/gui/watchedfoldersmodel.cpp +++ b/src/gui/watchedfoldersmodel.cpp @@ -49,9 +49,8 @@ int WatchedFoldersModel::rowCount(const QModelIndex &parent) const return parent.isValid() ? 0 : m_watchedFolders.count(); } -int WatchedFoldersModel::columnCount(const QModelIndex &parent) const +int WatchedFoldersModel::columnCount([[maybe_unused]] const QModelIndex &parent) const { - Q_UNUSED(parent); return 1; } diff --git a/test/testalgorithm.cpp b/test/testalgorithm.cpp index dccfeb36b..3cfeadddf 100644 --- a/test/testalgorithm.cpp +++ b/test/testalgorithm.cpp @@ -69,9 +69,8 @@ private slots: {3, 'b'}, {4, 'd'} }; - Algorithm::removeIf(data, [](const int key, const char value) + Algorithm::removeIf(data, []([[maybe_unused]] const int key, const char value) { - Q_UNUSED(key); return (value == 'b'); }); QCOMPARE(data.size(), 3); @@ -83,9 +82,8 @@ private slots: } { QHash data; - Algorithm::removeIf(data, [](const int key, const char value) + Algorithm::removeIf(data, []([[maybe_unused]] const int key, const char value) { - Q_UNUSED(key); return (value == 'b'); }); QVERIFY(data.empty());