Replace single-character string with character literal

Also remove unnecessary dynamic allocation.
This commit is contained in:
Chocobo1
2018-07-21 13:28:13 +08:00
committed by sledgehammer999
parent d088ab6f43
commit 9e99a0d3f5
32 changed files with 96 additions and 96 deletions

View File

@@ -445,7 +445,7 @@ void AddNewTorrentDialog::updateDiskSpaceLabel()
sizeString += " (";
sizeString += tr("Free space on disk: %1").arg(Utils::Misc::friendlyUnit(Utils::Fs::freeDiskSpaceOnPath(
m_ui->savePath->selectedPath())));
sizeString += ")";
sizeString += ')';
m_ui->labelSize->setText(sizeString);
}

View File

@@ -2037,7 +2037,7 @@ bool MainWindow::addPythonPathToEnv()
QString pathEnvar = QString::fromLocal8Bit(qgetenv("PATH").constData());
if (pathEnvar.isNull())
pathEnvar = "";
pathEnvar = pythonPath + ";" + pathEnvar;
pathEnvar = pythonPath + ';' + pathEnvar;
qDebug("New PATH envvar is: %s", qUtf8Printable(pathEnvar));
qputenv("PATH", Utils::Fs::toNativePath(pathEnvar).toLocal8Bit());
return true;
@@ -2069,7 +2069,7 @@ void MainWindow::pythonDownloadSuccess(const QString &url, const QString &filePa
if (QSysInfo::windowsVersion() >= QSysInfo::WV_VISTA) {
QFile::rename(filePath, filePath + ".exe");
installer.start("\"" + Utils::Fs::toNativePath(filePath) + ".exe\" /passive");
installer.start('"' + Utils::Fs::toNativePath(filePath) + ".exe\" /passive");
}
else {
QFile::rename(filePath, filePath + ".msi");

View File

@@ -70,7 +70,7 @@ public:
QStyleOptionProgressBar newopt;
qreal progress = index.data().toDouble() * 100.;
newopt.rect = opt.rect;
newopt.text = ((progress == 100.0) ? QString("100%") : Utils::String::fromDouble(progress, 1) + "%");
newopt.text = ((progress == 100.0) ? QString("100%") : Utils::String::fromDouble(progress, 1) + '%');
newopt.progress = static_cast<int>(progress);
newopt.maximum = 100;
newopt.minimum = 0;

View File

@@ -100,7 +100,7 @@ public:
case RELEVANCE: {
qreal progress = index.data().toDouble();
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::String::fromDouble(progress * 100.0, 1) + "%");
QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::String::fromDouble(progress * 100.0, 1) + '%');
}
break;
default:

View File

@@ -304,9 +304,9 @@ void PeerListWidget::copySelectedPeers()
QString ip = m_listModel->data(m_listModel->index(row, PeerListDelegate::IP_HIDDEN)).toString();
QString myport = m_listModel->data(m_listModel->index(row, PeerListDelegate::PORT)).toString();
if (ip.indexOf('.') == -1) // IPv6
selectedPeers << "[" + ip + "]:" + myport;
selectedPeers << '[' + ip + "]:" + myport;
else // IPv4
selectedPeers << ip + ":" + myport;
selectedPeers << ip + ':' + myport;
}
QApplication::clipboard()->setText(selectedPeers.join('\n'));
}
@@ -404,8 +404,8 @@ QStandardItem *PeerListWidget::addPeer(const QString &ip, BitTorrent::TorrentHan
m_listModel->setData(m_listModel->index(row, PeerListDelegate::TOT_UP), peer.totalUpload());
m_listModel->setData(m_listModel->index(row, PeerListDelegate::RELEVANCE), peer.relevance());
QStringList downloadingFiles(torrent->info().filesForPiece(peer.downloadingPieceIndex()));
m_listModel->setData(m_listModel->index(row, PeerListDelegate::DOWNLOADING_PIECE), downloadingFiles.join(QLatin1String(";")));
m_listModel->setData(m_listModel->index(row, PeerListDelegate::DOWNLOADING_PIECE), downloadingFiles.join(QLatin1String("\n")), Qt::ToolTipRole);
m_listModel->setData(m_listModel->index(row, PeerListDelegate::DOWNLOADING_PIECE), downloadingFiles.join(QLatin1Char(';')));
m_listModel->setData(m_listModel->index(row, PeerListDelegate::DOWNLOADING_PIECE), downloadingFiles.join(QLatin1Char('\n')), Qt::ToolTipRole);
return m_listModel->item(row, PeerListDelegate::IP);
}

View File

