ok ecdf3f75d67985147b0667c947b121cdffc3a53c
@@ -1,48 +1,51 | |||
|
1 | 1 | #ifndef SCIQLOP_VARIABLECONTROLLER_H |
|
2 | 2 | #define SCIQLOP_VARIABLECONTROLLER_H |
|
3 | 3 | |
|
4 | 4 | #include <QLoggingCategory> |
|
5 | 5 | #include <QObject> |
|
6 | 6 | |
|
7 | 7 | #include <Common/spimpl.h> |
|
8 | 8 | |
|
9 | 9 | class IDataProvider; |
|
10 | class TimeController; | |
|
10 | 11 | class Variable; |
|
11 | 12 | class VariableModel; |
|
12 | 13 | |
|
13 | 14 | Q_DECLARE_LOGGING_CATEGORY(LOG_VariableController) |
|
14 | 15 | |
|
15 | 16 | /** |
|
16 | 17 | * @brief The VariableController class aims to handle the variables in SciQlop. |
|
17 | 18 | */ |
|
18 | 19 | class VariableController : public QObject { |
|
19 | 20 | Q_OBJECT |
|
20 | 21 | public: |
|
21 | 22 | explicit VariableController(QObject *parent = 0); |
|
22 | 23 | virtual ~VariableController(); |
|
23 | 24 | |
|
24 | 25 | VariableModel *variableModel() noexcept; |
|
25 | 26 | |
|
27 | void setTimeController(TimeController *timeController) noexcept; | |
|
28 | ||
|
26 | 29 | signals: |
|
27 | 30 | /// Signal emitted when a variable has been created |
|
28 | 31 | void variableCreated(std::shared_ptr<Variable> variable); |
|
29 | 32 | |
|
30 | 33 | public slots: |
|
31 | 34 | /** |
|
32 | 35 | * Creates a new variable and adds it to the model |
|
33 | 36 | * @param name the name of the new variable |
|
34 | 37 | * @param provider the data provider for the new variable |
|
35 | 38 | */ |
|
36 | 39 | void createVariable(const QString &name, std::shared_ptr<IDataProvider> provider) noexcept; |
|
37 | 40 | |
|
38 | 41 | void initialize(); |
|
39 | 42 | void finalize(); |
|
40 | 43 | |
|
41 | 44 | private: |
|
42 | 45 | void waitForFinish(); |
|
43 | 46 | |
|
44 | 47 | class VariableControllerPrivate; |
|
45 | 48 | spimpl::unique_impl_ptr<VariableControllerPrivate> impl; |
|
46 | 49 | }; |
|
47 | 50 | |
|
48 | 51 | #endif // SCIQLOP_VARIABLECONTROLLER_H |
@@ -1,91 +1,110 | |||
|
1 | 1 | #include <Variable/VariableController.h> |
|
2 | 2 | #include <Variable/VariableModel.h> |
|
3 | 3 | |
|
4 | 4 | #include <Data/DataProviderParameters.h> |
|
5 | 5 | #include <Data/IDataProvider.h> |
|
6 | 6 | #include <Data/IDataSeries.h> |
|
7 | #include <Time/TimeController.h> | |
|
7 | 8 | |
|
8 | 9 | #include <QDateTime> |
|
9 | 10 | #include <QMutex> |
|
10 | 11 | #include <QThread> |
|
11 | 12 | |
|
12 | 13 | Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController") |
|
13 | 14 | |
|
14 | 15 | namespace { |
|
15 | 16 | |
|
16 | 17 | /// @todo Generates default dataseries, according to the provider passed in parameter. This method |
|
17 | 18 | /// will be deleted when the timerange is recovered from SciQlop |
|
18 |
std::unique_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider |
|
|
19 | std::unique_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider, | |
|
20 | const SqpDateTime &dateTime) noexcept | |
|
19 | 21 | { |
|
20 | auto parameters = DataProviderParameters{ | |
|
21 | // Remarks : we don't use toSecsSinceEpoch() here (method is for Qt 5.8 or above) | |
|
22 | static_cast<double>(QDateTime{QDate{2017, 01, 01}, QTime{12, 00}}.toMSecsSinceEpoch() | |
|
23 | / 1000.), | |
|
24 | static_cast<double>(QDateTime{QDate{2017, 01, 01}, QTime{12, 01}}.toMSecsSinceEpoch()) | |
|
25 | / 1000.}; | |
|
22 | auto parameters = DataProviderParameters{dateTime}; | |
|
26 | 23 | |
|
27 | 24 | return provider.retrieveData(parameters); |
|
28 | 25 | } |
|
29 | 26 | |
|
30 | 27 | } // namespace |
|
31 | 28 | |
|
32 | 29 | struct VariableController::VariableControllerPrivate { |
|
33 | 30 | explicit VariableControllerPrivate(VariableController *parent) |
|
34 | 31 | : m_WorkingMutex{}, m_VariableModel{new VariableModel{parent}} |
|
35 | 32 | { |
|
36 | 33 | } |
|
37 | 34 | |
|
38 | 35 | QMutex m_WorkingMutex; |
|
39 | 36 | /// Variable model. The VariableController has the ownership |
|
40 | 37 | VariableModel *m_VariableModel; |
|
38 | ||
|
39 |
TimeController *m_TimeController;
|
|
|
41 | 40 | }; |
|
42 | 41 | |
|
43 | 42 | VariableController::VariableController(QObject *parent) |
|
44 | 43 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)} |
|
45 | 44 | { |
|
46 | 45 | qCDebug(LOG_VariableController()) << tr("VariableController construction") |
|
47 | 46 | << QThread::currentThread(); |
|
48 | 47 | } |
|
49 | 48 | |
|
50 | 49 | VariableController::~VariableController() |
|
51 | 50 | { |
|
52 | 51 | qCDebug(LOG_VariableController()) << tr("VariableController destruction") |
|
53 | 52 | << QThread::currentThread(); |
|
54 | 53 | this->waitForFinish(); |
|
55 | 54 | } |
|
56 | 55 | |
|
57 | 56 | VariableModel *VariableController::variableModel() noexcept |
|
58 | 57 | { |
|
59 | 58 | return impl->m_VariableModel; |
|
60 | 59 | } |
|
61 | 60 | |
|
61 | void VariableController::setTimeController(TimeController *timeController) noexcept | |
|
62 | { | |
|
63 | impl->m_TimeController = timeController; | |
|
64 | } | |
|
65 | ||
|
62 | 66 | void VariableController::createVariable(const QString &name, |
|
63 | 67 | std::shared_ptr<IDataProvider> provider) noexcept |
|
64 | 68 | { |
|
69 | // TORM | |
|
70 | // auto dateTime = SqpDateTime{ | |
|
71 | // // Remarks : we don't use toSecsSinceEpoch() here (method is for Qt 5.8 or above) | |
|
72 | // static_cast<double>(QDateTime{QDate{2017, 01, 01}, QTime{12, 00}}.toMSecsSinceEpoch() | |
|
73 | // / 1000.), | |
|
74 | // static_cast<double>(QDateTime{QDate{2017, 01, 01}, QTime{12, 01}}.toMSecsSinceEpoch()) | |
|
75 | // / 1000.}; | |
|
76 | ||
|
77 | if (!impl->m_TimeController) { | |
|
78 | qCCritical(LOG_VariableController()) | |
|
79 | << tr("Impossible to create variable: The time controller is null"); | |
|
80 | return; | |
|
81 | } | |
|
82 | ||
|
83 | ||
|
65 | 84 | /// @todo : for the moment : |
|
66 | 85 | /// - the provider is only used to retrieve data from the variable for its initialization, but |
|
67 | 86 | /// it will be retained later |
|
68 | 87 | /// - default data are generated for the variable, without taking into account the timerange set |
|
69 | 88 | /// in sciqlop |
|
70 | if (auto newVariable | |
|
71 | = impl->m_VariableModel->createVariable(name, generateDefaultDataSeries(*provider))) { | |
|
89 | if (auto newVariable = impl->m_VariableModel->createVariable( | |
|
90 | name, generateDefaultDataSeries(*provider, impl->m_TimeController->dateTime()))) { | |
|
72 | 91 | emit variableCreated(newVariable); |
|
73 | 92 | } |
|
74 | 93 | } |
|
75 | 94 | |
|
76 | 95 | void VariableController::initialize() |
|
77 | 96 | { |
|
78 | 97 | qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread(); |
|
79 | 98 | impl->m_WorkingMutex.lock(); |
|
80 | 99 | qCDebug(LOG_VariableController()) << tr("VariableController init END"); |
|
81 | 100 | } |
|
82 | 101 | |
|
83 | 102 | void VariableController::finalize() |
|
84 | 103 | { |
|
85 | 104 | impl->m_WorkingMutex.unlock(); |
|
86 | 105 | } |
|
87 | 106 | |
|
88 | 107 | void VariableController::waitForFinish() |
|
89 | 108 | { |
|
90 | 109 | QMutexLocker locker{&impl->m_WorkingMutex}; |
|
91 | 110 | } |
@@ -1,48 +1,50 | |||
|
1 | 1 | #ifndef SCIQLOP_SQPAPPLICATION_H |
|
2 | 2 | #define SCIQLOP_SQPAPPLICATION_H |
|
3 | 3 | |
|
4 | 4 | #include "SqpApplication.h" |
|
5 | 5 | |
|
6 | 6 | #include <QApplication> |
|
7 | 7 | #include <QLoggingCategory> |
|
8 | 8 | |
|
9 | 9 | #include <Common/spimpl.h> |
|
10 | 10 | |
|
11 | 11 | Q_DECLARE_LOGGING_CATEGORY(LOG_SqpApplication) |
|
12 | 12 | |
|
13 | 13 | #if defined(sqpApp) |
|
14 | 14 | #undef sqpApp |
|
15 | 15 | #endif |
|
16 | 16 | #define sqpApp (static_cast<SqpApplication *>(QCoreApplication::instance())) |
|
17 | 17 | |
|
18 | 18 | class DataSourceController; |
|
19 | class TimeController; | |
|
19 | 20 | class VariableController; |
|
20 | 21 | class VisualizationController; |
|
21 | 22 | |
|
22 | 23 | /** |
|
23 | 24 | * @brief The SqpApplication class aims to make the link between SciQlop |
|
24 | 25 | * and its plugins. This is the intermediate class that SciQlop has to use |
|
25 | 26 | * in the way to connect a data source. Please first use load method to initialize |
|
26 | 27 | * a plugin specified by its metadata name (JSON plugin source) then others specifics |
|
27 | 28 | * method will be able to access it. |
|
28 | 29 | * You can load a data source driver plugin then create a data source. |
|
29 | 30 | */ |
|
30 | 31 | |
|
31 | 32 | class SqpApplication : public QApplication { |
|
32 | 33 | Q_OBJECT |
|
33 | 34 | public: |
|
34 | 35 | explicit SqpApplication(int &argc, char **argv); |
|
35 | 36 | virtual ~SqpApplication(); |
|
36 | 37 | void initialize(); |
|
37 | 38 | |
|
38 | 39 | /// Accessors for the differents sciqlop controllers |
|
39 | 40 | DataSourceController &dataSourceController() noexcept; |
|
41 | TimeController &timeController() noexcept; | |
|
40 | 42 | VariableController &variableController() noexcept; |
|
41 | 43 | VisualizationController &visualizationController() noexcept; |
|
42 | 44 | |
|
43 | 45 | private: |
|
44 | 46 | class SqpApplicationPrivate; |
|
45 | 47 | spimpl::unique_impl_ptr<SqpApplicationPrivate> impl; |
|
46 | 48 | }; |
|
47 | 49 | |
|
48 | 50 | #endif // SCIQLOP_SQPAPPLICATION_H |
@@ -1,109 +1,120 | |||
|
1 | 1 | #include "SqpApplication.h" |
|
2 | 2 | |
|
3 | 3 | #include <Data/IDataProvider.h> |
|
4 | 4 | #include <DataSource/DataSourceController.h> |
|
5 | 5 | #include <QThread> |
|
6 | #include <Time/TimeController.h> | |
|
6 | 7 | #include <Variable/Variable.h> |
|
7 | 8 | #include <Variable/VariableController.h> |
|
8 | 9 | #include <Visualization/VisualizationController.h> |
|
9 | 10 | |
|
10 | 11 | Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication") |
|
11 | 12 | |
|
12 | 13 | class SqpApplication::SqpApplicationPrivate { |
|
13 | 14 | public: |
|
14 | 15 | SqpApplicationPrivate() |
|
15 | 16 | : m_DataSourceController{std::make_unique<DataSourceController>()}, |
|
17 | m_TimeController{std::make_unique<TimeController>()}, | |
|
16 | 18 | m_VariableController{std::make_unique<VariableController>()}, |
|
17 | 19 | m_VisualizationController{std::make_unique<VisualizationController>()} |
|
18 | 20 | { |
|
19 | 21 | // /////////////////////////////// // |
|
20 | 22 | // Connections between controllers // |
|
21 | 23 | // /////////////////////////////// // |
|
22 | 24 | |
|
23 | 25 | // VariableController <-> DataSourceController |
|
24 | 26 | qRegisterMetaType<std::shared_ptr<IDataProvider> >(); |
|
25 | 27 | connect(m_DataSourceController.get(), |
|
26 | 28 | SIGNAL(variableCreationRequested(const QString &, std::shared_ptr<IDataProvider>)), |
|
27 | 29 | m_VariableController.get(), |
|
28 | 30 | SLOT(createVariable(const QString &, std::shared_ptr<IDataProvider>))); |
|
29 | 31 | |
|
30 | 32 | // VariableController <-> VisualizationController |
|
31 | 33 | qRegisterMetaType<std::shared_ptr<Variable> >(); |
|
32 | 34 | connect(m_VariableController.get(), SIGNAL(variableCreated(std::shared_ptr<Variable>)), |
|
33 | 35 | m_VisualizationController.get(), |
|
34 | 36 | SIGNAL(variableCreated(std::shared_ptr<Variable>))); |
|
35 | 37 | |
|
36 | 38 | m_DataSourceController->moveToThread(&m_DataSourceControllerThread); |
|
37 | 39 | m_VariableController->moveToThread(&m_VariableControllerThread); |
|
38 | 40 | m_VisualizationController->moveToThread(&m_VisualizationControllerThread); |
|
41 | ||
|
42 | // Additionnal init | |
|
43 | m_VariableController->setTimeController(m_TimeController.get()); | |
|
39 | 44 | } |
|
40 | 45 | |
|
41 | 46 | virtual ~SqpApplicationPrivate() |
|
42 | 47 | { |
|
43 | 48 | qCInfo(LOG_SqpApplication()) << tr("SqpApplicationPrivate destruction"); |
|
44 | 49 | m_DataSourceControllerThread.quit(); |
|
45 | 50 | m_DataSourceControllerThread.wait(); |
|
46 | 51 | |
|
47 | 52 | m_VariableControllerThread.quit(); |
|
48 | 53 | m_VariableControllerThread.wait(); |
|
49 | 54 | |
|
50 | 55 | m_VisualizationControllerThread.quit(); |
|
51 | 56 | m_VisualizationControllerThread.wait(); |
|
52 | 57 | } |
|
53 | 58 | |
|
54 | 59 | std::unique_ptr<DataSourceController> m_DataSourceController; |
|
55 | 60 | std::unique_ptr<VariableController> m_VariableController; |
|
61 | std::unique_ptr<TimeController> m_TimeController; | |
|
56 | 62 | std::unique_ptr<VisualizationController> m_VisualizationController; |
|
57 | 63 | QThread m_DataSourceControllerThread; |
|
58 | 64 | QThread m_VariableControllerThread; |
|
59 | 65 | QThread m_VisualizationControllerThread; |
|
60 | 66 | }; |
|
61 | 67 | |
|
62 | 68 | |
|
63 | 69 | SqpApplication::SqpApplication(int &argc, char **argv) |
|
64 | 70 | : QApplication{argc, argv}, impl{spimpl::make_unique_impl<SqpApplicationPrivate>()} |
|
65 | 71 | { |
|
66 | 72 | qCInfo(LOG_SqpApplication()) << tr("SqpApplication construction"); |
|
67 | 73 | |
|
68 | 74 | connect(&impl->m_DataSourceControllerThread, &QThread::started, |
|
69 | 75 | impl->m_DataSourceController.get(), &DataSourceController::initialize); |
|
70 | 76 | connect(&impl->m_DataSourceControllerThread, &QThread::finished, |
|
71 | 77 | impl->m_DataSourceController.get(), &DataSourceController::finalize); |
|
72 | 78 | |
|
73 | 79 | connect(&impl->m_VariableControllerThread, &QThread::started, impl->m_VariableController.get(), |
|
74 | 80 | &VariableController::initialize); |
|
75 | 81 | connect(&impl->m_VariableControllerThread, &QThread::finished, impl->m_VariableController.get(), |
|
76 | 82 | &VariableController::finalize); |
|
77 | 83 | |
|
78 | 84 | connect(&impl->m_VisualizationControllerThread, &QThread::started, |
|
79 | 85 | impl->m_VisualizationController.get(), &VisualizationController::initialize); |
|
80 | 86 | connect(&impl->m_VisualizationControllerThread, &QThread::finished, |
|
81 | 87 | impl->m_VisualizationController.get(), &VisualizationController::finalize); |
|
82 | 88 | |
|
83 | 89 | impl->m_DataSourceControllerThread.start(); |
|
84 | 90 | impl->m_VariableControllerThread.start(); |
|
85 | 91 | impl->m_VisualizationControllerThread.start(); |
|
86 | 92 | } |
|
87 | 93 | |
|
88 | 94 | SqpApplication::~SqpApplication() |
|
89 | 95 | { |
|
90 | 96 | } |
|
91 | 97 | |
|
92 | 98 | void SqpApplication::initialize() |
|
93 | 99 | { |
|
94 | 100 | } |
|
95 | 101 | |
|
96 | 102 | DataSourceController &SqpApplication::dataSourceController() noexcept |
|
97 | 103 | { |
|
98 | 104 | return *impl->m_DataSourceController; |
|
99 | 105 | } |
|
100 | 106 | |
|
107 | TimeController &SqpApplication::timeController() noexcept | |
|
108 | { | |
|
109 | return *impl->m_TimeController; | |
|
110 | } | |
|
111 | ||
|
101 | 112 | VariableController &SqpApplication::variableController() noexcept |
|
102 | 113 | { |
|
103 | 114 | return *impl->m_VariableController; |
|
104 | 115 | } |
|
105 | 116 | |
|
106 | 117 | VisualizationController &SqpApplication::visualizationController() noexcept |
|
107 | 118 | { |
|
108 | 119 | return *impl->m_VisualizationController; |
|
109 | 120 | } |
General Comments 4
Pull request updated. Auto status change to "Under Review"
Changed commits: * 1 added * 0 removed Changed files: * M gui/include/Visualization/VisualizationGraphWidget.h * M gui/src/Visualization/VisualizationGraphWidget.cpp
Status change > Approved
You need to be logged in to leave comments.
Login now