Construct QString more efficiently

This commit is contained in:
Chocobo1
2020-03-22 18:35:16 +08:00
parent 2c23840947
commit 7de8a4d6e0
25 changed files with 60 additions and 61 deletions

View File

@@ -43,7 +43,7 @@ AboutDialog::AboutDialog(QWidget *parent)
setAttribute(Qt::WA_DeleteOnClose);
// Title
m_ui->labelName->setText(QString("<b><h2>qBittorrent " QBT_VERSION " (%1-bit)</h2></b>").arg(QT_POINTER_SIZE * 8));
m_ui->labelName->setText(QString::fromLatin1("<b><h2>qBittorrent " QBT_VERSION " (%1-bit)</h2></b>").arg(QT_POINTER_SIZE * 8));
m_ui->logo->setPixmap(Utils::Gui::scaledPixmapSvg(":/icons/skin/qbittorrent-tray.svg", this, 32));

View File

@@ -333,7 +333,7 @@ void AdvancedSettings::loadAdvancedSettings()
, tr("Open documentation"))
, this);
labelQbtLink->setOpenExternalLinks(true);
addRow(QBITTORRENT_HEADER, QString("<b>%1</b>").arg(tr("qBittorrent Section")), labelQbtLink);
addRow(QBITTORRENT_HEADER, QString::fromLatin1("<b>%1</b>").arg(tr("qBittorrent Section")), labelQbtLink);
static_cast<QLabel *>(cellWidget(QBITTORRENT_HEADER, PROPERTY))->setAlignment(Qt::AlignCenter | Qt::AlignVCenter);
auto *labelLibtorrentLink = new QLabel(
@@ -341,7 +341,7 @@ void AdvancedSettings::loadAdvancedSettings()
, tr("Open documentation"))
, this);
labelLibtorrentLink->setOpenExternalLinks(true);
addRow(LIBTORRENT_HEADER, QString("<b>%1</b>").arg(tr("libtorrent Section")), labelLibtorrentLink);
addRow(LIBTORRENT_HEADER, QString::fromLatin1("<b>%1</b>").arg(tr("libtorrent Section")), labelLibtorrentLink);
static_cast<QLabel *>(cellWidget(LIBTORRENT_HEADER, PROPERTY))->setAlignment(Qt::AlignCenter | Qt::AlignVCenter);
#if defined(Q_OS_WIN)

View File

@@ -75,7 +75,7 @@ public:
if (!m_parent || m_parent->name().isEmpty())
return m_name;
return QString("%1/%2").arg(m_parent->fullName(), m_name);
return QString::fromLatin1("%1/%2").arg(m_parent->fullName(), m_name);
}
CategoryModelItem *parent() const

View File

@@ -27,7 +27,7 @@ LineEdit::LineEdit(QWidget *parent)
m_searchButton->setStyleSheet("QToolButton {border: none; padding: 2px;}");
// padding between text and widget borders
setStyleSheet(QString("QLineEdit {padding-left: %1px;}").arg(m_searchButton->sizeHint().width()));
setStyleSheet(QString::fromLatin1("QLineEdit {padding-left: %1px;}").arg(m_searchButton->sizeHint().width()));
setClearButtonEnabled(true);

View File

