CppEditor: Use FilePath for licenseTemplatePath

Change-Id: I0a7d957a9308a5e696f4af7f06226e407584ceba
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
hjk
2024-01-23 10:29:23 +01:00
parent ff25fa6ca7
commit 6215206a06
3 changed files with 14 additions and 14 deletions

View File

@@ -481,7 +481,7 @@ void CppEditorPlugin::registerVariables()
[] { return globalCppFileSettings().licenseTemplate(); }); [] { return globalCppFileSettings().licenseTemplate(); });
expander->registerFileVariables("Cpp:LicenseTemplatePath", expander->registerFileVariables("Cpp:LicenseTemplatePath",
Tr::tr("The configured path to the license template"), Tr::tr("The configured path to the license template"),
[] { return FilePath::fromUserInput(globalCppFileSettings().licenseTemplatePath); }); [] { return globalCppFileSettings().licenseTemplatePath; });
expander->registerVariable( expander->registerVariable(
"Cpp:PragmaOnce", "Cpp:PragmaOnce",
Tr::tr("Insert \"#pragma once\" instead of \"#ifndef\" include guards into header file"), Tr::tr("Insert \"#pragma once\" instead of \"#ifndef\" include guards into header file"),

View File

@@ -65,7 +65,8 @@ void CppFileSettings::toSettings(QtcSettings *s) const
s->setValueWithDefault(sourceSearchPathsKeyC, sourceSearchPaths, def.sourceSearchPaths); s->setValueWithDefault(sourceSearchPathsKeyC, sourceSearchPaths, def.sourceSearchPaths);
s->setValueWithDefault(Constants::LOWERCASE_CPPFILES_KEY, lowerCaseFiles, def.lowerCaseFiles); s->setValueWithDefault(Constants::LOWERCASE_CPPFILES_KEY, lowerCaseFiles, def.lowerCaseFiles);
s->setValueWithDefault(headerPragmaOnceC, headerPragmaOnce, def.headerPragmaOnce); s->setValueWithDefault(headerPragmaOnceC, headerPragmaOnce, def.headerPragmaOnce);
s->setValueWithDefault(licenseTemplatePathKeyC, licenseTemplatePath, def.licenseTemplatePath); s->setValueWithDefault(licenseTemplatePathKeyC, licenseTemplatePath.toSettings(),
def.licenseTemplatePath.toSettings());
s->endGroup(); s->endGroup();
} }
@@ -81,7 +82,8 @@ void CppFileSettings::fromSettings(QtcSettings *s)
sourceSearchPaths = s->value(sourceSearchPathsKeyC, def.sourceSearchPaths).toStringList(); sourceSearchPaths = s->value(sourceSearchPathsKeyC, def.sourceSearchPaths).toStringList();
lowerCaseFiles = s->value(Constants::LOWERCASE_CPPFILES_KEY, def.lowerCaseFiles).toBool(); lowerCaseFiles = s->value(Constants::LOWERCASE_CPPFILES_KEY, def.lowerCaseFiles).toBool();
headerPragmaOnce = s->value(headerPragmaOnceC, def.headerPragmaOnce).toBool(); headerPragmaOnce = s->value(headerPragmaOnceC, def.headerPragmaOnce).toBool();
licenseTemplatePath = s->value(licenseTemplatePathKeyC, def.licenseTemplatePath).toString(); licenseTemplatePath = FilePath::fromSettings(s->value(licenseTemplatePathKeyC,
def.licenseTemplatePath.toSettings()));
s->endGroup(); s->endGroup();
} }
@@ -213,9 +215,10 @@ QString CppFileSettings::licenseTemplate() const
{ {
if (licenseTemplatePath.isEmpty()) if (licenseTemplatePath.isEmpty())
return QString(); return QString();
QFile file(licenseTemplatePath); QFile file(licenseTemplatePath.toFSPathString());
if (!file.open(QIODevice::ReadOnly|QIODevice::Text)) { if (!file.open(QIODevice::ReadOnly|QIODevice::Text)) {
qWarning("Unable to open the license template %s: %s", qPrintable(licenseTemplatePath), qWarning("Unable to open the license template %s: %s",
qPrintable(licenseTemplatePath.toUserOutput()),
qPrintable(file.errorString())); qPrintable(file.errorString()));
return QString(); return QString();
} }
@@ -413,7 +416,7 @@ void CppFileSettingsWidget::setSettings(const CppFileSettings &s)
setComboText(m_sourceSuffixComboBox, s.sourceSuffix); setComboText(m_sourceSuffixComboBox, s.sourceSuffix);
m_headerSearchPathsEdit->setText(s.headerSearchPaths.join(comma)); m_headerSearchPathsEdit->setText(s.headerSearchPaths.join(comma));
m_sourceSearchPathsEdit->setText(s.sourceSearchPaths.join(comma)); m_sourceSearchPathsEdit->setText(s.sourceSearchPaths.join(comma));
setLicenseTemplatePath(FilePath::fromString(s.licenseTemplatePath)); setLicenseTemplatePath(s.licenseTemplatePath);
} }
CppFileSettings CppFileSettingsWidget::currentSettings() const CppFileSettings CppFileSettingsWidget::currentSettings() const
@@ -427,7 +430,7 @@ CppFileSettings CppFileSettingsWidget::currentSettings() const
rc.sourceSuffix = m_sourceSuffixComboBox->currentText(); rc.sourceSuffix = m_sourceSuffixComboBox->currentText();
rc.headerSearchPaths = trimmedPaths(m_headerSearchPathsEdit->text()); rc.headerSearchPaths = trimmedPaths(m_headerSearchPathsEdit->text());
rc.sourceSearchPaths = trimmedPaths(m_sourceSearchPathsEdit->text()); rc.sourceSearchPaths = trimmedPaths(m_sourceSearchPathsEdit->text());
rc.licenseTemplatePath = licenseTemplatePath().toString(); rc.licenseTemplatePath = licenseTemplatePath();
return rc; return rc;
} }
@@ -534,7 +537,8 @@ void CppFileSettingsForProject::loadSettings()
m_customSettings.headerPragmaOnce = data.value(headerPragmaOnceC, m_customSettings.headerPragmaOnce = data.value(headerPragmaOnceC,
m_customSettings.headerPragmaOnce).toBool(); m_customSettings.headerPragmaOnce).toBool();
m_customSettings.licenseTemplatePath m_customSettings.licenseTemplatePath
= data.value(licenseTemplatePathKeyC, m_customSettings.licenseTemplatePath).toString(); = FilePath::fromSettings(data.value(licenseTemplatePathKeyC,
m_customSettings.licenseTemplatePath.toSettings()));
} }
void CppFileSettingsForProject::saveSettings() void CppFileSettingsForProject::saveSettings()
@@ -556,7 +560,7 @@ void CppFileSettingsForProject::saveSettings()
data.insert(sourceSearchPathsKeyC, m_customSettings.sourceSearchPaths); data.insert(sourceSearchPathsKeyC, m_customSettings.sourceSearchPaths);
data.insert(Constants::LOWERCASE_CPPFILES_KEY, m_customSettings.lowerCaseFiles); data.insert(Constants::LOWERCASE_CPPFILES_KEY, m_customSettings.lowerCaseFiles);
data.insert(headerPragmaOnceC, m_customSettings.headerPragmaOnce); data.insert(headerPragmaOnceC, m_customSettings.headerPragmaOnce);
data.insert(licenseTemplatePathKeyC, m_customSettings.licenseTemplatePath); data.insert(licenseTemplatePathKeyC, m_customSettings.licenseTemplatePath.toSettings());
m_project->setNamedSettings(projectSettingsKeyC, data); m_project->setNamedSettings(projectSettingsKeyC, data);
} }

View File

@@ -9,10 +9,6 @@
#include <QDir> #include <QDir>
QT_BEGIN_NAMESPACE
class QSettings;
QT_END_NAMESPACE
namespace ProjectExplorer { class Project; } namespace ProjectExplorer { class Project; }
namespace CppEditor::Internal { namespace CppEditor::Internal {
@@ -31,7 +27,7 @@ public:
QStringList sourceSearchPaths = {QDir::toNativeSeparators("../src"), QStringList sourceSearchPaths = {QDir::toNativeSeparators("../src"),
QDir::toNativeSeparators("../Src"), QDir::toNativeSeparators("../Src"),
".."}; ".."};
QString licenseTemplatePath; Utils::FilePath licenseTemplatePath;
bool headerPragmaOnce = false; bool headerPragmaOnce = false;
bool lowerCaseFiles = Constants::LOWERCASE_CPPFILES_DEFAULT; bool lowerCaseFiles = Constants::LOWERCASE_CPPFILES_DEFAULT;