2019-08-14 11:48:13 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2016 BlackBerry Limited. All rights reserved.
|
|
|
|
|
** Contact: BlackBerry (qt@blackberry.com)
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "mcusupportconstants.h"
|
|
|
|
|
#include "mcusupportoptionspage.h"
|
2019-10-22 14:33:31 +02:00
|
|
|
#include "mcusupportoptions.h"
|
2019-08-14 11:48:13 +02:00
|
|
|
|
2019-11-29 00:07:04 +01:00
|
|
|
#include <cmakeprojectmanager/cmakeprojectconstants.h>
|
|
|
|
|
#include <cmakeprojectmanager/cmaketoolmanager.h>
|
2019-08-14 11:48:13 +02:00
|
|
|
#include <coreplugin/icore.h>
|
2019-11-13 18:37:27 +01:00
|
|
|
#include <projectexplorer/kitmanager.h>
|
2019-08-14 11:48:13 +02:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
|
|
|
|
#include <utils/algorithm.h>
|
2019-12-11 21:17:53 +01:00
|
|
|
#include <utils/infolabel.h>
|
2019-08-14 11:48:13 +02:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
#include <utils/utilsicons.h>
|
|
|
|
|
|
|
|
|
|
#include <QComboBox>
|
|
|
|
|
#include <QDir>
|
2019-11-29 00:07:04 +01:00
|
|
|
#include <QHBoxLayout>
|
2019-08-14 11:48:13 +02:00
|
|
|
#include <QFormLayout>
|
|
|
|
|
#include <QGroupBox>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
|
|
namespace McuSupport {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2019-11-29 00:07:04 +01:00
|
|
|
static bool cMakeAvailable()
|
|
|
|
|
{
|
|
|
|
|
return !CMakeProjectManager::CMakeToolManager::cmakeTools().isEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-07 17:42:57 +01:00
|
|
|
class McuSupportOptionsWidget : public Core::IOptionsPageWidget
|
2019-08-14 11:48:13 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2020-01-07 17:42:57 +01:00
|
|
|
McuSupportOptionsWidget();
|
2019-08-14 11:48:13 +02:00
|
|
|
|
|
|
|
|
void updateStatus();
|
2019-11-15 08:38:55 +01:00
|
|
|
void showMcuTargetPackages();
|
|
|
|
|
McuTarget *currentMcuTarget() const;
|
2019-08-14 11:48:13 +02:00
|
|
|
|
|
|
|
|
private:
|
2020-01-07 17:42:57 +01:00
|
|
|
void apply() final;
|
|
|
|
|
|
|
|
|
|
void showEvent(QShowEvent *event) final;
|
|
|
|
|
|
2019-08-14 11:48:13 +02:00
|
|
|
QString m_armGccPath;
|
2020-01-07 17:42:57 +01:00
|
|
|
McuSupportOptions m_options;
|
2019-11-15 08:38:55 +01:00
|
|
|
QMap <McuPackage*, QWidget*> m_packageWidgets;
|
|
|
|
|
QMap <McuTarget*, QWidget*> m_mcuTargetPacketWidgets;
|
2019-08-14 11:48:13 +02:00
|
|
|
QFormLayout *m_packagesLayout = nullptr;
|
2019-12-11 21:17:53 +01:00
|
|
|
Utils::InfoLabel *m_infoLabel = nullptr;
|
2019-11-15 08:38:55 +01:00
|
|
|
QComboBox *m_mcuTargetComboBox = nullptr;
|
2019-08-14 11:48:13 +02:00
|
|
|
};
|
|
|
|
|
|
2020-01-07 17:42:57 +01:00
|
|
|
McuSupportOptionsWidget::McuSupportOptionsWidget()
|
2019-08-14 11:48:13 +02:00
|
|
|
{
|
|
|
|
|
auto mainLayout = new QVBoxLayout(this);
|
|
|
|
|
|
2019-11-15 08:38:55 +01:00
|
|
|
auto mcuTargetChooserlayout = new QHBoxLayout;
|
|
|
|
|
auto mcuTargetChooserLabel = new QLabel(McuSupportOptionsPage::tr("Target:"));
|
|
|
|
|
mcuTargetChooserlayout->addWidget(mcuTargetChooserLabel);
|
|
|
|
|
m_mcuTargetComboBox = new QComboBox;
|
|
|
|
|
mcuTargetChooserLabel->setBuddy(m_mcuTargetComboBox);
|
|
|
|
|
mcuTargetChooserLabel->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
|
|
|
|
|
m_mcuTargetComboBox->addItems(
|
2020-01-07 17:42:57 +01:00
|
|
|
Utils::transform<QStringList>(m_options.mcuTargets, [this](McuTarget *t){
|
|
|
|
|
return m_options.kitName(t);
|
2019-11-12 13:58:23 +01:00
|
|
|
}));
|
2019-11-15 08:38:55 +01:00
|
|
|
mcuTargetChooserlayout->addWidget(m_mcuTargetComboBox);
|
|
|
|
|
mainLayout->addLayout(mcuTargetChooserlayout);
|
2019-08-14 11:48:13 +02:00
|
|
|
|
|
|
|
|
auto m_packagesGroupBox = new QGroupBox(McuSupportOptionsPage::tr("Packages"));
|
|
|
|
|
mainLayout->addWidget(m_packagesGroupBox);
|
|
|
|
|
m_packagesLayout = new QFormLayout;
|
|
|
|
|
m_packagesGroupBox->setLayout(m_packagesLayout);
|
|
|
|
|
|
2019-12-11 21:17:53 +01:00
|
|
|
mainLayout->addStretch();
|
|
|
|
|
|
|
|
|
|
m_infoLabel = new Utils::InfoLabel;
|
|
|
|
|
m_infoLabel->setOpenExternalLinks(false);
|
|
|
|
|
m_infoLabel->setElideMode(Qt::ElideNone);
|
|
|
|
|
m_infoLabel->setWordWrap(true);
|
|
|
|
|
mainLayout->addWidget(m_infoLabel);
|
2019-08-14 11:48:13 +02:00
|
|
|
|
2020-01-07 17:42:57 +01:00
|
|
|
connect(&m_options, &McuSupportOptions::changed, this, &McuSupportOptionsWidget::updateStatus);
|
2019-11-15 08:38:55 +01:00
|
|
|
connect(m_mcuTargetComboBox, &QComboBox::currentTextChanged,
|
|
|
|
|
this, &McuSupportOptionsWidget::showMcuTargetPackages);
|
2019-12-11 21:17:53 +01:00
|
|
|
connect(m_infoLabel, &QLabel::linkActivated, this, []{
|
2019-11-29 00:07:04 +01:00
|
|
|
Core::ICore::showOptionsDialog(
|
|
|
|
|
CMakeProjectManager::Constants::CMAKE_SETTINGSPAGE_ID,
|
|
|
|
|
Core::ICore::mainWindow());
|
|
|
|
|
});
|
2019-08-14 11:48:13 +02:00
|
|
|
|
2019-11-15 08:38:55 +01:00
|
|
|
showMcuTargetPackages();
|
2019-08-14 11:48:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void McuSupportOptionsWidget::updateStatus()
|
|
|
|
|
{
|
2019-11-15 08:38:55 +01:00
|
|
|
const McuTarget *mcuTarget = currentMcuTarget();
|
|
|
|
|
if (!mcuTarget)
|
2019-11-13 18:37:27 +01:00
|
|
|
return;
|
|
|
|
|
|
2019-12-11 21:17:53 +01:00
|
|
|
m_infoLabel->setType(cMakeAvailable() && mcuTarget->isValid()
|
|
|
|
|
? Utils::InfoLabel::Ok : Utils::InfoLabel::NotOk);
|
2019-11-29 00:07:04 +01:00
|
|
|
|
|
|
|
|
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 "
|
|
|
|
|
"<a href=\"cmake\">CMake options</a> and press Apply.";
|
|
|
|
|
|
2019-12-11 21:17:53 +01:00
|
|
|
m_infoLabel->setText(errorStrings.isEmpty()
|
2019-11-13 18:37:27 +01:00
|
|
|
? QString::fromLatin1("A kit <b>%1</b> for the selected target can be generated. "
|
2020-01-07 17:42:57 +01:00
|
|
|
"Press Apply to generate it.").arg(m_options.kitName(
|
2019-11-15 08:38:55 +01:00
|
|
|
mcuTarget))
|
2019-11-29 00:07:04 +01:00
|
|
|
: errorStrings.join("<br/>"));
|
2019-08-14 11:48:13 +02:00
|
|
|
}
|
|
|
|
|
|
2019-11-15 08:38:55 +01:00
|
|
|
void McuSupportOptionsWidget::showMcuTargetPackages()
|
2019-08-14 11:48:13 +02:00
|
|
|
{
|
2019-11-15 08:38:55 +01:00
|
|
|
const McuTarget *mcuTarget = currentMcuTarget();
|
|
|
|
|
if (!mcuTarget)
|
2019-11-13 18:37:27 +01:00
|
|
|
return;
|
|
|
|
|
|
2019-08-14 11:48:13 +02:00
|
|
|
while (m_packagesLayout->rowCount() > 0) {
|
|
|
|
|
QFormLayout::TakeRowResult row = m_packagesLayout->takeRow(0);
|
|
|
|
|
row.labelItem->widget()->hide();
|
|
|
|
|
row.fieldItem->widget()->hide();
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-07 17:42:57 +01:00
|
|
|
for (auto package : m_options.packages) {
|
2019-08-14 11:48:13 +02:00
|
|
|
QWidget *packageWidget = package->widget();
|
2019-11-15 08:38:55 +01:00
|
|
|
if (!mcuTarget->packages().contains(package))
|
2019-08-14 11:48:13 +02:00
|
|
|
continue;
|
|
|
|
|
m_packagesLayout->addRow(package->label(), packageWidget);
|
|
|
|
|
packageWidget->show();
|
|
|
|
|
}
|
2019-11-13 18:37:27 +01:00
|
|
|
|
|
|
|
|
updateStatus();
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-15 08:38:55 +01:00
|
|
|
McuTarget *McuSupportOptionsWidget::currentMcuTarget() const
|
2019-11-13 18:37:27 +01:00
|
|
|
{
|
2019-11-15 08:38:55 +01:00
|
|
|
const int mcuTargetIndex = m_mcuTargetComboBox->currentIndex();
|
2020-01-07 17:42:57 +01:00
|
|
|
return m_options.mcuTargets.isEmpty() ? nullptr : m_options.mcuTargets.at(mcuTargetIndex);
|
2019-08-14 11:48:13 +02:00
|
|
|
}
|
|
|
|
|
|
2019-11-29 00:07:04 +01:00
|
|
|
void McuSupportOptionsWidget::showEvent(QShowEvent *event)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(event)
|
|
|
|
|
updateStatus();
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-07 17:42:57 +01:00
|
|
|
void McuSupportOptionsWidget::apply()
|
2019-08-14 11:48:13 +02:00
|
|
|
{
|
2020-01-07 17:42:57 +01:00
|
|
|
for (auto package : m_options.packages)
|
2019-08-14 11:48:13 +02:00
|
|
|
package->writeToSettings();
|
|
|
|
|
|
2020-01-07 17:42:57 +01:00
|
|
|
QTC_ASSERT(m_options.armGccPackage, return);
|
|
|
|
|
QTC_ASSERT(m_options.qtForMCUsSdkPackage, return);
|
2019-08-14 11:48:13 +02:00
|
|
|
|
2020-01-07 17:42:57 +01:00
|
|
|
if (!isVisible() || !cMakeAvailable())
|
2019-11-29 00:07:04 +01:00
|
|
|
return;
|
2019-11-19 17:27:32 +01:00
|
|
|
|
2020-01-07 17:42:57 +01:00
|
|
|
const McuTarget *mcuTarget = currentMcuTarget();
|
2019-11-15 08:38:55 +01:00
|
|
|
if (!mcuTarget)
|
2019-11-13 18:37:27 +01:00
|
|
|
return;
|
2019-08-14 11:48:13 +02:00
|
|
|
|
2020-01-07 17:42:57 +01:00
|
|
|
for (auto existingKit : m_options.existingKits(mcuTarget))
|
2019-11-13 18:37:27 +01:00
|
|
|
ProjectExplorer::KitManager::deregisterKit(existingKit);
|
2020-01-07 17:42:57 +01:00
|
|
|
m_options.newKit(mcuTarget);
|
2019-08-14 11:48:13 +02:00
|
|
|
}
|
|
|
|
|
|
2020-01-07 17:42:57 +01:00
|
|
|
McuSupportOptionsPage::McuSupportOptionsPage()
|
2019-08-14 11:48:13 +02:00
|
|
|
{
|
2020-01-07 17:42:57 +01:00
|
|
|
setId(Core::Id(Constants::SETTINGS_ID));
|
|
|
|
|
setDisplayName(tr("MCU"));
|
|
|
|
|
setCategory(ProjectExplorer::Constants::DEVICE_SETTINGS_CATEGORY);
|
|
|
|
|
setWidgetCreator([] { return new McuSupportOptionsWidget; });
|
2019-08-14 11:48:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // Internal
|
|
|
|
|
} // McuSupport
|