mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-31 20:58:07 -06:00
Remove usage of QTextStream
Other classes already provide rich methods so avoid another layer of QTextStream which slow things down (slightly). PR #17180.
This commit is contained in:
@@ -34,7 +34,6 @@
|
||||
#include <QHelpEvent>
|
||||
#include <QPainter>
|
||||
#include <QPainterPath>
|
||||
#include <QTextStream>
|
||||
#include <QToolTip>
|
||||
|
||||
#include "base/bittorrent/torrent.h"
|
||||
@@ -88,25 +87,29 @@ namespace
|
||||
class DetailedTooltipRenderer
|
||||
{
|
||||
public:
|
||||
DetailedTooltipRenderer(QTextStream &stream, const QString &header)
|
||||
: m_stream(stream)
|
||||
DetailedTooltipRenderer(QString &string, const QString &header)
|
||||
: m_string(string)
|
||||
{
|
||||
m_stream << header
|
||||
<< R"(<table style="width:100%; padding: 3px; vertical-align: middle;">)";
|
||||
m_string += header
|
||||
+ uR"(<table style="width:100%; padding: 3px; vertical-align: middle;">)";
|
||||
}
|
||||
|
||||
~DetailedTooltipRenderer()
|
||||
{
|
||||
m_stream << "</table>";
|
||||
m_string += u"</table>";
|
||||
}
|
||||
|
||||
void operator()(const QString &size, const Path &path)
|
||||
{
|
||||
m_stream << R"(<tr><td style="white-space:nowrap">)" << size << "</td><td>" << path.toString() << "</td></tr>";
|
||||
m_string += uR"(<tr><td style="white-space:nowrap">)"
|
||||
+ size
|
||||
+ u"</td><td>"
|
||||
+ path.toString()
|
||||
+ u"</td></tr>";
|
||||
}
|
||||
|
||||
private:
|
||||
QTextStream &m_stream;
|
||||
QString &m_string;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -252,17 +255,16 @@ void PiecesBar::showToolTip(const QHelpEvent *e)
|
||||
return;
|
||||
|
||||
QString toolTipText;
|
||||
QTextStream stream(&toolTipText, QIODevice::WriteOnly);
|
||||
|
||||
const bool showDetailedInformation = QApplication::keyboardModifiers().testFlag(Qt::ShiftModifier);
|
||||
if (showDetailedInformation && m_torrent->hasMetadata())
|
||||
{
|
||||
const BitTorrent::TorrentInfo torrentInfo = m_torrent->info();
|
||||
const int imagePos = e->pos().x() - borderWidth;
|
||||
if ((imagePos >=0) && (imagePos < m_image.width()))
|
||||
if ((imagePos >= 0) && (imagePos < m_image.width()))
|
||||
{
|
||||
stream << "<html><body>";
|
||||
PieceIndexToImagePos transform {torrentInfo, m_image};
|
||||
int pieceIndex = transform.pieceIndex(imagePos);
|
||||
const PieceIndexToImagePos transform {torrentInfo, m_image};
|
||||
const int pieceIndex = transform.pieceIndex(imagePos);
|
||||
const QVector<int> files {torrentInfo.fileIndicesForPiece(pieceIndex)};
|
||||
|
||||
QString tooltipTitle;
|
||||
@@ -278,27 +280,28 @@ void PiecesBar::showToolTip(const QHelpEvent *e)
|
||||
tooltipTitle = tr("File in these pieces");
|
||||
}
|
||||
|
||||
DetailedTooltipRenderer renderer(stream, tooltipTitle);
|
||||
toolTipText.reserve(files.size() * 128);
|
||||
toolTipText += u"<html><body>";
|
||||
|
||||
for (int f : files)
|
||||
DetailedTooltipRenderer renderer {toolTipText, tooltipTitle};
|
||||
|
||||
for (const int f : files)
|
||||
{
|
||||
const Path filePath = torrentInfo.filePath(f);
|
||||
renderer(Utils::Misc::friendlyUnit(torrentInfo.fileSize(f)), filePath);
|
||||
}
|
||||
stream << "</body></html>";
|
||||
toolTipText += u"</body></html>";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
stream << simpleToolTipText();
|
||||
toolTipText += simpleToolTipText();
|
||||
if (showDetailedInformation) // metadata are not available at this point
|
||||
stream << '\n' << tr("Wait until metadata become available to see detailed information");
|
||||
toolTipText += u'\n' + tr("Wait until metadata become available to see detailed information");
|
||||
else
|
||||
stream << '\n' << tr("Hold Shift key for detailed information");
|
||||
toolTipText += u'\n' + tr("Hold Shift key for detailed information");
|
||||
}
|
||||
|
||||
stream.flush();
|
||||
|
||||
QToolTip::showText(e->globalPos(), toolTipText, this);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,6 @@
|
||||
#include <QObject>
|
||||
#include <QRegularExpression>
|
||||
#include <QShortcut>
|
||||
#include <QTextStream>
|
||||
#include <QVector>
|
||||
|
||||
#include "base/global.h"
|
||||
@@ -93,22 +92,20 @@ SearchWidget::SearchWidget(MainWindow *mainWindow)
|
||||
m_ui->setupUi(this);
|
||||
m_ui->tabWidget->tabBar()->installEventFilter(this);
|
||||
|
||||
QString searchPatternHint;
|
||||
QTextStream stream(&searchPatternHint, QIODevice::WriteOnly);
|
||||
stream << "<html><head/><body><p>"
|
||||
<< tr("A phrase to search for.") << "<br>"
|
||||
<< tr("Spaces in a search term may be protected by double quotes.")
|
||||
<< "</p><p>"
|
||||
<< tr("Example:", "Search phrase example")
|
||||
<< "<br>"
|
||||
<< tr("<b>foo bar</b>: search for <b>foo</b> and <b>bar</b>",
|
||||
const QString searchPatternHint = u"<html><head/><body><p>"
|
||||
+ tr("A phrase to search for.") + u"<br>"
|
||||
+ tr("Spaces in a search term may be protected by double quotes.")
|
||||
+ u"</p><p>"
|
||||
+ tr("Example:", "Search phrase example")
|
||||
+ u"<br>"
|
||||
+ tr("<b>foo bar</b>: search for <b>foo</b> and <b>bar</b>",
|
||||
"Search phrase example, illustrates quotes usage, a pair of "
|
||||
"space delimited words, individal words are highlighted")
|
||||
<< "<br>"
|
||||
<< tr("<b>"foo bar"</b>: search for <b>foo bar</b>",
|
||||
+ u"<br>"
|
||||
+ tr("<b>"foo bar"</b>: search for <b>foo bar</b>",
|
||||
"Search phrase example, illustrates quotes usage, double quoted"
|
||||
"pair of space delimited words, the whole pair is highlighted")
|
||||
<< "</p></body></html>";
|
||||
+ u"</p></body></html>";
|
||||
m_ui->lineEditSearchPattern->setToolTip(searchPatternHint);
|
||||
|
||||
#ifndef Q_OS_MACOS
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
#include <QProcess>
|
||||
#include <QRegularExpression>
|
||||
#include <QScreen>
|
||||
#include <QSize>
|
||||
#include <QStyle>
|
||||
#include <QThread>
|
||||
#include <QUrl>
|
||||
|
||||
@@ -28,13 +28,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QSize>
|
||||
|
||||
#include "base/pathfwd.h"
|
||||
|
||||
class QIcon;
|
||||
class QPixmap;
|
||||
class QPoint;
|
||||
class QSize;
|
||||
class QWidget;
|
||||
|
||||
namespace Utils::Gui
|
||||
|
||||
Reference in New Issue
Block a user