diff --git a/libtransmission/torrent-ctor.c b/libtransmission/torrent-ctor.c index 4e7676d4d..bb0f48170 100644 --- a/libtransmission/torrent-ctor.c +++ b/libtransmission/torrent-ctor.c @@ -80,7 +80,7 @@ static void clearMetainfo(tr_ctor* ctor) setSourceFile(ctor, NULL); } -int tr_ctorSetMetainfo(tr_ctor* ctor, uint8_t const* metainfo, size_t len) +int tr_ctorSetMetainfo(tr_ctor* ctor, void const* metainfo, size_t len) { int err; diff --git a/libtransmission/transmission.h b/libtransmission/transmission.h index c34e1d6df..7ee6f8b79 100644 --- a/libtransmission/transmission.h +++ b/libtransmission/transmission.h @@ -853,7 +853,7 @@ void tr_ctorSetDeleteSource(tr_ctor* ctor, bool doDelete); int tr_ctorSetMetainfoFromMagnetLink(tr_ctor* ctor, char const* magnet); /** @brief Set the constructor's metainfo from a raw benc already in memory */ -int tr_ctorSetMetainfo(tr_ctor* ctor, uint8_t const* metainfo, size_t len); +int tr_ctorSetMetainfo(tr_ctor* ctor, void const* metainfo, size_t len); /** @brief Set the constructor's metainfo from a local .torrent file */ int tr_ctorSetMetainfoFromFile(tr_ctor* ctor, char const* filename); diff --git a/qt/.clang-tidy b/qt/.clang-tidy index f2535132b..42b6992d2 100644 --- a/qt/.clang-tidy +++ b/qt/.clang-tidy @@ -20,9 +20,7 @@ Checks: > -cppcoreguidelines-pro-bounds-pointer-arithmetic, -cppcoreguidelines-pro-type-const-cast, -cppcoreguidelines-pro-type-cstyle-cast, - -cppcoreguidelines-pro-type-reinterpret-cast, -cppcoreguidelines-pro-type-static-cast-downcast, - -cppcoreguidelines-special-member-functions, google-readability-*, google-runtime-operator, hicpp-*, diff --git a/qt/AddData.cc b/qt/AddData.cc index 8784652e4..df61c7f09 100644 --- a/qt/AddData.cc +++ b/qt/AddData.cc @@ -100,7 +100,7 @@ QString AddData::readableName() const tr_info inf; tr_ctor* ctor = tr_ctorNew(nullptr); - tr_ctorSetMetainfo(ctor, reinterpret_cast(metainfo.constData()), metainfo.size()); + tr_ctorSetMetainfo(ctor, metainfo.constData(), metainfo.size()); if (tr_torrentParse(ctor, &inf) == TR_PARSE_OK) { diff --git a/qt/ComInteropHelper.cc b/qt/ComInteropHelper.cc index 42b5f4b91..395671e42 100644 --- a/qt/ComInteropHelper.cc +++ b/qt/ComInteropHelper.cc @@ -10,13 +10,13 @@ #include #include -#include #include #include #include "ComInteropHelper.h" #include "InteropObject.h" +// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions) QAXFACTORY_BEGIN("{1e405fc2-1a3a-468b-8bd6-bfbb58770390}", "{792d1aac-53cc-4dc9-bc29-e5295fdb93a9}") QAXCLASS(InteropObject) QAXFACTORY_END() @@ -32,8 +32,6 @@ ComInteropHelper::ComInteropHelper() : { } -ComInteropHelper::~ComInteropHelper() = default; - bool ComInteropHelper::isConnected() const { return !client_->isNull(); diff --git a/qt/ComInteropHelper.h b/qt/ComInteropHelper.h index 2bf29bf0e..163f4df93 100644 --- a/qt/ComInteropHelper.h +++ b/qt/ComInteropHelper.h @@ -10,7 +10,8 @@ #include -class QAxObject; +#include + class QObject; class QString; class QVariant; @@ -19,7 +20,6 @@ class ComInteropHelper { public: ComInteropHelper(); - ~ComInteropHelper(); bool isConnected() const; diff --git a/qt/DBusInteropHelper.h b/qt/DBusInteropHelper.h index e129aba3c..c89af0ca2 100644 --- a/qt/DBusInteropHelper.h +++ b/qt/DBusInteropHelper.h @@ -16,7 +16,6 @@ class DBusInteropHelper { public: DBusInteropHelper() = default; - ~DBusInteropHelper() = default; bool isConnected() const; diff --git a/qt/DetailsDialog.cc b/qt/DetailsDialog.cc index 7a6c2bda5..0d3d9a45d 100644 --- a/qt/DetailsDialog.cc +++ b/qt/DetailsDialog.cc @@ -99,8 +99,6 @@ public: { } - ~PeerItem() override = default; - void refresh(Peer const& p) { if (p.address != peer_.address) diff --git a/qt/FaviconCache.cc b/qt/FaviconCache.cc index e96235afe..7f0f1540c 100644 --- a/qt/FaviconCache.cc +++ b/qt/FaviconCache.cc @@ -19,16 +19,11 @@ ***/ FaviconCache::FaviconCache() : - nam_(new QNetworkAccessManager()) + nam_(new QNetworkAccessManager(this)) { connect(nam_, SIGNAL(finished(QNetworkReply*)), this, SLOT(onRequestFinished(QNetworkReply*))); } -FaviconCache::~FaviconCache() -{ - delete nam_; -} - /*** **** ***/ diff --git a/qt/FaviconCache.h b/qt/FaviconCache.h index 8ded3bd6d..f60d0fd1d 100644 --- a/qt/FaviconCache.h +++ b/qt/FaviconCache.h @@ -26,7 +26,6 @@ class FaviconCache : public QObject public: FaviconCache(); - virtual ~FaviconCache(); // returns a cached pixmap, or a NULL pixmap if there's no match in the cache QPixmap find(QString const& key); diff --git a/qt/FilterBar.cc b/qt/FilterBar.cc index ac82b5080..361f55030 100644 --- a/qt/FilterBar.cc +++ b/qt/FilterBar.cc @@ -246,11 +246,6 @@ FilterBar::FilterBar(Prefs& prefs, TorrentModel const& torrents, TorrentFilter c } } -FilterBar::~FilterBar() -{ - delete recount_timer_; -} - /*** **** ***/ diff --git a/qt/FilterBar.h b/qt/FilterBar.h index 0963af59c..982607807 100644 --- a/qt/FilterBar.h +++ b/qt/FilterBar.h @@ -28,7 +28,6 @@ class FilterBar : public QWidget public: FilterBar(Prefs& prefs, TorrentModel const& torrents, TorrentFilter const& filter, QWidget* parent = nullptr); - virtual ~FilterBar(); public slots: void clear(); diff --git a/qt/FreeSpaceLabel.h b/qt/FreeSpaceLabel.h index fddc9042a..a91e177b1 100644 --- a/qt/FreeSpaceLabel.h +++ b/qt/FreeSpaceLabel.h @@ -26,8 +26,6 @@ class FreeSpaceLabel : public QLabel public: FreeSpaceLabel(QWidget* parent = nullptr); - virtual ~FreeSpaceLabel() = default; - void setSession(Session& session); void setPath(QString const& folder); diff --git a/qt/InteropHelper.h b/qt/InteropHelper.h index 1cd75d216..bd0675b32 100644 --- a/qt/InteropHelper.h +++ b/qt/InteropHelper.h @@ -15,9 +15,7 @@ #include "DBusInteropHelper.h" #endif -class QAxObject; class QString; -class QVariant; class InteropHelper { diff --git a/qt/LicenseDialog.h b/qt/LicenseDialog.h index 5efb1c46c..9f7a7919b 100644 --- a/qt/LicenseDialog.h +++ b/qt/LicenseDialog.h @@ -19,8 +19,6 @@ class LicenseDialog : public BaseDialog public: LicenseDialog(QWidget* parent = nullptr); - virtual ~LicenseDialog() = default; - private: Ui::LicenseDialog ui_ = {}; }; diff --git a/qt/MainWindow.cc b/qt/MainWindow.cc index 0f9a05b3f..bcbf9d4dd 100644 --- a/qt/MainWindow.cc +++ b/qt/MainWindow.cc @@ -360,8 +360,6 @@ MainWindow::MainWindow(Session& session, Prefs& prefs, TorrentModel& model, bool refreshSoon(); } -MainWindow::~MainWindow() = default; - void MainWindow::onSessionSourceChanged() { model_.clear(); diff --git a/qt/MainWindow.h b/qt/MainWindow.h index eaf29464d..c2ae44d4c 100644 --- a/qt/MainWindow.h +++ b/qt/MainWindow.h @@ -52,7 +52,6 @@ class MainWindow : public QMainWindow public: MainWindow(Session&, Prefs&, TorrentModel&, bool minized); - virtual ~MainWindow(); QSystemTrayIcon& trayIcon() { diff --git a/qt/MakeDialog.cc b/qt/MakeDialog.cc index 2d1140df0..9fbd60a2c 100644 --- a/qt/MakeDialog.cc +++ b/qt/MakeDialog.cc @@ -258,8 +258,6 @@ MakeDialog::MakeDialog(Session& session, QWidget* parent) : onSourceChanged(); } -MakeDialog::~MakeDialog() = default; - /*** **** ***/ diff --git a/qt/MakeDialog.h b/qt/MakeDialog.h index 58c740830..7cffec5d2 100644 --- a/qt/MakeDialog.h +++ b/qt/MakeDialog.h @@ -29,7 +29,6 @@ class MakeDialog : public BaseDialog public: MakeDialog(Session&, QWidget* parent = nullptr); - virtual ~MakeDialog(); protected: // QWidget diff --git a/qt/OptionsDialog.cc b/qt/OptionsDialog.cc index c86efd39d..8c0e792d5 100644 --- a/qt/OptionsDialog.cc +++ b/qt/OptionsDialog.cc @@ -160,7 +160,7 @@ void OptionsDialog::reload() break; case AddData::METAINFO: - tr_ctorSetMetainfo(ctor, reinterpret_cast(add_.metainfo.constData()), add_.metainfo.size()); + tr_ctorSetMetainfo(ctor, add_.metainfo.constData(), add_.metainfo.size()); break; default: diff --git a/qt/PrefsDialog.cc b/qt/PrefsDialog.cc index a9dd2c173..4ab39a7a1 100644 --- a/qt/PrefsDialog.cc +++ b/qt/PrefsDialog.cc @@ -649,8 +649,6 @@ PrefsDialog::PrefsDialog(Session& session, Prefs& prefs, QWidget* parent) : adjustSize(); } -PrefsDialog::~PrefsDialog() = default; - void PrefsDialog::setPref(int key, QVariant const& v) { prefs_.set(key, v); diff --git a/qt/PrefsDialog.h b/qt/PrefsDialog.h index c5a09838a..ff980f7eb 100644 --- a/qt/PrefsDialog.h +++ b/qt/PrefsDialog.h @@ -28,7 +28,6 @@ class PrefsDialog : public BaseDialog public: PrefsDialog(Session&, Prefs&, QWidget* parent = nullptr); - virtual ~PrefsDialog(); private: using key2widget_t = QMap; diff --git a/qt/RelocateDialog.h b/qt/RelocateDialog.h index 2ea6a61dc..0bd7f1f73 100644 --- a/qt/RelocateDialog.h +++ b/qt/RelocateDialog.h @@ -23,8 +23,6 @@ class RelocateDialog : public BaseDialog public: RelocateDialog(Session&, TorrentModel const&, torrent_ids_t ids, QWidget* parent = nullptr); - virtual ~RelocateDialog() = default; - private: QString newLocation() const; diff --git a/qt/RpcClient.h b/qt/RpcClient.h index f07e1580e..99048cccf 100644 --- a/qt/RpcClient.h +++ b/qt/RpcClient.h @@ -53,7 +53,6 @@ class RpcClient : public QObject public: RpcClient(QObject* parent = nullptr); - virtual ~RpcClient() = default; void stop(); void start(tr_session* session); diff --git a/qt/StatsDialog.cc b/qt/StatsDialog.cc index 154f7a2d6..489f287f1 100644 --- a/qt/StatsDialog.cc +++ b/qt/StatsDialog.cc @@ -38,8 +38,6 @@ StatsDialog::StatsDialog(Session& session, QWidget* parent) : session_.refreshSessionStats(); } -StatsDialog::~StatsDialog() = default; - void StatsDialog::setVisible(bool visible) { timer_->stop(); diff --git a/qt/StatsDialog.h b/qt/StatsDialog.h index bf202ea54..6d41074cb 100644 --- a/qt/StatsDialog.h +++ b/qt/StatsDialog.h @@ -22,7 +22,6 @@ class StatsDialog : public BaseDialog public: StatsDialog(Session&, QWidget* parent = nullptr); - ~StatsDialog() override; // QWidget void setVisible(bool visible) override; diff --git a/qt/TorrentDelegate.cc b/qt/TorrentDelegate.cc index 13c12bcec..50ef927de 100644 --- a/qt/TorrentDelegate.cc +++ b/qt/TorrentDelegate.cc @@ -127,11 +127,10 @@ ItemLayout::ItemLayout(QString name_text, QString status_text, QString progress_ } // namespace TorrentDelegate::TorrentDelegate(QObject* parent) : - QStyledItemDelegate(parent), - progress_bar_style_(new QStyleOptionProgressBar) + QStyledItemDelegate(parent) { - progress_bar_style_->minimum = 0; - progress_bar_style_->maximum = 1000; + progress_bar_style_.minimum = 0; + progress_bar_style_.maximum = 1000; green_brush = QColor("forestgreen"); green_back = QColor("darkseagreen"); @@ -143,11 +142,6 @@ TorrentDelegate::TorrentDelegate(QObject* parent) : silver_back = QColor("grey"); } -TorrentDelegate::~TorrentDelegate() -{ - delete progress_bar_style_; -} - /*** **** ***/ @@ -452,15 +446,15 @@ void TorrentDelegate::setProgressBarPercentDone(QStyleOptionViewItem const& opti if (tor.isSeeding() && tor.getSeedRatio(seed_ratio_limit)) { double const seed_rate_ratio = tor.ratio() / seed_ratio_limit; - int const scaled_progress = seed_rate_ratio * (progress_bar_style_->maximum - progress_bar_style_->minimum); - progress_bar_style_->progress = progress_bar_style_->minimum + scaled_progress; + int const scaled_progress = seed_rate_ratio * (progress_bar_style_.maximum - progress_bar_style_.minimum); + progress_bar_style_.progress = progress_bar_style_.minimum + scaled_progress; } else { bool const is_magnet(!tor.hasMetadata()); - progress_bar_style_->direction = option.direction; - progress_bar_style_->progress = static_cast(progress_bar_style_->minimum + (is_magnet ? tor.metadataPercentDone() : - tor.percentDone()) * (progress_bar_style_->maximum - progress_bar_style_->minimum)); + progress_bar_style_.direction = option.direction; + progress_bar_style_.progress = static_cast(progress_bar_style_.minimum + (is_magnet ? tor.metadataPercentDone() : + tor.percentDone()) * (progress_bar_style_.maximum - progress_bar_style_.minimum)); } } @@ -578,31 +572,31 @@ void TorrentDelegate::drawTorrent(QPainter* painter, QStyleOptionViewItem const& painter->drawText(layout.status_rect, Qt::AlignLeft | Qt::AlignVCenter, layout.statusText()); painter->setFont(layout.progress_font); painter->drawText(layout.progress_rect, Qt::AlignLeft | Qt::AlignVCenter, layout.progressText()); - progress_bar_style_->rect = layout.bar_rect; + progress_bar_style_.rect = layout.bar_rect; if (tor.isDownloading()) { - progress_bar_style_->palette.setBrush(QPalette::Highlight, blue_brush); - progress_bar_style_->palette.setColor(QPalette::Base, blue_back); - progress_bar_style_->palette.setColor(QPalette::Window, blue_back); + progress_bar_style_.palette.setBrush(QPalette::Highlight, blue_brush); + progress_bar_style_.palette.setColor(QPalette::Base, blue_back); + progress_bar_style_.palette.setColor(QPalette::Window, blue_back); } else if (tor.isSeeding()) { - progress_bar_style_->palette.setBrush(QPalette::Highlight, green_brush); - progress_bar_style_->palette.setColor(QPalette::Base, green_back); - progress_bar_style_->palette.setColor(QPalette::Window, green_back); + progress_bar_style_.palette.setBrush(QPalette::Highlight, green_brush); + progress_bar_style_.palette.setColor(QPalette::Base, green_back); + progress_bar_style_.palette.setColor(QPalette::Window, green_back); } else { - progress_bar_style_->palette.setBrush(QPalette::Highlight, silver_brush); - progress_bar_style_->palette.setColor(QPalette::Base, silver_back); - progress_bar_style_->palette.setColor(QPalette::Window, silver_back); + progress_bar_style_.palette.setBrush(QPalette::Highlight, silver_brush); + progress_bar_style_.palette.setColor(QPalette::Base, silver_back); + progress_bar_style_.palette.setColor(QPalette::Window, silver_back); } - progress_bar_style_->state = progress_bar_state; + progress_bar_style_.state = progress_bar_state; setProgressBarPercentDone(option, tor); - style->drawControl(QStyle::CE_ProgressBar, progress_bar_style_, painter); + style->drawControl(QStyle::CE_ProgressBar, &progress_bar_style_, painter); painter->restore(); } diff --git a/qt/TorrentDelegate.h b/qt/TorrentDelegate.h index 56956f006..9be170937 100644 --- a/qt/TorrentDelegate.h +++ b/qt/TorrentDelegate.h @@ -23,7 +23,6 @@ class TorrentDelegate : public QStyledItemDelegate public: explicit TorrentDelegate(QObject* parent = nullptr); - virtual ~TorrentDelegate(); // QAbstractItemDelegate QSize sizeHint(QStyleOptionViewItem const& option, QModelIndex const& index) const override; @@ -43,8 +42,6 @@ protected: static QString shortStatusString(Torrent const& tor); static QString shortTransferString(Torrent const& tor); - QStyleOptionProgressBar* progress_bar_style_ = {}; - static QColor blue_brush; static QColor green_brush; static QColor silver_brush; @@ -52,6 +49,8 @@ protected: static QColor green_back; static QColor silver_back; + mutable QStyleOptionProgressBar progress_bar_style_ = {}; + private: mutable std::optional height_hint_; mutable QFont height_font_; diff --git a/qt/TorrentDelegateMin.cc b/qt/TorrentDelegateMin.cc index d07cf8a5a..86d24fa6e 100644 --- a/qt/TorrentDelegateMin.cc +++ b/qt/TorrentDelegateMin.cc @@ -251,33 +251,33 @@ void TorrentDelegateMin::drawTorrent(QPainter* painter, QStyleOptionViewItem con painter->drawText(layout.name_rect, Qt::AlignLeft | Qt::AlignVCenter, layout.nameText()); painter->setFont(layout.status_font); painter->drawText(layout.status_rect, Qt::AlignLeft | Qt::AlignVCenter, layout.statusText()); - progress_bar_style_->rect = layout.bar_rect; + progress_bar_style_.rect = layout.bar_rect; if (tor.isDownloading()) { - progress_bar_style_->palette.setBrush(QPalette::Highlight, blue_brush); - progress_bar_style_->palette.setColor(QPalette::Base, blue_back); - progress_bar_style_->palette.setColor(QPalette::Window, blue_back); + progress_bar_style_.palette.setBrush(QPalette::Highlight, blue_brush); + progress_bar_style_.palette.setColor(QPalette::Base, blue_back); + progress_bar_style_.palette.setColor(QPalette::Window, blue_back); } else if (tor.isSeeding()) { - progress_bar_style_->palette.setBrush(QPalette::Highlight, green_brush); - progress_bar_style_->palette.setColor(QPalette::Base, green_back); - progress_bar_style_->palette.setColor(QPalette::Window, green_back); + progress_bar_style_.palette.setBrush(QPalette::Highlight, green_brush); + progress_bar_style_.palette.setColor(QPalette::Base, green_back); + progress_bar_style_.palette.setColor(QPalette::Window, green_back); } else { - progress_bar_style_->palette.setBrush(QPalette::Highlight, silver_brush); - progress_bar_style_->palette.setColor(QPalette::Base, silver_back); - progress_bar_style_->palette.setColor(QPalette::Window, silver_back); + progress_bar_style_.palette.setBrush(QPalette::Highlight, silver_brush); + progress_bar_style_.palette.setColor(QPalette::Base, silver_back); + progress_bar_style_.palette.setColor(QPalette::Window, silver_back); } - progress_bar_style_->state = progress_bar_state; - progress_bar_style_->text = QStringLiteral("%1%").arg(static_cast(tr_truncd(100.0 * tor.percentDone(), 0))); - progress_bar_style_->textVisible = true; - progress_bar_style_->textAlignment = Qt::AlignCenter; + progress_bar_style_.state = progress_bar_state; + progress_bar_style_.text = QStringLiteral("%1%").arg(static_cast(tr_truncd(100.0 * tor.percentDone(), 0))); + progress_bar_style_.textVisible = true; + progress_bar_style_.textAlignment = Qt::AlignCenter; setProgressBarPercentDone(option, tor); - style->drawControl(QStyle::CE_ProgressBar, progress_bar_style_, painter); + style->drawControl(QStyle::CE_ProgressBar, &progress_bar_style_, painter); painter->restore(); } diff --git a/qt/TorrentFilter.cc b/qt/TorrentFilter.cc index 3cccf03ab..52ba3d520 100644 --- a/qt/TorrentFilter.cc +++ b/qt/TorrentFilter.cc @@ -27,8 +27,6 @@ TorrentFilter::TorrentFilter(Prefs const& prefs) : refilter(); } -TorrentFilter::~TorrentFilter() = default; - /*** **** ***/ diff --git a/qt/TorrentFilter.h b/qt/TorrentFilter.h index e55078cc1..afe95aaa7 100644 --- a/qt/TorrentFilter.h +++ b/qt/TorrentFilter.h @@ -35,7 +35,6 @@ public: public: explicit TorrentFilter(Prefs const& prefs); - virtual ~TorrentFilter(); [[nodiscard]] std::array countTorrentsPerMode() const; protected: diff --git a/qt/Utils.cc b/qt/Utils.cc index 66feb092f..e08aeba42 100644 --- a/qt/Utils.cc +++ b/qt/Utils.cc @@ -58,11 +58,11 @@ void addAssociatedFileIcon(QFileInfo const& file_info, UINT icon_size, QIcon& ic if (!QPixmapCache::find(pixmap_cache_key, &pixmap)) { - QString const filename = file_info.fileName(); + auto const filename = file_info.fileName().toStdWString(); SHFILEINFO shell_file_info; - if (::SHGetFileInfoW(reinterpret_cast(filename.utf16()), FILE_ATTRIBUTE_NORMAL, &shell_file_info, + if (::SHGetFileInfoW(filename.data(), FILE_ATTRIBUTE_NORMAL, &shell_file_info, sizeof(shell_file_info), SHGFI_ICON | icon_size | SHGFI_USEFILEATTRIBUTES) != 0) { if (shell_file_info.hIcon != nullptr)