Gui: Use QStringLiteral

This commit is contained in:
Benjamin Bræstrup Sayoc
2025-02-09 18:33:01 +01:00
parent bad9499d50
commit f647d4a1eb
83 changed files with 519 additions and 520 deletions

View File

@@ -331,10 +331,10 @@ QString Action::createToolTip(QString helpText,
helpText.resize(helpText.size() - shortcut.size());
}
if (!shortcut.isEmpty()) {
shortcut = QString::fromLatin1(" (%1)").arg(shortcut);
shortcut = QStringLiteral(" (%1)").arg(shortcut);
}
QString tooltip = QString::fromLatin1(
QString tooltip = QStringLiteral(
"<p style='white-space:pre; margin-bottom:0.5em;'><b>%1</b>%2</p>").arg(
text.toHtmlEscaped(), shortcut.toHtmlEscaped());
@@ -371,12 +371,11 @@ QString Action::createToolTip(QString helpText,
return tooltip + helpText + cmdName;
}
tooltip += QString::fromLatin1(
"<p style='white-space:pre; margin:0;'>");
tooltip += QStringLiteral("<p style='white-space:pre; margin:0;'>");
// If the user supplied tooltip contains line break, we shall honour it.
if (helpText.indexOf(QLatin1Char('\n')) >= 0) {
tooltip += helpText.toHtmlEscaped() + QString::fromLatin1("</p>") ;
tooltip += helpText.toHtmlEscaped() + QStringLiteral("</p>") ;
}
else {
// If not, try to end the non wrapping paragraph at some pre defined
@@ -385,7 +384,7 @@ QString Action::createToolTip(QString helpText,
QFontMetrics fm(font);
int width = QtTools::horizontalAdvance(fm, helpText);
if (width <= tipWidth) {
tooltip += helpText.toHtmlEscaped() + QString::fromLatin1("</p>") ;
tooltip += helpText.toHtmlEscaped() + QStringLiteral("</p>") ;
}
else {
int index = tipWidth / width * helpText.size();
@@ -396,7 +395,7 @@ QString Action::createToolTip(QString helpText,
}
}
tooltip += helpText.left(index).toHtmlEscaped()
+ QString::fromLatin1("</p>")
+ QStringLiteral("</p>")
+ helpText.right(helpText.size()-index).trimmed().toHtmlEscaped();
}
}
@@ -475,7 +474,7 @@ void ActionGroup::addTo(QWidget *widget)
widget->addAction(action());
QToolButton* tb = widget->findChildren<QToolButton*>().constLast();
tb->setPopupMode(QToolButton::MenuButtonPopup);
tb->setObjectName(QString::fromLatin1("qt_toolbutton_menubutton"));
tb->setObjectName(QStringLiteral("qt_toolbutton_menubutton"));
QList<QAction*> acts = groupAction()->actions();
auto menu = new QMenu(tb);
menu->addActions(acts);
@@ -692,7 +691,7 @@ void WorkbenchGroup::refreshWorkbenchList()
action->setToolTip(tip);
action->setStatusTip(tr("Select the '%1' workbench").arg(name));
if (index < 9) {
action->setShortcut(QKeySequence(QString::fromUtf8("W,%1").arg(index + 1)));
action->setShortcut(QKeySequence(QStringLiteral("W,%1").arg(index + 1)));
}
if (wbName.toStdString() == activeWbName) {
action->setChecked(true);
@@ -850,10 +849,10 @@ void RecentFilesAction::appendFile(const QString& filename)
static QString numberToLabel(int number) {
if (number > 0 && number < 10) { // NOLINT: *-magic-numbers
return QString::fromLatin1("&%1").arg(number);
return QStringLiteral("&%1").arg(number);
}
if (number == 10) { // NOLINT: *-magic-numbers
return QString::fromLatin1("1&0");
return QStringLiteral("1&0");
}
// If we have a number greater than 10, we start using the alphabet.
// So 11 becomes 'A' and so on.
@@ -861,10 +860,10 @@ static QString numberToLabel(int number) {
constexpr char lettersEnd = lettersStart + ('Z' - 'A');
if (number >= lettersStart && number < lettersEnd) {
QChar letter = QChar::fromLatin1('A' + (number - lettersStart));
return QString::fromLatin1("%1 (&%2)").arg(number).arg(letter);
return QStringLiteral("%1 (&%2)").arg(number).arg(letter);
}
// Not enough accelerators to cover this number.
return QString::fromLatin1("%1").arg(number);
return QStringLiteral("%1").arg(number);
}
/**
@@ -879,7 +878,7 @@ void RecentFilesAction::setFiles(const QStringList& files)
for (int index = 0; index < numRecentFiles; index++) {
QString numberLabel = numberToLabel(index + 1);
QFileInfo fi(files[index]);
recentFiles[index]->setText(QString::fromLatin1("%1 %2").arg(numberLabel).arg(fi.fileName()));
recentFiles[index]->setText(QStringLiteral("%1 %2").arg(numberLabel).arg(fi.fileName()));
recentFiles[index]->setStatusTip(tr("Open file %1").arg(files[index]));
recentFiles[index]->setToolTip(files[index]); // set the full name that we need later for saving
recentFiles[index]->setData(QVariant(index));
@@ -977,7 +976,7 @@ void RecentFilesAction::save()
QList<QAction*> recentFiles = groupAction()->actions();
int num = std::min<int>(count, recentFiles.count());
for (int index = 0; index < num; index++) {
QString key = QString::fromLatin1("MRU%1").arg(index);
QString key = QStringLiteral("MRU%1").arg(index);
QString value = recentFiles[index]->toolTip();
if (value.isEmpty()) {
break;
@@ -1041,7 +1040,7 @@ void RecentMacrosAction::setFiles(const QStringList& files)
for (int index = 0; index < numRecentFiles; index++) {
QFileInfo fi(files[index]);
QString numberLabel = numberToLabel(index + 1);
recentFiles[index]->setText(QString::fromLatin1("%1 %2").arg(numberLabel).arg(fi.completeBaseName()));
recentFiles[index]->setText(QStringLiteral("%1 %2").arg(numberLabel).arg(fi.completeBaseName()));
recentFiles[index]->setToolTip(files[index]); // set the full name that we need later for saving
recentFiles[index]->setData(QVariant(index));
QString accel(tr("none"));
@@ -1192,7 +1191,7 @@ void RecentMacrosAction::save()
QList<QAction*> recentFiles = groupAction()->actions();
int num = std::min<int>(count, recentFiles.count());
for (int index = 0; index < num; index++) {
QString key = QString::fromLatin1("MRU%1").arg(index);
QString key = QStringLiteral("MRU%1").arg(index);
QString value = recentFiles[index]->toolTip();
if (value.isEmpty()) {
break;