From e4dca97fc6022e873fc66009b2be823bb520a1f3 Mon Sep 17 00:00:00 2001 From: hjk Date: Mon, 1 Feb 2016 12:15:44 +0100 Subject: [PATCH] ProjectExplorer: Pimpl RunControl It is a fairly central exported class, no need to expose storage details to user code. Change-Id: Ibe199969450bc30b46ab7500e04a22300c492f2c Reviewed-by: Tobias Hunger --- .../projectexplorer/runconfiguration.cpp | 116 ++++++++++++------ .../projectexplorer/runconfiguration.h | 27 +--- 2 files changed, 86 insertions(+), 57 deletions(-) diff --git a/src/plugins/projectexplorer/runconfiguration.cpp b/src/plugins/projectexplorer/runconfiguration.cpp index 99cd72c9519..3a7156eb5f5 100644 --- a/src/plugins/projectexplorer/runconfiguration.cpp +++ b/src/plugins/projectexplorer/runconfiguration.cpp @@ -42,7 +42,7 @@ #include #include -#ifdef Q_OS_MAC +#ifdef Q_OS_OSX #include #endif @@ -531,93 +531,139 @@ IRunConfigurationAspect *IRunControlFactory::createRunConfigurationAspect(RunCon than it needs to be. */ -RunControl::RunControl(RunConfiguration *runConfiguration, Core::Id mode) - : m_runMode(mode), m_runConfiguration(runConfiguration), m_outputFormatter(0) -{ - if (runConfiguration) { - m_displayName = runConfiguration->displayName(); - m_outputFormatter = runConfiguration->createOutputFormatter(); +namespace Internal { - if (runConfiguration->target()) - m_project = m_runConfiguration->target()->project(); +class RunControlPrivate +{ +public: + RunControlPrivate(RunConfiguration *runConfiguration, Core::Id mode) + : runMode(mode), runConfiguration(runConfiguration) + { + if (runConfiguration) { + displayName = runConfiguration->displayName(); + outputFormatter = runConfiguration->createOutputFormatter(); + + if (runConfiguration->target()) + project = runConfiguration->target()->project(); + } + + // We need to ensure that there's always a OutputFormatter + if (!outputFormatter) + outputFormatter = new Utils::OutputFormatter(); } - // We need to ensure that there's always a OutputFormatter - if (!m_outputFormatter) - m_outputFormatter = new Utils::OutputFormatter(); + ~RunControlPrivate() + { + delete outputFormatter; + } + + QString displayName; + Runnable runnable; + Connection connection; + Core::Id runMode; + Utils::Icon icon; + const QPointer runConfiguration; + QPointer project; + Utils::OutputFormatter *outputFormatter = 0; + + // A handle to the actual application process. + ProcessHandle applicationProcessHandle; + +#ifdef Q_OS_OSX + //these two are used to bring apps in the foreground on Mac + qint64 internalPid; + int foregroundCount; +#endif +}; + +} // Internal + +RunControl::RunControl(RunConfiguration *runConfiguration, Core::Id mode) + : d(new Internal::RunControlPrivate(runConfiguration, mode)) +{ } RunControl::~RunControl() { - delete m_outputFormatter; + delete d; } Utils::OutputFormatter *RunControl::outputFormatter() { - return m_outputFormatter; + return d->outputFormatter; } Core::Id RunControl::runMode() const { - return m_runMode; + return d->runMode; +} + +const Runnable &RunControl::runnable() const +{ + return d->runnable; } void RunControl::setRunnable(const Runnable &runnable) { - m_runnable = runnable; + d->runnable = runnable; +} + +const Connection &RunControl::connection() const +{ + return d->connection; } void RunControl::setConnection(const Connection &connection) { - m_connection = connection; + d->connection = connection; } QString RunControl::displayName() const { - return m_displayName; + return d->displayName; } void RunControl::setDisplayName(const QString &displayName) { - m_displayName = displayName; + d->displayName = displayName; } void RunControl::setIcon(const Utils::Icon &icon) { - m_icon = icon; + d->icon = icon; } Utils::Icon RunControl::icon() const { - return m_icon; + return d->icon; } Abi RunControl::abi() const { - if (const RunConfiguration *rc = m_runConfiguration.data()) + if (const RunConfiguration *rc = d->runConfiguration.data()) return rc->abi(); return Abi(); } RunConfiguration *RunControl::runConfiguration() const { - return m_runConfiguration.data(); + return d->runConfiguration.data(); } Project *RunControl::project() const { - return m_project.data(); + return d->project.data(); } ProcessHandle RunControl::applicationProcessHandle() const { - return m_applicationProcessHandle; + return d->applicationProcessHandle; } void RunControl::setApplicationProcessHandle(const ProcessHandle &handle) { - if (m_applicationProcessHandle != handle) { - m_applicationProcessHandle = handle; + if (d->applicationProcessHandle != handle) { + d->applicationProcessHandle = handle; emit applicationProcessHandleChanged(); } } @@ -679,14 +725,14 @@ bool RunControl::showPromptToStopDialog(const QString &title, bool RunControl::sameRunConfiguration(const RunControl *other) const { - return other->m_runConfiguration.data() == m_runConfiguration.data(); + return other->d->runConfiguration.data() == d->runConfiguration.data(); } void RunControl::bringApplicationToForeground(qint64 pid) { -#ifdef Q_OS_MAC - m_internalPid = pid; - m_foregroundCount = 0; +#ifdef Q_OS_OSX + d->internalPid = pid; + d->foregroundCount = 0; bringApplicationToForegroundInternal(); #else Q_UNUSED(pid) @@ -695,14 +741,14 @@ void RunControl::bringApplicationToForeground(qint64 pid) void RunControl::bringApplicationToForegroundInternal() { -#ifdef Q_OS_MAC +#ifdef Q_OS_OSX ProcessSerialNumber psn; - GetProcessForPID(m_internalPid, &psn); - if (SetFrontProcess(&psn) == procNotFound && m_foregroundCount < 15) { + GetProcessForPID(d->internalPid, &psn); + if (SetFrontProcess(&psn) == procNotFound && d->foregroundCount < 15) { // somehow the mac/carbon api says // "-600 no eligible process with specified process id" // if we call SetFrontProcess too early - ++m_foregroundCount; + ++d->foregroundCount; QTimer::singleShot(200, this, &RunControl::bringApplicationToForegroundInternal); return; } diff --git a/src/plugins/projectexplorer/runconfiguration.h b/src/plugins/projectexplorer/runconfiguration.h index 68a3b15be31..b16a159d5e5 100644 --- a/src/plugins/projectexplorer/runconfiguration.h +++ b/src/plugins/projectexplorer/runconfiguration.h @@ -27,11 +27,9 @@ #define RUNCONFIGURATION_H #include "projectconfiguration.h" -#include "projectexplorer_export.h" #include "projectexplorerconstants.h" #include "applicationlauncher.h" -#include #include #include @@ -55,6 +53,8 @@ class RunConfigWidget; class RunControl; class Target; +namespace Internal { class RunControlPrivate; } + // FIXME: This should also contain a handle to an remote device if used. class PROJECTEXPLORER_EXPORT ProcessHandle { @@ -368,10 +368,10 @@ public: Utils::OutputFormatter *outputFormatter(); Core::Id runMode() const; - const Runnable &runnable() const { return m_runnable; } + const Runnable &runnable() const; void setRunnable(const Runnable &runnable); - const Connection &connection() const { return m_connection; } + const Connection &connection() const; void setConnection(const Connection &connection); public slots: @@ -393,24 +393,7 @@ protected: private: void bringApplicationToForegroundInternal(); - - QString m_displayName; - Runnable m_runnable; - Connection m_connection; - Core::Id m_runMode; - Utils::Icon m_icon; - const QPointer m_runConfiguration; - QPointer m_project; - Utils::OutputFormatter *m_outputFormatter; - - // A handle to the actual application process. - ProcessHandle m_applicationProcessHandle; - -#ifdef Q_OS_MAC - //these two are used to bring apps in the foreground on Mac - qint64 m_internalPid; - int m_foregroundCount; -#endif + Internal::RunControlPrivate *d; }; } // namespace ProjectExplorer