diff --git a/src/libs/utils/macroexpander.cpp b/src/libs/utils/macroexpander.cpp index 50861f5a973..5e203762132 100644 --- a/src/libs/utils/macroexpander.cpp +++ b/src/libs/utils/macroexpander.cpp @@ -395,22 +395,22 @@ void MacroExpander::registerIntVariable(const QByteArray &variable, * \sa registerVariable(), registerIntVariable(), registerPrefix() */ void MacroExpander::registerFileVariables(const QByteArray &prefix, - const QString &heading, const StringFunction &base, bool visibleInChooser) + const QString &heading, const FileFunction &base, bool visibleInChooser) { registerVariable(prefix + kFilePathPostfix, tr("%1: Full path including file name.").arg(heading), - [base]() -> QString { QString tmp = base(); return tmp.isEmpty() ? QString() : QFileInfo(tmp).filePath(); }, + [base]() -> QString { QString tmp = base().toString(); return tmp.isEmpty() ? QString() : QFileInfo(tmp).filePath(); }, visibleInChooser); registerVariable(prefix + kPathPostfix, tr("%1: Full path excluding file name.").arg(heading), - [base]() -> QString { QString tmp = base(); return tmp.isEmpty() ? QString() : QFileInfo(tmp).path(); }, + [base]() -> QString { QString tmp = base().toString(); return tmp.isEmpty() ? QString() : QFileInfo(tmp).path(); }, visibleInChooser); registerVariable(prefix + kNativeFilePathPostfix, tr("%1: Full path including file name, with native path separator (backslash on Windows).").arg(heading), [base]() -> QString { - QString tmp = base(); + QString tmp = base().toString(); return tmp.isEmpty() ? QString() : QDir::toNativeSeparators(QFileInfo(tmp).filePath()); }, visibleInChooser); @@ -418,19 +418,19 @@ void MacroExpander::registerFileVariables(const QByteArray &prefix, registerVariable(prefix + kNativePathPostfix, tr("%1: Full path excluding file name, with native path separator (backslash on Windows).").arg(heading), [base]() -> QString { - QString tmp = base(); + QString tmp = base().toString(); return tmp.isEmpty() ? QString() : QDir::toNativeSeparators(QFileInfo(tmp).path()); }, visibleInChooser); registerVariable(prefix + kFileNamePostfix, tr("%1: File name without path.").arg(heading), - [base]() -> QString { QString tmp = base(); return tmp.isEmpty() ? QString() : FilePath::fromString(tmp).fileName(); }, + [base]() -> QString { QString tmp = base().toString(); return tmp.isEmpty() ? QString() : FilePath::fromString(tmp).fileName(); }, visibleInChooser); registerVariable(prefix + kFileBaseNamePostfix, tr("%1: File base name without path and suffix.").arg(heading), - [base]() -> QString { QString tmp = base(); return tmp.isEmpty() ? QString() : QFileInfo(tmp).baseName(); }, + [base]() -> QString { QString tmp = base().toString(); return tmp.isEmpty() ? QString() : QFileInfo(tmp).baseName(); }, visibleInChooser); } diff --git a/src/libs/utils/macroexpander.h b/src/libs/utils/macroexpander.h index e0a330956c9..de24e44c1f2 100644 --- a/src/libs/utils/macroexpander.h +++ b/src/libs/utils/macroexpander.h @@ -65,6 +65,7 @@ public: using PrefixFunction = std::function; using ResolverFunction = std::function; using StringFunction = std::function; + using FileFunction = std::function; using IntFunction = std::function; void registerPrefix(const QByteArray &prefix, @@ -78,7 +79,7 @@ public: const QString &description, const IntFunction &value); void registerFileVariables(const QByteArray &prefix, - const QString &heading, const StringFunction &value, + const QString &heading, const FileFunction &value, bool visibleInChooser = true); void registerExtraResolver(const ResolverFunction &value); diff --git a/src/plugins/cmakeprojectmanager/cmakekitinformation.cpp b/src/plugins/cmakeprojectmanager/cmakekitinformation.cpp index e8cc867ae92..13e3a3d960f 100644 --- a/src/plugins/cmakeprojectmanager/cmakekitinformation.cpp +++ b/src/plugins/cmakeprojectmanager/cmakekitinformation.cpp @@ -297,10 +297,10 @@ void CMakeKitAspect::addToMacroExpander(Kit *k, Utils::MacroExpander *expander) { QTC_ASSERT(k, return); expander->registerFileVariables("CMake:Executable", tr("Path to the cmake executable"), - [k]() -> QString { - CMakeTool *tool = CMakeKitAspect::cmakeTool(k); - return tool ? tool->cmakeExecutable().toString() : QString(); - }); + [k] { + CMakeTool *tool = CMakeKitAspect::cmakeTool(k); + return tool ? tool->cmakeExecutable() : Utils::FilePath(); + }); } QSet CMakeKitAspect::availableFeatures(const Kit *k) const diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp index 206598b2388..658d5e045ba 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.cpp +++ b/src/plugins/coreplugin/editormanager/editormanager.cpp @@ -704,9 +704,9 @@ void EditorManagerPrivate::init() d->m_openEditorsFactory = new OpenEditorsViewFactory(); globalMacroExpander()->registerFileVariables(kCurrentDocumentPrefix, tr("Current document"), - []() -> QString { + [] { IDocument *document = EditorManager::currentDocument(); - return document ? document->filePath().toString() : QString(); + return document ? document->filePath() : FilePath(); }); globalMacroExpander()->registerIntVariable(kCurrentDocumentXPos, diff --git a/src/plugins/cpptools/cpptoolsplugin.cpp b/src/plugins/cpptools/cpptoolsplugin.cpp index fa13b359a30..c5796e0dba2 100644 --- a/src/plugins/cpptools/cpptoolsplugin.cpp +++ b/src/plugins/cpptools/cpptoolsplugin.cpp @@ -201,7 +201,7 @@ bool CppToolsPlugin::initialize(const QStringList &arguments, QString *error) []() { return CppToolsPlugin::licenseTemplate(); }); expander->registerFileVariables("Cpp:LicenseTemplatePath", tr("The configured path to the license template"), - []() { return CppToolsPlugin::licenseTemplatePath().toString(); }); + []() { return CppToolsPlugin::licenseTemplatePath(); }); expander->registerVariable( "Cpp:PragmaOnce", diff --git a/src/plugins/debugger/debuggerruncontrol.cpp b/src/plugins/debugger/debuggerruncontrol.cpp index 25f5b837dbf..6d2e58e56b1 100644 --- a/src/plugins/debugger/debuggerruncontrol.cpp +++ b/src/plugins/debugger/debuggerruncontrol.cpp @@ -598,7 +598,7 @@ void DebuggerRunTool::start() Utils::globalMacroExpander()->registerFileVariables( "DebuggedExecutable", tr("Debugged executable"), - [this] { return m_runParameters.inferior.executable.toString(); } + [this] { return m_runParameters.inferior.executable; } ); runControl()->setDisplayName(m_runParameters.displayName); diff --git a/src/plugins/projectexplorer/kitinformation.cpp b/src/plugins/projectexplorer/kitinformation.cpp index 5b5f7ebade5..6052323fec4 100644 --- a/src/plugins/projectexplorer/kitinformation.cpp +++ b/src/plugins/projectexplorer/kitinformation.cpp @@ -167,8 +167,8 @@ void SysRootKitAspect::addToMacroExpander(Kit *kit, Utils::MacroExpander *expand { QTC_ASSERT(kit, return); - expander->registerFileVariables("SysRoot", tr("Sys Root"), [kit]() -> QString { - return SysRootKitAspect::sysRoot(kit).toString(); + expander->registerFileVariables("SysRoot", tr("Sys Root"), [kit] { + return SysRootKitAspect::sysRoot(kit); }); } diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index 75c9ce59eb9..1885df2a46e 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -1779,19 +1779,19 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er Utils::MacroExpander *expander = Utils::globalMacroExpander(); expander->registerFileVariables(Constants::VAR_CURRENTPROJECT_PREFIX, tr("Current project's main file."), - []() -> QString { - Utils::FilePath projectFilePath; + []() -> FilePath { + FilePath projectFilePath; if (Project *project = ProjectTree::currentProject()) projectFilePath = project->projectFilePath(); - return projectFilePath.toString(); + return projectFilePath; }, false); expander->registerFileVariables("CurrentDocument:Project", tr("Main file of the project the current document belongs to."), - []() -> QString { - Utils::FilePath projectFilePath; + []() -> FilePath { + FilePath projectFilePath; if (Project *project = ProjectTree::currentProject()) projectFilePath = project->projectFilePath(); - return projectFilePath.toString(); + return projectFilePath; }, false); expander->registerVariable(Constants::VAR_CURRENTPROJECT_NAME, @@ -1850,9 +1850,9 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er return {}; }); expander->registerFileVariables("ActiveProject", tr("Active project's main file."), - []() -> QString { + []() -> FilePath { if (const Project * const project = SessionManager::startupProject()) - return project->projectFilePath().toString(); + return project->projectFilePath(); return {}; }); expander->registerVariable("ActiveProject:Kit:Name", @@ -1909,10 +1909,10 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er }); expander->registerFileVariables("ActiveProject:RunConfig:Executable", tr("The executable of the active project's active run configuration."), - []() -> QString { + []() -> FilePath { if (const RunConfiguration * const rc = activeRunConfiguration()) - return rc->commandLine().executable().toString(); - return QString(); + return rc->commandLine().executable(); + return {}; }); const char activeRunEnvVar[] = "ActiveProject:RunConfig:Env"; Utils::EnvironmentProvider::addProvider( @@ -1944,7 +1944,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er }); const auto fileHandler = [] { - return SessionManager::sessionNameToFileName(SessionManager::activeSession()).toString(); + return SessionManager::sessionNameToFileName(SessionManager::activeSession()); }; expander->registerFileVariables("Session", tr("File where current session is saved."), fileHandler); diff --git a/src/plugins/projectexplorer/projectmacroexpander.cpp b/src/plugins/projectexplorer/projectmacroexpander.cpp index 03f095caf2d..93d63ce89ce 100644 --- a/src/plugins/projectexplorer/projectmacroexpander.cpp +++ b/src/plugins/projectexplorer/projectmacroexpander.cpp @@ -36,10 +36,10 @@ ProjectMacroExpander::ProjectMacroExpander(const Utils::FilePath &mainFilePath, // TODO: Remove "Current" variants in ~4.16 registerFileVariables(Constants::VAR_CURRENTPROJECT_PREFIX, QCoreApplication::translate("ProjectExplorer", "Main file of current project"), - [mainFilePath] { return mainFilePath.toString(); }, false); + [mainFilePath] { return mainFilePath; }, false); registerFileVariables("Project", QCoreApplication::translate("ProjectExplorer", "Main file of the project"), - [mainFilePath] { return mainFilePath.toString(); }); + [mainFilePath] { return mainFilePath; }); registerVariable(Constants::VAR_CURRENTPROJECT_NAME, QCoreApplication::translate("ProjectExplorer", "Name of current project"), [projectName] { return projectName; }, false); diff --git a/src/plugins/projectexplorer/runconfiguration.cpp b/src/plugins/projectexplorer/runconfiguration.cpp index 542d0732fa3..e74127fced9 100644 --- a/src/plugins/projectexplorer/runconfiguration.cpp +++ b/src/plugins/projectexplorer/runconfiguration.cpp @@ -203,7 +203,7 @@ RunConfiguration::RunConfiguration(Target *target, Utils::Id id) [this] { return displayName(); }); m_expander.registerFileVariables("RunConfig:Executable", tr("The run configuration's executable."), - [this] { return commandLine().executable().toString(); }); + [this] { return commandLine().executable(); }); m_commandLineGetter = [this] { diff --git a/src/plugins/projectexplorer/target.cpp b/src/plugins/projectexplorer/target.cpp index d44a2944428..3e2e8ca40f0 100644 --- a/src/plugins/projectexplorer/target.cpp +++ b/src/plugins/projectexplorer/target.cpp @@ -180,10 +180,10 @@ Target::Target(Project *project, Kit *k, _constructor_tag) : }, false); d->m_macroExpander.registerFileVariables("CurrentRun:Executable", tr("The currently active run configuration's executable (if applicable)."), - [this]() -> QString { + [this]() -> FilePath { if (RunConfiguration * const rc = activeRunConfiguration()) - return rc->commandLine().executable().toString(); - return QString(); + return rc->commandLine().executable(); + return FilePath(); }, false); d->m_macroExpander.registerPrefix("CurrentRun:Env", tr("Variables in the current run environment."), [this](const QString &var) {