forked from qt-creator/qt-creator
EnvironmentAspectWidget: Add addWidget() method
Replace additionalWidget() getter with addWidget() setter. Remove additionalWidget from c'tor. Change-Id: I955e00228ed9b6b49535569be782793c3bafccb8 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -41,9 +41,8 @@ namespace ProjectExplorer {
|
||||
// EnvironmentAspectWidget:
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
EnvironmentAspectWidget::EnvironmentAspectWidget(EnvironmentAspect *aspect, QWidget *additionalWidget) :
|
||||
m_aspect(aspect),
|
||||
m_additionalWidget(additionalWidget)
|
||||
EnvironmentAspectWidget::EnvironmentAspectWidget(EnvironmentAspect *aspect)
|
||||
: m_aspect(aspect)
|
||||
{
|
||||
QTC_CHECK(m_aspect);
|
||||
|
||||
@@ -52,10 +51,10 @@ EnvironmentAspectWidget::EnvironmentAspectWidget(EnvironmentAspect *aspect, QWid
|
||||
topLayout->setContentsMargins(0, 0, 0, 25);
|
||||
|
||||
auto baseEnvironmentWidget = new QWidget;
|
||||
auto baseLayout = new QHBoxLayout(baseEnvironmentWidget);
|
||||
baseLayout->setContentsMargins(0, 0, 0, 0);
|
||||
m_baseLayout = new QHBoxLayout(baseEnvironmentWidget);
|
||||
m_baseLayout->setContentsMargins(0, 0, 0, 0);
|
||||
auto label = new QLabel(tr("Base environment for this run configuration:"), this);
|
||||
baseLayout->addWidget(label);
|
||||
m_baseLayout->addWidget(label);
|
||||
|
||||
m_baseEnvironmentComboBox = new QComboBox;
|
||||
for (const QString &displayName : m_aspect->displayNames())
|
||||
@@ -67,10 +66,8 @@ EnvironmentAspectWidget::EnvironmentAspectWidget(EnvironmentAspect *aspect, QWid
|
||||
connect(m_baseEnvironmentComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
||||
this, &EnvironmentAspectWidget::baseEnvironmentSelected);
|
||||
|
||||
baseLayout->addWidget(m_baseEnvironmentComboBox);
|
||||
baseLayout->addStretch(10);
|
||||
if (additionalWidget)
|
||||
baseLayout->addWidget(additionalWidget);
|
||||
m_baseLayout->addWidget(m_baseEnvironmentComboBox);
|
||||
m_baseLayout->addStretch(10);
|
||||
|
||||
const EnvironmentWidget::Type widgetType = aspect->isLocal()
|
||||
? EnvironmentWidget::TypeLocal : EnvironmentWidget::TypeRemote;
|
||||
@@ -92,9 +89,9 @@ EnvironmentAspectWidget::EnvironmentAspectWidget(EnvironmentAspect *aspect, QWid
|
||||
this, &EnvironmentAspectWidget::environmentChanged);
|
||||
}
|
||||
|
||||
QWidget *EnvironmentAspectWidget::additionalWidget() const
|
||||
void EnvironmentAspectWidget::addWidget(QWidget *widget)
|
||||
{
|
||||
return m_additionalWidget;
|
||||
m_baseLayout->addWidget(widget);
|
||||
}
|
||||
|
||||
void EnvironmentAspectWidget::baseEnvironmentSelected(int idx)
|
||||
|
@@ -37,6 +37,7 @@
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QComboBox;
|
||||
class QHBoxLayout;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Utils { class DetailsWidget; }
|
||||
@@ -50,12 +51,12 @@ class PROJECTEXPLORER_EXPORT EnvironmentAspectWidget : public QWidget
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit EnvironmentAspectWidget(EnvironmentAspect *aspect, QWidget *additionalWidget = nullptr);
|
||||
explicit EnvironmentAspectWidget(EnvironmentAspect *aspect);
|
||||
|
||||
protected:
|
||||
EnvironmentAspect *aspect() const { return m_aspect; }
|
||||
EnvironmentWidget *envWidget() const { return m_environmentWidget; }
|
||||
QWidget *additionalWidget() const;
|
||||
void addWidget(QWidget *widget);
|
||||
|
||||
private:
|
||||
void baseEnvironmentSelected(int idx);
|
||||
@@ -66,8 +67,7 @@ private:
|
||||
|
||||
EnvironmentAspect *m_aspect;
|
||||
bool m_ignoreChange = false;
|
||||
|
||||
QWidget *m_additionalWidget = nullptr;
|
||||
QHBoxLayout *m_baseLayout = nullptr;
|
||||
QComboBox *m_baseEnvironmentComboBox = nullptr;
|
||||
EnvironmentWidget *m_environmentWidget = nullptr;
|
||||
};
|
||||
|
@@ -53,20 +53,21 @@ namespace RemoteLinux {
|
||||
|
||||
RemoteLinuxEnvironmentAspectWidget::RemoteLinuxEnvironmentAspectWidget
|
||||
(RemoteLinuxEnvironmentAspect *aspect, Target *target)
|
||||
: EnvironmentAspectWidget(aspect, new QPushButton)
|
||||
: EnvironmentAspectWidget(aspect)
|
||||
, m_fetchButton(new QPushButton(FetchEnvButtonText))
|
||||
{
|
||||
addWidget(m_fetchButton);
|
||||
|
||||
IDevice::ConstPtr device = DeviceKitAspect::device(target->kit());
|
||||
|
||||
deviceEnvReader = new RemoteLinuxEnvironmentReader(device, this);
|
||||
m_deviceEnvReader = new RemoteLinuxEnvironmentReader(device, this);
|
||||
connect(target, &ProjectExplorer::Target::kitChanged,
|
||||
deviceEnvReader, &RemoteLinuxEnvironmentReader::handleCurrentDeviceConfigChanged);
|
||||
m_deviceEnvReader, &RemoteLinuxEnvironmentReader::handleCurrentDeviceConfigChanged);
|
||||
|
||||
QPushButton *button = fetchButton();
|
||||
button->setText(FetchEnvButtonText);
|
||||
connect(button, &QPushButton::clicked, this, &RemoteLinuxEnvironmentAspectWidget::fetchEnvironment);
|
||||
connect(deviceEnvReader, &RemoteLinuxEnvironmentReader::finished,
|
||||
connect(m_fetchButton, &QPushButton::clicked, this, &RemoteLinuxEnvironmentAspectWidget::fetchEnvironment);
|
||||
connect(m_deviceEnvReader, &RemoteLinuxEnvironmentReader::finished,
|
||||
this, &RemoteLinuxEnvironmentAspectWidget::fetchEnvironmentFinished);
|
||||
connect(deviceEnvReader, &RemoteLinuxEnvironmentReader::error,
|
||||
connect(m_deviceEnvReader, &RemoteLinuxEnvironmentReader::error,
|
||||
this, &RemoteLinuxEnvironmentAspectWidget::fetchEnvironmentError);
|
||||
|
||||
const EnvironmentWidget::OpenTerminalFunc openTerminalFunc
|
||||
@@ -85,32 +86,25 @@ RemoteLinuxEnvironmentAspectWidget::RemoteLinuxEnvironmentAspectWidget
|
||||
envWidget()->setOpenTerminalFunc(openTerminalFunc);
|
||||
}
|
||||
|
||||
QPushButton *RemoteLinuxEnvironmentAspectWidget::fetchButton() const
|
||||
{
|
||||
return qobject_cast<QPushButton *>(additionalWidget());
|
||||
}
|
||||
|
||||
void RemoteLinuxEnvironmentAspectWidget::fetchEnvironment()
|
||||
{
|
||||
QPushButton *button = fetchButton();
|
||||
disconnect(button, &QPushButton::clicked,
|
||||
disconnect(m_fetchButton, &QPushButton::clicked,
|
||||
this, &RemoteLinuxEnvironmentAspectWidget::fetchEnvironment);
|
||||
connect(button, &QPushButton::clicked,
|
||||
connect(m_fetchButton, &QPushButton::clicked,
|
||||
this, &RemoteLinuxEnvironmentAspectWidget::stopFetchEnvironment);
|
||||
button->setText(tr("Cancel Fetch Operation"));
|
||||
deviceEnvReader->start();
|
||||
m_fetchButton->setText(tr("Cancel Fetch Operation"));
|
||||
m_deviceEnvReader->start();
|
||||
}
|
||||
|
||||
void RemoteLinuxEnvironmentAspectWidget::fetchEnvironmentFinished()
|
||||
{
|
||||
QPushButton *button = fetchButton();
|
||||
disconnect(button, &QPushButton::clicked,
|
||||
disconnect(m_fetchButton, &QPushButton::clicked,
|
||||
this, &RemoteLinuxEnvironmentAspectWidget::stopFetchEnvironment);
|
||||
connect(button, &QPushButton::clicked,
|
||||
connect(m_fetchButton, &QPushButton::clicked,
|
||||
this, &RemoteLinuxEnvironmentAspectWidget::fetchEnvironment);
|
||||
button->setText(FetchEnvButtonText);
|
||||
m_fetchButton->setText(FetchEnvButtonText);
|
||||
qobject_cast<RemoteLinuxEnvironmentAspect *>(aspect())->setRemoteEnvironment(
|
||||
deviceEnvReader->remoteEnvironment());
|
||||
m_deviceEnvReader->remoteEnvironment());
|
||||
}
|
||||
|
||||
void RemoteLinuxEnvironmentAspectWidget::fetchEnvironmentError(const QString &error)
|
||||
@@ -121,7 +115,7 @@ void RemoteLinuxEnvironmentAspectWidget::fetchEnvironmentError(const QString &er
|
||||
|
||||
void RemoteLinuxEnvironmentAspectWidget::stopFetchEnvironment()
|
||||
{
|
||||
deviceEnvReader->stop();
|
||||
m_deviceEnvReader->stop();
|
||||
fetchEnvironmentFinished();
|
||||
}
|
||||
|
||||
|
@@ -44,14 +44,13 @@ public:
|
||||
ProjectExplorer::Target *target);
|
||||
|
||||
private:
|
||||
QPushButton *fetchButton() const;
|
||||
|
||||
void fetchEnvironment();
|
||||
void fetchEnvironmentFinished();
|
||||
void fetchEnvironmentError(const QString &error);
|
||||
void stopFetchEnvironment();
|
||||
|
||||
Internal::RemoteLinuxEnvironmentReader *deviceEnvReader;
|
||||
Internal::RemoteLinuxEnvironmentReader *m_deviceEnvReader = nullptr;
|
||||
QPushButton *m_fetchButton = nullptr;
|
||||
};
|
||||
|
||||
} // namespace RemoteLinux
|
||||
|
Reference in New Issue
Block a user