diff --git a/src/plugins/python/pythonrunconfiguration.cpp b/src/plugins/python/pythonrunconfiguration.cpp index 139d8a5dfb2..1bd7ccf6c0f 100644 --- a/src/plugins/python/pythonrunconfiguration.cpp +++ b/src/plugins/python/pythonrunconfiguration.cpp @@ -145,6 +145,7 @@ public: Interpreter currentInterpreter() const; void updateInterpreters(const QList &interpreters); void setDefaultInterpreter(const Interpreter &interpreter) { m_defaultId = interpreter.id; } + void setCurrentInterpreter(const Interpreter &interpreter); void fromMap(const QVariantMap &) override; void toMap(QVariantMap &) const override; @@ -171,6 +172,12 @@ void InterpreterAspect::updateInterpreters(const QList &interpreter updateComboBox(); } +void InterpreterAspect::setCurrentInterpreter(const Interpreter &interpreter) +{ + m_currentId = interpreter.id; + emit changed(); +} + void InterpreterAspect::fromMap(const QVariantMap &map) { m_currentId = map.value(settingsKey(), m_defaultId).toString(); @@ -297,7 +304,7 @@ void PythonRunConfiguration::interpreterChanged() { using namespace LanguageClient; - const FilePath python(FilePath::fromUserInput(interpreter())); + const FilePath python = interpreter().command; for (FilePath &file : project()->files(Project::AllFiles)) { if (auto document = TextEditor::TextDocument::textDocumentForFilePath(file)) { @@ -324,9 +331,19 @@ QString PythonRunConfiguration::arguments() const return aspect()->arguments(macroExpander()); } -QString PythonRunConfiguration::interpreter() const +Interpreter PythonRunConfiguration::interpreter() const { - return aspect()->currentInterpreter().command.toString(); + return aspect()->currentInterpreter(); +} + +QString PythonRunConfiguration::interpreterPath() const +{ + return interpreter().command.toString(); +} + +void PythonRunConfiguration::setInterpreter(const Interpreter &interpreter) +{ + aspect()->setCurrentInterpreter(interpreter); } PythonRunConfigurationFactory::PythonRunConfigurationFactory() diff --git a/src/plugins/python/pythonrunconfiguration.h b/src/plugins/python/pythonrunconfiguration.h index b498b3a0542..cf1c829bdb5 100644 --- a/src/plugins/python/pythonrunconfiguration.h +++ b/src/plugins/python/pythonrunconfiguration.h @@ -31,18 +31,22 @@ namespace Python { namespace Internal { +class Interpreter; + class PythonRunConfiguration : public ProjectExplorer::RunConfiguration { Q_OBJECT Q_PROPERTY(bool supportsDebugger READ supportsDebugger) - Q_PROPERTY(QString interpreter READ interpreter) + Q_PROPERTY(QString interpreter READ interpreterPath) Q_PROPERTY(QString mainScript READ mainScript) Q_PROPERTY(QString arguments READ arguments) public: PythonRunConfiguration(ProjectExplorer::Target *target, Utils::Id id); - QString interpreter() const; + Interpreter interpreter() const; + QString interpreterPath() const; + void setInterpreter(const Interpreter &interpreterId); private: void interpreterChanged(); diff --git a/src/plugins/python/pythonutils.cpp b/src/plugins/python/pythonutils.cpp index 1ddad5cfcfe..cd88efe8f20 100644 --- a/src/plugins/python/pythonutils.cpp +++ b/src/plugins/python/pythonutils.cpp @@ -59,7 +59,7 @@ FilePath detectPython(const FilePath &documentPath) if (auto target = project->activeTarget()) { if (auto runConfig = qobject_cast( target->activeRunConfiguration())) { - python = FilePath::fromString(runConfig->interpreter()); + python = runConfig->interpreter().command; } } }