2013-01-29 16:46:04 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2013-01-29 16:46:04 +01:00
|
|
|
**
|
|
|
|
|
** 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
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2013-01-29 16:46:04 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2013-01-29 16:46:04 +01:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "environmentaspectwidget.h"
|
|
|
|
|
|
|
|
|
|
#include "environmentwidget.h"
|
|
|
|
|
|
|
|
|
|
#include <utils/environment.h>
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
|
|
|
|
#include <QComboBox>
|
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
|
|
namespace ProjectExplorer {
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
// EnvironmentAspectWidget:
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
EnvironmentAspectWidget::EnvironmentAspectWidget(EnvironmentAspect *aspect, QWidget *additionalWidget) :
|
|
|
|
|
m_aspect(aspect),
|
|
|
|
|
m_additionalWidget(additionalWidget)
|
|
|
|
|
{
|
|
|
|
|
QTC_CHECK(m_aspect);
|
|
|
|
|
|
|
|
|
|
setContentsMargins(0, 0, 0, 0);
|
2016-04-13 15:52:14 +02:00
|
|
|
auto topLayout = new QVBoxLayout(this);
|
2013-01-29 16:46:04 +01:00
|
|
|
topLayout->setMargin(0);
|
|
|
|
|
|
2016-04-13 15:52:14 +02:00
|
|
|
auto baseEnvironmentWidget = new QWidget;
|
|
|
|
|
auto baseLayout = new QHBoxLayout(baseEnvironmentWidget);
|
2013-01-29 16:46:04 +01:00
|
|
|
baseLayout->setMargin(0);
|
2016-04-13 15:52:14 +02:00
|
|
|
auto label = new QLabel(tr("Base environment for this run configuration:"), this);
|
2013-01-29 16:46:04 +01:00
|
|
|
baseLayout->addWidget(label);
|
|
|
|
|
m_baseEnvironmentComboBox = new QComboBox;
|
|
|
|
|
QList<int> bases = m_aspect->possibleBaseEnvironments();
|
|
|
|
|
int currentBase = m_aspect->baseEnvironmentBase();
|
|
|
|
|
QString baseDisplayName;
|
|
|
|
|
foreach (int i, bases) {
|
|
|
|
|
const QString displayName = m_aspect->baseEnvironmentDisplayName(i);
|
|
|
|
|
m_baseEnvironmentComboBox->addItem(displayName, i);
|
|
|
|
|
if (i == currentBase) {
|
|
|
|
|
m_baseEnvironmentComboBox->setCurrentIndex(m_baseEnvironmentComboBox->count() - 1);
|
|
|
|
|
baseDisplayName = displayName;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (m_baseEnvironmentComboBox->count() == 1)
|
|
|
|
|
m_baseEnvironmentComboBox->setEnabled(false);
|
|
|
|
|
|
2019-02-26 09:40:49 +01:00
|
|
|
connect(m_baseEnvironmentComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
2016-01-29 16:38:37 +02:00
|
|
|
this, &EnvironmentAspectWidget::baseEnvironmentSelected);
|
2013-01-29 16:46:04 +01:00
|
|
|
|
|
|
|
|
baseLayout->addWidget(m_baseEnvironmentComboBox);
|
|
|
|
|
baseLayout->addStretch(10);
|
|
|
|
|
if (additionalWidget)
|
|
|
|
|
baseLayout->addWidget(additionalWidget);
|
|
|
|
|
|
2014-10-13 22:37:28 +03:00
|
|
|
m_environmentWidget = new EnvironmentWidget(this, baseEnvironmentWidget);
|
2013-01-29 16:46:04 +01:00
|
|
|
m_environmentWidget->setBaseEnvironment(m_aspect->baseEnvironment());
|
|
|
|
|
m_environmentWidget->setBaseEnvironmentText(baseDisplayName);
|
|
|
|
|
m_environmentWidget->setUserChanges(m_aspect->userEnvironmentChanges());
|
|
|
|
|
m_environmentWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
|
|
|
topLayout->addWidget(m_environmentWidget);
|
|
|
|
|
|
2016-01-29 16:38:37 +02:00
|
|
|
connect(m_environmentWidget, &EnvironmentWidget::userChangesChanged,
|
|
|
|
|
this, &EnvironmentAspectWidget::userChangesEdited);
|
2013-01-29 16:46:04 +01:00
|
|
|
|
2016-01-29 16:38:37 +02:00
|
|
|
connect(m_aspect, &EnvironmentAspect::baseEnvironmentChanged,
|
|
|
|
|
this, &EnvironmentAspectWidget::changeBaseEnvironment);
|
|
|
|
|
connect(m_aspect, &EnvironmentAspect::userEnvironmentChangesChanged,
|
|
|
|
|
this, &EnvironmentAspectWidget::changeUserChanges);
|
|
|
|
|
connect(m_aspect, &EnvironmentAspect::environmentChanged,
|
|
|
|
|
this, &EnvironmentAspectWidget::environmentChanged);
|
2013-01-29 16:46:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EnvironmentAspect *EnvironmentAspectWidget::aspect() const
|
|
|
|
|
{
|
|
|
|
|
return m_aspect;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *EnvironmentAspectWidget::additionalWidget() const
|
|
|
|
|
{
|
|
|
|
|
return m_additionalWidget;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EnvironmentAspectWidget::baseEnvironmentSelected(int idx)
|
|
|
|
|
{
|
|
|
|
|
m_ignoreChange = true;
|
2013-11-12 14:17:58 +01:00
|
|
|
int base = m_baseEnvironmentComboBox->itemData(idx).toInt();
|
|
|
|
|
m_aspect->setBaseEnvironmentBase(base);
|
2013-07-04 18:23:28 +02:00
|
|
|
m_environmentWidget->setBaseEnvironment(m_aspect->baseEnvironment());
|
2013-11-12 14:17:58 +01:00
|
|
|
m_environmentWidget->setBaseEnvironmentText(m_aspect->baseEnvironmentDisplayName(base));
|
2013-01-29 16:46:04 +01:00
|
|
|
m_ignoreChange = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EnvironmentAspectWidget::changeBaseEnvironment()
|
|
|
|
|
{
|
|
|
|
|
if (m_ignoreChange)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
int base = m_aspect->baseEnvironmentBase();
|
|
|
|
|
for (int i = 0; i < m_baseEnvironmentComboBox->count(); ++i) {
|
|
|
|
|
if (m_baseEnvironmentComboBox->itemData(i).toInt() == base)
|
|
|
|
|
m_baseEnvironmentComboBox->setCurrentIndex(i);
|
|
|
|
|
}
|
|
|
|
|
m_environmentWidget->setBaseEnvironmentText(m_aspect->baseEnvironmentDisplayName(base));
|
2013-07-04 18:23:28 +02:00
|
|
|
m_environmentWidget->setBaseEnvironment(m_aspect->baseEnvironment());
|
2013-01-29 16:46:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EnvironmentAspectWidget::userChangesEdited()
|
|
|
|
|
{
|
|
|
|
|
m_ignoreChange = true;
|
|
|
|
|
m_aspect->setUserEnvironmentChanges(m_environmentWidget->userChanges());
|
|
|
|
|
m_ignoreChange = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EnvironmentAspectWidget::changeUserChanges(QList<Utils::EnvironmentItem> changes)
|
|
|
|
|
{
|
|
|
|
|
if (m_ignoreChange)
|
|
|
|
|
return;
|
|
|
|
|
m_environmentWidget->setUserChanges(changes);
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-04 18:23:28 +02:00
|
|
|
void EnvironmentAspectWidget::environmentChanged()
|
|
|
|
|
{
|
|
|
|
|
if (m_ignoreChange)
|
|
|
|
|
return;
|
|
|
|
|
m_environmentWidget->setBaseEnvironment(m_aspect->baseEnvironment());
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-29 16:46:04 +01:00
|
|
|
} // namespace ProjectExplorer
|