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
|
|
|
|
|
|
|
|
#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>
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
#include <utils/utilsicons.h>
|
|
|
|
|
|
|
|
|
|
#include <QComboBox>
|
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QFormLayout>
|
|
|
|
|
#include <QGroupBox>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
|
|
namespace McuSupport {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
class McuSupportOptionsWidget : public QWidget
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
McuSupportOptionsWidget(const McuSupportOptions *options, QWidget *parent = nullptr);
|
|
|
|
|
|
|
|
|
|
void updateStatus();
|
2019-11-13 18:37:27 +01:00
|
|
|
void showBoardPackages();
|
|
|
|
|
BoardOptions *currentBoard() const;
|
2019-08-14 11:48:13 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QString m_armGccPath;
|
|
|
|
|
const McuSupportOptions *m_options;
|
|
|
|
|
QMap <PackageOptions*, QWidget*> m_packageWidgets;
|
|
|
|
|
QMap <BoardOptions*, QWidget*> m_boardPacketWidgets;
|
|
|
|
|
QFormLayout *m_packagesLayout = nullptr;
|
|
|
|
|
QLabel *m_statusLabel = nullptr;
|
2019-11-13 18:37:27 +01:00
|
|
|
QComboBox *m_boardComboBox = nullptr;
|
2019-08-14 11:48:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
McuSupportOptionsWidget::McuSupportOptionsWidget(const McuSupportOptions *options, QWidget *parent)
|
|
|
|
|
: QWidget(parent)
|
|
|
|
|
, m_options(options)
|
|
|
|
|
{
|
|
|
|
|
auto mainLayout = new QVBoxLayout(this);
|
|
|
|
|
|
|
|
|
|
auto boardChooserlayout = new QHBoxLayout;
|
2019-10-30 19:05:41 +01:00
|
|
|
auto boardChooserLabel = new QLabel(McuSupportOptionsPage::tr("Target:"));
|
2019-08-14 11:48:13 +02:00
|
|
|
boardChooserlayout->addWidget(boardChooserLabel);
|
2019-11-13 18:37:27 +01:00
|
|
|
m_boardComboBox = new QComboBox;
|
|
|
|
|
boardChooserLabel->setBuddy(m_boardComboBox);
|
2019-08-14 11:48:13 +02:00
|
|
|
boardChooserLabel->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
|
2019-11-13 18:37:27 +01:00
|
|
|
m_boardComboBox->addItems(
|
2019-11-12 13:58:23 +01:00
|
|
|
Utils::transform<QStringList>(m_options->boards, [this](BoardOptions *b){
|
|
|
|
|
return m_options->kitName(b);
|
|
|
|
|
}));
|
2019-11-13 18:37:27 +01:00
|
|
|
boardChooserlayout->addWidget(m_boardComboBox);
|
2019-08-14 11:48:13 +02:00
|
|
|
mainLayout->addLayout(boardChooserlayout);
|
|
|
|
|
|
|
|
|
|
auto m_packagesGroupBox = new QGroupBox(McuSupportOptionsPage::tr("Packages"));
|
|
|
|
|
mainLayout->addWidget(m_packagesGroupBox);
|
|
|
|
|
m_packagesLayout = new QFormLayout;
|
|
|
|
|
m_packagesGroupBox->setLayout(m_packagesLayout);
|
|
|
|
|
|
|
|
|
|
m_statusLabel = new QLabel;
|
2019-11-13 18:37:27 +01:00
|
|
|
mainLayout->addWidget(m_statusLabel, 2);
|
2019-08-14 11:48:13 +02:00
|
|
|
m_statusLabel->setWordWrap(true);
|
2019-11-13 18:37:27 +01:00
|
|
|
m_statusLabel->setAlignment(Qt::AlignBottom | Qt::AlignLeft);
|
2019-08-14 11:48:13 +02:00
|
|
|
|
|
|
|
|
connect(options, &McuSupportOptions::changed, this, &McuSupportOptionsWidget::updateStatus);
|
2019-11-13 18:37:27 +01:00
|
|
|
connect(m_boardComboBox, &QComboBox::currentTextChanged,
|
2019-08-14 11:48:13 +02:00
|
|
|
this, &McuSupportOptionsWidget::showBoardPackages);
|
|
|
|
|
|
2019-11-13 18:37:27 +01:00
|
|
|
showBoardPackages();
|
|
|
|
|
updateStatus();
|
2019-08-14 11:48:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void McuSupportOptionsWidget::updateStatus()
|
|
|
|
|
{
|
2019-11-13 18:37:27 +01:00
|
|
|
const BoardOptions *board = currentBoard();
|
|
|
|
|
if (!board)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
m_statusLabel->setText(board->isValid()
|
|
|
|
|
? QString::fromLatin1("A kit <b>%1</b> for the selected target can be generated. "
|
|
|
|
|
"Press Apply to generate it.").arg(m_options->kitName(board))
|
|
|
|
|
: QString::fromLatin1("Provide the package paths in order to create a kit for "
|
|
|
|
|
"your target."));
|
2019-08-14 11:48:13 +02:00
|
|
|
}
|
|
|
|
|
|
2019-11-13 18:37:27 +01:00
|
|
|
void McuSupportOptionsWidget::showBoardPackages()
|
2019-08-14 11:48:13 +02:00
|
|
|
{
|
2019-11-13 18:37:27 +01:00
|
|
|
const BoardOptions *board = currentBoard();
|
|
|
|
|
if (!board)
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (auto package : m_options->packages) {
|
|
|
|
|
QWidget *packageWidget = package->widget();
|
2019-11-13 18:37:27 +01:00
|
|
|
if (!board->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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BoardOptions *McuSupportOptionsWidget::currentBoard() const
|
|
|
|
|
{
|
|
|
|
|
const int boardIndex = m_boardComboBox->currentIndex();
|
|
|
|
|
return m_options->boards.isEmpty() ? nullptr : m_options->boards.at(boardIndex);
|
2019-08-14 11:48:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
McuSupportOptionsPage::McuSupportOptionsPage(QObject* parent)
|
|
|
|
|
: Core::IOptionsPage(parent)
|
|
|
|
|
{
|
|
|
|
|
setId(Core::Id(Constants::SETTINGS_ID));
|
|
|
|
|
setDisplayName(tr("MCU"));
|
|
|
|
|
setCategory(ProjectExplorer::Constants::DEVICE_SETTINGS_CATEGORY);
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-22 14:33:31 +02:00
|
|
|
QWidget *McuSupportOptionsPage::widget()
|
2019-08-14 11:48:13 +02:00
|
|
|
{
|
|
|
|
|
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->toolchainPackage, return);
|
2019-11-12 10:39:18 +01:00
|
|
|
QTC_ASSERT(m_options->qulSdkPackage, return);
|
2019-08-14 11:48:13 +02:00
|
|
|
|
2019-11-13 18:37:27 +01:00
|
|
|
const BoardOptions *board = m_widget->currentBoard();
|
|
|
|
|
if (!board)
|
|
|
|
|
return;
|
2019-08-14 11:48:13 +02:00
|
|
|
|
|
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
|
2019-11-13 18:37:27 +01:00
|
|
|
for (auto existingKit : m_options->existingKits(board))
|
|
|
|
|
ProjectExplorer::KitManager::deregisterKit(existingKit);
|
|
|
|
|
m_options->newKit(board);
|
2019-08-14 11:48:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void McuSupportOptionsPage::finish()
|
|
|
|
|
{
|
|
|
|
|
delete m_options;
|
|
|
|
|
m_options = nullptr;
|
|
|
|
|
delete m_widget;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // Internal
|
|
|
|
|
} // McuSupport
|