@@ -1539,7 +1539,7 @@ void MainWindow::reloadSessionStats()
, tr("UP speed: %1", "e.g: Upload speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadUploadRate, true)));
#else
// OSes such as Windows do not support html here
const QString toolTip = QString("%1\n%2").arg(
const QString toolTip = QString::fromLatin1("%1\n%2").arg(
tr("DL speed: %1", "e.g: Download speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadDownloadRate, true))
, tr("UP speed: %1", "e.g: Upload speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadUploadRate, true)));
#endif // Q_OS_UNIX
@@ -1818,7 +1818,7 @@ void MainWindow::handleUpdateCheckFinished(bool updateAvailable, QString newVers
answer = QMessageBox::question(this, tr("qBittorrent Update Available")
, tr("A new version is available.") + "<br/>"
+ tr("Do you want to download %1?").arg(newVersion) + "<br/><br/>"
+ QString("<a href=\"https://www.qbittorrent.org/news.php\">%1</a>").arg(tr("Open changelog..."))
+ QString::fromLatin1("<a href=\"https://www.qbittorrent.org/news.php\">%1</a>").arg(tr("Open changelog..."))
, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
if (answer == QMessageBox::Yes) {
// The user want to update, let's download the update

View File

@@ -1559,7 +1559,7 @@ void OptionsDialog::on_addScanFolderButton_clicked()
}
if (!error.isEmpty())
QMessageBox::critical(this, tr("Adding entry failed"), QString("%1\n%2").arg(error, dir));
QMessageBox::critical(this, tr("Adding entry failed"), QString::fromLatin1("%1\n%2").arg(error, dir));
}
}

View File

@@ -59,8 +59,8 @@ const QString EXT_LEGACY {QStringLiteral(".rssrules")};
AutomatedRssDownloader::AutomatedRssDownloader(QWidget *parent)
: QDialog(parent)
, m_formatFilterJSON(QString("%1 (*%2)").arg(tr("Rules"), EXT_JSON))
, m_formatFilterLegacy(QString("%1 (*%2)").arg(tr("Rules (legacy)"), EXT_LEGACY))
, m_formatFilterJSON(QString::fromLatin1("%1 (*%2)").arg(tr("Rules"), EXT_JSON))
, m_formatFilterLegacy(QString::fromLatin1("%1 (*%2)").arg(tr("Rules (legacy)"), EXT_LEGACY))
, m_ui(new Ui::AutomatedRssDownloader)
, m_currentRuleItem(nullptr)
{
@@ -413,7 +413,7 @@ void AutomatedRssDownloader::on_exportBtn_clicked()
QString selectedFilter {m_formatFilterJSON};
QString path = QFileDialog::getSaveFileName(
this, tr("Export RSS rules"), QDir::homePath()
, QString("%1;;%2").arg(m_formatFilterJSON, m_formatFilterLegacy), &selectedFilter);
, QString::fromLatin1("%1;;%2").arg(m_formatFilterJSON, m_formatFilterLegacy), &selectedFilter);
if (path.isEmpty()) return;
const RSS::AutoDownloader::RulesFileFormat format {
@@ -445,7 +445,7 @@ void AutomatedRssDownloader::on_importBtn_clicked()
QString selectedFilter {m_formatFilterJSON};
QString path = QFileDialog::getOpenFileName(
this, tr("Import RSS rules"), QDir::homePath()
, QString("%1;;%2").arg(m_formatFilterJSON, m_formatFilterLegacy), &selectedFilter);
, QString::fromLatin1("%1;;%2").arg(m_formatFilterJSON, m_formatFilterLegacy), &selectedFilter);
if (path.isEmpty() || !QFile::exists(path))
return;

View File

@@ -113,7 +113,7 @@ void FeedListWidget::handleItemUnreadCountChanged(RSS::Item *rssItem)
else {
QTreeWidgetItem *item = mapRSSItem(rssItem);
Q_ASSERT(item);
item->setData(0, Qt::DisplayRole, QString("%1 (%2)").arg(rssItem->name()).arg(rssItem->unreadCount()));
item->setData(0, Qt::DisplayRole, QString::fromLatin1("%1 (%2)").arg(rssItem->name(), QString::number(rssItem->unreadCount())));
}
}
@@ -122,7 +122,7 @@ void FeedListWidget::handleItemPathChanged(RSS::Item *rssItem)
QTreeWidgetItem *item = mapRSSItem(rssItem);
Q_ASSERT(item);
item->setData(0, Qt::DisplayRole, QString("%1 (%2)").arg(rssItem->name()).arg(rssItem->unreadCount()));
item->setData(0, Qt::DisplayRole, QString::fromLatin1("%1 (%2)").arg(rssItem->name(), QString::number(rssItem->unreadCount())));
RSS::Item *parentRssItem = RSS::Session::instance()->itemByPath(RSS::Item::parentPath(rssItem->path()));
QTreeWidgetItem *parentItem = mapRSSItem(parentRssItem);
@@ -228,7 +228,7 @@ void FeedListWidget::dropEvent(QDropEvent *event)
QTreeWidgetItem *FeedListWidget::createItem(RSS::Item *rssItem, QTreeWidgetItem *parentItem)
{
auto *item = new QTreeWidgetItem;
item->setData(0, Qt::DisplayRole, QString("%1 (%2)").arg(rssItem->name()).arg(rssItem->unreadCount()));
item->setData(0, Qt::DisplayRole, QString::fromLatin1("%1 (%2)").arg(rssItem->name(), QString::number(rssItem->unreadCount())));
item->setData(0, Qt::UserRole, reinterpret_cast<quintptr>(rssItem));
m_rssToTreeItemMapping[rssItem] = item;

View File

@@ -80,20 +80,19 @@ void StatsDialog::update()
: "-");
// Cache hits
qreal readRatio = cs.readRatio;
m_ui->labelCacheHits->setText(QString("%1%").arg(
readRatio > 0
m_ui->labelCacheHits->setText(QString::fromLatin1("%1%").arg((readRatio > 0)
? Utils::String::fromDouble(100 * readRatio, 2)
: "0"));
: QLatin1String("0")));
// Buffers size
m_ui->labelTotalBuf->setText(Utils::Misc::friendlyUnit(cs.totalUsedBuffers * 16 * 1024));
// Disk overload (100%) equivalent
// From lt manual: disk_write_queue and disk_read_queue are the number of peers currently waiting on a disk write or disk read
// to complete before it receives or sends any more data on the socket. It's a metric of how disk bound you are.
m_ui->labelWriteStarve->setText(QString("%1%").arg(((ss.diskWriteQueue > 0) && (ss.peersCount > 0))
m_ui->labelWriteStarve->setText(QString::fromLatin1("%1%").arg(((ss.diskWriteQueue > 0) && (ss.peersCount > 0))
? Utils::String::fromDouble((100. * ss.diskWriteQueue / ss.peersCount), 2)
: QLatin1String("0")));
m_ui->labelReadStarve->setText(QString("%1%").arg(((ss.diskReadQueue > 0) && (ss.peersCount > 0))
m_ui->labelReadStarve->setText(QString::fromLatin1("%1%").arg(((ss.diskReadQueue > 0) && (ss.peersCount > 0))
? Utils::String::fromDouble((100. * ss.diskReadQueue / ss.peersCount), 2)
: QLatin1String("0")));

View File

@@ -319,7 +319,7 @@ QVector<TagModelItem *> TagFilterModel::findItems(const QSet<QString> &tags)
if (item)
items.push_back(item);
else
qWarning() << QString("Requested tag '%1' missing from the model.").arg(tag);
qWarning() << QString::fromLatin1("Requested tag '%1' missing from the model.").arg(tag);
}
return items;
}

View File

@@ -215,7 +215,7 @@ void TorrentCreatorDialog::handleCreationSuccess(const QString &path, const QStr
BitTorrent::Session::instance()->addTorrent(info, params);
}
QMessageBox::information(this, tr("Torrent creator")
, QString("%1\n%2").arg(tr("Torrent created:"), Utils::Fs::toNativePath(path)));
, QString::fromLatin1("%1\n%2").arg(tr("Torrent created:"), Utils::Fs::toNativePath(path)));
setInteractionEnabled(true);
}

View File

@@ -327,7 +327,7 @@ void TrackerFiltersList::addItem(const QString &tracker, const QString &hash)
trackerItem->setData(Qt::DecorationRole, UIThemeManager::instance()->getIcon("network-server"));
const QString scheme = getScheme(tracker);
downloadFavicon(QString("%1://%2/favicon.ico").arg((scheme.startsWith("http") ? scheme : "http"), host));
downloadFavicon(QString::fromLatin1("%1://%2/favicon.ico").arg((scheme.startsWith("http") ? scheme : "http"), host));
}
if (!trackerItem) return;
@@ -340,7 +340,7 @@ void TrackerFiltersList::addItem(const QString &tracker, const QString &hash)
return;
}
trackerItem->setText(QString("%1 (%2)").arg(host).arg(tmp.size()));
trackerItem->setText(QString::fromLatin1("%1 (%2)").arg(host, QString::number(tmp.size())));
if (exists) {
if (currentRow() == rowFromTracker(host))
applyFilter(currentRow());
@@ -384,7 +384,7 @@ void TrackerFiltersList::removeItem(const QString &tracker, const QString &hash)
return;
}
if (trackerItem)
trackerItem->setText(QString("%1 (%2)").arg(host).arg(tmp.size()));
trackerItem->setText(QString::fromLatin1("%1 (%2)").arg(host, QString::number(tmp.size())));
}
else {
row = 1;