ProjectExplorer: Postpone ToolChainConfigWidget creation

... until they are actually used, i.e. when the respective
tool chain is selected in the Toolchain tab. Some of them
(QNX) can be expensive to set up.

Previously all of were created when the Kits settings page
was opened.

Change-Id: I80e4238269b9f08788c330e2052c525dcf41d1ba
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2023-04-18 15:58:03 +02:00
parent 0ab7a14731
commit e7d6501553

View File

@@ -48,20 +48,8 @@ class ToolChainTreeItem : public TreeItem
{ {
public: public:
ToolChainTreeItem(QStackedWidget *parentWidget, ToolChain *tc, bool c) : ToolChainTreeItem(QStackedWidget *parentWidget, ToolChain *tc, bool c) :
toolChain(tc), changed(c) toolChain(tc), changed(c), m_parentWidget(parentWidget)
{ {}
widget = tc->createConfigurationWidget().release();
if (widget) {
parentWidget->addWidget(widget);
if (tc->isAutoDetected())
widget->makeReadOnly();
QObject::connect(widget, &ToolChainConfigWidget::dirty,
[this] {
changed = true;
update();
});
}
}
QVariant data(int column, int role) const override QVariant data(int column, int role) const override
{ {
@@ -93,9 +81,30 @@ public:
return QVariant(); return QVariant();
} }
ToolChainConfigWidget *widget()
{
if (!m_widget) {
m_widget = toolChain->createConfigurationWidget().release();
if (m_widget) {
m_parentWidget->addWidget(m_widget);
if (toolChain->isAutoDetected())
m_widget->makeReadOnly();
QObject::connect(m_widget, &ToolChainConfigWidget::dirty,
[this] {
changed = true;
update();
});
}
}
return m_widget;
}
ToolChain *toolChain; ToolChain *toolChain;
ToolChainConfigWidget *widget;
bool changed; bool changed;
private:
ToolChainConfigWidget *m_widget = nullptr;
QStackedWidget *m_parentWidget = nullptr;
}; };
class DetectionSettingsDialog : public QDialog class DetectionSettingsDialog : public QDialog
@@ -423,7 +432,7 @@ void ToolChainOptionsWidget::toolChainSelectionChanged()
{ {
ToolChainTreeItem *item = currentTreeItem(); ToolChainTreeItem *item = currentTreeItem();
QWidget *currentTcWidget = item ? item->widget : nullptr; QWidget *currentTcWidget = item ? item->widget() : nullptr;
if (currentTcWidget) if (currentTcWidget)
m_widgetStack->setCurrentWidget(currentTcWidget); m_widgetStack->setCurrentWidget(currentTcWidget);
m_container->setVisible(currentTcWidget); m_container->setVisible(currentTcWidget);
@@ -447,8 +456,8 @@ void ToolChainOptionsWidget::apply()
for (TreeItem *item : *parent) { for (TreeItem *item : *parent) {
auto tcItem = static_cast<ToolChainTreeItem *>(item); auto tcItem = static_cast<ToolChainTreeItem *>(item);
Q_ASSERT(tcItem->toolChain); Q_ASSERT(tcItem->toolChain);
if (!tcItem->toolChain->isAutoDetected() && tcItem->widget && tcItem->changed) if (!tcItem->toolChain->isAutoDetected() && tcItem->widget() && tcItem->changed)
tcItem->widget->apply(); tcItem->widget()->apply();
tcItem->changed = false; tcItem->changed = false;
tcItem->update(); tcItem->update();
} }