mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-18 03:15:34 +08:00
refs #195, base class for runtime aware GUI widgets
This commit is contained in:
70
src/blackgui/runtimebasedcomponent.cpp
Normal file
70
src/blackgui/runtimebasedcomponent.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
#include "runtimebasedcomponent.h"
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
const BlackCore::IContextApplication *CRuntimeBasedComponent::getIContextApplication() const
|
||||
{
|
||||
if (!this->m_runtime) return nullptr;
|
||||
return this->m_runtime->getIContextApplication();
|
||||
}
|
||||
|
||||
BlackCore::IContextApplication *CRuntimeBasedComponent::getIContextApplication()
|
||||
{
|
||||
if (!this->m_runtime) return nullptr;
|
||||
return this->m_runtime->getIContextApplication();
|
||||
}
|
||||
|
||||
BlackCore::IContextAudio *CRuntimeBasedComponent::getIContextAudio()
|
||||
{
|
||||
if (!this->m_runtime) return nullptr;
|
||||
return this->m_runtime->getIContextAudio();
|
||||
}
|
||||
|
||||
const BlackCore::IContextAudio *CRuntimeBasedComponent::getIContextAudio() const
|
||||
{
|
||||
if (!this->m_runtime) return nullptr;
|
||||
return this->m_runtime->getIContextAudio();
|
||||
}
|
||||
|
||||
void CRuntimeBasedComponent::createRuntime(const BlackCore::CRuntimeConfig &config, QObject *parent)
|
||||
{
|
||||
this->m_runtime = new BlackCore::CRuntime(config, parent);
|
||||
this->m_runtimeOwner = true;
|
||||
}
|
||||
|
||||
BlackCore::IContextNetwork *CRuntimeBasedComponent::getIContextNetwork()
|
||||
{
|
||||
if (!this->m_runtime) return nullptr;
|
||||
return this->m_runtime->getIContextNetwork();
|
||||
}
|
||||
|
||||
const BlackCore::IContextNetwork *CRuntimeBasedComponent::getIContextNetwork() const
|
||||
{
|
||||
if (!this->m_runtime) return nullptr;
|
||||
return this->m_runtime->getIContextNetwork();
|
||||
}
|
||||
|
||||
BlackCore::IContextSettings *CRuntimeBasedComponent::getIContextSettings()
|
||||
{
|
||||
if (!this->m_runtime) return nullptr;
|
||||
return this->m_runtime->getIContextSettings();
|
||||
}
|
||||
|
||||
const BlackCore::IContextSettings *CRuntimeBasedComponent::getIContextSettings() const
|
||||
{
|
||||
if (!this->m_runtime) return nullptr;
|
||||
return this->m_runtime->getIContextSettings();
|
||||
}
|
||||
|
||||
const BlackCore::IContextSimulator *CRuntimeBasedComponent::getIContextSimulator() const
|
||||
{
|
||||
if (!this->m_runtime) return nullptr;
|
||||
return this->m_runtime->getIContextSimulator();
|
||||
}
|
||||
|
||||
BlackCore::IContextSimulator *CRuntimeBasedComponent::getIContextSimulator()
|
||||
{
|
||||
if (!this->m_runtime) return nullptr;
|
||||
return this->m_runtime->getIContextSimulator();
|
||||
}
|
||||
}
|
||||
78
src/blackgui/runtimebasedcomponent.h
Normal file
78
src/blackgui/runtimebasedcomponent.h
Normal file
@@ -0,0 +1,78 @@
|
||||
#ifndef BLACKGUI_RUNTIMEBASEDCOMPONENT_H
|
||||
#define BLACKGUI_RUNTIMEBASEDCOMPONENT_H
|
||||
|
||||
#include "blackcore/context_runtime.h"
|
||||
#include "blackcore/context_all_interfaces.h"
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
/*!
|
||||
* \brief Component, which provides reference to runtime object
|
||||
* \details Access to runtime allows to encapsualate many aspects of data access and makes
|
||||
* the component widely independent from a central data provideer
|
||||
* \sa BlackCore::CRuntime
|
||||
*/
|
||||
class CRuntimeBasedComponent
|
||||
{
|
||||
public:
|
||||
//! Set runtime, usually set by runtime owner (must only be one, usually main window)
|
||||
void setRuntime(BlackCore::CRuntime *runtime, bool runtimeOwner = false) { this->m_runtime = runtime; this->m_runtimeOwner = runtimeOwner; }
|
||||
|
||||
protected:
|
||||
//! Constructor
|
||||
//! \remarks usually runtime will be provide later, not at initialization time
|
||||
CRuntimeBasedComponent(BlackCore::CRuntime *runtime = nullptr, bool runtimeOwner = false) :
|
||||
m_runtime(runtime), m_runtimeOwner(runtimeOwner)
|
||||
{}
|
||||
|
||||
//! Runtime const
|
||||
const BlackCore::CRuntime *getRuntime() const { return this->m_runtime;}
|
||||
|
||||
//! Runtime non const
|
||||
BlackCore::CRuntime *getRuntime() { return this->m_runtime;}
|
||||
|
||||
//! Create a runtime (becomes owner). Only create one runtime.
|
||||
void createRuntime(const BlackCore::CRuntimeConfig &config, QObject *parent);
|
||||
|
||||
//! Context for network
|
||||
BlackCore::IContextNetwork *getIContextNetwork();
|
||||
|
||||
//! Context for network
|
||||
const BlackCore::IContextNetwork *getIContextNetwork() const;
|
||||
|
||||
//! Context for audio
|
||||
BlackCore::IContextAudio *getIContextAudio();
|
||||
|
||||
//! Context for audio
|
||||
const BlackCore::IContextAudio *getIContextAudio() const;
|
||||
|
||||
//! Context for settings
|
||||
BlackCore::IContextSettings *getIContextSettings();
|
||||
|
||||
//! Context for settings
|
||||
const BlackCore::IContextSettings *getIContextSettings() const;
|
||||
|
||||
//! Context for application
|
||||
const BlackCore::IContextApplication *getIContextApplication() const;
|
||||
|
||||
//! Context for application
|
||||
BlackCore::IContextApplication *getIContextApplication();
|
||||
|
||||
//! Context for simulator
|
||||
const BlackCore::IContextSimulator *getIContextSimulator() const;
|
||||
|
||||
//! Context for simulator
|
||||
BlackCore::IContextSimulator *getIContextSimulator();
|
||||
|
||||
//! Owner?
|
||||
bool isRuntimeOwner() const { return this->m_runtimeOwner; }
|
||||
|
||||
private:
|
||||
BlackCore::CRuntime *m_runtime;
|
||||
bool m_runtimeOwner;
|
||||
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // guard
|
||||
Reference in New Issue
Block a user