From cb2894a51f1529e66d9daf017abe969a25048cb2 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Fri, 27 May 2022 10:42:33 +0200 Subject: [PATCH] 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: Reviewed-by: Christian Kandeler --- .../projectexplorer/environmentaspectwidget.cpp | 5 ----- .../projectexplorer/environmentaspectwidget.h | 4 ++-- .../remotelinuxenvironmentaspectwidget.cpp | 12 ++++-------- .../remotelinux/remotelinuxenvironmentaspectwidget.h | 3 +-- .../remotelinux/uploadandinstalltarpackagestep.cpp | 2 +- 5 files changed, 8 insertions(+), 18 deletions(-) diff --git a/src/plugins/projectexplorer/environmentaspectwidget.cpp b/src/plugins/projectexplorer/environmentaspectwidget.cpp index 280cc5ac9da..bb84a49f6a6 100644 --- a/src/plugins/projectexplorer/environmentaspectwidget.cpp +++ b/src/plugins/projectexplorer/environmentaspectwidget.cpp @@ -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; diff --git a/src/plugins/projectexplorer/environmentaspectwidget.h b/src/plugins/projectexplorer/environmentaspectwidget.h index 44acee2f616..bb51a14bee8 100644 --- a/src/plugins/projectexplorer/environmentaspectwidget.h +++ b/src/plugins/projectexplorer/environmentaspectwidget.h @@ -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: diff --git a/src/plugins/remotelinux/remotelinuxenvironmentaspectwidget.cpp b/src/plugins/remotelinux/remotelinuxenvironmentaspectwidget.cpp index 0aab43c44ab..309509ec149 100644 --- a/src/plugins/remotelinux/remotelinuxenvironmentaspectwidget.cpp +++ b/src/plugins/remotelinux/remotelinuxenvironmentaspectwidget.cpp @@ -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(EnvironmentAspectWidget::aspect()); -} - QPushButton *RemoteLinuxEnvironmentAspectWidget::fetchButton() const { return qobject_cast(additionalWidget()); @@ -114,7 +109,8 @@ void RemoteLinuxEnvironmentAspectWidget::fetchEnvironmentFinished() connect(button, &QPushButton::clicked, this, &RemoteLinuxEnvironmentAspectWidget::fetchEnvironment); button->setText(FetchEnvButtonText); - aspect()->setRemoteEnvironment(deviceEnvReader->remoteEnvironment()); + qobject_cast(aspect())->setRemoteEnvironment( + deviceEnvReader->remoteEnvironment()); } void RemoteLinuxEnvironmentAspectWidget::fetchEnvironmentError(const QString &error) diff --git a/src/plugins/remotelinux/remotelinuxenvironmentaspectwidget.h b/src/plugins/remotelinux/remotelinuxenvironmentaspectwidget.h index ae254fda62b..cc03d7e75c0 100644 --- a/src/plugins/remotelinux/remotelinuxenvironmentaspectwidget.h +++ b/src/plugins/remotelinux/remotelinuxenvironmentaspectwidget.h @@ -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); diff --git a/src/plugins/remotelinux/uploadandinstalltarpackagestep.cpp b/src/plugins/remotelinux/uploadandinstalltarpackagestep.cpp index a1bcfe58a6e..c320fc68cd1 100644 --- a/src/plugins/remotelinux/uploadandinstalltarpackagestep.cpp +++ b/src/plugins/remotelinux/uploadandinstalltarpackagestep.cpp @@ -185,7 +185,7 @@ UploadAndInstallTarPackageStep::UploadAndInstallTarPackageStep(BuildStepList *bs for (BuildStep *step : deployConfiguration()->stepList()->steps()) { if (step == this) break; - if ((pStep = dynamic_cast(step))) + if ((pStep = qobject_cast(step))) break; } if (!pStep)