From 9d206a2bc45af5ae4680fad0ab0db9b6415abcda Mon Sep 17 00:00:00 2001 From: hjk Date: Fri, 16 Aug 2019 12:16:17 +0200 Subject: [PATCH] ProjectExplorer: Hide parts of BuildStep's QObject-ness from users This lets the compiler catch issues like QTCREATORBUG-22818 and saves visible casts on the user side. Change-Id: I5a307a55364daa0bec039a4c38cc9827841ff9c1 Reviewed-by: Christian Kandeler --- src/plugins/android/androiddeployqtstep.cpp | 2 +- src/plugins/cmakeprojectmanager/cmakebuildstep.cpp | 5 +++-- src/plugins/projectexplorer/buildstep.cpp | 5 +++++ src/plugins/projectexplorer/buildstep.h | 4 ++++ src/plugins/qmakeprojectmanager/qmakemakestep.cpp | 5 ++--- src/plugins/qmakeprojectmanager/qmakestep.cpp | 2 +- 6 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/plugins/android/androiddeployqtstep.cpp b/src/plugins/android/androiddeployqtstep.cpp index a725fc55eab..02f0ecda83b 100644 --- a/src/plugins/android/androiddeployqtstep.cpp +++ b/src/plugins/android/androiddeployqtstep.cpp @@ -193,7 +193,7 @@ bool AndroidDeployQtStep::init() << "Min target API" << minTargetApi; // Try to re-use user-provided information from an earlier step of the same type. - auto bsl = qobject_cast(parent()); + BuildStepList *bsl = stepList(); QTC_ASSERT(bsl, return false); auto androidDeployQtStep = bsl->firstOfType(); QTC_ASSERT(androidDeployQtStep, return false); diff --git a/src/plugins/cmakeprojectmanager/cmakebuildstep.cpp b/src/plugins/cmakeprojectmanager/cmakebuildstep.cpp index 68d7bc44384..ecaefda599d 100644 --- a/src/plugins/cmakeprojectmanager/cmakebuildstep.cpp +++ b/src/plugins/cmakeprojectmanager/cmakebuildstep.cpp @@ -262,8 +262,9 @@ BuildStepConfigWidget *CMakeBuildStep::createConfigWidget() QString CMakeBuildStep::defaultBuildTarget() const { - const auto pc = qobject_cast(parent()); - const Core::Id parentId = pc ? pc->id() : Core::Id(); + const BuildStepList *const bsl = stepList(); + QTC_ASSERT(bsl, return {}); + const Core::Id parentId = bsl->id(); if (parentId == ProjectExplorer::Constants::BUILDSTEPS_CLEAN) return cleanTarget(); if (parentId == ProjectExplorer::Constants::BUILDSTEPS_DEPLOY) diff --git a/src/plugins/projectexplorer/buildstep.cpp b/src/plugins/projectexplorer/buildstep.cpp index 193e66b7f70..3067b8c800a 100644 --- a/src/plugins/projectexplorer/buildstep.cpp +++ b/src/plugins/projectexplorer/buildstep.cpp @@ -286,6 +286,11 @@ void BuildStep::setEnabled(bool b) emit enabledChanged(); } +BuildStepList *BuildStep::stepList() const +{ + return qobject_cast(parent()); +} + bool BuildStep::enabled() const { return m_enabled; diff --git a/src/plugins/projectexplorer/buildstep.h b/src/plugins/projectexplorer/buildstep.h index 2ddc168cba6..f9fb6fbec68 100644 --- a/src/plugins/projectexplorer/buildstep.h +++ b/src/plugins/projectexplorer/buildstep.h @@ -69,6 +69,8 @@ public: bool enabled() const; void setEnabled(bool b); + BuildStepList *stepList() const; + BuildConfiguration *buildConfiguration() const; DeployConfiguration *deployConfiguration() const; ProjectConfiguration *projectConfiguration() const; @@ -122,6 +124,8 @@ protected: bool isCanceled() const; private: + using ProjectConfiguration::parent; + virtual void doRun() = 0; virtual void doCancel(); diff --git a/src/plugins/qmakeprojectmanager/qmakemakestep.cpp b/src/plugins/qmakeprojectmanager/qmakemakestep.cpp index 337d26daebd..ec318b63e63 100644 --- a/src/plugins/qmakeprojectmanager/qmakemakestep.cpp +++ b/src/plugins/qmakeprojectmanager/qmakemakestep.cpp @@ -80,7 +80,7 @@ bool QmakeMakeStep::init() // Ignore all but the first make step for a non-top-level build. See QTCREATORBUG-15794. m_ignoredNonTopLevelBuild = (bc->fileNodeBuild() || bc->subNodeBuild()) - && static_cast(parent())->firstOfType() != this; + && stepList()->firstOfType() != this; ProcessParameters *pp = processParameters(); pp->setMacroExpander(bc->macroExpander()); @@ -173,8 +173,7 @@ bool QmakeMakeStep::init() // A user doing "make clean" indicates they want a proper rebuild, so make sure to really // execute qmake on the next build. - if (static_cast(parent())->id() - == ProjectExplorer::Constants::BUILDSTEPS_CLEAN) { + if (stepList()->id() == ProjectExplorer::Constants::BUILDSTEPS_CLEAN) { const auto qmakeStep = bc->qmakeStep(); if (qmakeStep) qmakeStep->setForced(true); diff --git a/src/plugins/qmakeprojectmanager/qmakestep.cpp b/src/plugins/qmakeprojectmanager/qmakestep.cpp index 892bc897743..d97931f08b9 100644 --- a/src/plugins/qmakeprojectmanager/qmakestep.cpp +++ b/src/plugins/qmakeprojectmanager/qmakestep.cpp @@ -442,7 +442,7 @@ void QMakeStep::setSeparateDebugInfo(bool enable) FilePath QMakeStep::makeCommand() const { - auto ms = qobject_cast(parent())->firstOfType(); + auto ms = stepList()->firstOfType(); return ms ? ms->effectiveMakeCommand().executable() : FilePath(); }