ProjectExplorer: fix Interpreter::changed emits

Only emit changed if the current interpreter changes.
This is more in line with the other aspects.

This fixes the pyside detection since the changed signal was not
emitted in all relevant code paths.

Change-Id: I53409b17f260b35914e39de894b48d7bd1ce27c0
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
David Schulz
2023-08-15 10:01:33 +02:00
parent b8acef5d8c
commit 01cac8299b
3 changed files with 17 additions and 7 deletions

View File

@@ -809,6 +809,8 @@ Interpreter InterpreterAspect::currentInterpreter() const
void InterpreterAspect::updateInterpreters(const QList<Interpreter> &interpreters) void InterpreterAspect::updateInterpreters(const QList<Interpreter> &interpreters)
{ {
if (m_interpreters == interpreters)
return;
m_interpreters = interpreters; m_interpreters = interpreters;
if (m_comboBox) if (m_comboBox)
updateComboBox(); updateComboBox();
@@ -816,9 +818,11 @@ void InterpreterAspect::updateInterpreters(const QList<Interpreter> &interpreter
void InterpreterAspect::setDefaultInterpreter(const Interpreter &interpreter) void InterpreterAspect::setDefaultInterpreter(const Interpreter &interpreter)
{ {
if (m_defaultId == interpreter.id)
return;
m_defaultId = interpreter.id; m_defaultId = interpreter.id;
if (m_currentId.isEmpty()) if (m_currentId.isEmpty())
m_currentId = m_defaultId; setCurrentInterpreter(interpreter);
} }
void InterpreterAspect::setCurrentInterpreter(const Interpreter &interpreter) void InterpreterAspect::setCurrentInterpreter(const Interpreter &interpreter)
@@ -829,14 +833,13 @@ void InterpreterAspect::setCurrentInterpreter(const Interpreter &interpreter)
return; return;
m_comboBox->setCurrentIndex(index); m_comboBox->setCurrentIndex(index);
} else { } else {
m_currentId = interpreter.id; setCurrentInterpreterId(interpreter.id);
} }
emit changed();
} }
void InterpreterAspect::fromMap(const QVariantMap &map) void InterpreterAspect::fromMap(const QVariantMap &map)
{ {
m_currentId = map.value(settingsKey(), m_defaultId).toString(); setCurrentInterpreterId(map.value(settingsKey(), m_defaultId).toString());
} }
void InterpreterAspect::toMap(QVariantMap &map) const void InterpreterAspect::toMap(QVariantMap &map) const
@@ -862,15 +865,22 @@ void InterpreterAspect::addToLayout(LayoutItem &builder)
builder.addItems({Tr::tr("Interpreter:"), m_comboBox.data(), manageButton}); builder.addItems({Tr::tr("Interpreter:"), m_comboBox.data(), manageButton});
} }
void InterpreterAspect::setCurrentInterpreterId(const QString &id)
{
if (id == m_currentId)
return;
m_currentId = id;
emit changed();
}
void InterpreterAspect::updateCurrentInterpreter() void InterpreterAspect::updateCurrentInterpreter()
{ {
const int index = m_comboBox->currentIndex(); const int index = m_comboBox->currentIndex();
if (index < 0) if (index < 0)
return; return;
QTC_ASSERT(index < m_interpreters.size(), return); QTC_ASSERT(index < m_interpreters.size(), return);
m_currentId = m_interpreters[index].id;
m_comboBox->setToolTip(m_interpreters[index].command.toUserOutput()); m_comboBox->setToolTip(m_interpreters[index].command.toUserOutput());
emit changed(); setCurrentInterpreterId(m_interpreters[index].id);
} }
void InterpreterAspect::updateComboBox() void InterpreterAspect::updateComboBox()

View File

@@ -245,6 +245,7 @@ public:
struct Data : Utils::BaseAspect::Data { Interpreter interpreter; }; struct Data : Utils::BaseAspect::Data { Interpreter interpreter; };
private: private:
void setCurrentInterpreterId(const QString &id);
void updateCurrentInterpreter(); void updateCurrentInterpreter();
void updateComboBox(); void updateComboBox();
QList<Interpreter> m_interpreters; QList<Interpreter> m_interpreters;

View File

@@ -127,7 +127,6 @@ public:
{ {
connect(q, &InterpreterAspect::changed, connect(q, &InterpreterAspect::changed,
this, &PythonInterpreterAspectPrivate::currentInterpreterChanged); this, &PythonInterpreterAspectPrivate::currentInterpreterChanged);
currentInterpreterChanged();
connect(PySideInstaller::instance(), &PySideInstaller::pySideInstalled, this, connect(PySideInstaller::instance(), &PySideInstaller::pySideInstalled, this,
[this](const FilePath &python) { [this](const FilePath &python) {