Skip to content

Commit

Permalink
refactor: use arg() to concatenate strings for better readability
Browse files Browse the repository at this point in the history
  • Loading branch information
Integral-Tech committed Nov 3, 2024
1 parent 94a9cac commit 0b4545a
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 29 deletions.
8 changes: 4 additions & 4 deletions src/customdocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ bool CustomDocument::openLinkAtCursorPosition()
}

if (isLocalFilePath && convertLocalFilepathsToURLs) {
openUrl(QStringLiteral("file://") + urlString);
openUrl(QStringLiteral("file://%1").arg(urlString));
} else {
openUrl(urlString);
}
Expand Down Expand Up @@ -284,7 +284,7 @@ QMap<QString, QString> CustomDocument::parseMarkdownUrlsFromText(const QString &
while (iterator.hasNext()) {
QRegularExpressionMatch match = iterator.next();
QString url = match.captured(0);
urlMap[url] = QStringLiteral("http://") + url;
urlMap[url] = QStringLiteral("http://%1").arg(url);
}

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

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

if (urlMatch.hasMatch()) {
Expand Down
25 changes: 16 additions & 9 deletions src/dbmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,8 @@ void DBManager::moveNode(int nodeId, const NodeData &target)
QSqlQuery query(m_db);
auto node = getNode(nodeId);

QString newAbsolutePath = target.absolutePath() + PATH_SEPARATOR + QString::number(nodeId);
QString newAbsolutePath =
QStringLiteral("%1%2%3").arg(target.absolutePath(), PATH_SEPARATOR).arg(nodeId);
if (target.id() == SpecialNodeID::TrashFolder) {
qint64 deletionTime = QDateTime::currentMSecsSinceEpoch();
query.prepare(QStringLiteral(
Expand Down Expand Up @@ -2415,13 +2416,15 @@ void DBManager::exportNotes(const QString &baseExportPath, const QString &extens
{
// Ensure the export directory exists
QString rootFolderName = QStringLiteral("Notes");
QString exportPathNew = baseExportPath + QDir::separator() + rootFolderName;
QString exportPathNew =
QStringLiteral("%1%2%3").arg(baseExportPath, QDir::separator(), rootFolderName);
QDir directory;

int counter = 1;
while (directory.exists(exportPathNew)) {
exportPathNew = baseExportPath + QDir::separator() + rootFolderName + " "
+ QString::number(counter++);
exportPathNew = QStringLiteral("%1%2%3 %4")
.arg(baseExportPath, QDir::separator(), rootFolderName)
.arg(counter++);
}
qDebug() << "Exporting notes to:" << exportPathNew;
directory.mkpath(exportPathNew);
Expand Down Expand Up @@ -2449,8 +2452,9 @@ void DBManager::exportNotes(const QString &baseExportPath, const QString &extens

counter = 1;
while (directory.exists(path)) {
path = exportPathNew + QDir::separator() + relativePath + " "
+ QString::number(counter++);
path = QStringLiteral("%1%2%3 %4")
.arg(exportPathNew, QDir::separator(), relativePath)
.arg(counter++);
}

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

if (safeTitle.isEmpty()) {
safeTitle = QStringLiteral("Untitled Note");
}

counter = 1;
while (directory.exists(filePath)) {
filePath = notePath + QDir::separator() + safeTitle + " " + QString::number(counter++)
+ extension;
filePath = QStringLiteral("%1%2%3 %4%5")
.arg(notePath, QDir::separator(), safeTitle)
.arg(counter++)
.arg(extension);
}

// qDebug() << "Exporting note:" << filePath;
Expand Down
10 changes: 5 additions & 5 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ void MainWindow::InitData()
{
QFileInfo fi(m_settingsDatabase->fileName());
QDir dir(fi.absolutePath());
QString oldNoteDBPath(dir.path() + QStringLiteral("/Notes.ini"));
QString oldTrashDBPath(dir.path() + QStringLiteral("/Trash.ini"));
QString oldNoteDBPath = QStringLiteral("%1/Notes.ini").arg(dir.path());
QString oldTrashDBPath = QStringLiteral("%1/Trash.ini").arg(dir.path());

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

QString noteDBFilePath =
m_settingsDatabase->value(QStringLiteral("noteDBFilePath"), QString()).toString();
Expand Down Expand Up @@ -3522,12 +3522,12 @@ void MainWindow::migrateFromV0_9_0()
QFileInfo fi(m_settingsDatabase->fileName());
QDir dir(fi.absolutePath());

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

QString oldTrashDBPath(dir.path() + QDir::separator() + "Trash.ini");
QString oldTrashDBPath = QStringLiteral("%1%2Trash.ini").arg(dir.path(), QDir::separator());
if (QFile::exists(oldTrashDBPath)) {
migrateTrashFromV0_9_0(oldTrashDBPath);
}
Expand Down
8 changes: 5 additions & 3 deletions src/nodepath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ NodePath NodePath::parentPath() const

QString NodePath::getAllNoteFolderPath()
{
return PATH_SEPARATOR + QString::number(SpecialNodeID::RootFolder);
return QStringLiteral("%1%2").arg(PATH_SEPARATOR).arg(SpecialNodeID::RootFolder);
}

QString NodePath::getTrashFolderPath()
{
return PATH_SEPARATOR + QString::number(SpecialNodeID::RootFolder) + PATH_SEPARATOR
+ QString::number(SpecialNodeID::TrashFolder);
return QStringLiteral("%1%2%1%3")
.arg(PATH_SEPARATOR)
.arg(SpecialNodeID::RootFolder)
.arg(SpecialNodeID::TrashFolder);
}
10 changes: 5 additions & 5 deletions src/noteeditorlogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ void NoteEditorLogic::updateTaskText(int startLinePosition, int endLinePosition,
}
}

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

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

Expand Down Expand Up @@ -631,9 +631,9 @@ bool NoteEditorLogic::checkForTasksInEditor()
else if (!line.isEmpty() && isPreviousLineATask) {
if (tasks.size() > 0) {
QJsonObject newTask = tasks[tasks.size() - 1].toObject();
QString newTaskText = newTask["text"].toString() + " \n"
+ lineTrimmed; // For markdown rendering a line break needs two white
// spaces
QString newTaskText =
QStringLiteral("%1 \n%2").arg(newTask["text"].toString(), lineTrimmed);
// For markdown rendering a line break needs two white spaces
newTask["text"] = newTaskText;
newTask["taskEndLine"] = i;
tasks[tasks.size() - 1] = newTask;
Expand Down
7 changes: 4 additions & 3 deletions src/notelistview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void NoteListView::setIsPinnedNotesCollapsed(bool newIsPinnedNotesCollapsed)
for (int i = 0; i < model()->rowCount(); ++i) {
auto index = model()->index(i, 0);
if (index.isValid()) {
emit itemDelegate()->sizeHintChanged(index);
emit itemDelegate() -> sizeHintChanged(index);
}
}
update();
Expand Down Expand Up @@ -741,7 +741,8 @@ void NoteListView::onCustomContextMenu(QPoint point)
}
for (auto id : std::as_const(tagInNote)) {
auto tag = m_tagPool->getTag(id);
auto tagAction = new QAction(QStringLiteral("✓ Remove tag ") + tag.name(), this);
auto tagAction =
new QAction(QStringLiteral("✓ Remove tag %1").arg(tag.name()), this);
connect(tagAction, &QAction::triggered, this,
[this, id, notes] { removeNotesFromTag(notes, id); });
tagAction->setIcon(createTagIcon(tag.color()));
Expand All @@ -754,7 +755,7 @@ void NoteListView::onCustomContextMenu(QPoint point)
continue;
}
auto tag = m_tagPool->getTag(id);
auto tagAction = new QAction(QStringLiteral(" ") + tag.name(), this);
auto tagAction = new QAction(QStringLiteral(" %1").arg(tag.name()), this);
connect(tagAction, &QAction::triggered, this,
[this, id, notes] { addNotesToTag(notes, id); });
tagAction->setIcon(createTagIcon(tag.color()));
Expand Down

0 comments on commit 0b4545a

Please sign in to comment.