Python: work with Interpreter in PythonRunConfiguration

This saves some unneeded file path conversion and lookups in the
python settings.

Change-Id: I8647858320183dc1da027363b4ab265f6c75e1ae
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2022-03-23 10:12:56 +01:00
parent 7cb3a726d4
commit bf5114dcee
3 changed files with 27 additions and 6 deletions

View File

@@ -145,6 +145,7 @@ public:
Interpreter currentInterpreter() const;
void updateInterpreters(const QList<Interpreter> &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> &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<ArgumentsAspect>()->arguments(macroExpander());
}
QString PythonRunConfiguration::interpreter() const
Interpreter PythonRunConfiguration::interpreter() const
{
return aspect<InterpreterAspect>()->currentInterpreter().command.toString();
return aspect<InterpreterAspect>()->currentInterpreter();
}
QString PythonRunConfiguration::interpreterPath() const
{
return interpreter().command.toString();
}
void PythonRunConfiguration::setInterpreter(const Interpreter &interpreter)
{
aspect<InterpreterAspect>()->setCurrentInterpreter(interpreter);
}
PythonRunConfigurationFactory::PythonRunConfigurationFactory()

View File

@@ -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();

View File

@@ -59,7 +59,7 @@ FilePath detectPython(const FilePath &documentPath)
if (auto target = project->activeTarget()) {
if (auto runConfig = qobject_cast<PythonRunConfiguration *>(
target->activeRunConfiguration())) {
python = FilePath::fromString(runConfig->interpreter());
python = runConfig->interpreter().command;
}
}
}