##// END OF EJS Templates
Updates VariableController::createVariable() method...
Alexandre Leroux -
r166:ab6272d8de5a
parent child
Show More
@@ -6,6 +6,7
6
6
7 #include <Common/spimpl.h>
7 #include <Common/spimpl.h>
8
8
9 class IDataProvider;
9 class Variable;
10 class Variable;
10 class VariableModel;
11 class VariableModel;
11
12
@@ -20,16 +21,20 public:
20 explicit VariableController(QObject *parent = 0);
21 explicit VariableController(QObject *parent = 0);
21 virtual ~VariableController();
22 virtual ~VariableController();
22
23
24 VariableModel *variableModel() noexcept;
25
26 signals:
27 /// Signal emitted when a variable has been created
28 void variableCreated(std::shared_ptr<Variable> variable);
29
30 public slots:
23 /**
31 /**
24 * Creates a new variable
32 * Creates a new variable and adds it to the model
25 * @param name the name of the new variable
33 * @param name the name of the new variable
26 * @return the variable if it was created successfully, nullptr otherwise
34 * @param provider the data provider for the new variable
27 */
35 */
28 Variable *createVariable(const QString &name) noexcept;
36 void createVariable(const QString &name, std::shared_ptr<IDataProvider> provider) noexcept;
29
37
30 VariableModel *variableModel() noexcept;
31
32 public slots:
33 void initialize();
38 void initialize();
34 void finalize();
39 void finalize();
35
40
@@ -1,11 +1,31
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>
5 #include <Data/IDataProvider.h>
6 #include <Data/IDataSeries.h>
7
8 #include <QDateTime>
4 #include <QMutex>
9 #include <QMutex>
5 #include <QThread>
10 #include <QThread>
6
11
7 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
12 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
8
13
14 namespace {
15
16 /// @todo Generates default dataseries, according to the provider passed in parameter. This method
17 /// will be deleted when the timerange is recovered from SciQlop
18 std::unique_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider) noexcept
19 {
20 auto parameters = DataProviderParameters{
21 static_cast<double>(QDateTime{QDate{2017, 01, 01}}.toSecsSinceEpoch()),
22 static_cast<double>(QDateTime{QDate{2017, 01, 03}}.toSecsSinceEpoch())};
23
24 return provider.retrieveData(parameters);
25 }
26
27 } // namespace
28
9 struct VariableController::VariableControllerPrivate {
29 struct VariableController::VariableControllerPrivate {
10 explicit VariableControllerPrivate(VariableController *parent)
30 explicit VariableControllerPrivate(VariableController *parent)
11 : m_WorkingMutex{}, m_VariableModel{new VariableModel{parent}}
31 : m_WorkingMutex{}, m_VariableModel{new VariableModel{parent}}
@@ -31,14 +51,23 VariableController::~VariableController()
31 this->waitForFinish();
51 this->waitForFinish();
32 }
52 }
33
53
34 Variable *VariableController::createVariable(const QString &name) noexcept
54 VariableModel *VariableController::variableModel() noexcept
35 {
55 {
36 return impl->m_VariableModel->createVariable(name);
56 return impl->m_VariableModel;
37 }
57 }
38
58
39 VariableModel *VariableController::variableModel() noexcept
59 void VariableController::createVariable(const QString &name,
60 std::shared_ptr<IDataProvider> provider) noexcept
40 {
61 {
41 return impl->m_VariableModel;
62 /// @todo : for the moment :
63 /// - the provider is only used to retrieve data from the variable for its initialization, but
64 /// it will be retained later
65 /// - default data are generated for the variable, without taking into account the timerange set
66 /// in sciqlop
67 if (auto newVariable
68 = impl->m_VariableModel->createVariable(name, generateDefaultDataSeries(*provider))) {
69 emit variableCreated(newVariable);
70 }
42 }
71 }
43
72
44 void VariableController::initialize()
73 void VariableController::initialize()
General Comments 0
You need to be logged in to leave comments. Login now