Python: register python infos to the kits macro expander

... and use the name in the autogenerated kits display name

Change-Id: I928533e6f8238189d64350463897a86ff5512ae7
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
David Schulz
2023-12-12 14:40:37 +01:00
parent 8bfb6dbf35
commit 76b61a7993
2 changed files with 25 additions and 1 deletions

View File

@@ -42,6 +42,10 @@ public:
PythonKitAspect::setPython(m_kit, m_comboBox->currentData().toString()); PythonKitAspect::setPython(m_kit, m_comboBox->currentData().toString());
}); });
connect(PythonSettings::instance(),
&PythonSettings::interpretersChanged,
this,
&PythonKitAspectImpl::refresh);
} }
void makeReadOnly() override void makeReadOnly() override
@@ -59,6 +63,7 @@ public:
m_comboBox->addItem(interpreter.name, interpreter.id); m_comboBox->addItem(interpreter.name, interpreter.id);
updateComboBox(PythonKitAspect::python(m_kit)); updateComboBox(PythonKitAspect::python(m_kit));
emit changed(); // we need to emit changed here to update changes in the macro expander
} }
void updateComboBox(const std::optional<Interpreter> &python) void updateComboBox(const std::optional<Interpreter> &python)
@@ -146,6 +151,25 @@ public:
return {PythonKitAspect::id()}; return {PythonKitAspect::id()};
return {}; return {};
} }
void addToMacroExpander(Kit *kit, MacroExpander *expander) const override
{
QTC_ASSERT(kit, return);
expander->registerVariable("Python:Name",
Tr::tr("Name of Python Interpreter"),
[kit]() -> QString {
if (auto python = PythonKitAspect::python(kit))
return python->name;
return {};
});
expander->registerVariable("Python:Path",
Tr::tr("Path to Python Interpreter"),
[kit]() -> QString {
if (auto python = PythonKitAspect::python(kit))
return python->command.toUserOutput();
return {};
});
}
}; };
std::optional<Interpreter> PythonKitAspect::python(const Kit *kit) std::optional<Interpreter> PythonKitAspect::python(const Kit *kit)

View File

@@ -819,7 +819,7 @@ void PythonSettings::addKitsForInterpreter(const Interpreter &interpreter)
[interpreter](Kit *k) { [interpreter](Kit *k) {
k->setAutoDetected(true); k->setAutoDetected(true);
k->setAutoDetectionSource("Python"); k->setAutoDetectionSource("Python");
k->setUnexpandedDisplayName(interpreter.name); k->setUnexpandedDisplayName("%{Python:Name}");
setRelevantAspectsToKit(k); setRelevantAspectsToKit(k);
PythonKitAspect::setPython(k, interpreter.id); PythonKitAspect::setPython(k, interpreter.id);
k->setSticky(PythonKitAspect::id(), true); k->setSticky(PythonKitAspect::id(), true);