Use QList explicitly

PR #21016.
This commit is contained in:
Vladimir Golovnev
2024-07-04 08:30:39 +03:00
committed by GitHub
parent d2fceaa228
commit 5ef2a1df07
95 changed files with 408 additions and 373 deletions

View File

@@ -32,7 +32,7 @@
#include <cmath>
#include <QDebug>
#include <QVector>
#include <QList>
#include "base/global.h"
@@ -51,9 +51,9 @@ DownloadedPiecesBar::DownloadedPiecesBar(QWidget *parent)
{
}
QVector<float> DownloadedPiecesBar::bitfieldToFloatVector(const QBitArray &vecin, int reqSize)
QList<float> DownloadedPiecesBar::bitfieldToFloatVector(const QBitArray &vecin, int reqSize)
{
QVector<float> result(reqSize, 0.0);
QList<float> result(reqSize, 0.0);
if (vecin.isEmpty()) return result;
const float ratio = vecin.size() / static_cast<float>(reqSize);
@@ -145,8 +145,8 @@ bool DownloadedPiecesBar::updateImage(QImage &image)
return true;
}
QVector<float> scaledPieces = bitfieldToFloatVector(m_pieces, image2.width());
QVector<float> scaledPiecesDl = bitfieldToFloatVector(m_downloadedPieces, image2.width());
QList<float> scaledPieces = bitfieldToFloatVector(m_pieces, image2.width());
QList<float> scaledPiecesDl = bitfieldToFloatVector(m_downloadedPieces, image2.width());
// filling image
for (int x = 0; x < scaledPieces.size(); ++x)

View File

@@ -51,7 +51,7 @@ public:
private:
// scale bitfield vector to float vector
QVector<float> bitfieldToFloatVector(const QBitArray &vecin, int reqSize);
QList<float> bitfieldToFloatVector(const QBitArray &vecin, int reqSize);
bool updateImage(QImage &image) override;
QString simpleToolTipText() const override;

View File

