From 2a84345835e076504062b699aa4c9e34f06e486f Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 16 Dec 2018 15:51:36 +0800 Subject: [PATCH] Mark constructors as explicit --- src/app/cmdoptions.cpp | 40 +++++++++---------- src/app/cmdoptions.h | 4 +- src/base/bittorrent/private/statistics.h | 2 +- src/base/bittorrent/session.cpp | 38 +++++++++++------- src/base/bittorrent/torrenthandle.h | 2 +- src/base/net/private/geoipdatabase.h | 2 +- src/base/private/profile_p.h | 6 +-- src/base/rss/rss_feed.cpp | 2 +- src/base/settingsstorage.cpp | 2 +- src/base/torrentfileguard.h | 4 +- src/gui/properties/proplistdelegate.h | 2 +- src/gui/properties/speedwidget.h | 2 +- src/gui/properties/trackerlistwidget.h | 2 +- src/gui/properties/trackersadditiondialog.cpp | 2 +- src/gui/torrentcontentmodelfolder.h | 2 +- src/gui/torrentcontentmodelitem.h | 2 +- 16 files changed, 61 insertions(+), 53 deletions(-) diff --git a/src/app/cmdoptions.cpp b/src/app/cmdoptions.cpp index 507b97eb4..b0c87db38 100644 --- a/src/app/cmdoptions.cpp +++ b/src/app/cmdoptions.cpp @@ -55,7 +55,7 @@ namespace class Option { protected: - constexpr Option(const char *name, char shortcut = 0) + explicit constexpr Option(const char *name, char shortcut = 0) : m_name {name} , m_shortcut {shortcut} { @@ -102,7 +102,7 @@ namespace class BoolOption : protected Option { public: - constexpr BoolOption(const char *name, char shortcut = 0) + explicit constexpr BoolOption(const char *name, char shortcut = 0) : Option {name, shortcut} { } @@ -139,7 +139,7 @@ namespace struct StringOption : protected Option { public: - constexpr StringOption(const char *name) + explicit constexpr StringOption(const char *name) : Option {name, 0} { } @@ -186,7 +186,7 @@ namespace class IntOption : protected StringOption { public: - constexpr IntOption(const char *name) + explicit constexpr IntOption(const char *name) : StringOption {name} { } @@ -305,25 +305,25 @@ namespace return o == s; } - constexpr const BoolOption SHOW_HELP_OPTION = {"help", 'h'}; - constexpr const BoolOption SHOW_VERSION_OPTION = {"version", 'v'}; + constexpr const BoolOption SHOW_HELP_OPTION {"help", 'h'}; + constexpr const BoolOption SHOW_VERSION_OPTION {"version", 'v'}; #ifdef DISABLE_GUI - constexpr const BoolOption DAEMON_OPTION = {"daemon", 'd'}; + constexpr const BoolOption DAEMON_OPTION {"daemon", 'd'}; #else - constexpr const BoolOption NO_SPLASH_OPTION = {"no-splash"}; + constexpr const BoolOption NO_SPLASH_OPTION {"no-splash"}; #endif - constexpr const IntOption WEBUI_PORT_OPTION = {"webui-port"}; - constexpr const StringOption PROFILE_OPTION = {"profile"}; - constexpr const StringOption CONFIGURATION_OPTION = {"configuration"}; - constexpr const BoolOption PORTABLE_OPTION = {"portable"}; - constexpr const BoolOption RELATIVE_FASTRESUME = {"relative-fastresume"}; - constexpr const StringOption SAVE_PATH_OPTION = {"save-path"}; - constexpr const TriStateBoolOption PAUSED_OPTION = {"add-paused", true}; - constexpr const BoolOption SKIP_HASH_CHECK_OPTION = {"skip-hash-check"}; - constexpr const StringOption CATEGORY_OPTION = {"category"}; - constexpr const BoolOption SEQUENTIAL_OPTION = {"sequential"}; - constexpr const BoolOption FIRST_AND_LAST_OPTION = {"first-and-last"}; - constexpr const TriStateBoolOption SKIP_DIALOG_OPTION = {"skip-dialog", true}; + constexpr const IntOption WEBUI_PORT_OPTION {"webui-port"}; + constexpr const StringOption PROFILE_OPTION {"profile"}; + constexpr const StringOption CONFIGURATION_OPTION {"configuration"}; + constexpr const BoolOption PORTABLE_OPTION {"portable"}; + constexpr const BoolOption RELATIVE_FASTRESUME {"relative-fastresume"}; + constexpr const StringOption SAVE_PATH_OPTION {"save-path"}; + constexpr const TriStateBoolOption PAUSED_OPTION {"add-paused", true}; + constexpr const BoolOption SKIP_HASH_CHECK_OPTION {"skip-hash-check"}; + constexpr const StringOption CATEGORY_OPTION {"category"}; + constexpr const BoolOption SEQUENTIAL_OPTION {"sequential"}; + constexpr const BoolOption FIRST_AND_LAST_OPTION {"first-and-last"}; + constexpr const TriStateBoolOption SKIP_DIALOG_OPTION {"skip-dialog", true}; } QBtCommandLineParameters::QBtCommandLineParameters(const QProcessEnvironment &env) diff --git a/src/app/cmdoptions.h b/src/app/cmdoptions.h index fcd89e0dc..2b0762650 100644 --- a/src/app/cmdoptions.h +++ b/src/app/cmdoptions.h @@ -56,14 +56,14 @@ struct QBtCommandLineParameters QStringList torrents; QString profileDir, configurationName, savePath, category, unknownParameter; - QBtCommandLineParameters(const QProcessEnvironment&); + explicit QBtCommandLineParameters(const QProcessEnvironment&); QStringList paramList() const; }; class CommandLineParameterError : public std::runtime_error { public: - CommandLineParameterError(const QString &messageForUser); + explicit CommandLineParameterError(const QString &messageForUser); const QString &messageForUser() const; private: diff --git a/src/base/bittorrent/private/statistics.h b/src/base/bittorrent/private/statistics.h index 017f32197..c9ed63fca 100644 --- a/src/base/bittorrent/private/statistics.h +++ b/src/base/bittorrent/private/statistics.h @@ -15,7 +15,7 @@ class Statistics : public QObject Q_DISABLE_COPY(Statistics) public: - Statistics(BitTorrent::Session *session); + explicit Statistics(BitTorrent::Session *session); ~Statistics(); quint64 getAlltimeDL() const; diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 08ef4ec60..c9e0d442c 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -1847,14 +1847,15 @@ void Session::handleDownloadFailed(const QString &url, const QString &reason) void Session::handleRedirectedToMagnet(const QString &url, const QString &magnetUri) { - addTorrent_impl(m_downloadedTorrents.take(url), MagnetUri(magnetUri)); + addTorrent_impl(CreateTorrentParams(m_downloadedTorrents.take(url)), MagnetUri(magnetUri)); } // Add to BitTorrent session the downloaded torrent file void Session::handleDownloadFinished(const QString &url, const QByteArray &data) { emit downloadFromUrlFinished(url); - addTorrent_impl(m_downloadedTorrents.take(url), MagnetUri(), TorrentInfo::load(data)); + addTorrent_impl(CreateTorrentParams(m_downloadedTorrents.take(url)) + , MagnetUri(), TorrentInfo::load(data)); } // Return the torrent handle, given its hash @@ -2094,7 +2095,7 @@ bool Session::addTorrent(QString source, const AddTorrentParams ¶ms) { MagnetUri magnetUri(source); if (magnetUri.isValid()) - return addTorrent_impl(params, magnetUri); + return addTorrent_impl(CreateTorrentParams(params), magnetUri); if (Utils::Misc::isUrl(source)) { LogMsg(tr("Downloading '%1', please wait...", "e.g: Downloading 'xxx.torrent', please wait...").arg(source)); @@ -2110,7 +2111,8 @@ bool Session::addTorrent(QString source, const AddTorrentParams ¶ms) } TorrentFileGuard guard(source); - if (addTorrent_impl(params, MagnetUri(), TorrentInfo::loadFromFile(source))) { + if (addTorrent_impl(CreateTorrentParams(params) + , MagnetUri(), TorrentInfo::loadFromFile(source))) { guard.markAsAddedToSession(); return true; } @@ -2122,7 +2124,7 @@ bool Session::addTorrent(const TorrentInfo &torrentInfo, const AddTorrentParams { if (!torrentInfo.isValid()) return false; - return addTorrent_impl(params, MagnetUri(), torrentInfo); + return addTorrent_impl(CreateTorrentParams(params), MagnetUri(), torrentInfo); } // Add a torrent to the BitTorrent session @@ -4280,23 +4282,27 @@ void Session::handleAddTorrentAlert(libt::add_torrent_alert *p) void Session::handleTorrentRemovedAlert(libt::torrent_removed_alert *p) { - if (m_loadedMetadata.contains(p->info_hash)) - emit metadataLoaded(m_loadedMetadata.take(p->info_hash)); + const InfoHash infoHash {p->info_hash}; - if (m_removingTorrents.contains(p->info_hash)) { - const RemovingTorrentData tmpRemovingTorrentData = m_removingTorrents[p->info_hash]; + if (m_loadedMetadata.contains(infoHash)) + emit metadataLoaded(m_loadedMetadata.take(infoHash)); + + if (m_removingTorrents.contains(infoHash)) { + const RemovingTorrentData tmpRemovingTorrentData = m_removingTorrents[infoHash]; if (!tmpRemovingTorrentData.requestedFileDeletion) { LogMsg(tr("'%1' was removed from the transfer list.", "'xxx.avi' was removed...").arg(tmpRemovingTorrentData.name)); - m_removingTorrents.remove(p->info_hash); + m_removingTorrents.remove(infoHash); } } } void Session::handleTorrentDeletedAlert(libt::torrent_deleted_alert *p) { - if (!m_removingTorrents.contains(p->info_hash)) + const InfoHash infoHash {p->info_hash}; + + if (!m_removingTorrents.contains(infoHash)) return; - const RemovingTorrentData tmpRemovingTorrentData = m_removingTorrents.take(p->info_hash); + const RemovingTorrentData tmpRemovingTorrentData = m_removingTorrents.take(infoHash); Utils::Fs::smartRemoveEmptyFolderTree(tmpRemovingTorrentData.savePathToRemove); LogMsg(tr("'%1' was removed from the transfer list and hard disk.", "'xxx.avi' was removed...").arg(tmpRemovingTorrentData.name)); @@ -4304,9 +4310,11 @@ void Session::handleTorrentDeletedAlert(libt::torrent_deleted_alert *p) void Session::handleTorrentDeleteFailedAlert(libt::torrent_delete_failed_alert *p) { - if (!m_removingTorrents.contains(p->info_hash)) + const InfoHash infoHash {p->info_hash}; + + if (!m_removingTorrents.contains(infoHash)) return; - const RemovingTorrentData tmpRemovingTorrentData = m_removingTorrents.take(p->info_hash); + const RemovingTorrentData tmpRemovingTorrentData = m_removingTorrents.take(infoHash); // libtorrent won't delete the directory if it contains files not listed in the torrent, // so we remove the directory ourselves Utils::Fs::smartRemoveEmptyFolderTree(tmpRemovingTorrentData.savePathToRemove); @@ -4318,7 +4326,7 @@ void Session::handleTorrentDeleteFailedAlert(libt::torrent_delete_failed_alert * void Session::handleMetadataReceivedAlert(libt::metadata_received_alert *p) { - InfoHash hash = p->handle.info_hash(); + const InfoHash hash {p->handle.info_hash()}; if (m_loadedMetadata.contains(hash)) { --m_extraLimit; diff --git a/src/base/bittorrent/torrenthandle.h b/src/base/bittorrent/torrenthandle.h index df66766e3..8e5c0d698 100644 --- a/src/base/bittorrent/torrenthandle.h +++ b/src/base/bittorrent/torrenthandle.h @@ -113,7 +113,7 @@ namespace BitTorrent int seedingTimeLimit; CreateTorrentParams(); - CreateTorrentParams(const AddTorrentParams ¶ms); + explicit CreateTorrentParams(const AddTorrentParams ¶ms); }; struct TrackerInfo diff --git a/src/base/net/private/geoipdatabase.h b/src/base/net/private/geoipdatabase.h index dc702d4df..5ba3d0196 100644 --- a/src/base/net/private/geoipdatabase.h +++ b/src/base/net/private/geoipdatabase.h @@ -55,7 +55,7 @@ public: QString lookup(const QHostAddress &hostAddr) const; private: - GeoIPDatabase(quint32 size); + explicit GeoIPDatabase(quint32 size); bool parseMetadata(const QVariantHash &metadata, QString &error); bool loadDB(QString &error) const; diff --git a/src/base/private/profile_p.h b/src/base/private/profile_p.h index 80fca303e..57ae0a91c 100644 --- a/src/base/private/profile_p.h +++ b/src/base/private/profile_p.h @@ -55,7 +55,7 @@ namespace Private QString profileName() const; protected: - Profile(const QString &configurationName); + explicit Profile(const QString &configurationName); QString configurationSuffix() const; private: @@ -66,7 +66,7 @@ namespace Private class DefaultProfile : public Profile { public: - DefaultProfile(const QString &configurationName); + explicit DefaultProfile(const QString &configurationName); QString baseDirectory() const override; QString cacheLocation() const override; @@ -124,7 +124,7 @@ namespace Private class Converter : public PathConverter { public: - Converter(const QString &basePath); + explicit Converter(const QString &basePath); QString toPortablePath(const QString &path) const override; QString fromPortablePath(const QString &portablePath) const override; diff --git a/src/base/rss/rss_feed.cpp b/src/base/rss/rss_feed.cpp index b66073c55..68afb2eac 100644 --- a/src/base/rss/rss_feed.cpp +++ b/src/base/rss/rss_feed.cpp @@ -131,7 +131,7 @@ void Feed::refresh() // NOTE: Should we allow manually refreshing for disabled session? - Net::DownloadHandler *handler = Net::DownloadManager::instance()->download({m_url}); + Net::DownloadHandler *handler = Net::DownloadManager::instance()->download(m_url); connect(handler , static_cast(&Net::DownloadHandler::downloadFinished) , this, &Feed::handleDownloadFinished); diff --git a/src/base/settingsstorage.cpp b/src/base/settingsstorage.cpp index bf909a5f6..afb820a81 100644 --- a/src/base/settingsstorage.cpp +++ b/src/base/settingsstorage.cpp @@ -46,7 +46,7 @@ namespace class TransactionalSettings { public: - TransactionalSettings(const QString &name) + explicit TransactionalSettings(const QString &name) : m_name(name) { } diff --git a/src/base/torrentfileguard.h b/src/base/torrentfileguard.h index 57fc765d2..7f508273e 100644 --- a/src/base/torrentfileguard.h +++ b/src/base/torrentfileguard.h @@ -38,7 +38,7 @@ template class CachedSettingValue; class FileGuard { public: - FileGuard(const QString &path = QString()); + explicit FileGuard(const QString &path = QString()); ~FileGuard(); /// Cancels or re-enables deferred file deletion @@ -56,7 +56,7 @@ class TorrentFileGuard : private FileGuard Q_GADGET public: - TorrentFileGuard(const QString &path = QString()); + explicit TorrentFileGuard(const QString &path = QString()); ~TorrentFileGuard(); /// marks the torrent file as loaded (added) into the BitTorrent::Session diff --git a/src/gui/properties/proplistdelegate.h b/src/gui/properties/proplistdelegate.h index 2f465644c..dd5e54105 100644 --- a/src/gui/properties/proplistdelegate.h +++ b/src/gui/properties/proplistdelegate.h @@ -53,7 +53,7 @@ class PropListDelegate : public QItemDelegate Q_OBJECT public: - PropListDelegate(PropertiesWidget *properties); + explicit PropListDelegate(PropertiesWidget *properties); void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; void setEditorData(QWidget *editor, const QModelIndex &index) const override; diff --git a/src/gui/properties/speedwidget.h b/src/gui/properties/speedwidget.h index f4d5fb170..bcfa68f9b 100644 --- a/src/gui/properties/speedwidget.h +++ b/src/gui/properties/speedwidget.h @@ -59,7 +59,7 @@ class SpeedWidget : public QWidget Q_OBJECT public: - SpeedWidget(PropertiesWidget *parent); + explicit SpeedWidget(PropertiesWidget *parent); ~SpeedWidget(); private slots: diff --git a/src/gui/properties/trackerlistwidget.h b/src/gui/properties/trackerlistwidget.h index f8b28c547..378023e27 100644 --- a/src/gui/properties/trackerlistwidget.h +++ b/src/gui/properties/trackerlistwidget.h @@ -63,7 +63,7 @@ public: COL_COUNT }; - TrackerListWidget(PropertiesWidget *properties); + explicit TrackerListWidget(PropertiesWidget *properties); ~TrackerListWidget(); int visibleColumnsCount() const; diff --git a/src/gui/properties/trackersadditiondialog.cpp b/src/gui/properties/trackersadditiondialog.cpp index 518fe9bf7..c63628e86 100644 --- a/src/gui/properties/trackersadditiondialog.cpp +++ b/src/gui/properties/trackersadditiondialog.cpp @@ -71,7 +71,7 @@ QStringList TrackersAdditionDialog::newTrackers() const void TrackersAdditionDialog::on_uTorrentListButton_clicked() { m_ui->uTorrentListButton->setEnabled(false); - Net::DownloadHandler *handler = Net::DownloadManager::instance()->download({m_ui->lineEditListURL->text()}); + Net::DownloadHandler *handler = Net::DownloadManager::instance()->download(m_ui->lineEditListURL->text()); connect(handler, static_cast(&Net::DownloadHandler::downloadFinished) , this, &TrackersAdditionDialog::parseUTorrentList); connect(handler, &Net::DownloadHandler::downloadFailed, this, &TrackersAdditionDialog::getTrackerError); diff --git a/src/gui/torrentcontentmodelfolder.h b/src/gui/torrentcontentmodelfolder.h index 983b73477..93019c269 100644 --- a/src/gui/torrentcontentmodelfolder.h +++ b/src/gui/torrentcontentmodelfolder.h @@ -39,7 +39,7 @@ public: TorrentContentModelFolder(const QString &name, TorrentContentModelFolder *parent); // Invisible root item constructor - TorrentContentModelFolder(const QList &data); + explicit TorrentContentModelFolder(const QList &data); ~TorrentContentModelFolder() override; diff --git a/src/gui/torrentcontentmodelitem.h b/src/gui/torrentcontentmodelitem.h index f31fe3f9f..4b2b50e0a 100644 --- a/src/gui/torrentcontentmodelitem.h +++ b/src/gui/torrentcontentmodelitem.h @@ -56,7 +56,7 @@ public: FolderType }; - TorrentContentModelItem(TorrentContentModelFolder *parent); + explicit TorrentContentModelItem(TorrentContentModelFolder *parent); virtual ~TorrentContentModelItem(); bool isRootItem() const;