##// END OF EJS Templates
A variable is now created with its dateTime too....
perrinel -
r212:8e4faeed90b4
parent child
Show More
@@ -1,14 +1,19
1 1 #ifndef SCIQLOP_SQPDATETIME_H
2 2 #define SCIQLOP_SQPDATETIME_H
3 3
4 4 /**
5 5 * @brief The SqpDateTime struct holds the information of time parameters
6 6 */
7 7 struct SqpDateTime {
8 8 /// Start time
9 9 double m_TStart;
10 10 /// End time
11 11 double m_TEnd;
12
13 bool contains(const SqpDateTime &dateTime)
14 {
15 return (m_TStart <= dateTime.m_TStart && m_TEnd >= dateTime.m_TEnd);
16 }
12 17 };
13 18
14 19 #endif // SCIQLOP_SQPDATETIME_H
@@ -1,44 +1,45
1 1 #ifndef SCIQLOP_VARIABLE_H
2 2 #define SCIQLOP_VARIABLE_H
3 3
4 4 #include <Data/SqpDateTime.h>
5 5
6 6
7 7 #include <QLoggingCategory>
8 8 #include <QObject>
9 9
10 10 #include <Common/spimpl.h>
11 11
12 12 Q_DECLARE_LOGGING_CATEGORY(LOG_Variable)
13 13
14 14 class IDataSeries;
15 15 class QString;
16 16
17 17 /**
18 18 * @brief The Variable class represents a variable in SciQlop.
19 19 */
20 20 class Variable {
21 21 public:
22 explicit Variable(const QString &name, const QString &unit, const QString &mission);
22 explicit Variable(const QString &name, const QString &unit, const QString &mission,
23 const SqpDateTime &dateTime);
23 24
24 25 QString name() const noexcept;
25 26 QString mission() const noexcept;
26 27 QString unit() const noexcept;
27 28
28 29 void addDataSeries(std::unique_ptr<IDataSeries> dataSeries) noexcept;
29 30
30 31 /// @return the data of the variable, nullptr if there is no data
31 32 IDataSeries *dataSeries() const noexcept;
32 33
33 34 public slots:
34 35 void onXRangeChanged(SqpDateTime dateTime);
35 36
36 37 private:
37 38 class VariablePrivate;
38 39 spimpl::unique_impl_ptr<VariablePrivate> impl;
39 40 };
40 41
41 42 // Required for using shared_ptr in signals/slots
42 43 Q_DECLARE_METATYPE(std::shared_ptr<Variable>)
43 44
44 45 #endif // SCIQLOP_VARIABLE_H
@@ -1,44 +1,49
1 1 #ifndef SCIQLOP_VARIABLEMODEL_H
2 2 #define SCIQLOP_VARIABLEMODEL_H
3 3
4 #include <Common/spimpl.h>
4
5 #include <Data/SqpDateTime.h>
5 6
6 7 #include <QAbstractTableModel>
7 8 #include <QLoggingCategory>
8 9
10 #include <Common/spimpl.h>
11
9 12 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableModel)
10 13
11 14 class IDataSeries;
12 15 class Variable;
13 16
14 17 /**
15 18 * @brief The VariableModel class aims to hold the variables that have been created in SciQlop
16 19 */
17 20 class VariableModel : public QAbstractTableModel {
18 21 public:
19 22 explicit VariableModel(QObject *parent = nullptr);
20 23
21 24 /**
22 25 * Creates a new variable in the model
23 26 * @param name the name of the new variable
27 * @param dateTime the dateTime of the new variable
24 28 * @param defaultDataSeries the default data of the new variable
25 29 * @return the pointer to the new variable
26 30 */
27 31 std::shared_ptr<Variable>
28 createVariable(const QString &name, std::unique_ptr<IDataSeries> defaultDataSeries) noexcept;
32 createVariable(const QString &name, const SqpDateTime &dateTime,
33 std::unique_ptr<IDataSeries> defaultDataSeries) noexcept;
29 34
30 35 // /////////////////////////// //
31 36 // QAbstractTableModel methods //
32 37 // /////////////////////////// //
33 38 virtual int columnCount(const QModelIndex &parent = QModelIndex{}) const override;
34 39 virtual int rowCount(const QModelIndex &parent = QModelIndex{}) const override;
35 40 virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
36 41 virtual QVariant headerData(int section, Qt::Orientation orientation,
37 42 int role = Qt::DisplayRole) const override;
38 43
39 44 private:
40 45 class VariableModelPrivate;
41 46 spimpl::unique_impl_ptr<VariableModelPrivate> impl;
42 47 };
43 48
44 49 #endif // SCIQLOP_VARIABLEMODEL_H
@@ -1,58 +1,74
1 1 #include "Variable/Variable.h"
2 2
3 3 #include <Data/IDataSeries.h>
4 4 #include <Data/SqpDateTime.h>
5 5
6 6 Q_LOGGING_CATEGORY(LOG_Variable, "Variable")
7 7
8 8 struct Variable::VariablePrivate {
9 explicit VariablePrivate(const QString &name, const QString &unit, const QString &mission)
10 : m_Name{name}, m_Unit{unit}, m_Mission{mission}, m_DataSeries{nullptr}
9 explicit VariablePrivate(const QString &name, const QString &unit, const QString &mission,
10 const SqpDateTime &dateTime)
11 : m_Name{name},
12 m_Unit{unit},
13 m_Mission{mission},
14 m_DateTime{dateTime},
15 m_DataSeries{nullptr}
11 16 {
12 17 }
13 18
14 19 QString m_Name;
15 20 QString m_Unit;
16 21 QString m_Mission;
17 22
18 23 SqpDateTime m_DateTime; // The dateTime available in the view and loaded. not the cache.
19 24 std::unique_ptr<IDataSeries> m_DataSeries;
20 25 };
21 26
22 Variable::Variable(const QString &name, const QString &unit, const QString &mission)
23 : impl{spimpl::make_unique_impl<VariablePrivate>(name, unit, mission)}
27 Variable::Variable(const QString &name, const QString &unit, const QString &mission,
28 const SqpDateTime &dateTime)
29 : impl{spimpl::make_unique_impl<VariablePrivate>(name, unit, mission, dateTime)}
24 30 {
25 31 }
26 32
27 33 QString Variable::name() const noexcept
28 34 {
29 35 return impl->m_Name;
30 36 }
31 37
32 38 QString Variable::mission() const noexcept
33 39 {
34 40 return impl->m_Mission;
35 41 }
36 42
37 43 QString Variable::unit() const noexcept
38 44 {
39 45 return impl->m_Unit;
40 46 }
41 47
42 48 void Variable::addDataSeries(std::unique_ptr<IDataSeries> dataSeries) noexcept
43 49 {
44 50 if (!impl->m_DataSeries) {
45 51 impl->m_DataSeries = std::move(dataSeries);
46 52 }
47 53 /// @todo : else, merge the two data series (if possible)
48 54 }
49 55
50 56 IDataSeries *Variable::dataSeries() const noexcept
51 57 {
52 58 return impl->m_DataSeries.get();
53 59 }
54 60
55 61 void Variable::onXRangeChanged(SqpDateTime dateTime)
56 62 {
57 63 qCInfo(LOG_Variable()) << "onXRangeChanged detected";
64
65 if (!impl->m_DateTime.contains(dateTime)) {
66 // The current variable dateTime isn't enough to display the dateTime requested.
67 // We have to update it to the new dateTime requested.
68 // the correspondant new data to display will be given by the cache if possible and the
69 // provider if necessary.
70 qCInfo(LOG_Variable()) << "NEW DATE NEEDED";
71
72 impl->m_DateTime = dateTime;
73 }
58 74 }
@@ -1,123 +1,123
1 1 #include <Variable/VariableCacheController.h>
2 2 #include <Variable/VariableController.h>
3 3 #include <Variable/VariableModel.h>
4 4
5 5 #include <Data/DataProviderParameters.h>
6 6 #include <Data/IDataProvider.h>
7 7 #include <Data/IDataSeries.h>
8 8 #include <Time/TimeController.h>
9 9
10 10 #include <QDateTime>
11 11 #include <QMutex>
12 12 #include <QThread>
13 13
14 14 #include <unordered_map>
15 15
16 16 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
17 17
18 18 namespace {
19 19
20 20 /// @todo Generates default dataseries, according to the provider passed in parameter. This method
21 21 /// will be deleted when the timerange is recovered from SciQlop
22 22 std::unique_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider,
23 23 const SqpDateTime &dateTime) noexcept
24 24 {
25 25 auto parameters = DataProviderParameters{dateTime};
26 26
27 27 return provider.retrieveData(parameters);
28 28 }
29 29
30 30 } // namespace
31 31
32 32 struct VariableController::VariableControllerPrivate {
33 33 explicit VariableControllerPrivate(VariableController *parent)
34 34 : m_WorkingMutex{},
35 35 m_VariableModel{new VariableModel{parent}},
36 36 m_VariableCacheController{std::make_unique<VariableCacheController>()}
37 37 {
38 38 }
39 39
40 40 QMutex m_WorkingMutex;
41 41 /// Variable model. The VariableController has the ownership
42 42 VariableModel *m_VariableModel;
43 43
44 44
45 45 TimeController *m_TimeController{nullptr};
46 46 std::unique_ptr<VariableCacheController> m_VariableCacheController;
47 47 };
48 48
49 49 VariableController::VariableController(QObject *parent)
50 50 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
51 51 {
52 52 qCDebug(LOG_VariableController()) << tr("VariableController construction")
53 53 << QThread::currentThread();
54 54 }
55 55
56 56 VariableController::~VariableController()
57 57 {
58 58 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
59 59 << QThread::currentThread();
60 60 this->waitForFinish();
61 61 }
62 62
63 63 VariableModel *VariableController::variableModel() noexcept
64 64 {
65 65 return impl->m_VariableModel;
66 66 }
67 67
68 68 void VariableController::setTimeController(TimeController *timeController) noexcept
69 69 {
70 70 impl->m_TimeController = timeController;
71 71 }
72 72
73 73 void VariableController::createVariable(const QString &name,
74 74 std::shared_ptr<IDataProvider> provider) noexcept
75 75 {
76 76 // TORM
77 77 // auto dateTime = SqpDateTime{
78 78 // // Remarks : we don't use toSecsSinceEpoch() here (method is for Qt 5.8 or above)
79 79 // static_cast<double>(QDateTime{QDate{2017, 01, 01}, QTime{12, 00}}.toMSecsSinceEpoch()
80 80 // / 1000.),
81 81 // static_cast<double>(QDateTime{QDate{2017, 01, 01}, QTime{12, 01}}.toMSecsSinceEpoch())
82 82 // / 1000.};
83 83
84 84 if (!impl->m_TimeController) {
85 85 qCCritical(LOG_VariableController())
86 86 << tr("Impossible to create variable: The time controller is null");
87 87 return;
88 88 }
89 89
90 90
91 91 /// @todo : for the moment :
92 92 /// - the provider is only used to retrieve data from the variable for its initialization, but
93 93 /// it will be retained later
94 94 /// - default data are generated for the variable, without taking into account the timerange set
95 95 /// in sciqlop
96 96 auto dateTime = impl->m_TimeController->dateTime();
97 97 if (auto newVariable = impl->m_VariableModel->createVariable(
98 name, generateDefaultDataSeries(*provider, dateTime))) {
98 name, dateTime, generateDefaultDataSeries(*provider, dateTime))) {
99 99
100 100 // store in cache
101 101 impl->m_VariableCacheController->addDateTime(newVariable, dateTime);
102 102
103 103 // notify the creation
104 104 emit variableCreated(newVariable);
105 105 }
106 106 }
107 107
108 108 void VariableController::initialize()
109 109 {
110 110 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
111 111 impl->m_WorkingMutex.lock();
112 112 qCDebug(LOG_VariableController()) << tr("VariableController init END");
113 113 }
114 114
115 115 void VariableController::finalize()
116 116 {
117 117 impl->m_WorkingMutex.unlock();
118 118 }
119 119
120 120 void VariableController::waitForFinish()
121 121 {
122 122 QMutexLocker locker{&impl->m_WorkingMutex};
123 123 }
@@ -1,120 +1,120
1 1 #include <Variable/Variable.h>
2 2 #include <Variable/VariableModel.h>
3 3
4 4 #include <Data/IDataSeries.h>
5 5
6 6 Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel")
7 7
8 8 namespace {
9 9
10 10 // Column indexes
11 11 const auto NAME_COLUMN = 0;
12 12 const auto UNIT_COLUMN = 1;
13 13 const auto MISSION_COLUMN = 2;
14 14 const auto NB_COLUMNS = 3;
15 15
16 16 } // namespace
17 17
18 18 struct VariableModel::VariableModelPrivate {
19 19 /// Variables created in SciQlop
20 20 std::vector<std::shared_ptr<Variable> > m_Variables;
21 21 };
22 22
23 23 VariableModel::VariableModel(QObject *parent)
24 24 : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()}
25 25 {
26 26 }
27 27
28 28 std::shared_ptr<Variable>
29 VariableModel::createVariable(const QString &name,
29 VariableModel::createVariable(const QString &name, const SqpDateTime &dateTime,
30 30 std::unique_ptr<IDataSeries> defaultDataSeries) noexcept
31 31 {
32 32 auto insertIndex = rowCount();
33 33 beginInsertRows({}, insertIndex, insertIndex);
34 34
35 35 /// @todo For the moment, the other data of the variable is initialized with default values
36 auto variable
37 = std::make_shared<Variable>(name, QStringLiteral("unit"), QStringLiteral("mission"));
36 auto variable = std::make_shared<Variable>(name, QStringLiteral("unit"),
37 QStringLiteral("mission"), dateTime);
38 38 variable->addDataSeries(std::move(defaultDataSeries));
39 39
40 40 impl->m_Variables.push_back(variable);
41 41
42 42 endInsertRows();
43 43
44 44 return variable;
45 45 }
46 46
47 47 int VariableModel::columnCount(const QModelIndex &parent) const
48 48 {
49 49 Q_UNUSED(parent);
50 50
51 51 return NB_COLUMNS;
52 52 }
53 53
54 54 int VariableModel::rowCount(const QModelIndex &parent) const
55 55 {
56 56 Q_UNUSED(parent);
57 57
58 58 return impl->m_Variables.size();
59 59 }
60 60
61 61 QVariant VariableModel::data(const QModelIndex &index, int role) const
62 62 {
63 63 if (!index.isValid()) {
64 64 return QVariant{};
65 65 }
66 66
67 67 if (index.row() < 0 || index.row() >= rowCount()) {
68 68 return QVariant{};
69 69 }
70 70
71 71 if (role == Qt::DisplayRole) {
72 72 if (auto variable = impl->m_Variables.at(index.row()).get()) {
73 73 switch (index.column()) {
74 74 case NAME_COLUMN:
75 75 return variable->name();
76 76 case UNIT_COLUMN:
77 77 return variable->unit();
78 78 case MISSION_COLUMN:
79 79 return variable->mission();
80 80 default:
81 81 // No action
82 82 break;
83 83 }
84 84
85 85 qWarning(LOG_VariableModel())
86 86 << tr("Can't get data (unknown column %1)").arg(index.column());
87 87 }
88 88 else {
89 89 qWarning(LOG_VariableModel()) << tr("Can't get data (no variable)");
90 90 }
91 91 }
92 92
93 93 return QVariant{};
94 94 }
95 95
96 96 QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const
97 97 {
98 98 if (role != Qt::DisplayRole) {
99 99 return QVariant{};
100 100 }
101 101
102 102 if (orientation == Qt::Horizontal) {
103 103 switch (section) {
104 104 case NAME_COLUMN:
105 105 return tr("Name");
106 106 case UNIT_COLUMN:
107 107 return tr("Unit");
108 108 case MISSION_COLUMN:
109 109 return tr("Mission");
110 110 default:
111 111 // No action
112 112 break;
113 113 }
114 114
115 115 qWarning(LOG_VariableModel())
116 116 << tr("Can't get header data (unknown column %1)").arg(section);
117 117 }
118 118
119 119 return QVariant{};
120 120 }
General Comments 0
You need to be logged in to leave comments. Login now