EnvironmentWidget: Devirtualize aspect() method

The RemoteLinuxEnvironmentAspectWidget subclass was
overloading it, however, it was returning the
subclass of EnvironmentAspect (i.e. returning
RemoteLinuxEnvironmentAspect).

Instead, we use the base aspect() method in
RemoteLinuxEnvironmentAspectWidget subclass and we
cast it into expected RemoteLinuxEnvironmentAspect class.

Move some methods into protected section, as they
are used only in subclass.

Use qobject_cast instead of dynamic_cast inside
UploadAndInstallTarPackageStep.

Change-Id: Ic3119ca15d46187e0aa7b8b4013e7fc4efec4bd9
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Jarek Kobus
2022-05-27 10:42:33 +02:00
parent ffe1ff2368
commit cb2894a51f
5 changed files with 8 additions and 18 deletions

View File

@@ -92,11 +92,6 @@ EnvironmentAspectWidget::EnvironmentAspectWidget(EnvironmentAspect *aspect, QWid
this, &EnvironmentAspectWidget::environmentChanged);
}
EnvironmentAspect *EnvironmentAspectWidget::aspect() const
{
return m_aspect;
}
QWidget *EnvironmentAspectWidget::additionalWidget() const
{
return m_additionalWidget;

View File

@@ -52,9 +52,9 @@ class PROJECTEXPLORER_EXPORT EnvironmentAspectWidget : public QWidget
public:
explicit EnvironmentAspectWidget(EnvironmentAspect *aspect, QWidget *additionalWidget = nullptr);
virtual EnvironmentAspect *aspect() const;
protected:
EnvironmentAspect *aspect() const { return m_aspect; }
EnvironmentWidget *envWidget() const { return m_environmentWidget; }
QWidget *additionalWidget() const;
private:

View File

@@ -52,8 +52,8 @@ const QString FetchEnvButtonText
namespace RemoteLinux {
RemoteLinuxEnvironmentAspectWidget::RemoteLinuxEnvironmentAspectWidget
(RemoteLinuxEnvironmentAspect *aspect, Target *target) :
EnvironmentAspectWidget(aspect, new QPushButton)
(RemoteLinuxEnvironmentAspect *aspect, Target *target)
: EnvironmentAspectWidget(aspect, new QPushButton)
{
IDevice::ConstPtr device = DeviceKitAspect::device(target->kit());
@@ -85,11 +85,6 @@ RemoteLinuxEnvironmentAspectWidget::RemoteLinuxEnvironmentAspectWidget
envWidget()->setOpenTerminalFunc(openTerminalFunc);
}
RemoteLinuxEnvironmentAspect *RemoteLinuxEnvironmentAspectWidget::aspect() const
{
return dynamic_cast<RemoteLinuxEnvironmentAspect *>(EnvironmentAspectWidget::aspect());
}
QPushButton *RemoteLinuxEnvironmentAspectWidget::fetchButton() const
{
return qobject_cast<QPushButton *>(additionalWidget());
@@ -114,7 +109,8 @@ void RemoteLinuxEnvironmentAspectWidget::fetchEnvironmentFinished()
connect(button, &QPushButton::clicked,
this, &RemoteLinuxEnvironmentAspectWidget::fetchEnvironment);
button->setText(FetchEnvButtonText);
aspect()->setRemoteEnvironment(deviceEnvReader->remoteEnvironment());
qobject_cast<RemoteLinuxEnvironmentAspect *>(aspect())->setRemoteEnvironment(
deviceEnvReader->remoteEnvironment());
}
void RemoteLinuxEnvironmentAspectWidget::fetchEnvironmentError(const QString &error)

View File

@@ -43,10 +43,9 @@ public:
RemoteLinuxEnvironmentAspectWidget(RemoteLinuxEnvironmentAspect *aspect,
ProjectExplorer::Target *target);
RemoteLinuxEnvironmentAspect *aspect() const override;
private:
QPushButton *fetchButton() const;
private:
void fetchEnvironment();
void fetchEnvironmentFinished();
void fetchEnvironmentError(const QString &error);

View File

@@ -185,7 +185,7 @@ UploadAndInstallTarPackageStep::UploadAndInstallTarPackageStep(BuildStepList *bs
for (BuildStep *step : deployConfiguration()->stepList()->steps()) {
if (step == this)
break;
if ((pStep = dynamic_cast<TarPackageCreationStep *>(step)))
if ((pStep = qobject_cast<TarPackageCreationStep *>(step)))
break;
}
if (!pStep)