##// END OF EJS Templates
Create a variable notify the variable cache parameter
perrinel -
r225:9423975d81b3
parent child
Show More
@@ -0,0 +1,26
1 #ifndef SCIQLOP_VARIABLECACHECONTROLLER_H
2 #define SCIQLOP_VARIABLECACHECONTROLLER_H
3
4 #include <QObject>
5
6 #include <Data/SqpDateTime.h>
7
8 #include <Common/spimpl.h>
9
10 class Variable;
11
12 /// This class aims to store in the cash all of the dateTime already requested to the variable.
13 class VariableCacheController : public QObject {
14 Q_OBJECT
15 public:
16 explicit VariableCacheController(QObject *parent = 0);
17
18
19 void addDateTime(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime);
20
21 private:
22 class VariableCacheControllerPrivate;
23 spimpl::unique_impl_ptr<VariableCacheControllerPrivate> impl;
24 };
25
26 #endif // SCIQLOP_VARIABLECACHECONTROLLER_H
@@ -0,0 +1,25
1 #include "Variable/VariableCacheController.h"
2
3 #include "Variable/Variable.h"
4 #include <unordered_map>
5
6 struct VariableCacheController::VariableCacheControllerPrivate {
7
8 std::unordered_map<std::shared_ptr<Variable>, std::list<SqpDateTime> >
9 m_VariableToSqpDateTimeListMap;
10 };
11
12
13 VariableCacheController::VariableCacheController(QObject *parent)
14 : QObject(parent), impl{spimpl::make_unique_impl<VariableCacheControllerPrivate>()}
15 {
16 }
17
18 void VariableCacheController::addDateTime(std::shared_ptr<Variable> variable,
19 const SqpDateTime &dateTime)
20 {
21 if (variable) {
22 // TODO: squeeze the map to let it only some SqpDateTime without intersection
23 impl->m_VariableToSqpDateTimeListMap[variable].push_back(dateTime);
24 }
25 }
@@ -1,3 +1,4
1 #include <Variable/VariableCacheController.h>
1 #include <Variable/VariableController.h>
2 #include <Variable/VariableController.h>
2 #include <Variable/VariableModel.h>
3 #include <Variable/VariableModel.h>
3
4
@@ -10,6 +11,8
10 #include <QMutex>
11 #include <QMutex>
11 #include <QThread>
12 #include <QThread>
12
13
14 #include <unordered_map>
15
13 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
16 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
14
17
15 namespace {
18 namespace {
@@ -28,7 +31,9 std::unique_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &prov
28
31
29 struct VariableController::VariableControllerPrivate {
32 struct VariableController::VariableControllerPrivate {
30 explicit VariableControllerPrivate(VariableController *parent)
33 explicit VariableControllerPrivate(VariableController *parent)
31 : m_WorkingMutex{}, m_VariableModel{new VariableModel{parent}}
34 : m_WorkingMutex{},
35 m_VariableModel{new VariableModel{parent}},
36 m_VariableCacheController{std::make_unique<VariableCacheController>()}
32 {
37 {
33 }
38 }
34
39
@@ -36,7 +41,9 struct VariableController::VariableControllerPrivate {
36 /// Variable model. The VariableController has the ownership
41 /// Variable model. The VariableController has the ownership
37 VariableModel *m_VariableModel;
42 VariableModel *m_VariableModel;
38
43
44
39 TimeController *m_TimeController{nullptr};
45 TimeController *m_TimeController{nullptr};
46 std::unique_ptr<VariableCacheController> m_VariableCacheController;
40 };
47 };
41
48
42 VariableController::VariableController(QObject *parent)
49 VariableController::VariableController(QObject *parent)
@@ -86,8 +93,14 void VariableController::createVariable(const QString &name,
86 /// it will be retained later
93 /// it will be retained later
87 /// - default data are generated for the variable, without taking into account the timerange set
94 /// - default data are generated for the variable, without taking into account the timerange set
88 /// in sciqlop
95 /// in sciqlop
96 auto dateTime = impl->m_TimeController->dateTime();
89 if (auto newVariable = impl->m_VariableModel->createVariable(
97 if (auto newVariable = impl->m_VariableModel->createVariable(
90 name, generateDefaultDataSeries(*provider, impl->m_TimeController->dateTime()))) {
98 name, generateDefaultDataSeries(*provider, dateTime))) {
99
100 // store in cache
101 impl->m_VariableCacheController->addDateTime(newVariable, dateTime);
102
103 // notify the creation
91 emit variableCreated(newVariable);
104 emit variableCreated(newVariable);
92 }
105 }
93 }
106 }
General Comments 0
You need to be logged in to leave comments. Login now