diff --git a/src/plugins/mcusupport/mcusupportoptionspage.cpp b/src/plugins/mcusupport/mcusupportoptionspage.cpp index 18356fec399..a991af60ece 100644 --- a/src/plugins/mcusupport/mcusupportoptionspage.cpp +++ b/src/plugins/mcusupport/mcusupportoptionspage.cpp @@ -48,11 +48,6 @@ namespace McuSupport { namespace Internal { -static bool cMakeAvailable() -{ - return !CMakeProjectManager::CMakeToolManager::cmakeTools().isEmpty(); -} - class McuSupportOptionsWidget : public Core::IOptionsPageWidget { Q_DECLARE_TR_FUNCTIONS(McuSupport::Internal::McuSupportOptionsWidget) @@ -80,56 +75,71 @@ private: QComboBox *m_mcuTargetsComboBox = nullptr; QGroupBox *m_kitCreationGroupBox = nullptr; Utils::InfoLabel *m_kitCreationInfoLabel = nullptr; + Utils::InfoLabel *m_statusInfoLabel = nullptr; }; McuSupportOptionsWidget::McuSupportOptionsWidget() { auto mainLayout = new QVBoxLayout(this); - m_qtForMCUsSdkGroupBox = new QGroupBox(m_options.qtForMCUsSdkPackage->label()); - m_qtForMCUsSdkGroupBox->setFlat(true); - auto qtForMCUsSdkGroupBoxLayout = new QVBoxLayout(m_qtForMCUsSdkGroupBox); - qtForMCUsSdkGroupBoxLayout->addWidget(m_options.qtForMCUsSdkPackage->widget()); - mainLayout->addWidget(m_qtForMCUsSdkGroupBox); + { + m_statusInfoLabel = new Utils::InfoLabel; + m_statusInfoLabel->setElideMode(Qt::ElideNone); + m_statusInfoLabel->setOpenExternalLinks(false); + mainLayout->addWidget(m_statusInfoLabel); + connect(m_statusInfoLabel, &QLabel::linkActivated, this, []{ + Core::ICore::showOptionsDialog( + CMakeProjectManager::Constants::CMAKE_SETTINGSPAGE_ID, + Core::ICore::mainWindow()); + }); + } - m_mcuTargetsGroupBox = new QGroupBox(tr("Targets supported by the %1") - .arg(m_qtForMCUsSdkGroupBox->title())); - m_mcuTargetsGroupBox->setFlat(true); - mainLayout->addWidget(m_mcuTargetsGroupBox); - auto qtForMCUsTargetsGroupBoxLayout = new QVBoxLayout(m_mcuTargetsGroupBox); - m_mcuTargetsComboBox = new QComboBox; - m_mcuTargetsComboBox->addItems( - Utils::transform(m_options.mcuTargets, [this](McuTarget *t){ - return m_options.kitName(t); - })); - qtForMCUsTargetsGroupBoxLayout->addWidget(m_mcuTargetsComboBox); + { + m_qtForMCUsSdkGroupBox = new QGroupBox(m_options.qtForMCUsSdkPackage->label()); + m_qtForMCUsSdkGroupBox->setFlat(true); + auto layout = new QVBoxLayout(m_qtForMCUsSdkGroupBox); + layout->addWidget(m_options.qtForMCUsSdkPackage->widget()); + mainLayout->addWidget(m_qtForMCUsSdkGroupBox); + } - m_packagesGroupBox = new QGroupBox(tr("Requirements")); - m_packagesGroupBox->setFlat(true); - mainLayout->addWidget(m_packagesGroupBox); - m_packagesLayout = new QFormLayout; - m_packagesGroupBox->setLayout(m_packagesLayout); + { + m_mcuTargetsGroupBox = new QGroupBox(tr("Targets supported by the %1") + .arg(m_qtForMCUsSdkGroupBox->title())); + m_mcuTargetsGroupBox->setFlat(true); + mainLayout->addWidget(m_mcuTargetsGroupBox); + m_mcuTargetsComboBox = new QComboBox; + m_mcuTargetsComboBox->addItems( + Utils::transform(m_options.mcuTargets, [this](McuTarget *t){ + return m_options.kitName(t); + })); + auto layout = new QVBoxLayout(m_mcuTargetsGroupBox); + layout->addWidget(m_mcuTargetsComboBox); + connect(m_mcuTargetsComboBox, &QComboBox::currentTextChanged, + this, &McuSupportOptionsWidget::showMcuTargetPackages); + } - m_kitCreationGroupBox = new QGroupBox(tr("Create a Kit")); - m_kitCreationGroupBox->setFlat(true); - mainLayout->addWidget(m_kitCreationGroupBox); - auto kitCreationGroupBoxLayout = new QVBoxLayout(m_kitCreationGroupBox); - m_kitCreationInfoLabel = new Utils::InfoLabel; - m_kitCreationInfoLabel->setOpenExternalLinks(false); - m_kitCreationInfoLabel->setElideMode(Qt::ElideNone); - m_kitCreationInfoLabel->setWordWrap(true); - kitCreationGroupBoxLayout->addWidget(m_kitCreationInfoLabel); + { + m_packagesGroupBox = new QGroupBox(tr("Requirements")); + m_packagesGroupBox->setFlat(true); + mainLayout->addWidget(m_packagesGroupBox); + m_packagesLayout = new QFormLayout; + m_packagesGroupBox->setLayout(m_packagesLayout); + } + + { + m_kitCreationGroupBox = new QGroupBox(tr("Create a Kit")); + m_kitCreationGroupBox->setFlat(true); + mainLayout->addWidget(m_kitCreationGroupBox); + m_kitCreationInfoLabel = new Utils::InfoLabel; + m_kitCreationInfoLabel->setElideMode(Qt::ElideNone); + m_kitCreationInfoLabel->setWordWrap(true); + auto layout = new QVBoxLayout(m_kitCreationGroupBox); + layout->addWidget(m_kitCreationInfoLabel); + } mainLayout->addStretch(); connect(&m_options, &McuSupportOptions::changed, this, &McuSupportOptionsWidget::updateStatus); - connect(m_mcuTargetsComboBox, &QComboBox::currentTextChanged, - this, &McuSupportOptionsWidget::showMcuTargetPackages); - connect(m_kitCreationInfoLabel, &QLabel::linkActivated, this, []{ - Core::ICore::showOptionsDialog( - CMakeProjectManager::Constants::CMAKE_SETTINGSPAGE_ID, - Core::ICore::mainWindow()); - }); showMcuTargetPackages(); } @@ -140,27 +150,41 @@ void McuSupportOptionsWidget::updateStatus() if (!mcuTarget) return; - m_kitCreationInfoLabel->setType(cMakeAvailable() && mcuTarget->isValid() - ? Utils::InfoLabel::Ok : Utils::InfoLabel::NotOk); + const bool cMakeAvailable = !CMakeProjectManager::CMakeToolManager::cmakeTools().isEmpty(); - const bool sdkValid = m_options.qtForMCUsSdkPackage->status() == McuPackage::ValidPackage; - m_mcuTargetsGroupBox->setVisible(sdkValid); - m_packagesGroupBox->setVisible(sdkValid && !mcuTarget->packages().isEmpty()); - m_kitCreationGroupBox->setVisible(sdkValid); + // Page elements + { + m_qtForMCUsSdkGroupBox->setVisible(cMakeAvailable); + const bool ready = cMakeAvailable && + m_options.qtForMCUsSdkPackage->status() == McuPackage::ValidPackage; + m_mcuTargetsGroupBox->setVisible(ready); + m_packagesGroupBox->setVisible(ready && !mcuTarget->packages().isEmpty()); + m_kitCreationGroupBox->setVisible(ready); + } - QStringList errorStrings; - if (!mcuTarget->isValid()) - errorStrings << "Provide the package paths in order to create a kit for your target."; - if (!cMakeAvailable()) - errorStrings << "No CMake tool was detected. Add a CMake tool in the " - "CMake options and press Apply."; + // Kit creation status + { + const bool mcuTargetValid = mcuTarget->isValid(); + m_kitCreationInfoLabel->setType(mcuTargetValid ? Utils::InfoLabel::Ok + : Utils::InfoLabel::NotOk); + m_kitCreationInfoLabel->setText( + mcuTargetValid ? QString::fromLatin1( + "A kit %1 for the selected target can be " + "generated. Press Apply to generate it.") + .arg(m_options.kitName(mcuTarget)) + : "Provide the package paths in order to create a kit " + "for your target."); + } - m_kitCreationInfoLabel->setText( - errorStrings.isEmpty() - ? QString::fromLatin1("A kit %1 for the selected target can be generated. " - "Press Apply to generate it.").arg(m_options.kitName( - mcuTarget)) - : errorStrings.join("
")); + // Status label in the bottom + { + m_statusInfoLabel->setVisible(!cMakeAvailable); + if (m_statusInfoLabel->isVisible()) { + m_statusInfoLabel->setType(Utils::InfoLabel::NotOk); + m_statusInfoLabel->setText("No CMake tool was detected. Add a CMake tool in the " + "CMake options and press Apply."); + } + } } void McuSupportOptionsWidget::showMcuTargetPackages() @@ -205,7 +229,7 @@ void McuSupportOptionsWidget::apply() QTC_ASSERT(m_options.qtForMCUsSdkPackage, return); - if (!isVisible() || !cMakeAvailable()) + if (!isVisible()) return; const McuTarget *mcuTarget = currentMcuTarget();