diff --git a/samples/blackgui/mainwindow_init.cpp b/samples/blackgui/mainwindow_init.cpp index d55d4936a..3707ba59a 100644 --- a/samples/blackgui/mainwindow_init.cpp +++ b/samples/blackgui/mainwindow_init.cpp @@ -78,7 +78,7 @@ void MainWindow::init(const CRuntimeConfig &runtimeConfig) // context this->createRuntime(runtimeConfig, this); - this->ui->comp_Flightplan->setRuntime(this->getRuntime()); + CRuntimeBasedComponent::setRuntimeForComponents(this->getRuntime(), this); // wire GUI signals this->initGuiSignals(); diff --git a/src/blackgui/runtimebasedcomponent.cpp b/src/blackgui/runtimebasedcomponent.cpp index ab3b5d69a..54d767f70 100644 --- a/src/blackgui/runtimebasedcomponent.cpp +++ b/src/blackgui/runtimebasedcomponent.cpp @@ -1,4 +1,5 @@ #include "runtimebasedcomponent.h" +#include namespace BlackGui { @@ -26,6 +27,18 @@ namespace BlackGui return this->m_runtime->getIContextAudio(); } + void CRuntimeBasedComponent::setRuntimeForComponents(BlackCore::CRuntime *runtime, QWidget *parent) + { + if (!parent) return; + QList children = parent->findChildren(); + foreach(QWidget * widget, children) + { + if (widget->objectName().isEmpty()) continue; // rule out unamed widgets + CRuntimeBasedComponent *rbc = dynamic_cast(widget); + if (rbc) rbc->setRuntime(runtime, false); + } + } + void CRuntimeBasedComponent::createRuntime(const BlackCore::CRuntimeConfig &config, QObject *parent) { this->m_runtime = new BlackCore::CRuntime(config, parent); @@ -67,4 +80,16 @@ namespace BlackGui if (!this->m_runtime) return nullptr; return this->m_runtime->getIContextSimulator(); } + + void CRuntimeBasedComponent::sendStatusMessage(const BlackMisc::CStatusMessage &statusMessage) + { + Q_ASSERT(this->getIContextApplication()); + this->getIContextApplication()->sendStatusMessage(statusMessage); + } + + void CRuntimeBasedComponent::sendStatusMessages(const BlackMisc::CStatusMessageList &statusMessages) + { + Q_ASSERT(this->getIContextApplication()); + this->getIContextApplication()->sendStatusMessages(statusMessages); + } } diff --git a/src/blackgui/runtimebasedcomponent.h b/src/blackgui/runtimebasedcomponent.h index d54ec4ace..b50ce0e43 100644 --- a/src/blackgui/runtimebasedcomponent.h +++ b/src/blackgui/runtimebasedcomponent.h @@ -16,7 +16,13 @@ namespace BlackGui { 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; } + void setRuntime(BlackCore::CRuntime *runtime, bool runtimeOwner = false) + { + this->m_runtime = runtime; this->m_runtimeOwner = runtimeOwner; + } + + //! Set runtime for each CRuntimeBasedComponent + static void setRuntimeForComponents(BlackCore::CRuntime *runtime, QWidget *parent); protected: //! Constructor @@ -64,6 +70,12 @@ namespace BlackGui //! Context for simulator BlackCore::IContextSimulator *getIContextSimulator(); + //! Send status message (via application context) + void sendStatusMessage(const BlackMisc::CStatusMessage &statusMessage); + + //! Send status message (via application context) + void sendStatusMessages(const BlackMisc::CStatusMessageList &statusMessages); + //! Owner? bool isRuntimeOwner() const { return this->m_runtimeOwner; }