Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace non-empty QString constructors with QStringLiteral() #2563

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/core/buffer/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ void Buffer::writeBackupFile()

QString Buffer::generateBackupFileHead() const
{
return QString("vnotex_backup_file %1|").arg(getContentPath());
return QStringLiteral("vnotex_backup_file %1|").arg(getContentPath());
}

void Buffer::checkBackupFileOfPreviousSession()
Expand All @@ -373,7 +373,7 @@ void Buffer::checkBackupFileOfPreviousSession()
QDir backupDir(backupDirPath);
QStringList backupFiles;
{
const QString nameFilter = QString("%1*%2").arg(getName(), config.getBackupFileExtension());
const QString nameFilter = QStringLiteral("%1*%2").arg(getName(), config.getBackupFileExtension());
backupFiles = backupDir.entryList(QStringList(nameFilter),
QDir::Files | QDir::Hidden | QDir::NoSymLinks | QDir::NoDotAndDotDot);
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/buffermgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void BufferMgr::open(Node *p_node, const QSharedPointer<FileOpenParameters> &p_p
}

if (!p_node->checkExists()) {
auto msg = QString("Failed to open node that does not exist (%1)").arg(p_node->fetchAbsolutePath());
auto msg = QStringLiteral("Failed to open node that does not exist (%1)").arg(p_node->fetchAbsolutePath());
qWarning() << msg;
VNoteX::getInst().showStatusMessageShort(msg);
return;
Expand Down Expand Up @@ -133,7 +133,7 @@ void BufferMgr::open(const QString &p_filePath, const QSharedPointer<FileOpenPar

QFileInfo finfo(p_filePath);
if (!finfo.exists()) {
auto msg = QString("Failed to open file that does not exist (%1)").arg(p_filePath);
auto msg = QStringLiteral("Failed to open file that does not exist (%1)").arg(p_filePath);
qWarning() << msg;
VNoteX::getInst().showStatusMessageShort(msg);
WidgetUtils::openUrlByDesktop(QUrl::fromUserInput(p_filePath));
Expand Down
6 changes: 3 additions & 3 deletions src/core/clipboarddata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ void ClipboardData::fromJson(const QJsonObject &p_jobj)
|| !p_jobj.contains(c_action)
|| !p_jobj.contains(c_data)) {
Exception::throwOne(Exception::Type::InvalidArgument,
QString("fail to parse ClipboardData from json (%1)").arg(p_jobj.keys().join(',')));
QStringLiteral("fail to parse ClipboardData from json (%1)").arg(p_jobj.keys().join(',')));
return;
}

auto idRet = stringToID(p_jobj[c_instanceId].toString());
if (!idRet.first) {
Exception::throwOne(Exception::Type::InvalidArgument,
QString("fail to parse ClipboardData from json (%1)").arg(p_jobj.keys().join(',')));
QStringLiteral("fail to parse ClipboardData from json (%1)").arg(p_jobj.keys().join(',')));
return;
}
m_instanceId = idRet.second;
Expand All @@ -79,7 +79,7 @@ void ClipboardData::fromJson(const QJsonObject &p_jobj)
m_action = intToAction(act);
if (m_action == Action::Invalid) {
Exception::throwOne(Exception::Type::InvalidArgument,
QString("fail to parse ClipboardData from json (%1)").arg(p_jobj.keys().join(',')));
QStringLiteral("fail to parse ClipboardData from json (%1)").arg(p_jobj.keys().join(',')));
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/configmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ bool ConfigMgr::checkAppConfig()
bool ret = QResource::registerResource(extraRcc);
if (!ret) {
Exception::throwOne(Exception::Type::FailToReadFile,
QString("failed to register resource file %1").arg(extraRcc));
QStringLiteral("failed to register resource file %1").arg(extraRcc));
}
auto cleanup = qScopeGuard([extraRcc]() {
QResource::unregisterResource(extraRcc);
Expand Down
28 changes: 14 additions & 14 deletions src/core/exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,46 +47,46 @@ namespace vnotex
{
switch (p_type) {
case Type::InvalidPath:
return QString("InvalidPath");
return QStringLiteral("InvalidPath");

case Type::FailToCreateDir:
return QString("FailToCreateDir");
return QStringLiteral("FailToCreateDir");

case Type::FailToWriteFile:
return QString("FailToWriteFile");
return QStringLiteral("FailToWriteFile");

case Type::FailToReadFile:
return QString("FailToReadFile");
return QStringLiteral("FailToReadFile");

case Type::FailToRenameFile:
return QString("FailToRenameFile");
return QStringLiteral("FailToRenameFile");

case Type::FailToCopyFile:
return QString("FailToCopyFile");
return QStringLiteral("FailToCopyFile");

case Type::FailToCopyDir:
return QString("FailToCopyDir");
return QStringLiteral("FailToCopyDir");

case Type::FailToRemoveFile:
return QString("FailToRemoveFile");
return QStringLiteral("FailToRemoveFile");

case Type::FailToRemoveDir:
return QString("FailToRemoveDir");
return QStringLiteral("FailToRemoveDir");

case Type::FileMissingOnDisk:
return QString("FileMissingOnDisk");
return QStringLiteral("FileMissingOnDisk");

case Type::EssentialFileMissing:
return QString("EssentialFileMissing");
return QStringLiteral("EssentialFileMissing");

case Type::FileExistsOnCreate:
return QString("FileExistsOnCreate");
return QStringLiteral("FileExistsOnCreate");

case Type::DirExistsOnCreate:
return QString("DirExistsOnCreate");
return QStringLiteral("DirExistsOnCreate");

case Type::InvalidArgument:
return QString("InvalidArgument");
return QStringLiteral("InvalidArgument");
}

return QString::number(static_cast<int>(p_type));
Expand Down
48 changes: 24 additions & 24 deletions src/core/htmltemplatehelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,27 @@ HtmlTemplateHelper::Template HtmlTemplateHelper::s_mindMapEditorTemplate;
QString MarkdownWebGlobalOptions::toJavascriptObject() const
{
return QStringLiteral("window.vxOptions = {\n")
+ QString("webPlantUml: %1,\n").arg(Utils::boolToString(m_webPlantUml))
+ QString("plantUmlWebService: '%1',\n").arg(m_plantUmlWebService)
+ QString("webGraphviz: %1,\n").arg(Utils::boolToString(m_webGraphviz))
+ QString("mathJaxScript: '%1',\n").arg(m_mathJaxScript)
+ QString("constrainImageWidthEnabled: %1,\n").arg(Utils::boolToString(m_constrainImageWidthEnabled))
+ QString("imageAlignCenterEnabled: %1,\n").arg(Utils::boolToString(m_imageAlignCenterEnabled))
+ QString("protectFromXss: %1,\n").arg(Utils::boolToString(m_protectFromXss))
+ QString("htmlTagEnabled: %1,\n").arg(Utils::boolToString(m_htmlTagEnabled))
+ QString("autoBreakEnabled: %1,\n").arg(Utils::boolToString(m_autoBreakEnabled))
+ QString("linkifyEnabled: %1,\n").arg(Utils::boolToString(m_linkifyEnabled))
+ QString("indentFirstLineEnabled: %1,\n").arg(Utils::boolToString(m_indentFirstLineEnabled))
+ QString("codeBlockLineNumberEnabled: %1,\n").arg(Utils::boolToString(m_codeBlockLineNumberEnabled))
+ QString("sectionNumberEnabled: %1,\n").arg(Utils::boolToString(m_sectionNumberEnabled))
+ QString("transparentBackgroundEnabled: %1,\n").arg(Utils::boolToString(m_transparentBackgroundEnabled))
+ QString("scrollable: %1,\n").arg(Utils::boolToString(m_scrollable))
+ QString("bodyWidth: %1,\n").arg(m_bodyWidth)
+ QString("bodyHeight: %1,\n").arg(m_bodyHeight)
+ QString("transformSvgToPngEnabled: %1,\n").arg(Utils::boolToString(m_transformSvgToPngEnabled))
+ QString("mathJaxScale: %1,\n").arg(m_mathJaxScale)
+ QString("removeCodeToolBarEnabled: %1,\n").arg(Utils::boolToString(m_removeCodeToolBarEnabled))
+ QString("sectionNumberBaseLevel: %1\n").arg(m_sectionNumberBaseLevel)
+ QStringLiteral("webPlantUml: %1,\n").arg(Utils::boolToString(m_webPlantUml))
+ QStringLiteral("plantUmlWebService: '%1',\n").arg(m_plantUmlWebService)
+ QStringLiteral("webGraphviz: %1,\n").arg(Utils::boolToString(m_webGraphviz))
+ QStringLiteral("mathJaxScript: '%1',\n").arg(m_mathJaxScript)
+ QStringLiteral("constrainImageWidthEnabled: %1,\n").arg(Utils::boolToString(m_constrainImageWidthEnabled))
+ QStringLiteral("imageAlignCenterEnabled: %1,\n").arg(Utils::boolToString(m_imageAlignCenterEnabled))
+ QStringLiteral("protectFromXss: %1,\n").arg(Utils::boolToString(m_protectFromXss))
+ QStringLiteral("htmlTagEnabled: %1,\n").arg(Utils::boolToString(m_htmlTagEnabled))
+ QStringLiteral("autoBreakEnabled: %1,\n").arg(Utils::boolToString(m_autoBreakEnabled))
+ QStringLiteral("linkifyEnabled: %1,\n").arg(Utils::boolToString(m_linkifyEnabled))
+ QStringLiteral("indentFirstLineEnabled: %1,\n").arg(Utils::boolToString(m_indentFirstLineEnabled))
+ QStringLiteral("codeBlockLineNumberEnabled: %1,\n").arg(Utils::boolToString(m_codeBlockLineNumberEnabled))
+ QStringLiteral("sectionNumberEnabled: %1,\n").arg(Utils::boolToString(m_sectionNumberEnabled))
+ QStringLiteral("transparentBackgroundEnabled: %1,\n").arg(Utils::boolToString(m_transparentBackgroundEnabled))
+ QStringLiteral("scrollable: %1,\n").arg(Utils::boolToString(m_scrollable))
+ QStringLiteral("bodyWidth: %1,\n").arg(m_bodyWidth)
+ QStringLiteral("bodyHeight: %1,\n").arg(m_bodyHeight)
+ QStringLiteral("transformSvgToPngEnabled: %1,\n").arg(Utils::boolToString(m_transformSvgToPngEnabled))
+ QStringLiteral("mathJaxScale: %1,\n").arg(m_mathJaxScale)
+ QStringLiteral("removeCodeToolBarEnabled: %1,\n").arg(Utils::boolToString(m_removeCodeToolBarEnabled))
+ QStringLiteral("sectionNumberBaseLevel: %1\n").arg(m_sectionNumberBaseLevel)
+ QStringLiteral("}");
}

Expand Down Expand Up @@ -83,7 +83,7 @@ static QString fillStyleTag(const QString &p_styleFile)
return "";
}
auto url = PathUtils::pathToUrl(p_styleFile);
return QString("<link rel=\"stylesheet\" type=\"text/css\" href=\"%1\">\n").arg(url.toString());
return QStringLiteral("<link rel=\"stylesheet\" type=\"text/css\" href=\"%1\">\n").arg(url.toString());
}

static QString fillScriptTag(const QString &p_scriptFile)
Expand All @@ -92,7 +92,7 @@ static QString fillScriptTag(const QString &p_scriptFile)
return "";
}
auto url = PathUtils::pathToUrl(p_scriptFile);
return QString("<script type=\"text/javascript\" src=\"%1\"></script>\n").arg(url.toString());
return QStringLiteral("<script type=\"text/javascript\" src=\"%1\"></script>\n").arg(url.toString());
}