@@ -474,7 +474,7 @@ void PropertiesWidget::loadDynamicData()
// Progress
qreal progress = m_torrent->progress() * 100.;
m_ui->labelProgressVal->setText(Utils::String::fromDouble(progress, 1) + "%");
m_ui->labelProgressVal->setText(Utils::String::fromDouble(progress, 1) + '%');
m_downloadedPieces->setProgress(m_torrent->pieces(), m_torrent->downloadingPieces());
}
else {

View File

@@ -87,7 +87,7 @@ void PropListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
QStyleOptionProgressBar newopt;
qreal progress = index.data().toDouble() * 100.;
newopt.rect = opt.rect;
newopt.text = ((progress == 100.0) ? QString("100%") : Utils::String::fromDouble(progress, 1) + "%");
newopt.text = ((progress == 100.0) ? QString("100%") : Utils::String::fromDouble(progress, 1) + '%');
newopt.progress = int(progress);
newopt.maximum = 100;
newopt.minimum = 0;

View File

@@ -371,9 +371,9 @@ void TrackerListWidget::loadTrackers()
item->setText(COL_PEERS, QString::number(entry.nativeEntry().scrape_incomplete > 0 ? entry.nativeEntry().scrape_incomplete : 0));
item->setText(COL_DOWNLOADED, QString::number(entry.nativeEntry().scrape_downloaded > 0 ? entry.nativeEntry().scrape_downloaded : 0));
#else
item->setText(COL_SEEDS, "0");
item->setText(COL_PEERS, "0");
item->setText(COL_DOWNLOADED, "0");
item->setText(COL_SEEDS, '0');
item->setText(COL_PEERS, '0');
item->setText(COL_DOWNLOADED, '0');
#endif
item->setTextAlignment(COL_TIER, (Qt::AlignRight | Qt::AlignVCenter));

View File

@@ -675,7 +675,7 @@ void AutomatedRssDownloader::updateMustLineValidity()
if (isRegex)
tokens << text;
else
foreach (const QString &token, text.split("|"))
foreach (const QString &token, text.split('|'))
tokens << Utils::String::wildcardToRegex(token);
foreach (const QString &token, tokens) {
@@ -713,7 +713,7 @@ void AutomatedRssDownloader::updateMustNotLineValidity()
if (isRegex)
tokens << text;
else
foreach (const QString &token, text.split("|"))
foreach (const QString &token, text.split('|'))
tokens << Utils::String::wildcardToRegex(token);
foreach (const QString &token, tokens) {

View File

@@ -209,14 +209,14 @@ void StatusBar::updateSpeedLabels()
QString speedLbl = Utils::Misc::friendlyUnit(sessionStatus.payloadDownloadRate, true);
int speedLimit = BitTorrent::Session::instance()->downloadSpeedLimit();
if (speedLimit)
speedLbl += " [" + Utils::Misc::friendlyUnit(speedLimit, true) + "]";
speedLbl += " (" + Utils::Misc::friendlyUnit(sessionStatus.totalPayloadDownload) + ")";
speedLbl += " [" + Utils::Misc::friendlyUnit(speedLimit, true) + ']';
speedLbl += " (" + Utils::Misc::friendlyUnit(sessionStatus.totalPayloadDownload) + ')';
m_dlSpeedLbl->setText(speedLbl);
speedLimit = BitTorrent::Session::instance()->uploadSpeedLimit();
speedLbl = Utils::Misc::friendlyUnit(sessionStatus.payloadUploadRate, true);
if (speedLimit)
speedLbl += " [" + Utils::Misc::friendlyUnit(speedLimit, true) + "]";
speedLbl += " (" + Utils::Misc::friendlyUnit(sessionStatus.totalPayloadUpload) + ")";
speedLbl += " [" + Utils::Misc::friendlyUnit(speedLimit, true) + ']';
speedLbl += " (" + Utils::Misc::friendlyUnit(sessionStatus.totalPayloadUpload) + ')';
m_upSpeedLbl->setText(speedLbl);
}

View File

@@ -39,16 +39,16 @@ namespace
{
QString getSpecialAllTag()
{
static const QString *const ALL_TAG = new QString(" ");
Q_ASSERT(!BitTorrent::Session::isValidTag(*ALL_TAG));
return *ALL_TAG;
const QString ALL_TAG = QLatin1String(" ");
Q_ASSERT(!BitTorrent::Session::isValidTag(ALL_TAG));
return ALL_TAG;
}
QString getSpecialUntaggedTag()
{
static const QString *const UNTAGGED_TAG = new QString(" ");
Q_ASSERT(!BitTorrent::Session::isValidTag(*UNTAGGED_TAG));
return *UNTAGGED_TAG;
const QString UNTAGGED_TAG = QLatin1String(" ");
Q_ASSERT(!BitTorrent::Session::isValidTag(UNTAGGED_TAG));
return UNTAGGED_TAG;
}
}

View File

@@ -91,7 +91,7 @@ void TransferListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
qlonglong total = index.data(Qt::UserRole).toLongLong();
if (hideValues && (!value && !total))
break;
QString display = QString::number(value) + " (" + QString::number(total) + ")";
QString display = QString::number(value) + " (" + QString::number(total) + ')';
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
QItemDelegate::drawDisplay(painter, opt, opt.rect, display);
}
@@ -160,7 +160,7 @@ void TransferListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
QStyleOptionProgressBar newopt;
qreal progress = index.data().toDouble() * 100.;
newopt.rect = opt.rect;
newopt.text = ((progress == 100.0) ? QString("100%") : Utils::String::fromDouble(progress, 1) + "%");
newopt.text = ((progress == 100.0) ? QString("100%") : Utils::String::fromDouble(progress, 1) + '%');
newopt.progress = static_cast<int>(progress);
newopt.maximum = 100;
newopt.minimum = 0;

View File

@@ -93,7 +93,7 @@ QVariant TransferListModel::headerData(int section, Qt::Orientation orientation,
if (orientation == Qt::Horizontal) {
if (role == Qt::DisplayRole) {
switch (section) {
case TR_PRIORITY: return "#";
case TR_PRIORITY: return QChar('#');
case TR_NAME: return tr("Name", "i.e: torrent name");
case TR_SIZE: return tr("Size", "i.e: torrent size");
case TR_PROGRESS: return tr("Done", "% Done");

View File

@@ -73,7 +73,7 @@ QPixmap Utils::Gui::scaledPixmap(const QString &path, const QWidget *widget, con
QPixmap Utils::Gui::scaledPixmapSvg(const QString &path, const QWidget *widget, const int baseHeight)
{
const int scaledHeight = baseHeight * Utils::Gui::screenScalingFactor(widget);
const QString normalizedKey = path + "@" + QString::number(scaledHeight);
const QString normalizedKey = path + '@' + QString::number(scaledHeight);
QPixmap pm;
QPixmapCache cache;