##// END OF EJS Templates
Correction MR
perrinel -
r195:ecdf3f75d679
parent child
Show More
@@ -1,15 +1,14
1 #ifndef SCIQLOP_SQPDATETIME_H
1 #ifndef SCIQLOP_SQPDATETIME_H
2 #define SCIQLOP_SQPDATETIME_H
2 #define SCIQLOP_SQPDATETIME_H
3
3
4 /**
4 /**
5 * @brief The SqpDateTime struct holds the information of time parameters
5 * @brief The SqpDateTime struct holds the information of time parameters
6 * @sa SqpDateTime
7 */
6 */
8 struct SqpDateTime {
7 struct SqpDateTime {
9 /// Start time
8 /// Start time
10 double m_TStart;
9 double m_TStart;
11 /// End time
10 /// End time
12 double m_TEnd;
11 double m_TEnd;
13 };
12 };
14
13
15 #endif // SCIQLOP_SQPDATETIME_H
14 #endif // SCIQLOP_SQPDATETIME_H
@@ -1,110 +1,110
1 #include <Variable/VariableController.h>
1 #include <Variable/VariableController.h>
2 #include <Variable/VariableModel.h>
2 #include <Variable/VariableModel.h>
3
3
4 #include <Data/DataProviderParameters.h>
4 #include <Data/DataProviderParameters.h>
5 #include <Data/IDataProvider.h>
5 #include <Data/IDataProvider.h>
6 #include <Data/IDataSeries.h>
6 #include <Data/IDataSeries.h>
7 #include <Time/TimeController.h>
7 #include <Time/TimeController.h>
8
8
9 #include <QDateTime>
9 #include <QDateTime>
10 #include <QMutex>
10 #include <QMutex>
11 #include <QThread>
11 #include <QThread>
12
12
13 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
13 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
14
14
15 namespace {
15 namespace {
16
16
17 /// @todo Generates default dataseries, according to the provider passed in parameter. This method
17 /// @todo Generates default dataseries, according to the provider passed in parameter. This method
18 /// will be deleted when the timerange is recovered from SciQlop
18 /// will be deleted when the timerange is recovered from SciQlop
19 std::unique_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider,
19 std::unique_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider,
20 const SqpDateTime &dateTime) noexcept
20 const SqpDateTime &dateTime) noexcept
21 {
21 {
22 auto parameters = DataProviderParameters{dateTime};
22 auto parameters = DataProviderParameters{dateTime};
23
23
24 return provider.retrieveData(parameters);
24 return provider.retrieveData(parameters);
25 }
25 }
26
26
27 } // namespace
27 } // namespace
28
28
29 struct VariableController::VariableControllerPrivate {
29 struct VariableController::VariableControllerPrivate {
30 explicit VariableControllerPrivate(VariableController *parent)
30 explicit VariableControllerPrivate(VariableController *parent)
31 : m_WorkingMutex{}, m_VariableModel{new VariableModel{parent}}
31 : m_WorkingMutex{}, m_VariableModel{new VariableModel{parent}}
32 {
32 {
33 }
33 }
34
34
35 QMutex m_WorkingMutex;
35 QMutex m_WorkingMutex;
36 /// Variable model. The VariableController has the ownership
36 /// Variable model. The VariableController has the ownership
37 VariableModel *m_VariableModel;
37 VariableModel *m_VariableModel;
38
38
39 TimeController *m_TimeController;
39 TimeController *m_TimeController{nullptr};
40 };
40 };
41
41
42 VariableController::VariableController(QObject *parent)
42 VariableController::VariableController(QObject *parent)
43 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
43 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
44 {
44 {
45 qCDebug(LOG_VariableController()) << tr("VariableController construction")
45 qCDebug(LOG_VariableController()) << tr("VariableController construction")
46 << QThread::currentThread();
46 << QThread::currentThread();
47 }
47 }
48
48
49 VariableController::~VariableController()
49 VariableController::~VariableController()
50 {
50 {
51 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
51 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
52 << QThread::currentThread();
52 << QThread::currentThread();
53 this->waitForFinish();
53 this->waitForFinish();
54 }
54 }
55
55
56 VariableModel *VariableController::variableModel() noexcept
56 VariableModel *VariableController::variableModel() noexcept
57 {
57 {
58 return impl->m_VariableModel;
58 return impl->m_VariableModel;
59 }
59 }
60
60
61 void VariableController::setTimeController(TimeController *timeController) noexcept
61 void VariableController::setTimeController(TimeController *timeController) noexcept
62 {
62 {
63 impl->m_TimeController = timeController;
63 impl->m_TimeController = timeController;
64 }
64 }
65
65
66 void VariableController::createVariable(const QString &name,
66 void VariableController::createVariable(const QString &name,
67 std::shared_ptr<IDataProvider> provider) noexcept
67 std::shared_ptr<IDataProvider> provider) noexcept
68 {
68 {
69 // TORM
69 // TORM
70 // auto dateTime = SqpDateTime{
70 // auto dateTime = SqpDateTime{
71 // // Remarks : we don't use toSecsSinceEpoch() here (method is for Qt 5.8 or above)
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()
72 // static_cast<double>(QDateTime{QDate{2017, 01, 01}, QTime{12, 00}}.toMSecsSinceEpoch()
73 // / 1000.),
73 // / 1000.),
74 // static_cast<double>(QDateTime{QDate{2017, 01, 01}, QTime{12, 01}}.toMSecsSinceEpoch())
74 // static_cast<double>(QDateTime{QDate{2017, 01, 01}, QTime{12, 01}}.toMSecsSinceEpoch())
75 // / 1000.};
75 // / 1000.};
76
76
77 if (!impl->m_TimeController) {
77 if (!impl->m_TimeController) {
78 qCCritical(LOG_VariableController())
78 qCCritical(LOG_VariableController())
79 << tr("Impossible to create variable: The time controller is null");
79 << tr("Impossible to create variable: The time controller is null");
80 return;
80 return;
81 }
81 }
82
82
83
83
84 /// @todo : for the moment :
84 /// @todo : for the moment :
85 /// - the provider is only used to retrieve data from the variable for its initialization, but
85 /// - the provider is only used to retrieve data from the variable for its initialization, but
86 /// it will be retained later
86 /// it will be retained later
87 /// - default data are generated for the variable, without taking into account the timerange set
87 /// - default data are generated for the variable, without taking into account the timerange set
88 /// in sciqlop
88 /// in sciqlop
89 if (auto newVariable = impl->m_VariableModel->createVariable(
89 if (auto newVariable = impl->m_VariableModel->createVariable(
90 name, generateDefaultDataSeries(*provider, impl->m_TimeController->dateTime()))) {
90 name, generateDefaultDataSeries(*provider, impl->m_TimeController->dateTime()))) {
91 emit variableCreated(newVariable);
91 emit variableCreated(newVariable);
92 }
92 }
93 }
93 }
94
94
95 void VariableController::initialize()
95 void VariableController::initialize()
96 {
96 {
97 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
97 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
98 impl->m_WorkingMutex.lock();
98 impl->m_WorkingMutex.lock();
99 qCDebug(LOG_VariableController()) << tr("VariableController init END");
99 qCDebug(LOG_VariableController()) << tr("VariableController init END");
100 }
100 }
101
101
102 void VariableController::finalize()
102 void VariableController::finalize()
103 {
103 {
104 impl->m_WorkingMutex.unlock();
104 impl->m_WorkingMutex.unlock();
105 }
105 }
106
106
107 void VariableController::waitForFinish()
107 void VariableController::waitForFinish()
108 {
108 {
109 QMutexLocker locker{&impl->m_WorkingMutex};
109 QMutexLocker locker{&impl->m_WorkingMutex};
110 }
110 }
General Comments 0
You need to be logged in to leave comments. Login now