diff options
author | Alessandro Portale <alessandro.portale@qt.io> | 2020-04-23 23:30:40 +0200 |
---|---|---|
committer | Alessandro Portale <alessandro.portale@qt.io> | 2020-05-11 14:45:47 +0000 |
commit | ed9918a41c1fd223eac85705d1f77a832fe1f70e (patch) | |
tree | 97265c6240a10101da14ddfa46cd02a13971bbba | |
parent | d88d27e7cc12a7ab1df44df5a0588909aea2b88b (diff) |
McuSupport: Let user explicitly create or remove MCU target kits
So far, the user had to press "Apply" to generate a kit for the
currently selected target. The kit got silently added, there was no
immediate UI feedback that something happened.
Also, there was no possibility to remove a specific Qt for MCUs kit once
it was added, becoause it is under the "Auto-dected" kit category.
This change modifies the UI interaction so, that there is a specific
"Create Kit" button, and in case that the kit already exists, there is a
"Remove Kit" button.
Task-number: QTCREATORBUG-23929
Change-Id: I334ed75f86905ac762e0293bd3aa70b3433acf28
Reviewed-by: hjk <hjk@qt.io>
-rw-r--r-- | src/plugins/mcusupport/mcusupportoptionspage.cpp | 64 |
1 files changed, 38 insertions, 26 deletions
diff --git a/src/plugins/mcusupport/mcusupportoptionspage.cpp b/src/plugins/mcusupport/mcusupportoptionspage.cpp index b06a97f174..56db70972a 100644 --- a/src/plugins/mcusupport/mcusupportoptionspage.cpp +++ b/src/plugins/mcusupport/mcusupportoptionspage.cpp @@ -43,6 +43,7 @@ #include <QFormLayout> #include <QGroupBox> #include <QLabel> +#include <QPushButton> #include <QVBoxLayout> namespace McuSupport { @@ -77,6 +78,8 @@ private: QGroupBox *m_kitCreationGroupBox = nullptr; Utils::InfoLabel *m_kitCreationInfoLabel = nullptr; Utils::InfoLabel *m_statusInfoLabel = nullptr; + QPushButton *m_kitCreationPushButton = nullptr; + QPushButton *m_kitRemovalPushButton = nullptr; }; McuSupportOptionsWidget::McuSupportOptionsWidget() @@ -130,10 +133,24 @@ McuSupportOptionsWidget::McuSupportOptionsWidget() 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); + auto vLayout = new QHBoxLayout(m_kitCreationGroupBox); + vLayout->addWidget(m_kitCreationInfoLabel); + m_kitCreationPushButton = new QPushButton(tr("Create Kit")); + m_kitCreationPushButton->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); + connect(m_kitCreationPushButton, &QPushButton::clicked, this, [this] { + McuSupportOptions::newKit(currentMcuTarget(), m_options.qtForMCUsSdkPackage); + McuSupportOptions::registerQchFiles(); + updateStatus(); + }); + m_kitRemovalPushButton = new QPushButton(tr("Remove Kit")); + m_kitRemovalPushButton->setSizePolicy(m_kitCreationPushButton->sizePolicy()); + connect(m_kitRemovalPushButton, &QPushButton::clicked, this, [this] { + for (auto existingKit : McuSupportOptions::existingKits(currentMcuTarget())) + ProjectExplorer::KitManager::deregisterKit(existingKit); + updateStatus(); + }); + vLayout->addWidget(m_kitCreationPushButton); + vLayout->addWidget(m_kitRemovalPushButton); } mainLayout->addStretch(); @@ -162,15 +179,23 @@ void McuSupportOptionsWidget::updateStatus() // Kit creation status if (mcuTarget) { const bool mcuTargetValid = mcuTarget->isValid(); - m_kitCreationInfoLabel->setType(mcuTargetValid ? Utils::InfoLabel::Ok - : Utils::InfoLabel::NotOk); - m_kitCreationInfoLabel->setText( - mcuTargetValid ? QString::fromLatin1( - "A kit <b>%1</b> for the selected target can be " - "generated. Press Apply to generate it.") - .arg(McuSupportOptions::kitName(mcuTarget)) - : "Provide the package paths in order to create a kit " - "for your target."); + m_kitCreationPushButton->setVisible(mcuTargetValid); + m_kitRemovalPushButton->setVisible(mcuTargetValid); + if (mcuTargetValid) { + const bool mcuTargetKitExists = !McuSupportOptions::existingKits(mcuTarget).isEmpty(); + m_kitCreationInfoLabel->setType(mcuTargetKitExists + ? Utils::InfoLabel::Information + : Utils::InfoLabel::Ok); + m_kitCreationInfoLabel->setText(mcuTargetKitExists + ? tr("A kit for the selected target exists.") + : tr("A kit for the selected target can be created.")); + m_kitCreationPushButton->setEnabled(!mcuTargetKitExists); + m_kitRemovalPushButton->setEnabled(mcuTargetKitExists); + } else { + m_kitCreationInfoLabel->setType(Utils::InfoLabel::NotOk); + m_kitCreationInfoLabel->setText("Provide the package paths in order to create a kit " + "for your target."); + } } // Status label in the bottom @@ -226,19 +251,6 @@ void McuSupportOptionsWidget::apply() m_options.qtForMCUsSdkPackage->writeToSettings(); for (auto package : m_options.packages) package->writeToSettings(); - - if (!isVisible()) - return; - - McuSupportOptions::registerQchFiles(); - - const McuTarget *mcuTarget = currentMcuTarget(); - if (!mcuTarget) - return; - - for (auto existingKit : McuSupportOptions::existingKits(mcuTarget)) - ProjectExplorer::KitManager::deregisterKit(existingKit); - McuSupportOptions::newKit(mcuTarget, m_options.qtForMCUsSdkPackage); } void McuSupportOptionsWidget::populateMcuTargetsComboBox() |