Skip to content

Commit 39fc4ec

Browse files
authored
Merge pull request #723 from Integral-Tech/arg-refactor
refactor: use arg() to concatenate strings for better readability
2 parents b2d6f22 + b8f7f0a commit 39fc4ec

File tree

6 files changed

+38
-28
lines changed

6 files changed

+38
-28
lines changed

src/customdocument.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ bool CustomDocument::openLinkAtCursorPosition()
198198
}
199199

200200
if (isLocalFilePath && convertLocalFilepathsToURLs) {
201-
openUrl(QStringLiteral("file://") + urlString);
201+
openUrl(QStringLiteral("file://%1").arg(urlString));
202202
} else {
203203
openUrl(urlString);
204204
}
@@ -284,7 +284,7 @@ QMap<QString, QString> CustomDocument::parseMarkdownUrlsFromText(const QString &
284284
while (iterator.hasNext()) {
285285
QRegularExpressionMatch match = iterator.next();
286286
QString url = match.captured(0);
287-
urlMap[url] = QStringLiteral("http://") + url;
287+
urlMap[url] = QStringLiteral("http://%1").arg(url);
288288
}
289289

290290
// match reference urls like this: [this url][1] with this later:
@@ -296,8 +296,8 @@ QMap<QString, QString> CustomDocument::parseMarkdownUrlsFromText(const QString &
296296
QString linkText = match.captured(1);
297297
QString referenceId = match.captured(2);
298298

299-
QRegularExpression refRegExp(QStringLiteral("\\[") + QRegularExpression::escape(referenceId)
300-
+ QStringLiteral("\\]: (.+)"));
299+
QRegularExpression refRegExp(
300+
QStringLiteral("\\[%1\\]: (.+)").arg(QRegularExpression::escape(referenceId)));
301301
QRegularExpressionMatch urlMatch = refRegExp.match(toPlainText());
302302

303303
if (urlMatch.hasMatch()) {

src/dbmanager.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,8 @@ void DBManager::moveNode(int nodeId, const NodeData &target)
11031103
QSqlQuery query(m_db);
11041104
auto node = getNode(nodeId);
11051105

1106-
QString newAbsolutePath = target.absolutePath() + PATH_SEPARATOR + QString::number(nodeId);
1106+
QString newAbsolutePath =
1107+
QStringLiteral("%1%2%3").arg(target.absolutePath(), PATH_SEPARATOR).arg(nodeId);
11071108
if (target.id() == SpecialNodeID::TrashFolder) {
11081109
qint64 deletionTime = QDateTime::currentMSecsSinceEpoch();
11091110
query.prepare(QStringLiteral(
@@ -2415,13 +2416,15 @@ void DBManager::exportNotes(const QString &baseExportPath, const QString &extens
24152416
{
24162417
// Ensure the export directory exists
24172418
QString rootFolderName = QStringLiteral("Notes");
2418-
QString exportPathNew = baseExportPath + QDir::separator() + rootFolderName;
2419+
QString exportPathNew =
2420+
QStringLiteral("%1%2%3").arg(baseExportPath, QDir::separator(), rootFolderName);
24192421
QDir directory;
24202422

24212423
int counter = 1;
24222424
while (directory.exists(exportPathNew)) {
2423-
exportPathNew = baseExportPath + QDir::separator() + rootFolderName + " "
2424-
+ QString::number(counter++);
2425+
exportPathNew = QStringLiteral("%1%2%3 %4")
2426+
.arg(baseExportPath, QDir::separator(), rootFolderName)
2427+
.arg(counter++);
24252428
}
24262429
qDebug() << "Exporting notes to:" << exportPathNew;
24272430
directory.mkpath(exportPathNew);
@@ -2449,8 +2452,9 @@ void DBManager::exportNotes(const QString &baseExportPath, const QString &extens
24492452

24502453
counter = 1;
24512454
while (directory.exists(path)) {
2452-
path = exportPathNew + QDir::separator() + relativePath + " "
2453-
+ QString::number(counter++);
2455+
path = QStringLiteral("%1%2%3 %4")
2456+
.arg(exportPathNew, QDir::separator(), relativePath)
2457+
.arg(counter++);
24542458
}
24552459

24562460
QDir().mkpath(path);
@@ -2488,16 +2492,19 @@ void DBManager::exportNotes(const QString &baseExportPath, const QString &extens
24882492
safeTitle = doc.toPlainText();
24892493
safeTitle.replace(QRegularExpression(R"([\/\\:*?"<>|])"),
24902494
"_"); // Make the title filesystem-safe
2491-
QString filePath = notePath + QDir::separator() + safeTitle + extension;
2495+
QString filePath =
2496+
QStringLiteral("%1%2%3%4").arg(notePath, QDir::separator(), safeTitle, extension);
24922497

24932498
if (safeTitle.isEmpty()) {
24942499
safeTitle = QStringLiteral("Untitled Note");
24952500
}
24962501

24972502
counter = 1;
24982503
while (directory.exists(filePath)) {
2499-
filePath = notePath + QDir::separator() + safeTitle + " " + QString::number(counter++)
2500-
+ extension;
2504+
filePath = QStringLiteral("%1%2%3 %4%5")
2505+
.arg(notePath, QDir::separator(), safeTitle)
2506+
.arg(counter++)
2507+
.arg(extension);
25012508
}
25022509

25032510
// qDebug() << "Exporting note:" << filePath;

src/mainwindow.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ void MainWindow::InitData()
180180
{
181181
QFileInfo fi(m_settingsDatabase->fileName());
182182
QDir dir(fi.absolutePath());
183-
QString oldNoteDBPath(dir.path() + QStringLiteral("/Notes.ini"));
184-
QString oldTrashDBPath(dir.path() + QStringLiteral("/Trash.ini"));
183+
QString oldNoteDBPath = QStringLiteral("%1/Notes.ini").arg(dir.path());
184+
QString oldTrashDBPath = QStringLiteral("%1/Trash.ini").arg(dir.path());
185185

186186
bool isV0_9_0 = (QFile::exists(oldNoteDBPath) || QFile::exists(oldTrashDBPath));
187187
if (isV0_9_0) {
@@ -1657,7 +1657,7 @@ void MainWindow::setupDatabases()
16571657
if (!folderCreated)
16581658
qFatal("ERROR: Can't create settings folder : %s",
16591659
dir.absolutePath().toStdString().c_str());
1660-
QString defaultDBPath = dir.path() + QDir::separator() + QStringLiteral("notes.db");
1660+
QString defaultDBPath = QStringLiteral("%1%2notes.db").arg(dir.path(), QDir::separator());
16611661

16621662
QString noteDBFilePath =
16631663
m_settingsDatabase->value(QStringLiteral("noteDBFilePath"), QString()).toString();
@@ -3521,12 +3521,12 @@ void MainWindow::migrateFromV0_9_0()
35213521
QFileInfo fi(m_settingsDatabase->fileName());
35223522
QDir dir(fi.absolutePath());
35233523

3524-
QString oldNoteDBPath(dir.path() + QDir::separator() + "Notes.ini");
3524+
QString oldNoteDBPath = QStringLiteral("%1%2Notes.ini").arg(dir.path(), QDir::separator());
35253525
if (QFile::exists(oldNoteDBPath)) {
35263526
migrateNoteFromV0_9_0(oldNoteDBPath);
35273527
}
35283528

3529-
QString oldTrashDBPath(dir.path() + QDir::separator() + "Trash.ini");
3529+
QString oldTrashDBPath = QStringLiteral("%1%2Trash.ini").arg(dir.path(), QDir::separator());
35303530
if (QFile::exists(oldTrashDBPath)) {
35313531
migrateTrashFromV0_9_0(oldTrashDBPath);
35323532
}

src/nodepath.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ NodePath NodePath::parentPath() const
2222

2323
QString NodePath::getAllNoteFolderPath()
2424
{
25-
return PATH_SEPARATOR + QString::number(SpecialNodeID::RootFolder);
25+
return QStringLiteral("%1%2").arg(PATH_SEPARATOR).arg(SpecialNodeID::RootFolder);
2626
}
2727

2828
QString NodePath::getTrashFolderPath()
2929
{
30-
return PATH_SEPARATOR + QString::number(SpecialNodeID::RootFolder) + PATH_SEPARATOR
31-
+ QString::number(SpecialNodeID::TrashFolder);
30+
return QStringLiteral("%1%2%1%3")
31+
.arg(PATH_SEPARATOR)
32+
.arg(SpecialNodeID::RootFolder)
33+
.arg(SpecialNodeID::TrashFolder);
3234
}

src/noteeditorlogic.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ void NoteEditorLogic::updateTaskText(int startLinePosition, int endLinePosition,
411411
}
412412
}
413413

414-
QString newTaskText = taskExpressionText + " " + newTextModified;
414+
QString newTaskText = QStringLiteral("%1 %2").arg(taskExpressionText, newTextModified);
415415
if (newTaskText.size() > 0 && newTaskText[newTaskText.size() - 1] == '\n') {
416416
newTaskText.remove(newTaskText.size() - 1, 1);
417417
}
@@ -422,7 +422,7 @@ void NoteEditorLogic::updateTaskText(int startLinePosition, int endLinePosition,
422422

423423
void NoteEditorLogic::addNewTask(int startLinePosition, const QString newTaskText)
424424
{
425-
QString newText = "\n- [ ] " + newTaskText;
425+
QString newText = QStringLiteral("\n- [ ] %1").arg(newTaskText);
426426
QTextDocument *document = m_textEdit->document();
427427
QTextBlock startBlock = document->findBlockByLineNumber(startLinePosition);
428428

@@ -631,9 +631,9 @@ bool NoteEditorLogic::checkForTasksInEditor()
631631
else if (!line.isEmpty() && isPreviousLineATask) {
632632
if (tasks.size() > 0) {
633633
QJsonObject newTask = tasks[tasks.size() - 1].toObject();
634-
QString newTaskText = newTask["text"].toString() + " \n"
635-
+ lineTrimmed; // For markdown rendering a line break needs two white
636-
// spaces
634+
QString newTaskText =
635+
QStringLiteral("%1 \n%2").arg(newTask["text"].toString(), lineTrimmed);
636+
// For markdown rendering a line break needs two white spaces
637637
newTask["text"] = newTaskText;
638638
newTask["taskEndLine"] = i;
639639
tasks[tasks.size() - 1] = newTask;

src/notelistview.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,8 @@ void NoteListView::onCustomContextMenu(QPoint point)
741741
}
742742
for (auto id : std::as_const(tagInNote)) {
743743
auto tag = m_tagPool->getTag(id);
744-
auto tagAction = new QAction(QStringLiteral("✓ Remove tag ") + tag.name(), this);
744+
auto tagAction =
745+
new QAction(QStringLiteral("✓ Remove tag %1").arg(tag.name()), this);
745746
connect(tagAction, &QAction::triggered, this,
746747
[this, id, notes] { removeNotesFromTag(notes, id); });
747748
tagAction->setIcon(createTagIcon(tag.color()));
@@ -754,7 +755,7 @@ void NoteListView::onCustomContextMenu(QPoint point)
754755
continue;
755756
}
756757
auto tag = m_tagPool->getTag(id);
757-
auto tagAction = new QAction(QStringLiteral(" ") + tag.name(), this);
758+
auto tagAction = new QAction(QStringLiteral(" %1").arg(tag.name()), this);
758759
connect(tagAction, &QAction::triggered, this,
759760
[this, id, notes] { addNotesToTag(notes, id); });
760761
tagAction->setIcon(createTagIcon(tag.color()));

0 commit comments

Comments
 (0)