@@ -35,6 +35,7 @@
#include <QClipboard>
#include <QHeaderView>
#include <QHostAddress>
#include <QList>
#include <QMenu>
#include <QMessageBox>
#include <QPointer>
@@ -42,7 +43,6 @@
#include <QShortcut>
#include <QSortFilterProxyModel>
#include <QStandardItemModel>
#include <QVector>
#include <QWheelEvent>
#include "base/bittorrent/peeraddress.h"
@@ -290,7 +290,7 @@ void PeerListWidget::showPeerListMenu()
QAction *addNewPeer = menu->addAction(UIThemeManager::instance()->getIcon(u"peers-add"_s), tr("Add peers...")
, this, [this, torrent]()
{
const QVector<BitTorrent::PeerAddress> peersList = PeersAdditionDialog::askForPeers(this);
const QList<BitTorrent::PeerAddress> peersList = PeersAdditionDialog::askForPeers(this);
const int peerCount = std::count_if(peersList.cbegin(), peersList.cend(), [torrent](const BitTorrent::PeerAddress &peer)
{
return torrent->connectPeer(peer);
@@ -335,7 +335,7 @@ void PeerListWidget::banSelectedPeers()
// Store selected rows first as selected peers may disconnect
const QModelIndexList selectedIndexes = selectionModel()->selectedRows();
QVector<QString> selectedIPs;
QList<QString> selectedIPs;
selectedIPs.reserve(selectedIndexes.size());
for (const QModelIndex &index : selectedIndexes)
@@ -405,7 +405,7 @@ void PeerListWidget::loadPeers(const BitTorrent::Torrent *torrent)
return;
using TorrentPtr = QPointer<const BitTorrent::Torrent>;
torrent->fetchPeerInfo([this, torrent = TorrentPtr(torrent)](const QVector<BitTorrent::PeerInfo> &peers)
torrent->fetchPeerInfo([this, torrent = TorrentPtr(torrent)](const QList<BitTorrent::PeerInfo> &peers)
{
if (torrent != m_properties->getCurrentTorrent())
return;

View File

@@ -50,7 +50,7 @@ PeersAdditionDialog::~PeersAdditionDialog()
delete m_ui;
}
QVector<BitTorrent::PeerAddress> PeersAdditionDialog::askForPeers(QWidget *parent)
QList<BitTorrent::PeerAddress> PeersAdditionDialog::askForPeers(QWidget *parent)
{
PeersAdditionDialog dlg(parent);
dlg.exec();

View File

@@ -29,7 +29,7 @@
#pragma once
#include <QDialog>
#include <QVector>
#include <QList>
#include "base/bittorrent/peerinfo.h"
@@ -47,12 +47,12 @@ public:
PeersAdditionDialog(QWidget *parent);
~PeersAdditionDialog();
static QVector<BitTorrent::PeerAddress> askForPeers(QWidget *parent);
static QList<BitTorrent::PeerAddress> askForPeers(QWidget *parent);
protected slots:
void validateInput();
private:
Ui::PeersAdditionDialog *m_ui = nullptr;
QVector<BitTorrent::PeerAddress> m_peersList;
QList<BitTorrent::PeerAddress> m_peersList;
};

View File

@@ -40,9 +40,9 @@ PieceAvailabilityBar::PieceAvailabilityBar(QWidget *parent)
{
}
QVector<float> PieceAvailabilityBar::intToFloatVector(const QVector<int> &vecin, int reqSize)
QList<float> PieceAvailabilityBar::intToFloatVector(const QList<int> &vecin, int reqSize)
{
QVector<float> result(reqSize, 0.0);
QList<float> result(reqSize, 0.0);
if (vecin.isEmpty()) return result;
const float ratio = static_cast<float>(vecin.size()) / reqSize;
@@ -142,7 +142,7 @@ bool PieceAvailabilityBar::updateImage(QImage &image)
return true;
}
QVector<float> scaledPieces = intToFloatVector(m_pieces, image2.width());
QList<float> scaledPieces = intToFloatVector(m_pieces, image2.width());
// filling image
for (int x = 0; x < scaledPieces.size(); ++x)
@@ -154,7 +154,7 @@ bool PieceAvailabilityBar::updateImage(QImage &image)
return true;
}
void PieceAvailabilityBar::setAvailability(const QVector<int> &avail)
void PieceAvailabilityBar::setAvailability(const QList<int> &avail)
{
m_pieces = avail;

View File

@@ -40,7 +40,7 @@ class PieceAvailabilityBar final : public PiecesBar
public:
PieceAvailabilityBar(QWidget *parent);
void setAvailability(const QVector<int> &avail);
void setAvailability(const QList<int> &avail);
// PiecesBar interface
void clear() override;
@@ -51,8 +51,8 @@ private:
// last used int vector, uses to better resize redraw
// TODO: make a diff pieces to new pieces and update only changed pixels, speedup when update > 20x faster
QVector<int> m_pieces;
QList<int> m_pieces;
// scale int vector to float vector
QVector<float> intToFloatVector(const QVector<int> &vecin, int reqSize);
QList<float> intToFloatVector(const QList<int> &vecin, int reqSize);
};

View File

@@ -222,7 +222,7 @@ QColor PiecesBar::colorBoxBorderColor() const
return palette().color(QPalette::ToolTipText);
}
const QVector<QRgb> &PiecesBar::pieceColors() const
const QList<QRgb> &PiecesBar::pieceColors() const
{
return m_pieceColors;
}
@@ -261,7 +261,7 @@ void PiecesBar::showToolTip(const QHelpEvent *e)
{
const PieceIndexToImagePos transform {torrentInfo, m_image};
const int pieceIndex = transform.pieceIndex(imagePos);
const QVector<int> fileIndexes = torrentInfo.fileIndicesForPiece(pieceIndex);
const QList<int> fileIndexes = torrentInfo.fileIndicesForPiece(pieceIndex);
QString tooltipTitle;
if (fileIndexes.count() > 1)
@@ -305,7 +305,7 @@ void PiecesBar::highlightFile(int imagePos)
PieceIndexToImagePos transform {torrentInfo, m_image};
int pieceIndex = transform.pieceIndex(imagePos);
QVector<int> fileIndices {torrentInfo.fileIndicesForPiece(pieceIndex)};
QList<int> fileIndices {torrentInfo.fileIndicesForPiece(pieceIndex)};
if (fileIndices.count() == 1)
{
BitTorrent::TorrentInfo::PieceRange filePieces = torrentInfo.filePieces(fileIndices.first());
@@ -327,7 +327,7 @@ void PiecesBar::highlightFile(int imagePos)
void PiecesBar::updatePieceColors()
{
m_pieceColors = QVector<QRgb>(256);
m_pieceColors = QList<QRgb>(256);
for (int i = 0; i < 256; ++i)
{
float ratio = (i / 255.0);

View File

@@ -70,7 +70,7 @@ protected:
QColor borderColor() const;
QColor pieceColor() const;
QColor colorBoxBorderColor() const;
const QVector<QRgb> &pieceColors() const;
const QList<QRgb> &pieceColors() const;
// mix two colors by light model, ratio <0, 1>
static QRgb mixTwoColors(QRgb rgb1, QRgb rgb2, float ratio);
@@ -91,7 +91,7 @@ private:
const BitTorrent::Torrent *m_torrent = nullptr;
QImage m_image;
// buffered 256 levels gradient from bg_color to piece_color
QVector<QRgb> m_pieceColors;
QList<QRgb> m_pieceColors;
bool m_hovered = false;
QRect m_highlightedRegion; // part of the bar can be highlighted; this rectangle is in the same frame as m_image
};

View File

@@ -471,7 +471,7 @@ void PropertiesWidget::loadDynamicData()
{
// Pieces availability
showPiecesAvailability(true);
m_torrent->fetchPieceAvailability([this, torrent = TorrentPtr(m_torrent)](const QVector<int> &pieceAvailability)
m_torrent->fetchPieceAvailability([this, torrent = TorrentPtr(m_torrent)](const QList<int> &pieceAvailability)
{
if (torrent == m_torrent)
m_piecesAvailability->setAvailability(pieceAvailability);
@@ -517,7 +517,7 @@ void PropertiesWidget::loadUrlSeeds()
return;
using TorrentPtr = QPointer<BitTorrent::Torrent>;
m_torrent->fetchURLSeeds([this, torrent = TorrentPtr(m_torrent)](const QVector<QUrl> &urlSeeds)
m_torrent->fetchURLSeeds([this, torrent = TorrentPtr(m_torrent)](const QList<QUrl> &urlSeeds)
{
if (torrent != m_torrent)
return;
@@ -620,7 +620,7 @@ void PropertiesWidget::deleteSelectedUrlSeeds()
const QList<QListWidgetItem *> selectedItems = m_ui->listWebSeeds->selectedItems();
if (selectedItems.isEmpty()) return;
QVector<QUrl> urlSeeds;
QList<QUrl> urlSeeds;
urlSeeds.reserve(selectedItems.size());
for (const QListWidgetItem *item : selectedItems)

View File

@@ -292,7 +292,7 @@ void SpeedPlotView::paintEvent(QPaintEvent *)
rect.adjust(0, fontMetrics.height(), 0, 0); // Add top padding for top speed text
// draw Y axis speed labels
const QVector<QString> speedLabels =
const QList<QString> speedLabels =
{
formatLabel(niceScale.arg, niceScale.unit),
formatLabel((0.75 * niceScale.arg), niceScale.unit),
@@ -358,7 +358,7 @@ void SpeedPlotView::paintEvent(QPaintEvent *)
if (!m_properties[static_cast<GraphID>(id)].enable)
continue;
QVector<QPoint> points;
QList<QPoint> points;
milliseconds duration {0};
for (int i = static_cast<int>(queue.size()) - 1; i >= 0; --i)