##// END OF EJS Templates
Updates VariableController::createVariable() method...
Alexandre Leroux -
r154:ab6272d8de5a
parent child
Show More
@@ -1,43 +1,48
1 #ifndef SCIQLOP_VARIABLECONTROLLER_H
1 #ifndef SCIQLOP_VARIABLECONTROLLER_H
2 #define SCIQLOP_VARIABLECONTROLLER_H
2 #define SCIQLOP_VARIABLECONTROLLER_H
3
3
4 #include <QLoggingCategory>
4 #include <QLoggingCategory>
5 #include <QObject>
5 #include <QObject>
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
12 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableController)
13 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableController)
13
14
14 /**
15 /**
15 * @brief The VariableController class aims to handle the variables in SciQlop.
16 * @brief The VariableController class aims to handle the variables in SciQlop.
16 */
17 */
17 class VariableController : public QObject {
18 class VariableController : public QObject {
18 Q_OBJECT
19 Q_OBJECT
19 public:
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
36 private:
41 private:
37 void waitForFinish();
42 void waitForFinish();
38
43
39 class VariableControllerPrivate;
44 class VariableControllerPrivate;
40 spimpl::unique_impl_ptr<VariableControllerPrivate> impl;
45 spimpl::unique_impl_ptr<VariableControllerPrivate> impl;
41 };
46 };
42
47
43 #endif // SCIQLOP_VARIABLECONTROLLER_H
48 #endif // SCIQLOP_VARIABLECONTROLLER_H
@@ -1,59 +1,88
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}}
12 {
32 {
13 }
33 }
14
34
15 QMutex m_WorkingMutex;
35 QMutex m_WorkingMutex;
16 /// Variable model. The VariableController has the ownership
36 /// Variable model. The VariableController has the ownership
17 VariableModel *m_VariableModel;
37 VariableModel *m_VariableModel;
18 };
38 };
19
39
20 VariableController::VariableController(QObject *parent)
40 VariableController::VariableController(QObject *parent)
21 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
41 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
22 {
42 {
23 qCDebug(LOG_VariableController()) << tr("VariableController construction")
43 qCDebug(LOG_VariableController()) << tr("VariableController construction")
24 << QThread::currentThread();
44 << QThread::currentThread();
25 }
45 }
26
46
27 VariableController::~VariableController()
47 VariableController::~VariableController()
28 {
48 {
29 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
49 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
30 << QThread::currentThread();
50 << QThread::currentThread();
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()
45 {
74 {
46 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
75 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
47 impl->m_WorkingMutex.lock();
76 impl->m_WorkingMutex.lock();
48 qCDebug(LOG_VariableController()) << tr("VariableController init END");
77 qCDebug(LOG_VariableController()) << tr("VariableController init END");
49 }
78 }
50
79
51 void VariableController::finalize()
80 void VariableController::finalize()
52 {
81 {
53 impl->m_WorkingMutex.unlock();
82 impl->m_WorkingMutex.unlock();
54 }
83 }
55
84
56 void VariableController::waitForFinish()
85 void VariableController::waitForFinish()
57 {
86 {
58 QMutexLocker locker{&impl->m_WorkingMutex};
87 QMutexLocker locker{&impl->m_WorkingMutex};
59 }
88 }
General Comments 0
You need to be logged in to leave comments. Login now