From 93429840c8a92870b5cc17fef81beb02059d5c69 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 2 Nov 2022 12:21:05 +0800 Subject: [PATCH 1/4] Fix typos --- src/app/application.cpp | 2 +- src/base/net/downloadmanager.cpp | 2 +- src/gui/statusbar.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/application.cpp b/src/app/application.cpp index 4af731821..1b1bcfb85 100644 --- a/src/app/application.cpp +++ b/src/app/application.cpp @@ -882,7 +882,7 @@ void Application::createStartupProgressDialog() m_startupProgressDialog = new QProgressDialog(tr("Loading torrents..."), tr("Exit"), 0, 100); m_startupProgressDialog->setAttribute(Qt::WA_DeleteOnClose); m_startupProgressDialog->setWindowFlag(Qt::WindowMinimizeButtonHint); - m_startupProgressDialog->setMinimumDuration(0); // Show dialog immediatelly by default + m_startupProgressDialog->setMinimumDuration(0); // Show dialog immediately by default m_startupProgressDialog->setAutoReset(false); m_startupProgressDialog->setAutoClose(false); diff --git a/src/base/net/downloadmanager.cpp b/src/base/net/downloadmanager.cpp index ac3022c6d..da5c80c43 100644 --- a/src/base/net/downloadmanager.cpp +++ b/src/base/net/downloadmanager.cpp @@ -124,7 +124,7 @@ namespace // Spoof HTTP Referer to allow adding torrent link from Torcache/KickAssTorrents request.setRawHeader("Referer", request.url().toEncoded().data()); #ifdef QT_NO_COMPRESS - // The macro "QT_NO_COMPRESS" defined in QT will disable the zlib releated features + // The macro "QT_NO_COMPRESS" defined in QT will disable the zlib related features // and reply data auto-decompression in QT will also be disabled. But we can support // gzip encoding and manually decompress the reply data. request.setRawHeader("Accept-Encoding", "gzip"); diff --git a/src/gui/statusbar.cpp b/src/gui/statusbar.cpp index 09a6f290a..0f4bda38e 100644 --- a/src/gui/statusbar.cpp +++ b/src/gui/statusbar.cpp @@ -48,7 +48,7 @@ StatusBar::StatusBar(QWidget *parent) { #ifndef Q_OS_MACOS // Redefining global stylesheet breaks certain elements on mac like tabs. - // Qt checks whether the stylesheet class inherts("QMacStyle") and this becomes false. + // Qt checks whether the stylesheet class inherits("QMacStyle") and this becomes false. setStyleSheet(u"QStatusBar::item { border-width: 0; }"_qs); #endif From 529c1ec9f4c581ba7647fdd47916625b73f5de59 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 2 Nov 2022 16:35:40 +0800 Subject: [PATCH 2/4] Reserve space before appending elements --- src/gui/transferlistmodel.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/gui/transferlistmodel.cpp b/src/gui/transferlistmodel.cpp index a1a372e30..14c8c4cb8 100644 --- a/src/gui/transferlistmodel.cpp +++ b/src/gui/transferlistmodel.cpp @@ -632,9 +632,12 @@ bool TransferListModel::setData(const QModelIndex &index, const QVariant &value, void TransferListModel::addTorrents(const QVector &torrents) { - int row = m_torrentList.size(); - beginInsertRows({}, row, (row + torrents.size())); + qsizetype row = m_torrentList.size(); + const qsizetype total = row + torrents.size(); + beginInsertRows({}, row, total); + + m_torrentList.reserve(total); for (BitTorrent::Torrent *torrent : torrents) { Q_ASSERT(!m_torrentMap.contains(torrent)); From e7ece66717a7af04bd1237eebe554ae4df4d87d3 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sat, 5 Nov 2022 02:44:44 +0800 Subject: [PATCH 3/4] Clean up code --- src/gui/torrentcontenttreeview.cpp | 18 ++++++------------ src/gui/torrentcontenttreeview.h | 2 +- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/gui/torrentcontenttreeview.cpp b/src/gui/torrentcontenttreeview.cpp index 984baca52..81a90e2ee 100644 --- a/src/gui/torrentcontenttreeview.cpp +++ b/src/gui/torrentcontenttreeview.cpp @@ -79,25 +79,19 @@ void TorrentContentTreeView::keyPressEvent(QKeyEvent *event) event->accept(); - QModelIndex current = currentNameCell(); - - QVariant value = current.data(Qt::CheckStateRole); + const QVariant value = currentNameCell().data(Qt::CheckStateRole); if (!value.isValid()) { Q_ASSERT(false); return; } - Qt::CheckState state = (static_cast(value.toInt()) == Qt::Checked - ? Qt::Unchecked : Qt::Checked); - + const Qt::CheckState state = (static_cast(value.toInt()) == Qt::Checked) + ? Qt::Unchecked : Qt::Checked; const QModelIndexList selection = selectionModel()->selectedRows(TorrentContentModelItem::COL_NAME); for (const QModelIndex &index : selection) - { - Q_ASSERT(index.column() == TorrentContentModelItem::COL_NAME); model()->setData(index, state, Qt::CheckStateRole); - } } void TorrentContentTreeView::renameSelectedFile(BitTorrent::AbstractFileStorage &fileStorage) @@ -142,16 +136,16 @@ void TorrentContentTreeView::renameSelectedFile(BitTorrent::AbstractFileStorage } } -QModelIndex TorrentContentTreeView::currentNameCell() +QModelIndex TorrentContentTreeView::currentNameCell() const { - QModelIndex current = currentIndex(); + const QModelIndex current = currentIndex(); if (!current.isValid()) { Q_ASSERT(false); return {}; } - return model()->index(current.row(), TorrentContentModelItem::COL_NAME, current.parent()); + return current.siblingAtColumn(TorrentContentModelItem::COL_NAME); } void TorrentContentTreeView::wheelEvent(QWheelEvent *event) diff --git a/src/gui/torrentcontenttreeview.h b/src/gui/torrentcontenttreeview.h index 1e8a5cfa7..f03be6a2f 100644 --- a/src/gui/torrentcontenttreeview.h +++ b/src/gui/torrentcontenttreeview.h @@ -49,6 +49,6 @@ public: void renameSelectedFile(BitTorrent::AbstractFileStorage &fileStorage); private: - QModelIndex currentNameCell(); + QModelIndex currentNameCell() const; void wheelEvent(QWheelEvent *event) override; }; From d90ea0d3be2a919d1b9c754ea4a3d1f75a2a8db9 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 6 Nov 2022 15:10:23 +0800 Subject: [PATCH 4/4] Move increment out of loop --- src/base/bittorrent/sessionimpl.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/base/bittorrent/sessionimpl.cpp b/src/base/bittorrent/sessionimpl.cpp index 0bc64d05b..44e5e0807 100644 --- a/src/base/bittorrent/sessionimpl.cpp +++ b/src/base/bittorrent/sessionimpl.cpp @@ -2914,10 +2914,8 @@ void SessionImpl::generateResumeData() void SessionImpl::saveResumeData() { for (const TorrentImpl *torrent : asConst(m_torrents)) - { torrent->nativeHandle().save_resume_data(lt::torrent_handle::only_if_modified); - ++m_numResumeData; - } + m_numResumeData += m_torrents.size(); // clear queued storage move jobs except the current ongoing one if (m_moveStorageQueue.size() > 1)