forked from qt-creator/qt-creator
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:
@@ -81,7 +81,8 @@ public:
|
|||||||
enum Detection {
|
enum Detection {
|
||||||
ManualDetection,
|
ManualDetection,
|
||||||
AutoDetection,
|
AutoDetection,
|
||||||
AutoDetectionFromSettings
|
AutoDetectionFromSettings,
|
||||||
|
AutoDetectionFromSdk,
|
||||||
};
|
};
|
||||||
|
|
||||||
using Predicate = std::function<bool(const ToolChain *)>;
|
using Predicate = std::function<bool(const ToolChain *)>;
|
||||||
|
@@ -51,6 +51,7 @@
|
|||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
#include <QSet>
|
||||||
#include <QSpacerItem>
|
#include <QSpacerItem>
|
||||||
#include <QStackedWidget>
|
#include <QStackedWidget>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
@@ -210,6 +211,10 @@ public:
|
|||||||
|
|
||||||
m_delButton = new QPushButton(ToolChainOptionsPage::tr("Remove"), this);
|
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(
|
m_detectionSettingsButton = new QPushButton(
|
||||||
ToolChainOptionsPage::tr("Auto-detection Settings..."), this);
|
ToolChainOptionsPage::tr("Auto-detection Settings..."), this);
|
||||||
connect(m_detectionSettingsButton, &QAbstractButton::clicked, this,
|
connect(m_detectionSettingsButton, &QAbstractButton::clicked, this,
|
||||||
@@ -235,6 +240,7 @@ public:
|
|||||||
buttonLayout->addWidget(m_addButton);
|
buttonLayout->addWidget(m_addButton);
|
||||||
buttonLayout->addWidget(m_cloneButton);
|
buttonLayout->addWidget(m_cloneButton);
|
||||||
buttonLayout->addWidget(m_delButton);
|
buttonLayout->addWidget(m_delButton);
|
||||||
|
buttonLayout->addWidget(m_redetectButton);
|
||||||
buttonLayout->addWidget(m_detectionSettingsButton);
|
buttonLayout->addWidget(m_detectionSettingsButton);
|
||||||
buttonLayout->addItem(new QSpacerItem(10, 40, QSizePolicy::Minimum, QSizePolicy::Expanding));
|
buttonLayout->addItem(new QSpacerItem(10, 40, QSizePolicy::Minimum, QSizePolicy::Expanding));
|
||||||
|
|
||||||
@@ -283,6 +289,8 @@ public:
|
|||||||
return action;
|
return action;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void redetectToolchains();
|
||||||
|
|
||||||
void apply();
|
void apply();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -294,6 +302,7 @@ public:
|
|||||||
QPushButton *m_addButton;
|
QPushButton *m_addButton;
|
||||||
QPushButton *m_cloneButton;
|
QPushButton *m_cloneButton;
|
||||||
QPushButton *m_delButton;
|
QPushButton *m_delButton;
|
||||||
|
QPushButton *m_redetectButton;
|
||||||
QPushButton *m_detectionSettingsButton;
|
QPushButton *m_detectionSettingsButton;
|
||||||
|
|
||||||
QHash<Core::Id, QPair<StaticTreeItem *, StaticTreeItem *>> m_languageMap;
|
QHash<Core::Id, QPair<StaticTreeItem *, StaticTreeItem *>> m_languageMap;
|
||||||
@@ -366,6 +375,50 @@ StaticTreeItem *ToolChainOptionsWidget::parentForToolChain(ToolChain *tc)
|
|||||||
return tc->isAutoDetected() ? nodes.first : nodes.second;
|
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()
|
void ToolChainOptionsWidget::toolChainSelectionChanged()
|
||||||
{
|
{
|
||||||
ToolChainTreeItem *item = currentTreeItem();
|
ToolChainTreeItem *item = currentTreeItem();
|
||||||
@@ -388,14 +441,16 @@ void ToolChainOptionsWidget::apply()
|
|||||||
|
|
||||||
// Update tool chains:
|
// Update tool chains:
|
||||||
foreach (const Core::Id &l, m_languageMap.keys()) {
|
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 (TreeItem *item : *parent) {
|
for (StaticTreeItem *parent : {autoAndManual.first, autoAndManual.second}) {
|
||||||
auto tcItem = static_cast<ToolChainTreeItem *>(item);
|
for (TreeItem *item : *parent) {
|
||||||
Q_ASSERT(tcItem->toolChain);
|
auto tcItem = static_cast<ToolChainTreeItem *>(item);
|
||||||
if (tcItem->widget)
|
Q_ASSERT(tcItem->toolChain);
|
||||||
tcItem->widget->apply();
|
if (tcItem->widget)
|
||||||
tcItem->changed = false;
|
tcItem->widget->apply();
|
||||||
tcItem->update();
|
tcItem->changed = false;
|
||||||
|
tcItem->update();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -195,6 +195,8 @@ QList<ToolChain *> ToolChainSettingsAccessor::restoreToolChains(QWidget *parent)
|
|||||||
const QList<ToolChain *> systemFileTcs
|
const QList<ToolChain *> systemFileTcs
|
||||||
= toolChains(restoreSettings(FileName::fromString(Core::ICore::installerResourcePath() + TOOLCHAIN_FILENAME),
|
= toolChains(restoreSettings(FileName::fromString(Core::ICore::installerResourcePath() + TOOLCHAIN_FILENAME),
|
||||||
parent));
|
parent));
|
||||||
|
for (ToolChain * const systemTc : systemFileTcs)
|
||||||
|
systemTc->setDetection(ToolChain::AutoDetectionFromSdk);
|
||||||
|
|
||||||
// read all tool chains from user file.
|
// read all tool chains from user file.
|
||||||
const QList<ToolChain *> userFileTcs = toolChains(restoreSettings(parent));
|
const QList<ToolChain *> userFileTcs = toolChains(restoreSettings(parent));
|
||||||
|
Reference in New Issue
Block a user