Python: add clean up button to python settings

Change-Id: I633a8b20f4b02a989f2fd71448b611bbb0d0a3a4
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
David Schulz
2022-03-28 13:24:24 +02:00
parent d0c8cc20f5
commit 98a2600150

View File

@@ -113,13 +113,16 @@ private:
InterpreterDetailsWidget *m_detailsWidget = nullptr; InterpreterDetailsWidget *m_detailsWidget = nullptr;
QPushButton *m_deleteButton = nullptr; QPushButton *m_deleteButton = nullptr;
QPushButton *m_makeDefaultButton = nullptr; QPushButton *m_makeDefaultButton = nullptr;
QPushButton *m_cleanButton = nullptr;
QString m_defaultId; QString m_defaultId;
void currentChanged(const QModelIndex &index, const QModelIndex &previous); void currentChanged(const QModelIndex &index, const QModelIndex &previous);
void detailsChanged(); void detailsChanged();
void updateCleanButton();
void addItem(); void addItem();
void deleteItem(); void deleteItem();
void makeDefault(); void makeDefault();
void cleanUp();
}; };
InterpreterOptionsWidget::InterpreterOptionsWidget(const QList<Interpreter> &interpreters, const QString &defaultInterpreter) InterpreterOptionsWidget::InterpreterOptionsWidget(const QList<Interpreter> &interpreters, const QString &defaultInterpreter)
@@ -174,6 +177,13 @@ InterpreterOptionsWidget::InterpreterOptionsWidget(const QList<Interpreter> &int
m_makeDefaultButton->setEnabled(false); m_makeDefaultButton->setEnabled(false);
connect(m_makeDefaultButton, &QPushButton::pressed, this, &InterpreterOptionsWidget::makeDefault); connect(m_makeDefaultButton, &QPushButton::pressed, this, &InterpreterOptionsWidget::makeDefault);
m_cleanButton = new QPushButton(PythonSettings::tr("&Clean Up"));
connect(m_cleanButton, &QPushButton::pressed, this, &InterpreterOptionsWidget::cleanUp);
m_cleanButton->setToolTip(
PythonSettings::tr("Remove all python interpreters without a valid executable."));
updateCleanButton();
m_detailsWidget->hide(); m_detailsWidget->hide();
connect(m_detailsWidget, connect(m_detailsWidget,
&InterpreterDetailsWidget::changed, &InterpreterDetailsWidget::changed,
@@ -184,6 +194,7 @@ InterpreterOptionsWidget::InterpreterOptionsWidget(const QList<Interpreter> &int
addButton, addButton,
m_deleteButton, m_deleteButton,
m_makeDefaultButton, m_makeDefaultButton,
m_cleanButton,
Stretch() Stretch()
}; };
@@ -224,6 +235,14 @@ void InterpreterOptionsWidget::detailsChanged()
m_model.itemAt(index.row())->itemData = m_detailsWidget->toInterpreter(); m_model.itemAt(index.row())->itemData = m_detailsWidget->toInterpreter();
emit m_model.dataChanged(index, index); emit m_model.dataChanged(index, index);
} }
updateCleanButton();
}
void InterpreterOptionsWidget::updateCleanButton()
{
m_cleanButton->setEnabled(Utils::anyOf(m_model.allData(), [](const Interpreter &interpreter) {
return !interpreter.command.isExecutableFile();
}));
} }
void InterpreterOptionsWidget::addItem() void InterpreterOptionsWidget::addItem()
@@ -232,6 +251,7 @@ void InterpreterOptionsWidget::addItem()
m_model.appendItem({QUuid::createUuid().toString(), QString("Python"), FilePath(), false})); m_model.appendItem({QUuid::createUuid().toString(), QString("Python"), FilePath(), false}));
QTC_ASSERT(index.isValid(), return); QTC_ASSERT(index.isValid(), return);
m_view.setCurrentIndex(index); m_view.setCurrentIndex(index);
updateCleanButton();
} }
void InterpreterOptionsWidget::deleteItem() void InterpreterOptionsWidget::deleteItem()
@@ -239,6 +259,7 @@ void InterpreterOptionsWidget::deleteItem()
const QModelIndex &index = m_view.currentIndex(); const QModelIndex &index = m_view.currentIndex();
if (index.isValid()) if (index.isValid())
m_model.destroyItem(m_model.itemAt(index.row())); m_model.destroyItem(m_model.itemAt(index.row()));
updateCleanButton();
} }
class InterpreterOptionsPage : public Core::IOptionsPage class InterpreterOptionsPage : public Core::IOptionsPage
@@ -360,6 +381,13 @@ void InterpreterOptionsWidget::makeDefault()
} }
} }
void InterpreterOptionsWidget::cleanUp()
{
m_model.destroyItems(
[](const Interpreter &interpreter) { return !interpreter.command.isExecutableFile(); });
updateCleanButton();
}
constexpr char settingsGroupKey[] = "Python"; constexpr char settingsGroupKey[] = "Python";
constexpr char interpreterKey[] = "Interpeter"; constexpr char interpreterKey[] = "Interpeter";
constexpr char defaultKey[] = "DefaultInterpeter"; constexpr char defaultKey[] = "DefaultInterpeter";