SqpApplication.cpp
163 lines
| 6.4 KiB
| text/x-c
|
CppLexer
r21 | #include "SqpApplication.h" | |||
|
r169 | #include <Data/IDataProvider.h> | ||
r21 | #include <DataSource/DataSourceController.h> | |||
r884 | #include <DragAndDrop/DragDropHelper.h> | |||
r339 | #include <Network/NetworkController.h> | |||
r21 | #include <QThread> | |||
r193 | #include <Time/TimeController.h> | |||
|
r170 | #include <Variable/Variable.h> | ||
|
r111 | #include <Variable/VariableController.h> | ||
r870 | #include <Variable/VariableModel.h> | |||
r53 | #include <Visualization/VisualizationController.h> | |||
r21 | ||||
Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication") | ||||
class SqpApplication::SqpApplicationPrivate { | ||||
public: | ||||
r55 | SqpApplicationPrivate() | |||
: m_DataSourceController{std::make_unique<DataSourceController>()}, | ||||
r339 | m_NetworkController{std::make_unique<NetworkController>()}, | |||
r193 | m_TimeController{std::make_unique<TimeController>()}, | |||
|
r111 | m_VariableController{std::make_unique<VariableController>()}, | ||
r837 | m_VisualizationController{std::make_unique<VisualizationController>()}, | |||
m_DragDropHelper{std::make_unique<DragDropHelper>()} | ||||
|
r32 | { | ||
|
r169 | // /////////////////////////////// // | ||
// Connections between controllers // | ||||
// /////////////////////////////// // | ||||
// VariableController <-> DataSourceController | ||||
connect(m_DataSourceController.get(), | ||||
|
r410 | SIGNAL(variableCreationRequested(const QString &, const QVariantHash &, | ||
std::shared_ptr<IDataProvider>)), | ||||
|
r169 | m_VariableController.get(), | ||
|
r410 | SLOT(createVariable(const QString &, const QVariantHash &, | ||
std::shared_ptr<IDataProvider>))); | ||||
|
r169 | |||
r870 | connect(m_VariableController->variableModel(), &VariableModel::requestVariable, | |||
m_DataSourceController.get(), &DataSourceController::requestVariable); | ||||
|
r170 | // VariableController <-> VisualizationController | ||
|
r336 | connect(m_VariableController.get(), | ||
SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), | ||||
m_VisualizationController.get(), | ||||
SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), Qt::DirectConnection); | ||||
|
r170 | |||
r437 | connect(m_VariableController.get(), | |||
r512 | SIGNAL(rangeChanged(std::shared_ptr<Variable>, const SqpRange &)), | |||
r437 | m_VisualizationController.get(), | |||
r512 | SIGNAL(rangeChanged(std::shared_ptr<Variable>, const SqpRange &))); | |||
r437 | ||||
r193 | ||||
|
r32 | m_DataSourceController->moveToThread(&m_DataSourceControllerThread); | ||
r429 | m_DataSourceControllerThread.setObjectName("DataSourceControllerThread"); | |||
r339 | m_NetworkController->moveToThread(&m_NetworkControllerThread); | |||
r429 | m_NetworkControllerThread.setObjectName("NetworkControllerThread"); | |||
|
r111 | m_VariableController->moveToThread(&m_VariableControllerThread); | ||
r429 | m_VariableControllerThread.setObjectName("VariableControllerThread"); | |||
r55 | m_VisualizationController->moveToThread(&m_VisualizationControllerThread); | |||
r429 | m_VisualizationControllerThread.setObjectName("VsualizationControllerThread"); | |||
r193 | ||||
r374 | ||||
r193 | // Additionnal init | |||
m_VariableController->setTimeController(m_TimeController.get()); | ||||
|
r32 | } | ||
r24 | virtual ~SqpApplicationPrivate() | |||
r22 | { | |||
m_DataSourceControllerThread.quit(); | ||||
m_DataSourceControllerThread.wait(); | ||||
r53 | ||||
r339 | m_NetworkControllerThread.quit(); | |||
m_NetworkControllerThread.wait(); | ||||
|
r111 | m_VariableControllerThread.quit(); | ||
m_VariableControllerThread.wait(); | ||||
r55 | m_VisualizationControllerThread.quit(); | |||
m_VisualizationControllerThread.wait(); | ||||
r22 | } | |||
r21 | ||||
std::unique_ptr<DataSourceController> m_DataSourceController; | ||||
|
r111 | std::unique_ptr<VariableController> m_VariableController; | ||
r193 | std::unique_ptr<TimeController> m_TimeController; | |||
r339 | std::unique_ptr<NetworkController> m_NetworkController; | |||
r53 | std::unique_ptr<VisualizationController> m_VisualizationController; | |||
r21 | QThread m_DataSourceControllerThread; | |||
r339 | QThread m_NetworkControllerThread; | |||
|
r111 | QThread m_VariableControllerThread; | ||
r55 | QThread m_VisualizationControllerThread; | |||
r837 | ||||
std::unique_ptr<DragDropHelper> m_DragDropHelper; | ||||
r21 | }; | |||
SqpApplication::SqpApplication(int &argc, char **argv) | ||||
|
r32 | : QApplication{argc, argv}, impl{spimpl::make_unique_impl<SqpApplicationPrivate>()} | ||
r21 | { | |||
r389 | qCDebug(LOG_SqpApplication()) << tr("SqpApplication construction") << QThread::currentThread(); | |||
r21 | ||||
connect(&impl->m_DataSourceControllerThread, &QThread::started, | ||||
impl->m_DataSourceController.get(), &DataSourceController::initialize); | ||||
connect(&impl->m_DataSourceControllerThread, &QThread::finished, | ||||
impl->m_DataSourceController.get(), &DataSourceController::finalize); | ||||
r339 | connect(&impl->m_NetworkControllerThread, &QThread::started, impl->m_NetworkController.get(), | |||
&NetworkController::initialize); | ||||
connect(&impl->m_NetworkControllerThread, &QThread::finished, impl->m_NetworkController.get(), | ||||
&NetworkController::finalize); | ||||
|
r111 | connect(&impl->m_VariableControllerThread, &QThread::started, impl->m_VariableController.get(), | ||
&VariableController::initialize); | ||||
connect(&impl->m_VariableControllerThread, &QThread::finished, impl->m_VariableController.get(), | ||||
&VariableController::finalize); | ||||
r55 | connect(&impl->m_VisualizationControllerThread, &QThread::started, | |||
impl->m_VisualizationController.get(), &VisualizationController::initialize); | ||||
connect(&impl->m_VisualizationControllerThread, &QThread::finished, | ||||
impl->m_VisualizationController.get(), &VisualizationController::finalize); | ||||
r53 | ||||
r21 | impl->m_DataSourceControllerThread.start(); | |||
r339 | impl->m_NetworkControllerThread.start(); | |||
|
r111 | impl->m_VariableControllerThread.start(); | ||
r55 | impl->m_VisualizationControllerThread.start(); | |||
r21 | } | |||
r845 | SqpApplication::~SqpApplication() | |||
{ | ||||
} | ||||
r21 | ||||
r845 | void SqpApplication::initialize() | |||
{ | ||||
} | ||||
|
r33 | |||
|
r116 | DataSourceController &SqpApplication::dataSourceController() noexcept | ||
|
r33 | { | ||
return *impl->m_DataSourceController; | ||||
} | ||||
r53 | ||||
r339 | NetworkController &SqpApplication::networkController() noexcept | |||
{ | ||||
return *impl->m_NetworkController; | ||||
} | ||||
r193 | TimeController &SqpApplication::timeController() noexcept | |||
{ | ||||
return *impl->m_TimeController; | ||||
} | ||||
|
r116 | VariableController &SqpApplication::variableController() noexcept | ||
|
r111 | { | ||
return *impl->m_VariableController; | ||||
} | ||||
|
r116 | VisualizationController &SqpApplication::visualizationController() noexcept | ||
r53 | { | |||
return *impl->m_VisualizationController; | ||||
} | ||||
r837 | ||||
DragDropHelper &SqpApplication::dragDropHelper() noexcept | ||||
{ | ||||
return *impl->m_DragDropHelper; | ||||
} | ||||