From 49df1cd3c7e7f471c9cb9d8dd32f1391da683f2e Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Mon, 27 May 2019 16:19:24 +0800 Subject: [PATCH] Use less operations when building strings --- src/gui/addnewtorrentdialog.cpp | 8 +++----- src/gui/mainwindow.cpp | 27 +++++++++++++++------------ src/gui/rss/rsswidget.cpp | 10 +++++----- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/gui/addnewtorrentdialog.cpp b/src/gui/addnewtorrentdialog.cpp index b516f8468..7b90af8c8 100644 --- a/src/gui/addnewtorrentdialog.cpp +++ b/src/gui/addnewtorrentdialog.cpp @@ -402,11 +402,9 @@ void AddNewTorrentDialog::updateDiskSpaceLabel() } } - QString sizeString = torrentSize ? Utils::Misc::friendlyUnit(torrentSize) : QString(tr("Not Available", "This size is unavailable.")); - sizeString += " ("; - sizeString += tr("Free space on disk: %1").arg(Utils::Misc::friendlyUnit(Utils::Fs::freeDiskSpaceOnPath( - m_ui->savePath->selectedPath()))); - sizeString += ')'; + const QString sizeString = tr("%1 (Free space on disk: %2)").arg( + ((torrentSize > 0) ? Utils::Misc::friendlyUnit(torrentSize) : tr("Not available", "This size is unavailable.")) + , Utils::Misc::friendlyUnit(Utils::Fs::freeDiskSpaceOnPath(m_ui->savePath->selectedPath()))); m_ui->labelSizeData->setText(sizeString); } diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 2504a06b5..d27366f44 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -1529,20 +1529,23 @@ void MainWindow::updateGUI() #ifndef Q_OS_MAC if (m_systrayIcon) { #ifdef Q_OS_UNIX - QString html = "
"; - html += "qBittorrent"; - html += "
"; - html += "
"; - html += " " + tr("DL speed: %1", "e.g: Download speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadDownloadRate, true)); - html += "
"; - html += "
"; - html += " " + tr("UP speed: %1", "e.g: Upload speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadUploadRate, true)); - html += "
"; + const QString html = QString(QLatin1String( + "
" + "qBittorrent" + "
" + "
" + " %1" + "
" + "
" + " %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))); #else // OSes such as Windows do not support html here - QString html = tr("DL speed: %1", "e.g: Download speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadDownloadRate, true)); - html += '\n'; - html += tr("UP speed: %1", "e.g: Upload speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadUploadRate, true)); + const QString html = QString("%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 m_systrayIcon->setToolTip(html); // tray icon } diff --git a/src/gui/rss/rsswidget.cpp b/src/gui/rss/rsswidget.cpp index 6525cc7e6..7f2e33f26 100644 --- a/src/gui/rss/rsswidget.cpp +++ b/src/gui/rss/rsswidget.cpp @@ -448,15 +448,15 @@ void RSSWidget::handleCurrentArticleItemChanged(QListWidgetItem *currentItem, QL auto article = m_articleListWidget->getRSSArticle(currentItem); Q_ASSERT(article); - QString html; - html += "
"; - html += "
" + article->title() + "
"; + QString html = + "
" + "
" + article->title() + "
"; if (article->date().isValid()) html += "
" + tr("Date: ") + "" + article->date().toLocalTime().toString(Qt::SystemLocaleLongDate) + "
"; if (!article->author().isEmpty()) html += "
" + tr("Author: ") + "" + article->author() + "
"; - html += "
"; - html += "
"; + html += "
" + "
"; if (Qt::mightBeRichText(article->description())) { html += article->description(); }