forked from qt-creator/qt-creator
McuSupport: Use new settings page convenience
Change-Id: Id0c525a32b1c8b9e0d8d04da7bcd37c4f1958508 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -53,21 +53,23 @@ static bool cMakeAvailable()
|
|||||||
return !CMakeProjectManager::CMakeToolManager::cmakeTools().isEmpty();
|
return !CMakeProjectManager::CMakeToolManager::cmakeTools().isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
class McuSupportOptionsWidget : public QWidget
|
class McuSupportOptionsWidget : public Core::IOptionsPageWidget
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
McuSupportOptionsWidget(const McuSupportOptions *options, QWidget *parent = nullptr);
|
McuSupportOptionsWidget();
|
||||||
|
|
||||||
void updateStatus();
|
void updateStatus();
|
||||||
void showMcuTargetPackages();
|
void showMcuTargetPackages();
|
||||||
McuTarget *currentMcuTarget() const;
|
McuTarget *currentMcuTarget() const;
|
||||||
|
|
||||||
protected:
|
|
||||||
void showEvent(QShowEvent *event) override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void apply() final;
|
||||||
|
void finish() final {}
|
||||||
|
|
||||||
|
void showEvent(QShowEvent *event) final;
|
||||||
|
|
||||||
QString m_armGccPath;
|
QString m_armGccPath;
|
||||||
const McuSupportOptions *m_options;
|
McuSupportOptions m_options;
|
||||||
QMap <McuPackage*, QWidget*> m_packageWidgets;
|
QMap <McuPackage*, QWidget*> m_packageWidgets;
|
||||||
QMap <McuTarget*, QWidget*> m_mcuTargetPacketWidgets;
|
QMap <McuTarget*, QWidget*> m_mcuTargetPacketWidgets;
|
||||||
QFormLayout *m_packagesLayout = nullptr;
|
QFormLayout *m_packagesLayout = nullptr;
|
||||||
@@ -75,9 +77,7 @@ private:
|
|||||||
QComboBox *m_mcuTargetComboBox = nullptr;
|
QComboBox *m_mcuTargetComboBox = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
McuSupportOptionsWidget::McuSupportOptionsWidget(const McuSupportOptions *options, QWidget *parent)
|
McuSupportOptionsWidget::McuSupportOptionsWidget()
|
||||||
: QWidget(parent)
|
|
||||||
, m_options(options)
|
|
||||||
{
|
{
|
||||||
auto mainLayout = new QVBoxLayout(this);
|
auto mainLayout = new QVBoxLayout(this);
|
||||||
|
|
||||||
@@ -88,8 +88,8 @@ McuSupportOptionsWidget::McuSupportOptionsWidget(const McuSupportOptions *option
|
|||||||
mcuTargetChooserLabel->setBuddy(m_mcuTargetComboBox);
|
mcuTargetChooserLabel->setBuddy(m_mcuTargetComboBox);
|
||||||
mcuTargetChooserLabel->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
|
mcuTargetChooserLabel->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
|
||||||
m_mcuTargetComboBox->addItems(
|
m_mcuTargetComboBox->addItems(
|
||||||
Utils::transform<QStringList>(m_options->mcuTargets, [this](McuTarget *t){
|
Utils::transform<QStringList>(m_options.mcuTargets, [this](McuTarget *t){
|
||||||
return m_options->kitName(t);
|
return m_options.kitName(t);
|
||||||
}));
|
}));
|
||||||
mcuTargetChooserlayout->addWidget(m_mcuTargetComboBox);
|
mcuTargetChooserlayout->addWidget(m_mcuTargetComboBox);
|
||||||
mainLayout->addLayout(mcuTargetChooserlayout);
|
mainLayout->addLayout(mcuTargetChooserlayout);
|
||||||
@@ -107,7 +107,7 @@ McuSupportOptionsWidget::McuSupportOptionsWidget(const McuSupportOptions *option
|
|||||||
m_infoLabel->setWordWrap(true);
|
m_infoLabel->setWordWrap(true);
|
||||||
mainLayout->addWidget(m_infoLabel);
|
mainLayout->addWidget(m_infoLabel);
|
||||||
|
|
||||||
connect(options, &McuSupportOptions::changed, this, &McuSupportOptionsWidget::updateStatus);
|
connect(&m_options, &McuSupportOptions::changed, this, &McuSupportOptionsWidget::updateStatus);
|
||||||
connect(m_mcuTargetComboBox, &QComboBox::currentTextChanged,
|
connect(m_mcuTargetComboBox, &QComboBox::currentTextChanged,
|
||||||
this, &McuSupportOptionsWidget::showMcuTargetPackages);
|
this, &McuSupportOptionsWidget::showMcuTargetPackages);
|
||||||
connect(m_infoLabel, &QLabel::linkActivated, this, []{
|
connect(m_infoLabel, &QLabel::linkActivated, this, []{
|
||||||
@@ -137,7 +137,7 @@ void McuSupportOptionsWidget::updateStatus()
|
|||||||
|
|
||||||
m_infoLabel->setText(errorStrings.isEmpty()
|
m_infoLabel->setText(errorStrings.isEmpty()
|
||||||
? QString::fromLatin1("A kit <b>%1</b> for the selected target can be generated. "
|
? QString::fromLatin1("A kit <b>%1</b> for the selected target can be generated. "
|
||||||
"Press Apply to generate it.").arg(m_options->kitName(
|
"Press Apply to generate it.").arg(m_options.kitName(
|
||||||
mcuTarget))
|
mcuTarget))
|
||||||
: errorStrings.join("<br/>"));
|
: errorStrings.join("<br/>"));
|
||||||
}
|
}
|
||||||
@@ -154,7 +154,7 @@ void McuSupportOptionsWidget::showMcuTargetPackages()
|
|||||||
row.fieldItem->widget()->hide();
|
row.fieldItem->widget()->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto package : m_options->packages) {
|
for (auto package : m_options.packages) {
|
||||||
QWidget *packageWidget = package->widget();
|
QWidget *packageWidget = package->widget();
|
||||||
if (!mcuTarget->packages().contains(package))
|
if (!mcuTarget->packages().contains(package))
|
||||||
continue;
|
continue;
|
||||||
@@ -168,7 +168,7 @@ void McuSupportOptionsWidget::showMcuTargetPackages()
|
|||||||
McuTarget *McuSupportOptionsWidget::currentMcuTarget() const
|
McuTarget *McuSupportOptionsWidget::currentMcuTarget() const
|
||||||
{
|
{
|
||||||
const int mcuTargetIndex = m_mcuTargetComboBox->currentIndex();
|
const int mcuTargetIndex = m_mcuTargetComboBox->currentIndex();
|
||||||
return m_options->mcuTargets.isEmpty() ? nullptr : m_options->mcuTargets.at(mcuTargetIndex);
|
return m_options.mcuTargets.isEmpty() ? nullptr : m_options.mcuTargets.at(mcuTargetIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void McuSupportOptionsWidget::showEvent(QShowEvent *event)
|
void McuSupportOptionsWidget::showEvent(QShowEvent *event)
|
||||||
@@ -177,50 +177,32 @@ void McuSupportOptionsWidget::showEvent(QShowEvent *event)
|
|||||||
updateStatus();
|
updateStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
McuSupportOptionsPage::McuSupportOptionsPage(QObject* parent)
|
void McuSupportOptionsWidget::apply()
|
||||||
: Core::IOptionsPage(parent)
|
{
|
||||||
|
for (auto package : m_options.packages)
|
||||||
|
package->writeToSettings();
|
||||||
|
|
||||||
|
QTC_ASSERT(m_options.armGccPackage, return);
|
||||||
|
QTC_ASSERT(m_options.qtForMCUsSdkPackage, return);
|
||||||
|
|
||||||
|
if (!isVisible() || !cMakeAvailable())
|
||||||
|
return;
|
||||||
|
|
||||||
|
const McuTarget *mcuTarget = currentMcuTarget();
|
||||||
|
if (!mcuTarget)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (auto existingKit : m_options.existingKits(mcuTarget))
|
||||||
|
ProjectExplorer::KitManager::deregisterKit(existingKit);
|
||||||
|
m_options.newKit(mcuTarget);
|
||||||
|
}
|
||||||
|
|
||||||
|
McuSupportOptionsPage::McuSupportOptionsPage()
|
||||||
{
|
{
|
||||||
setId(Core::Id(Constants::SETTINGS_ID));
|
setId(Core::Id(Constants::SETTINGS_ID));
|
||||||
setDisplayName(tr("MCU"));
|
setDisplayName(tr("MCU"));
|
||||||
setCategory(ProjectExplorer::Constants::DEVICE_SETTINGS_CATEGORY);
|
setCategory(ProjectExplorer::Constants::DEVICE_SETTINGS_CATEGORY);
|
||||||
}
|
setWidgetCreator([] { return new McuSupportOptionsWidget; });
|
||||||
|
|
||||||
QWidget *McuSupportOptionsPage::widget()
|
|
||||||
{
|
|
||||||
if (!m_options)
|
|
||||||
m_options = new McuSupportOptions(this);
|
|
||||||
if (!m_widget)
|
|
||||||
m_widget = new McuSupportOptionsWidget(m_options);
|
|
||||||
return m_widget;
|
|
||||||
}
|
|
||||||
|
|
||||||
void McuSupportOptionsPage::apply()
|
|
||||||
{
|
|
||||||
for (auto package : m_options->packages)
|
|
||||||
package->writeToSettings();
|
|
||||||
|
|
||||||
QTC_ASSERT(m_options->armGccPackage, return);
|
|
||||||
QTC_ASSERT(m_options->qtForMCUsSdkPackage, return);
|
|
||||||
|
|
||||||
if (!widget()->isVisible() || !cMakeAvailable())
|
|
||||||
return;
|
|
||||||
|
|
||||||
const McuTarget *mcuTarget = m_widget->currentMcuTarget();
|
|
||||||
if (!mcuTarget)
|
|
||||||
return;
|
|
||||||
|
|
||||||
using namespace ProjectExplorer;
|
|
||||||
|
|
||||||
for (auto existingKit : m_options->existingKits(mcuTarget))
|
|
||||||
ProjectExplorer::KitManager::deregisterKit(existingKit);
|
|
||||||
m_options->newKit(mcuTarget);
|
|
||||||
}
|
|
||||||
|
|
||||||
void McuSupportOptionsPage::finish()
|
|
||||||
{
|
|
||||||
delete m_options;
|
|
||||||
m_options = nullptr;
|
|
||||||
delete m_widget;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // Internal
|
} // Internal
|
||||||
|
@@ -27,8 +27,6 @@
|
|||||||
|
|
||||||
#include <coreplugin/dialogs/ioptionspage.h>
|
#include <coreplugin/dialogs/ioptionspage.h>
|
||||||
|
|
||||||
#include <QPointer>
|
|
||||||
|
|
||||||
namespace McuSupport {
|
namespace McuSupport {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -37,14 +35,7 @@ class McuSupportOptionsPage : public Core::IOptionsPage
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit McuSupportOptionsPage(QObject *parent = nullptr);
|
McuSupportOptionsPage();
|
||||||
QWidget *widget() override;
|
|
||||||
void apply() override;
|
|
||||||
void finish() override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
QPointer<class McuSupportOptionsWidget> m_widget;
|
|
||||||
class McuSupportOptions *m_options = nullptr;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
Reference in New Issue
Block a user