ProjectExplorer: Add "Re-detect" button to toolchains page

This allows to take changed detection settings or added/removed
compilers into account without restarting Qt Creator.
It is also the only way to get rid of formerly auto-detected compilers
that would not get detected anymore with the current settings.

Change-Id: I3d8a7659e24fa5d55d1fb17864386cf19d3e2533
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Christian Kandeler
2019-04-08 17:36:39 +02:00
parent 6cb2e71c38
commit 3969a007c2
3 changed files with 67 additions and 9 deletions

View File

@@ -81,7 +81,8 @@ public:
enum Detection {
ManualDetection,
AutoDetection,
AutoDetectionFromSettings
AutoDetectionFromSettings,
AutoDetectionFromSdk,
};
using Predicate = std::function<bool(const ToolChain *)>;

View File

@@ -51,6 +51,7 @@
#include <QMenu>
#include <QMessageBox>
#include <QPushButton>
#include <QSet>
#include <QSpacerItem>
#include <QStackedWidget>
#include <QTextStream>
@@ -210,6 +211,10 @@ public:
m_delButton = new QPushButton(ToolChainOptionsPage::tr("Remove"), this);
m_redetectButton = new QPushButton(ToolChainOptionsPage::tr("Re-detect"), this);
connect(m_redetectButton, &QAbstractButton::clicked,
this, &ToolChainOptionsWidget::redetectToolchains);
m_detectionSettingsButton = new QPushButton(
ToolChainOptionsPage::tr("Auto-detection Settings..."), this);
connect(m_detectionSettingsButton, &QAbstractButton::clicked, this,
@@ -235,6 +240,7 @@ public:
buttonLayout->addWidget(m_addButton);
buttonLayout->addWidget(m_cloneButton);
buttonLayout->addWidget(m_delButton);
buttonLayout->addWidget(m_redetectButton);
buttonLayout->addWidget(m_detectionSettingsButton);
buttonLayout->addItem(new QSpacerItem(10, 40, QSizePolicy::Minimum, QSizePolicy::Expanding));
@@ -283,6 +289,8 @@ public:
return action;
}
void redetectToolchains();
void apply();
private:
@@ -294,6 +302,7 @@ public:
QPushButton *m_addButton;
QPushButton *m_cloneButton;
QPushButton *m_delButton;
QPushButton *m_redetectButton;
QPushButton *m_detectionSettingsButton;
QHash<Core::Id, QPair<StaticTreeItem *, StaticTreeItem *>> m_languageMap;
@@ -366,6 +375,50 @@ StaticTreeItem *ToolChainOptionsWidget::parentForToolChain(ToolChain *tc)
return tc->isAutoDetected() ? nodes.first : nodes.second;
}
void ToolChainOptionsWidget::redetectToolchains()
{
QList<ToolChainTreeItem *> itemsToRemove;
QList<ToolChain *> knownTcs;
m_model.forAllItems([&itemsToRemove, &knownTcs](TreeItem *item) {
if (item->level() != 3)
return;
const auto tcItem = static_cast<ToolChainTreeItem *>(item);
if (tcItem->toolChain->isAutoDetected()
&& tcItem->toolChain->detection() != ToolChain::AutoDetectionFromSdk) {
itemsToRemove << tcItem;
} else {
knownTcs << tcItem->toolChain;
}
});
QList<ToolChain *> toAdd;
QSet<ToolChain *> toDelete;
for (ToolChainFactory *f : ToolChainFactory::allToolChainFactories()) {
for (ToolChain * const tc : f->autoDetect(knownTcs)) {
if (knownTcs.contains(tc) || toDelete.contains(tc))
continue;
const auto matchItem = [tc](const ToolChainTreeItem *item) {
return item->toolChain->compilerCommand() == tc->compilerCommand()
&& item->toolChain->typeId() == tc->typeId()
&& item->toolChain->language() == tc->language()
&& item->toolChain->targetAbi() == tc->targetAbi();
};
ToolChainTreeItem * const item = findOrDefault(itemsToRemove, matchItem);
if (item) {
itemsToRemove.removeOne(item);
toDelete << tc;
continue;
}
knownTcs << tc;
toAdd << tc;
}
}
for (ToolChainTreeItem * const tcItem : qAsConst(itemsToRemove))
markForRemoval(tcItem);
for (ToolChain * const newTc : qAsConst(toAdd))
m_toAddList.append(insertToolChain(newTc, true));
qDeleteAll(toDelete);
}
void ToolChainOptionsWidget::toolChainSelectionChanged()
{
ToolChainTreeItem *item = currentTreeItem();
@@ -388,7 +441,8 @@ void ToolChainOptionsWidget::apply()
// Update tool chains:
foreach (const Core::Id &l, m_languageMap.keys()) {
StaticTreeItem *parent = m_languageMap.value(l).second;
const QPair<StaticTreeItem *, StaticTreeItem *> autoAndManual = m_languageMap.value(l);
for (StaticTreeItem *parent : {autoAndManual.first, autoAndManual.second}) {
for (TreeItem *item : *parent) {
auto tcItem = static_cast<ToolChainTreeItem *>(item);
Q_ASSERT(tcItem->toolChain);
@@ -398,6 +452,7 @@ void ToolChainOptionsWidget::apply()
tcItem->update();
}
}
}
// Add new (and already updated) tool chains
QStringList removedTcs;

View File

@@ -195,6 +195,8 @@ QList<ToolChain *> ToolChainSettingsAccessor::restoreToolChains(QWidget *parent)
const QList<ToolChain *> systemFileTcs
= toolChains(restoreSettings(FileName::fromString(Core::ICore::installerResourcePath() + TOOLCHAIN_FILENAME),
parent));
for (ToolChain * const systemTc : systemFileTcs)
systemTc->setDetection(ToolChain::AutoDetectionFromSdk);
// read all tool chains from user file.
const QList<ToolChain *> userFileTcs = toolChains(restoreSettings(parent));