static void fillThemeStyles(QString &p_template, const QString &p_webStyleSheetFile, const QString &p_highlightStyleSheetFile)
Expand Down Expand Up @@ -300,7 +300,7 @@ void HtmlTemplateHelper::fillTitle(QString &p_template, const QString &p_title)
{
if (!p_title.isEmpty()) {
p_template.replace("<!-- VX_TITLE_PLACEHOLDER -->",
QString("<title>%1</title>").arg(HtmlUtils::escapeHtml(p_title)));
QStringLiteral("<title>%1</title>").arg(HtmlUtils::escapeHtml(p_title)));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void Logger::log(QtMsgType p_type, const QMessageLogContext &p_context, const QS

if (!s_logToStderr) {
QTextStream stream(&s_file);
stream << header << (QString("(%1:%2) ").arg(fileName).arg(p_context.line))
stream << header << (QStringLiteral("(%1:%2) ").arg(fileName).arg(p_context.line))
<< localMsg << "\n";

if (p_type == QtFatalMsg) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/notebook/bundlenotebook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void BundleNotebook::remove()

// Remove notebook root folder if it is empty.
if (!FileUtils::removeDirIfEmpty(getRootFolderAbsolutePath())) {
qInfo() << QString("root folder of notebook (%1) is not empty and needs manual clean up")
qInfo() << QStringLiteral("root folder of notebook (%1) is not empty and needs manual clean up")
.arg(getRootFolderAbsolutePath());
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/notebook/bundlenotebookfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static void checkRootFolderForNewNotebook(const NotebookParameters &p_paras)
qCritical() << msg;
throw Exception(Exception::Type::InvalidPath, msg);
} else if (p_paras.m_ensureEmptyRootFolder && !PathUtils::isEmptyDir(p_paras.m_rootFolderPath)) {
QString msg = QString("local root folder must be empty: %1 (%2)")
QString msg = QStringLiteral("local root folder must be empty: %1 (%2)")
.arg(p_paras.m_rootFolderPath, PathUtils::absolutePath(p_paras.m_rootFolderPath));
qCritical() << msg;
throw Exception(Exception::Type::InvalidPath, msg);
Expand Down Expand Up @@ -88,7 +88,7 @@ void BundleNotebookFactory::checkParameters(const NotebookParameters &p_paras) c
auto configMgr = dynamic_cast<BundleNotebookConfigMgr *>(p_paras.m_notebookConfigMgr.data());
if (!configMgr) {
Exception::throwOne(Exception::Type::InvalidArgument,
QString("Invalid notebook configuration manager"));
QStringLiteral("Invalid notebook configuration manager"));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/notebook/notebook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ QSharedPointer<Node> Notebook::copyNodeAsChildOf(const QSharedPointer<Node> &p_s

if (Node::isAncestor(p_src.data(), p_dest)) {
Exception::throwOne(Exception::Type::InvalidArgument,
QString("source (%1) is the ancestor of destination (%2)")
QStringLiteral("source (%1) is the ancestor of destination (%2)")
.arg(p_src->fetchPath(), p_dest->fetchPath()));
return nullptr;
}
Expand Down
Loading
Loading