Skip to content

Commit

Permalink
Merge pull request #3148 from Integral-Tech/qstring-refactor
Browse files Browse the repository at this point in the history
refactor: replace non-empty QString constructors with QStringLiteral()
  • Loading branch information
pbek authored Nov 2, 2024
2 parents a50c68e + c6c3589 commit 4d50f3b
Show file tree
Hide file tree
Showing 16 changed files with 93 additions and 93 deletions.
2 changes: 1 addition & 1 deletion src/dialogs/nextclouddeckdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void NextcloudDeckDialog::on_saveButton_clicked() {

if (cardId > 0) {
auto linkText =
QString("[%1](%2)").arg(title, nextcloudDeckService.getCardLinkForId(cardId));
QStringLiteral("[%1](%2)").arg(title, nextcloudDeckService.getCardLinkForId(cardId));

#ifndef INTEGRATION_TESTS
MainWindow *mainWindow = MainWindow::instance();
Expand Down
2 changes: 1 addition & 1 deletion src/dialogs/settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4245,7 +4245,7 @@ void SettingsDialog::on_loginFlowButton_clicked() {

QPointer<SettingsDialog> alive(this);

auto postData = QString("token=" + token).toLocal8Bit();
auto postData = QStringLiteral("token=%1").arg(token).toLocal8Bit();
auto data = Utils::Misc::downloadUrl(pollUrl, true, postData);

if (!alive) {
Expand Down
2 changes: 1 addition & 1 deletion src/dialogs/tododialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ void TodoDialog::reloadCurrentTags() {
QString TodoDialog::getTagString() {
// Remove any possible empty items
_todoTagsList.removeAll(QString(""));
_todoTagsList.removeAll(QString(" "));
_todoTagsList.removeAll(QStringLiteral(" "));
QString fullTagString;
// We can't use regular join since it also joins escaped commas
for (const auto &str : _todoTagsList) {
Expand Down
2 changes: 1 addition & 1 deletion src/dialogs/welcomedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ bool WelcomeDialog::handleNoteFolderSetup() {
Utils::Misc::printInfo(QStringLiteral("Note path '%1' exists.").arg(_notesPath));
} else {
if (ui->createNoteFolderCheckBox->isChecked()) {
Utils::Misc::printInfo(QString("Note path '%1' doesn't exist yet and will "
Utils::Misc::printInfo(QStringLiteral("Note path '%1' doesn't exist yet and will "
"be created.")
.arg(_notesPath));

Expand Down
4 changes: 2 additions & 2 deletions src/entities/notefolder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,12 +530,12 @@ bool NoteFolder::isPathNoteFolder(const QString &path) {

void NoteFolder::setSettingsValue(const QString &key, const QVariant &value) {
SettingsService settings;
settings.setValue(QString("NoteFolder-%1/%2").arg(QString::number(id), key), value);
settings.setValue(QStringLiteral("NoteFolder-%1/%2").arg(id).arg(key), value);
}

QVariant NoteFolder::settingsValue(const QString &key, const QVariant &defaultValue) const {
const SettingsService settings;
return settings.value(QString("NoteFolder-%1/%2").arg(QString::number(id), key), defaultValue);
return settings.value(QStringLiteral("NoteFolder-%1/%2").arg(id).arg(key), defaultValue);
}

QDebug operator<<(QDebug dbg, const NoteFolder &noteFolder) {
Expand Down
48 changes: 24 additions & 24 deletions src/libraries/diff_match_patch/diff_match_patch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ QString Diff::toString() const {
QString prettyText = text;
// Replace linebreaks with Pilcrow signs.
prettyText.replace('\n', u'\u00b6');
return QString("Diff(") + strOperation(operation) + QString(",\"")
+ prettyText + QString("\")");
return QStringLiteral("Diff(") + strOperation(operation) + QStringLiteral(",\"")
+ prettyText + QStringLiteral("\")");
}

/**
Expand Down Expand Up @@ -125,24 +125,24 @@ bool Patch::isNull() const {
QString Patch::toString() {
QString coords1, coords2;
if (length1 == 0) {
coords1 = QString::number(start1) + QString(",0");
coords1 = QString::number(start1) + QStringLiteral(",0");
} else if (length1 == 1) {
coords1 = QString::number(start1 + 1);
} else {
coords1 = QString::number(start1 + 1) + QString(",")
coords1 = QString::number(start1 + 1) + QStringLiteral(",")
+ QString::number(length1);
}
if (length2 == 0) {
coords2 = QString::number(start2) + QString(",0");
coords2 = QString::number(start2) + QStringLiteral(",0");
} else if (length2 == 1) {
coords2 = QString::number(start2 + 1);
} else {
coords2 = QString::number(start2 + 1) + QString(",")
coords2 = QString::number(start2 + 1) + QStringLiteral(",")
+ QString::number(length2);
}
QString text;
text = QString("@@ -") + coords1 + QString(" +") + coords2
+ QString(" @@\n");
text = QStringLiteral("@@ -") + coords1 + QStringLiteral(" +") + coords2
+ QStringLiteral(" @@\n");
// Escape the body of the patch with %xx notation.
foreach (Diff aDiff, diffs) {
switch (aDiff.operation) {
Expand All @@ -157,7 +157,7 @@ QString Patch::toString() {
break;
}
text += QString(QUrl::toPercentEncoding(aDiff.text, " !~*'();/?:@&=+$,#"))
+ QString("\n");
+ QStringLiteral("\n");
}

return text;
Expand Down Expand Up @@ -1287,15 +1287,15 @@ QString diff_match_patch::diff_prettyHtml(const QList<Diff> &diffs) {
.replace(">", "&gt;").replace("\n", "&para;<br>");
switch (aDiff.operation) {
case INSERT:
html += QString("<ins style=\"background:#e6ffe6;\">") + text
+ QString("</ins>");
html += QStringLiteral("<ins style=\"background:#e6ffe6;\">") + text
+ QStringLiteral("</ins>");
break;
case DELETE:
html += QString("<del style=\"background:#ffe6e6;\">") + text
+ QString("</del>");
html += QStringLiteral("<del style=\"background:#ffe6e6;\">") + text
+ QStringLiteral("</del>");
break;
case EQUAL:
html += QString("<span>") + text + QString("</span>");
html += QStringLiteral("<span>") + text + QStringLiteral("</span>");
break;
}
}
Expand Down Expand Up @@ -1357,16 +1357,16 @@ QString diff_match_patch::diff_toDelta(const QList<Diff> &diffs) {
case INSERT: {
QString encoded = QString(QUrl::toPercentEncoding(aDiff.text,
" !~*'();/?:@&=+$,#"));
text += QString("+") + encoded + QString("\t");
text += QStringLiteral("+") + encoded + QStringLiteral("\t");
break;
}
case DELETE:
text += QString("-") + QString::number(aDiff.text.length())
+ QString("\t");
text += QStringLiteral("-") + QString::number(aDiff.text.length())
+ QStringLiteral("\t");
break;
case EQUAL:
text += QString("=") + QString::number(aDiff.text.length())
+ QString("\t");
text += QStringLiteral("=") + QString::number(aDiff.text.length())
+ QStringLiteral("\t");
break;
}
}
Expand Down Expand Up @@ -1402,7 +1402,7 @@ QList<Diff> diff_match_patch::diff_fromDelta(const QString &text1,
int n;
n = param.toInt();
if (n < 0) {
throw QString("Negative number in diff_fromDelta: %1").arg(param);
throw QStringLiteral("Negative number in diff_fromDelta: %1").arg(param);
}
QString text;
text = safeMid(text1, pointer, n);
Expand All @@ -1415,12 +1415,12 @@ QList<Diff> diff_match_patch::diff_fromDelta(const QString &text1,
break;
}
default:
throw QString("Invalid diff operation in diff_fromDelta: %1")
throw QStringLiteral("Invalid diff operation in diff_fromDelta: %1")
.arg(token[0]);
}
}
if (pointer != text1.length()) {
throw QString("Delta length (%1) smaller than source text length (%2)")
throw QStringLiteral("Delta length (%1) smaller than source text length (%2)")
.arg(pointer).arg(text1.length());
}
return diffs;
Expand Down Expand Up @@ -2058,7 +2058,7 @@ QList<Patch> diff_match_patch::patch_fromText(const QString &textline) {
while (!text.isEmpty()) {
auto patchHeader = patchHeaderRe.match(text.front());
if (!patchHeader.hasMatch()) {
throw QString("Invalid patch string: %1").arg(text.front());
throw QStringLiteral("Invalid patch string: %1").arg(text.front());
}

patch = Patch();
Expand Down Expand Up @@ -2108,7 +2108,7 @@ QList<Patch> diff_match_patch::patch_fromText(const QString &textline) {
break;
} else {
// WTF?
throw QString("Invalid patch mode '%1' in: %2").arg(sign).arg(line);
throw QStringLiteral("Invalid patch mode '%1' in: %2").arg(sign).arg(line);
return QList<Patch>();
}
text.removeFirst();
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/diff_match_patch/diff_match_patch.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
#include "diff_match_patch.h"
int main(int argc, char **argv) {
diff_match_patch dmp;
QString str1 = QString("First string in diff");
QString str2 = QString("Second string in diff");
QString str1 = QStringLiteral("First string in diff");
QString str2 = QStringLiteral("Second string in diff");
QString strPatch = dmp.patch_toText(dmp.patch_make(str1, str2));
QPair<QString, QVector<bool> > out
Expand Down
Loading

0 comments on commit 4d50f3b

Please sign in to comment.