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