From 077079cf2a79b4e4c2fd63c4b9cd0da3dff6c1ff Mon Sep 17 00:00:00 2001 From: hjk Date: Mon, 18 Jan 2016 17:11:31 +0100 Subject: [PATCH] ProjectExplorer: Introduce Runnable and Connection concepts. A 'Runnable' contains (possibly target-specific) data to describe something that could be run (e.g. a remote executable with arguments, working directory and environment). A 'Connection' contains (possibly target-specific) data to describe a connection to target that will be used to run a Runnable. Runnable and Connection objects are used in the target RunControlFactories and are opaque to the project explorer. Change-Id: I2293dffa71148646cfb52c9b582ccd2675b145a8 Reviewed-by: Tobias Hunger --- .../projectexplorer/runconfiguration.cpp | 10 +++ .../projectexplorer/runconfiguration.h | 72 +++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/src/plugins/projectexplorer/runconfiguration.cpp b/src/plugins/projectexplorer/runconfiguration.cpp index 4e5a1c0855f..764f8893445 100644 --- a/src/plugins/projectexplorer/runconfiguration.cpp +++ b/src/plugins/projectexplorer/runconfiguration.cpp @@ -541,6 +541,16 @@ Core::Id RunControl::runMode() const return m_runMode; } +void RunControl::setRunnable(const Runnable &runnable) +{ + m_runnable = runnable; +} + +void RunControl::setConnection(const Connection &connection) +{ + m_connection = connection; +} + QString RunControl::displayName() const { return m_displayName; diff --git a/src/plugins/projectexplorer/runconfiguration.h b/src/plugins/projectexplorer/runconfiguration.h index 8be85b1989d..36ea66fa8d5 100644 --- a/src/plugins/projectexplorer/runconfiguration.h +++ b/src/plugins/projectexplorer/runconfiguration.h @@ -29,6 +29,7 @@ #include "projectconfiguration.h" #include "projectexplorer_export.h" #include "projectexplorerconstants.h" +#include "applicationlauncher.h" #include #include @@ -37,6 +38,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE class QFormLayout; QT_END_NAMESPACE @@ -150,6 +153,67 @@ private: ISettingsAspect *m_globalSettings; // Not owned. }; +class PROJECTEXPLORER_EXPORT ClonableConcept +{ +public: + virtual ~ClonableConcept() = default; + virtual ClonableConcept *clone() const = 0; +}; + +template +class ClonableModel : public ClonableConcept +{ +public: + ClonableModel(const T &data) : m_data(data) {} + ClonableConcept *clone() const override { return new ClonableModel(*this); } + + T m_data; +}; + +class PROJECTEXPLORER_EXPORT Runnable +{ +public: + Runnable() {} + Runnable(const Runnable &other) : d(other.d->clone()) {} + Runnable(Runnable &&other) = default; + template Runnable(const T &data) : d(new ClonableModel(data)) {} + + void operator=(Runnable other) { d = std::move(other.d); } + + template bool is() const { + return dynamic_cast *>(d.get()) != 0; + } + + template const T &as() const { + return static_cast *>(d.get())->m_data; + } + +private: + std::unique_ptr d; +}; + +class PROJECTEXPLORER_EXPORT Connection +{ +public: + Connection() {} + Connection(const Connection &other) : d(other.d->clone()) {} + Connection(Connection &&other) = default; + template Connection(const T &data) : d(new ClonableModel(data)) {} + + void operator=(Connection other) { d = std::move(other.d); } + + template bool is() const { + return dynamic_cast *>(d.get()) != 0; + } + + template const T &as() const { + return static_cast *>(d.get())->m_data; + } + +private: + std::unique_ptr d; +}; + // Documentation inside. class PROJECTEXPLORER_EXPORT RunConfiguration : public ProjectConfiguration { @@ -303,6 +367,12 @@ public: Utils::OutputFormatter *outputFormatter(); Core::Id runMode() const; + const Runnable &runnable() const { return m_runnable; } + void setRunnable(const Runnable &runnable); + + const Connection &connection() const { return m_connection; } + void setConnection(const Connection &connection); + public slots: void bringApplicationToForeground(qint64 pid); void appendMessage(const QString &msg, Utils::OutputFormat format); @@ -325,6 +395,8 @@ protected: private: QString m_displayName; + Runnable m_runnable; + Connection m_connection; Core::Id m_runMode; Utils::Icon m_icon; const QPointer m_runConfiguration;