##// END OF EJS Templates
The mock plugin can now create data with view operation
perrinel -
r235:746eaca503e3
parent child
Show More
@@ -1,45 +1,54
1 #ifndef SCIQLOP_VARIABLE_H
1 #ifndef SCIQLOP_VARIABLE_H
2 #define SCIQLOP_VARIABLE_H
2 #define SCIQLOP_VARIABLE_H
3
3
4 #include <Data/SqpDateTime.h>
4 #include <Data/SqpDateTime.h>
5
5
6
6
7 #include <QLoggingCategory>
7 #include <QLoggingCategory>
8 #include <QObject>
8 #include <QObject>
9
9
10 #include <Common/spimpl.h>
10 #include <Common/spimpl.h>
11
11
12 Q_DECLARE_LOGGING_CATEGORY(LOG_Variable)
12 Q_DECLARE_LOGGING_CATEGORY(LOG_Variable)
13
13
14 class IDataSeries;
14 class IDataSeries;
15 class QString;
15 class QString;
16
16
17 /**
17 /**
18 * @brief The Variable class represents a variable in SciQlop.
18 * @brief The Variable class represents a variable in SciQlop.
19 */
19 */
20 class Variable {
20 class Variable : public QObject {
21
22 Q_OBJECT
23
21 public:
24 public:
22 explicit Variable(const QString &name, const QString &unit, const QString &mission,
25 explicit Variable(const QString &name, const QString &unit, const QString &mission,
23 const SqpDateTime &dateTime);
26 const SqpDateTime &dateTime);
24
27
25 QString name() const noexcept;
28 QString name() const noexcept;
26 QString mission() const noexcept;
29 QString mission() const noexcept;
27 QString unit() const noexcept;
30 QString unit() const noexcept;
28
31 SqpDateTime dateTime() const noexcept;
29 void addDataSeries(std::unique_ptr<IDataSeries> dataSeries) noexcept;
30
32
31 /// @return the data of the variable, nullptr if there is no data
33 /// @return the data of the variable, nullptr if there is no data
32 IDataSeries *dataSeries() const noexcept;
34 IDataSeries *dataSeries() const noexcept;
33
35
36 bool contains(SqpDateTime dateTime);
37 void setDataSeries(std::unique_ptr<IDataSeries> dataSeries) noexcept;
38
34 public slots:
39 public slots:
35 void onXRangeChanged(SqpDateTime dateTime);
40 void onAddDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept;
41
42 signals:
43 void dataCacheUpdated();
44
36
45
37 private:
46 private:
38 class VariablePrivate;
47 class VariablePrivate;
39 spimpl::unique_impl_ptr<VariablePrivate> impl;
48 spimpl::unique_impl_ptr<VariablePrivate> impl;
40 };
49 };
41
50
42 // Required for using shared_ptr in signals/slots
51 // Required for using shared_ptr in signals/slots
43 Q_DECLARE_METATYPE(std::shared_ptr<Variable>)
52 Q_DECLARE_METATYPE(std::shared_ptr<Variable>)
44
53
45 #endif // SCIQLOP_VARIABLE_H
54 #endif // SCIQLOP_VARIABLE_H
@@ -1,51 +1,58
1 #ifndef SCIQLOP_VARIABLECONTROLLER_H
1 #ifndef SCIQLOP_VARIABLECONTROLLER_H
2 #define SCIQLOP_VARIABLECONTROLLER_H
2 #define SCIQLOP_VARIABLECONTROLLER_H
3
3
4 #include <Data/SqpDateTime.h>
5
4 #include <QLoggingCategory>
6 #include <QLoggingCategory>
5 #include <QObject>
7 #include <QObject>
6
8
7 #include <Common/spimpl.h>
9 #include <Common/spimpl.h>
8
10
11
9 class IDataProvider;
12 class IDataProvider;
10 class TimeController;
13 class TimeController;
11 class Variable;
14 class Variable;
12 class VariableModel;
15 class VariableModel;
13
16
14 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableController)
17 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableController)
15
18
16 /**
19 /**
17 * @brief The VariableController class aims to handle the variables in SciQlop.
20 * @brief The VariableController class aims to handle the variables in SciQlop.
18 */
21 */
19 class VariableController : public QObject {
22 class VariableController : public QObject {
20 Q_OBJECT
23 Q_OBJECT
21 public:
24 public:
22 explicit VariableController(QObject *parent = 0);
25 explicit VariableController(QObject *parent = 0);
23 virtual ~VariableController();
26 virtual ~VariableController();
24
27
25 VariableModel *variableModel() noexcept;
28 VariableModel *variableModel() noexcept;
26
29
27 void setTimeController(TimeController *timeController) noexcept;
30 void setTimeController(TimeController *timeController) noexcept;
28
31
32
33 /// Request the data loading of the variable whithin dateTime
34 void requestDataLoading(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime);
35
29 signals:
36 signals:
30 /// Signal emitted when a variable has been created
37 /// Signal emitted when a variable has been created
31 void variableCreated(std::shared_ptr<Variable> variable);
38 void variableCreated(std::shared_ptr<Variable> variable);
32
39
33 public slots:
40 public slots:
34 /**
41 /**
35 * Creates a new variable and adds it to the model
42 * Creates a new variable and adds it to the model
36 * @param name the name of the new variable
43 * @param name the name of the new variable
37 * @param provider the data provider for the new variable
44 * @param provider the data provider for the new variable
38 */
45 */
39 void createVariable(const QString &name, std::shared_ptr<IDataProvider> provider) noexcept;
46 void createVariable(const QString &name, std::shared_ptr<IDataProvider> provider) noexcept;
40
47
41 void initialize();
48 void initialize();
42 void finalize();
49 void finalize();
43
50
44 private:
51 private:
45 void waitForFinish();
52 void waitForFinish();
46
53
47 class VariableControllerPrivate;
54 class VariableControllerPrivate;
48 spimpl::unique_impl_ptr<VariableControllerPrivate> impl;
55 spimpl::unique_impl_ptr<VariableControllerPrivate> impl;
49 };
56 };
50
57
51 #endif // SCIQLOP_VARIABLECONTROLLER_H
58 #endif // SCIQLOP_VARIABLECONTROLLER_H
@@ -1,74 +1,89
1 #include "Variable/Variable.h"
1 #include "Variable/Variable.h"
2
2
3 #include <Data/IDataSeries.h>
3 #include <Data/IDataSeries.h>
4 #include <Data/SqpDateTime.h>
4 #include <Data/SqpDateTime.h>
5
5
6 Q_LOGGING_CATEGORY(LOG_Variable, "Variable")
6 Q_LOGGING_CATEGORY(LOG_Variable, "Variable")
7
7
8 struct Variable::VariablePrivate {
8 struct Variable::VariablePrivate {
9 explicit VariablePrivate(const QString &name, const QString &unit, const QString &mission,
9 explicit VariablePrivate(const QString &name, const QString &unit, const QString &mission,
10 const SqpDateTime &dateTime)
10 const SqpDateTime &dateTime)
11 : m_Name{name},
11 : m_Name{name},
12 m_Unit{unit},
12 m_Unit{unit},
13 m_Mission{mission},
13 m_Mission{mission},
14 m_DateTime{dateTime},
14 m_DateTime{dateTime},
15 m_DataSeries{nullptr}
15 m_DataSeries{nullptr}
16 {
16 {
17 }
17 }
18
18
19 QString m_Name;
19 QString m_Name;
20 QString m_Unit;
20 QString m_Unit;
21 QString m_Mission;
21 QString m_Mission;
22
22
23 SqpDateTime m_DateTime; // The dateTime available in the view and loaded. not the cache.
23 SqpDateTime m_DateTime; // The dateTime available in the view and loaded. not the cache.
24 std::unique_ptr<IDataSeries> m_DataSeries;
24 std::unique_ptr<IDataSeries> m_DataSeries;
25 };
25 };
26
26
27 Variable::Variable(const QString &name, const QString &unit, const QString &mission,
27 Variable::Variable(const QString &name, const QString &unit, const QString &mission,
28 const SqpDateTime &dateTime)
28 const SqpDateTime &dateTime)
29 : impl{spimpl::make_unique_impl<VariablePrivate>(name, unit, mission, dateTime)}
29 : impl{spimpl::make_unique_impl<VariablePrivate>(name, unit, mission, dateTime)}
30 {
30 {
31 }
31 }
32
32
33 QString Variable::name() const noexcept
33 QString Variable::name() const noexcept
34 {
34 {
35 return impl->m_Name;
35 return impl->m_Name;
36 }
36 }
37
37
38 QString Variable::mission() const noexcept
38 QString Variable::mission() const noexcept
39 {
39 {
40 return impl->m_Mission;
40 return impl->m_Mission;
41 }
41 }
42
42
43 QString Variable::unit() const noexcept
43 QString Variable::unit() const noexcept
44 {
44 {
45 return impl->m_Unit;
45 return impl->m_Unit;
46 }
46 }
47
47
48 void Variable::addDataSeries(std::unique_ptr<IDataSeries> dataSeries) noexcept
48 SqpDateTime Variable::dateTime() const noexcept
49 {
50 return impl->m_DateTime;
51 }
52
53 void Variable::setDataSeries(std::unique_ptr<IDataSeries> dataSeries) noexcept
49 {
54 {
50 if (!impl->m_DataSeries) {
55 if (!impl->m_DataSeries) {
51 impl->m_DataSeries = std::move(dataSeries);
56 impl->m_DataSeries = std::move(dataSeries);
52 }
57 }
53 /// @todo : else, merge the two data series (if possible)
58 }
59
60 void Variable::onAddDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept
61 {
62 if (impl->m_DataSeries) {
63 impl->m_DataSeries->merge(dataSeries.get());
64
65 emit dataCacheUpdated();
66 }
54 }
67 }
55
68
56 IDataSeries *Variable::dataSeries() const noexcept
69 IDataSeries *Variable::dataSeries() const noexcept
57 {
70 {
58 return impl->m_DataSeries.get();
71 return impl->m_DataSeries.get();
59 }
72 }
60
73
61 void Variable::onXRangeChanged(SqpDateTime dateTime)
74 bool Variable::contains(SqpDateTime dateTime)
62 {
75 {
63 qCInfo(LOG_Variable()) << "onXRangeChanged detected";
64
65 if (!impl->m_DateTime.contains(dateTime)) {
76 if (!impl->m_DateTime.contains(dateTime)) {
66 // The current variable dateTime isn't enough to display the dateTime requested.
77 // The current variable dateTime isn't enough to display the dateTime requested.
67 // We have to update it to the new dateTime requested.
78 // 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
79 // the correspondant new data to display will be given by the cache if possible and the
69 // provider if necessary.
80 // provider if necessary.
70 qCInfo(LOG_Variable()) << "NEW DATE NEEDED";
81 qCInfo(LOG_Variable()) << "NEW DATE NEEDED";
71
82
72 impl->m_DateTime = dateTime;
83 impl->m_DateTime = dateTime;
84
85 return false;
73 }
86 }
87
88 return true;
74 }
89 }
@@ -1,123 +1,164
1 #include <Variable/Variable.h>
1 #include <Variable/VariableCacheController.h>
2 #include <Variable/VariableCacheController.h>
2 #include <Variable/VariableController.h>
3 #include <Variable/VariableController.h>
3 #include <Variable/VariableModel.h>
4 #include <Variable/VariableModel.h>
4
5
5 #include <Data/DataProviderParameters.h>
6 #include <Data/DataProviderParameters.h>
6 #include <Data/IDataProvider.h>
7 #include <Data/IDataProvider.h>
7 #include <Data/IDataSeries.h>
8 #include <Data/IDataSeries.h>
8 #include <Time/TimeController.h>
9 #include <Time/TimeController.h>
9
10
10 #include <QDateTime>
11 #include <QDateTime>
12 #include <QElapsedTimer>
11 #include <QMutex>
13 #include <QMutex>
12 #include <QThread>
14 #include <QThread>
13
15
14 #include <unordered_map>
16 #include <unordered_map>
15
17
16 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
18 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
17
19
18 namespace {
20 namespace {
19
21
20 /// @todo Generates default dataseries, according to the provider passed in parameter. This method
22 /// @todo Generates default dataseries, according to the provider passed in parameter. This method
21 /// will be deleted when the timerange is recovered from SciQlop
23 /// will be deleted when the timerange is recovered from SciQlop
22 std::unique_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider,
24 std::unique_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider,
23 const SqpDateTime &dateTime) noexcept
25 const SqpDateTime &dateTime) noexcept
24 {
26 {
25 auto parameters = DataProviderParameters{dateTime};
27 auto parameters = DataProviderParameters{dateTime};
26
28
27 return provider.retrieveData(parameters);
29 return provider.retrieveData(parameters);
28 }
30 }
29
31
30 } // namespace
32 } // namespace
31
33
32 struct VariableController::VariableControllerPrivate {
34 struct VariableController::VariableControllerPrivate {
33 explicit VariableControllerPrivate(VariableController *parent)
35 explicit VariableControllerPrivate(VariableController *parent)
34 : m_WorkingMutex{},
36 : m_WorkingMutex{},
35 m_VariableModel{new VariableModel{parent}},
37 m_VariableModel{new VariableModel{parent}},
36 m_VariableCacheController{std::make_unique<VariableCacheController>()}
38 m_VariableCacheController{std::make_unique<VariableCacheController>()}
37 {
39 {
38 }
40 }
39
41
40 QMutex m_WorkingMutex;
42 QMutex m_WorkingMutex;
41 /// Variable model. The VariableController has the ownership
43 /// Variable model. The VariableController has the ownership
42 VariableModel *m_VariableModel;
44 VariableModel *m_VariableModel;
43
45
44
46
45 TimeController *m_TimeController{nullptr};
47 TimeController *m_TimeController{nullptr};
46 std::unique_ptr<VariableCacheController> m_VariableCacheController;
48 std::unique_ptr<VariableCacheController> m_VariableCacheController;
49
50 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
51 m_VariableToProviderMap;
47 };
52 };
48
53
49 VariableController::VariableController(QObject *parent)
54 VariableController::VariableController(QObject *parent)
50 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
55 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
51 {
56 {
52 qCDebug(LOG_VariableController()) << tr("VariableController construction")
57 qCDebug(LOG_VariableController()) << tr("VariableController construction")
53 << QThread::currentThread();
58 << QThread::currentThread();
54 }
59 }
55
60
56 VariableController::~VariableController()
61 VariableController::~VariableController()
57 {
62 {
58 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
63 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
59 << QThread::currentThread();
64 << QThread::currentThread();
60 this->waitForFinish();
65 this->waitForFinish();
61 }
66 }
62
67
63 VariableModel *VariableController::variableModel() noexcept
68 VariableModel *VariableController::variableModel() noexcept
64 {
69 {
65 return impl->m_VariableModel;
70 return impl->m_VariableModel;
66 }
71 }
67
72
68 void VariableController::setTimeController(TimeController *timeController) noexcept
73 void VariableController::setTimeController(TimeController *timeController) noexcept
69 {
74 {
70 impl->m_TimeController = timeController;
75 impl->m_TimeController = timeController;
71 }
76 }
72
77
73 void VariableController::createVariable(const QString &name,
78 void VariableController::createVariable(const QString &name,
74 std::shared_ptr<IDataProvider> provider) noexcept
79 std::shared_ptr<IDataProvider> provider) noexcept
75 {
80 {
76 // TORM
77 // auto dateTime = SqpDateTime{
78 // // Remarks : we don't use toSecsSinceEpoch() here (method is for Qt 5.8 or above)
79 // static_cast<double>(QDateTime{QDate{2017, 01, 01}, QTime{12, 00}}.toMSecsSinceEpoch()
80 // / 1000.),
81 // static_cast<double>(QDateTime{QDate{2017, 01, 01}, QTime{12, 01}}.toMSecsSinceEpoch())
82 // / 1000.};
83
81
84 if (!impl->m_TimeController) {
82 if (!impl->m_TimeController) {
85 qCCritical(LOG_VariableController())
83 qCCritical(LOG_VariableController())
86 << tr("Impossible to create variable: The time controller is null");
84 << tr("Impossible to create variable: The time controller is null");
87 return;
85 return;
88 }
86 }
89
87
90
88
91 /// @todo : for the moment :
89 /// @todo : for the moment :
92 /// - the provider is only used to retrieve data from the variable for its initialization, but
90 /// - the provider is only used to retrieve data from the variable for its initialization, but
93 /// it will be retained later
91 /// it will be retained later
94 /// - default data are generated for the variable, without taking into account the timerange set
92 /// - default data are generated for the variable, without taking into account the timerange set
95 /// in sciqlop
93 /// in sciqlop
96 auto dateTime = impl->m_TimeController->dateTime();
94 auto dateTime = impl->m_TimeController->dateTime();
97 if (auto newVariable = impl->m_VariableModel->createVariable(
95 if (auto newVariable = impl->m_VariableModel->createVariable(
98 name, dateTime, generateDefaultDataSeries(*provider, dateTime))) {
96 name, dateTime, generateDefaultDataSeries(*provider, dateTime))) {
99
97
98 // store the provider
99 impl->m_VariableToProviderMap[newVariable] = provider;
100 qRegisterMetaType<std::shared_ptr<IDataSeries> >();
101 qRegisterMetaType<SqpDateTime>();
102 connect(provider.get(), &IDataProvider::dataProvided, newVariable.get(),
103 &Variable::onAddDataSeries);
104
105
100 // store in cache
106 // store in cache
101 impl->m_VariableCacheController->addDateTime(newVariable, dateTime);
107 impl->m_VariableCacheController->addDateTime(newVariable, dateTime);
102
108
103 // notify the creation
109 // notify the creation
104 emit variableCreated(newVariable);
110 emit variableCreated(newVariable);
105 }
111 }
106 }
112 }
107
113
114
115 void VariableController::requestDataLoading(std::shared_ptr<Variable> variable,
116 const SqpDateTime &dateTime)
117 {
118 // we want to load data of the variable for the dateTime.
119 // First we check if the cache contains some of them.
120 // For the other, we ask the provider to give them.
121 if (variable) {
122
123 QElapsedTimer timer;
124 timer.start();
125 qCInfo(LOG_VariableController()) << "The slow s0 operation took" << timer.elapsed()
126 << "milliseconds";
127 auto dateTimeListNotInCache
128 = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime);
129 qCInfo(LOG_VariableController()) << "The slow s1 operation took" << timer.elapsed()
130 << "milliseconds";
131
132 // Ask the provider for each data on the dateTimeListNotInCache
133 impl->m_VariableToProviderMap.at(variable)->requestDataLoading(dateTimeListNotInCache);
134
135 qCInfo(LOG_VariableController()) << "The slow s2 operation took" << timer.elapsed()
136 << "milliseconds";
137
138 // store in cache
139 impl->m_VariableCacheController->addDateTime(variable, dateTime);
140 qCInfo(LOG_VariableController()) << "The slow s3 operation took" << timer.elapsed()
141 << "milliseconds";
142 }
143 else {
144 qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null");
145 }
146 }
147
148
108 void VariableController::initialize()
149 void VariableController::initialize()
109 {
150 {
110 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
151 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
111 impl->m_WorkingMutex.lock();
152 impl->m_WorkingMutex.lock();
112 qCDebug(LOG_VariableController()) << tr("VariableController init END");
153 qCDebug(LOG_VariableController()) << tr("VariableController init END");
113 }
154 }
114
155
115 void VariableController::finalize()
156 void VariableController::finalize()
116 {
157 {
117 impl->m_WorkingMutex.unlock();
158 impl->m_WorkingMutex.unlock();
118 }
159 }
119
160
120 void VariableController::waitForFinish()
161 void VariableController::waitForFinish()
121 {
162 {
122 QMutexLocker locker{&impl->m_WorkingMutex};
163 QMutexLocker locker{&impl->m_WorkingMutex};
123 }
164 }
@@ -1,120 +1,120
1 #include <Variable/Variable.h>
1 #include <Variable/Variable.h>
2 #include <Variable/VariableModel.h>
2 #include <Variable/VariableModel.h>
3
3
4 #include <Data/IDataSeries.h>
4 #include <Data/IDataSeries.h>
5
5
6 Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel")
6 Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel")
7
7
8 namespace {
8 namespace {
9
9
10 // Column indexes
10 // Column indexes
11 const auto NAME_COLUMN = 0;
11 const auto NAME_COLUMN = 0;
12 const auto UNIT_COLUMN = 1;
12 const auto UNIT_COLUMN = 1;
13 const auto MISSION_COLUMN = 2;
13 const auto MISSION_COLUMN = 2;
14 const auto NB_COLUMNS = 3;
14 const auto NB_COLUMNS = 3;
15
15
16 } // namespace
16 } // namespace
17
17
18 struct VariableModel::VariableModelPrivate {
18 struct VariableModel::VariableModelPrivate {
19 /// Variables created in SciQlop
19 /// Variables created in SciQlop
20 std::vector<std::shared_ptr<Variable> > m_Variables;
20 std::vector<std::shared_ptr<Variable> > m_Variables;
21 };
21 };
22
22
23 VariableModel::VariableModel(QObject *parent)
23 VariableModel::VariableModel(QObject *parent)
24 : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()}
24 : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()}
25 {
25 {
26 }
26 }
27
27
28 std::shared_ptr<Variable>
28 std::shared_ptr<Variable>
29 VariableModel::createVariable(const QString &name, const SqpDateTime &dateTime,
29 VariableModel::createVariable(const QString &name, const SqpDateTime &dateTime,
30 std::unique_ptr<IDataSeries> defaultDataSeries) noexcept
30 std::unique_ptr<IDataSeries> defaultDataSeries) noexcept
31 {
31 {
32 auto insertIndex = rowCount();
32 auto insertIndex = rowCount();
33 beginInsertRows({}, insertIndex, insertIndex);
33 beginInsertRows({}, insertIndex, insertIndex);
34
34
35 /// @todo For the moment, the other data of the variable is initialized with default values
35 /// @todo For the moment, the other data of the variable is initialized with default values
36 auto variable = std::make_shared<Variable>(name, QStringLiteral("unit"),
36 auto variable = std::make_shared<Variable>(name, QStringLiteral("unit"),
37 QStringLiteral("mission"), dateTime);
37 QStringLiteral("mission"), dateTime);
38 variable->addDataSeries(std::move(defaultDataSeries));
38 variable->setDataSeries(std::move(defaultDataSeries));
39
39
40 impl->m_Variables.push_back(variable);
40 impl->m_Variables.push_back(variable);
41
41
42 endInsertRows();
42 endInsertRows();
43
43
44 return variable;
44 return variable;
45 }
45 }
46
46
47 int VariableModel::columnCount(const QModelIndex &parent) const
47 int VariableModel::columnCount(const QModelIndex &parent) const
48 {
48 {
49 Q_UNUSED(parent);
49 Q_UNUSED(parent);
50
50
51 return NB_COLUMNS;
51 return NB_COLUMNS;
52 }
52 }
53
53
54 int VariableModel::rowCount(const QModelIndex &parent) const
54 int VariableModel::rowCount(const QModelIndex &parent) const
55 {
55 {
56 Q_UNUSED(parent);
56 Q_UNUSED(parent);
57
57
58 return impl->m_Variables.size();
58 return impl->m_Variables.size();
59 }
59 }
60
60
61 QVariant VariableModel::data(const QModelIndex &index, int role) const
61 QVariant VariableModel::data(const QModelIndex &index, int role) const
62 {
62 {
63 if (!index.isValid()) {
63 if (!index.isValid()) {
64 return QVariant{};
64 return QVariant{};
65 }
65 }
66
66
67 if (index.row() < 0 || index.row() >= rowCount()) {
67 if (index.row() < 0 || index.row() >= rowCount()) {
68 return QVariant{};
68 return QVariant{};
69 }
69 }
70
70
71 if (role == Qt::DisplayRole) {
71 if (role == Qt::DisplayRole) {
72 if (auto variable = impl->m_Variables.at(index.row()).get()) {
72 if (auto variable = impl->m_Variables.at(index.row()).get()) {
73 switch (index.column()) {
73 switch (index.column()) {
74 case NAME_COLUMN:
74 case NAME_COLUMN:
75 return variable->name();
75 return variable->name();
76 case UNIT_COLUMN:
76 case UNIT_COLUMN:
77 return variable->unit();
77 return variable->unit();
78 case MISSION_COLUMN:
78 case MISSION_COLUMN:
79 return variable->mission();
79 return variable->mission();
80 default:
80 default:
81 // No action
81 // No action
82 break;
82 break;
83 }
83 }
84
84
85 qWarning(LOG_VariableModel())
85 qWarning(LOG_VariableModel())
86 << tr("Can't get data (unknown column %1)").arg(index.column());
86 << tr("Can't get data (unknown column %1)").arg(index.column());
87 }
87 }
88 else {
88 else {
89 qWarning(LOG_VariableModel()) << tr("Can't get data (no variable)");
89 qWarning(LOG_VariableModel()) << tr("Can't get data (no variable)");
90 }
90 }
91 }
91 }
92
92
93 return QVariant{};
93 return QVariant{};
94 }
94 }
95
95
96 QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const
96 QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const
97 {
97 {
98 if (role != Qt::DisplayRole) {
98 if (role != Qt::DisplayRole) {
99 return QVariant{};
99 return QVariant{};
100 }
100 }
101
101
102 if (orientation == Qt::Horizontal) {
102 if (orientation == Qt::Horizontal) {
103 switch (section) {
103 switch (section) {
104 case NAME_COLUMN:
104 case NAME_COLUMN:
105 return tr("Name");
105 return tr("Name");
106 case UNIT_COLUMN:
106 case UNIT_COLUMN:
107 return tr("Unit");
107 return tr("Unit");
108 case MISSION_COLUMN:
108 case MISSION_COLUMN:
109 return tr("Mission");
109 return tr("Mission");
110 default:
110 default:
111 // No action
111 // No action
112 break;
112 break;
113 }
113 }
114
114
115 qWarning(LOG_VariableModel())
115 qWarning(LOG_VariableModel())
116 << tr("Can't get header data (unknown column %1)").arg(section);
116 << tr("Can't get header data (unknown column %1)").arg(section);
117 }
117 }
118
118
119 return QVariant{};
119 return QVariant{};
120 }
120 }
@@ -1,38 +1,39
1 #ifndef SCIQLOP_DATASOURCEWIDGET_H
1 #ifndef SCIQLOP_DATASOURCEWIDGET_H
2 #define SCIQLOP_DATASOURCEWIDGET_H
2 #define SCIQLOP_DATASOURCEWIDGET_H
3
3
4 #include <QWidget>
4 #include <QWidget>
5
5
6 namespace Ui {
6 namespace Ui {
7 class DataSourceWidget;
7 class DataSourceWidget;
8 } // Ui
8 } // Ui
9
9
10 class DataSourceItem;
10 class DataSourceItem;
11
11
12 /**
12 /**
13 * @brief The DataSourceWidget handles the graphical representation (as a tree) of the data sources
13 * @brief The DataSourceWidget handles the graphical representation (as a tree) of the data sources
14 * attached to SciQlop.
14 * attached to SciQlop.
15 */
15 */
16 class DataSourceWidget : public QWidget {
16 class DataSourceWidget : public QWidget {
17 Q_OBJECT
17 Q_OBJECT
18
18
19 public:
19 public:
20 explicit DataSourceWidget(QWidget *parent = 0);
20 explicit DataSourceWidget(QWidget *parent = 0);
21 virtual ~DataSourceWidget() noexcept;
21
22
22 public slots:
23 public slots:
23 /**
24 /**
24 * Adds a data source. An item associated to the data source is created and then added to the
25 * Adds a data source. An item associated to the data source is created and then added to the
25 * representation tree
26 * representation tree
26 * @param dataSource the data source to add. The pointer has to be not null
27 * @param dataSource the data source to add. The pointer has to be not null
27 */
28 */
28 void addDataSource(DataSourceItem *dataSource) noexcept;
29 void addDataSource(DataSourceItem *dataSource) noexcept;
29
30
30 private:
31 private:
31 Ui::DataSourceWidget *ui;
32 Ui::DataSourceWidget *ui;
32
33
33 private slots:
34 private slots:
34 /// Slot called when right clicking on an item in the tree (displays a menu)
35 /// Slot called when right clicking on an item in the tree (displays a menu)
35 void onTreeMenuRequested(const QPoint &pos) noexcept;
36 void onTreeMenuRequested(const QPoint &pos) noexcept;
36 };
37 };
37
38
38 #endif // SCIQLOP_DATASOURCEWIDGET_H
39 #endif // SCIQLOP_DATASOURCEWIDGET_H
@@ -1,32 +1,38
1 #ifndef SCIQLOP_GRAPHPLOTTABLESFACTORY_H
1 #ifndef SCIQLOP_GRAPHPLOTTABLESFACTORY_H
2 #define SCIQLOP_GRAPHPLOTTABLESFACTORY_H
2 #define SCIQLOP_GRAPHPLOTTABLESFACTORY_H
3
3
4 #include <Data/SqpDateTime.h>
5
4 #include <QLoggingCategory>
6 #include <QLoggingCategory>
5 #include <QVector>
7 #include <QVector>
6
8
7 #include <memory>
9 #include <memory>
8
10
9 Q_DECLARE_LOGGING_CATEGORY(LOG_GraphPlottablesFactory)
11 Q_DECLARE_LOGGING_CATEGORY(LOG_GraphPlottablesFactory)
10
12
13 class IDataSeries;
11 class QCPAbstractPlottable;
14 class QCPAbstractPlottable;
12 class QCustomPlot;
15 class QCustomPlot;
13 class Variable;
16 class Variable;
14
17
15 /**
18 /**
16 * @brief The GraphPlottablesFactory class aims to create the QCustomPlot components relative to a
19 * @brief The GraphPlottablesFactory class aims to create the QCustomPlot components relative to a
17 * variable, depending on the data series of this variable
20 * variable, depending on the data series of this variable
18 */
21 */
19 struct GraphPlottablesFactory {
22 struct GraphPlottablesFactory {
20 /**
23 /**
21 * Creates (if possible) the QCustomPlot components relative to the variable passed in
24 * Creates (if possible) the QCustomPlot components relative to the variable passed in
22 * parameter, and adds these to the plot passed in parameter.
25 * parameter, and adds these to the plot passed in parameter.
23 * @param variable the variable for which to create the components
26 * @param variable the variable for which to create the components
24 * @param plot the plot in which to add the created components. It takes ownership of these
27 * @param plot the plot in which to add the created components. It takes ownership of these
25 * components.
28 * components.
26 * @return the list of the components created
29 * @return the list of the components created
27 */
30 */
28 static QVector<QCPAbstractPlottable *> create(std::shared_ptr<Variable> variable,
31 static QVector<QCPAbstractPlottable *> create(std::shared_ptr<Variable> variable,
29 QCustomPlot &plot) noexcept;
32 QCustomPlot &plot) noexcept;
33
34 static void updateData(QVector<QCPAbstractPlottable *> plotableVect, IDataSeries *dataSeries,
35 const SqpDateTime &dateTime);
30 };
36 };
31
37
32 #endif // SCIQLOP_GRAPHPLOTTABLESFACTORY_H
38 #endif // SCIQLOP_GRAPHPLOTTABLESFACTORY_H
@@ -1,51 +1,56
1 #ifndef SCIQLOP_VISUALIZATIONGRAPHWIDGET_H
1 #ifndef SCIQLOP_VISUALIZATIONGRAPHWIDGET_H
2 #define SCIQLOP_VISUALIZATIONGRAPHWIDGET_H
2 #define SCIQLOP_VISUALIZATIONGRAPHWIDGET_H
3
3
4 #include "Visualization/IVisualizationWidget.h"
4 #include "Visualization/IVisualizationWidget.h"
5
5
6 #include <QLoggingCategory>
6 #include <QLoggingCategory>
7 #include <QWidget>
7 #include <QWidget>
8
8
9 #include <memory>
9 #include <memory>
10
10
11 #include <Common/spimpl.h>
11 #include <Common/spimpl.h>
12
12
13 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationGraphWidget)
13 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationGraphWidget)
14
14
15 class QCPRange;
15 class QCPRange;
16 class Variable;
16 class Variable;
17
17
18 namespace Ui {
18 namespace Ui {
19 class VisualizationGraphWidget;
19 class VisualizationGraphWidget;
20 } // namespace Ui
20 } // namespace Ui
21
21
22 class VisualizationGraphWidget : public QWidget, public IVisualizationWidget {
22 class VisualizationGraphWidget : public QWidget, public IVisualizationWidget {
23 Q_OBJECT
23 Q_OBJECT
24
24
25 public:
25 public:
26 explicit VisualizationGraphWidget(const QString &name = {}, QWidget *parent = 0);
26 explicit VisualizationGraphWidget(const QString &name = {}, QWidget *parent = 0);
27 virtual ~VisualizationGraphWidget();
27 virtual ~VisualizationGraphWidget();
28
28
29 void addVariable(std::shared_ptr<Variable> variable);
29 void addVariable(std::shared_ptr<Variable> variable);
30
30
31 // IVisualizationWidget interface
31 // IVisualizationWidget interface
32 void accept(IVisualizationWidgetVisitor *visitor) override;
32 void accept(IVisualizationWidgetVisitor *visitor) override;
33 bool canDrop(const Variable &variable) const override;
33 bool canDrop(const Variable &variable) const override;
34 void close() override;
34 void close() override;
35 QString name() const override;
35 QString name() const override;
36
36
37 void updateDisplay(std::shared_ptr<Variable> variable);
38
39
37 private:
40 private:
38 Ui::VisualizationGraphWidget *ui;
41 Ui::VisualizationGraphWidget *ui;
39
42
40 class VisualizationGraphWidgetPrivate;
43 class VisualizationGraphWidgetPrivate;
41 spimpl::unique_impl_ptr<VisualizationGraphWidgetPrivate> impl;
44 spimpl::unique_impl_ptr<VisualizationGraphWidgetPrivate> impl;
42
45
43 private slots:
46 private slots:
44
47
45 void onRangeChanged(const QCPRange &t1, const QCPRange &t2);
48 void onRangeChanged(const QCPRange &t1, const QCPRange &t2);
46
49
47 /// Slot called when a mouse wheel was made, to perform some processing before the zoom is done
50 /// Slot called when a mouse wheel was made, to perform some processing before the zoom is done
48 void onMouseWheel(QWheelEvent *event) noexcept;
51 void onMouseWheel(QWheelEvent *event) noexcept;
52
53 void onDataCacheVariableUpdated();
49 };
54 };
50
55
51 #endif // SCIQLOP_VISUALIZATIONGRAPHWIDGET_H
56 #endif // SCIQLOP_VISUALIZATIONGRAPHWIDGET_H
@@ -1,91 +1,151
1 #include "Visualization/GraphPlottablesFactory.h"
1 #include "Visualization/GraphPlottablesFactory.h"
2 #include "Visualization/qcustomplot.h"
2 #include "Visualization/qcustomplot.h"
3
3
4 #include <Data/ScalarSeries.h>
4 #include <Data/ScalarSeries.h>
5
5
6 #include <Variable/Variable.h>
6 #include <Variable/Variable.h>
7
7
8 #include <QElapsedTimer>
9
8 Q_LOGGING_CATEGORY(LOG_GraphPlottablesFactory, "GraphPlottablesFactory")
10 Q_LOGGING_CATEGORY(LOG_GraphPlottablesFactory, "GraphPlottablesFactory")
9
11
10 namespace {
12 namespace {
11
13
12 /// Format for datetimes on a axis
14 /// Format for datetimes on a axis
13 const auto DATETIME_TICKER_FORMAT = QStringLiteral("yyyy/MM/dd \nhh:mm:ss");
15 const auto DATETIME_TICKER_FORMAT = QStringLiteral("yyyy/MM/dd \nhh:mm:ss");
14
16
15 /// Generates the appropriate ticker for an axis, depending on whether the axis displays time or
17 /// Generates the appropriate ticker for an axis, depending on whether the axis displays time or
16 /// non-time data
18 /// non-time data
17 QSharedPointer<QCPAxisTicker> axisTicker(bool isTimeAxis)
19 QSharedPointer<QCPAxisTicker> axisTicker(bool isTimeAxis)
18 {
20 {
19 if (isTimeAxis) {
21 if (isTimeAxis) {
20 auto dateTicker = QSharedPointer<QCPAxisTickerDateTime>::create();
22 auto dateTicker = QSharedPointer<QCPAxisTickerDateTime>::create();
21 dateTicker->setDateTimeFormat(DATETIME_TICKER_FORMAT);
23 dateTicker->setDateTimeFormat(DATETIME_TICKER_FORMAT);
22
24
23 return dateTicker;
25 return dateTicker;
24 }
26 }
25 else {
27 else {
26 // default ticker
28 // default ticker
27 return QSharedPointer<QCPAxisTicker>::create();
29 return QSharedPointer<QCPAxisTicker>::create();
28 }
30 }
29 }
31 }
30
32
31 QCPAbstractPlottable *createScalarSeriesComponent(ScalarSeries &scalarSeries, QCustomPlot &plot)
33 void updateScalarData(QCPAbstractPlottable *component, ScalarSeries &scalarSeries,
34 const SqpDateTime &dateTime)
35 {
36 QElapsedTimer timer;
37 timer.start();
38 if (auto qcpGraph = dynamic_cast<QCPGraph *>(component)) {
39 // Clean the graph
40 qCDebug(LOG_GraphPlottablesFactory()) << "The slow s1 operation took" << timer.elapsed()
41 << "milliseconds";
42 // NAIVE approch
43 const auto &xData = scalarSeries.xAxisData()->data();
44 const auto &valuesData = scalarSeries.valuesData()->data();
45
46 auto xValue = QVector<double>();
47 auto vValue = QVector<double>();
48
49 const auto count = xData.count();
50 auto ite = 0;
51 for (auto i = 0; i < count; ++i) {
52 const auto x = xData.at(i);
53 if (x >= dateTime.m_TStart && x <= dateTime.m_TEnd) {
54 xValue.push_back(x);
55 vValue.push_back(valuesData.at(i));
56 ++ite;
57 }
58 }
59
60 qcpGraph->setData(xValue, vValue);
61
62 qCDebug(LOG_GraphPlottablesFactory()) << "The slow s2 operation took" << timer.elapsed()
63 << "milliseconds";
64 }
65 else {
66 /// @todo DEBUG
67 }
68 }
69
70 QCPAbstractPlottable *createScalarSeriesComponent(ScalarSeries &scalarSeries, QCustomPlot &plot,
71 const SqpDateTime &dateTime)
32 {
72 {
33 auto component = plot.addGraph();
73 auto component = plot.addGraph();
34
74
35 if (component) {
75 if (component) {
36 // Graph data
76 // // Graph data
37 component->setData(scalarSeries.xAxisData()->data(), scalarSeries.valuesData()->data(),
77 component->setData(scalarSeries.xAxisData()->data(), scalarSeries.valuesData()->data(),
38 true);
78 true);
39
79
80 updateScalarData(component, scalarSeries, dateTime);
81
40 // Axes properties
82 // Axes properties
41 /// @todo : for the moment, no control is performed on the axes: the units and the tickers
83 /// @todo : for the moment, no control is performed on the axes: the units and the tickers
42 /// are fixed for the default x-axis and y-axis of the plot, and according to the new graph
84 /// are fixed for the default x-axis and y-axis of the plot, and according to the new graph
43
85
44 auto setAxisProperties = [](auto axis, const auto &unit) {
86 auto setAxisProperties = [](auto axis, const auto &unit) {
45 // label (unit name)
87 // label (unit name)
46 axis->setLabel(unit.m_Name);
88 axis->setLabel(unit.m_Name);
47
89
48 // ticker (depending on the type of unit)
90 // ticker (depending on the type of unit)
49 axis->setTicker(axisTicker(unit.m_TimeUnit));
91 axis->setTicker(axisTicker(unit.m_TimeUnit));
50 };
92 };
51 setAxisProperties(plot.xAxis, scalarSeries.xAxisUnit());
93 setAxisProperties(plot.xAxis, scalarSeries.xAxisUnit());
52 setAxisProperties(plot.yAxis, scalarSeries.valuesUnit());
94 setAxisProperties(plot.yAxis, scalarSeries.valuesUnit());
53
95
54 // Display all data
96 // Display all data
55 component->rescaleAxes();
97 component->rescaleAxes();
56
98
57 plot.replot();
99 plot.replot();
58 }
100 }
59 else {
101 else {
60 qCDebug(LOG_GraphPlottablesFactory())
102 qCDebug(LOG_GraphPlottablesFactory())
61 << QObject::tr("Can't create graph for the scalar series");
103 << QObject::tr("Can't create graph for the scalar series");
62 }
104 }
63
105
64 return component;
106 return component;
65 }
107 }
66
108
67 } // namespace
109 } // namespace
68
110
69 QVector<QCPAbstractPlottable *> GraphPlottablesFactory::create(std::shared_ptr<Variable> variable,
111 QVector<QCPAbstractPlottable *> GraphPlottablesFactory::create(std::shared_ptr<Variable> variable,
70 QCustomPlot &plot) noexcept
112 QCustomPlot &plot) noexcept
71 {
113 {
72 auto result = QVector<QCPAbstractPlottable *>{};
114 auto result = QVector<QCPAbstractPlottable *>{};
73
115
74 if (variable) {
116 if (variable) {
75 // Gets the data series of the variable to call the creation of the right components
117 // Gets the data series of the variable to call the creation of the right components
76 // according to its type
118 // according to its type
77 if (auto scalarSeries = dynamic_cast<ScalarSeries *>(variable->dataSeries())) {
119 if (auto scalarSeries = dynamic_cast<ScalarSeries *>(variable->dataSeries())) {
78 result.append(createScalarSeriesComponent(*scalarSeries, plot));
120 result.append(createScalarSeriesComponent(*scalarSeries, plot, variable->dateTime()));
79 }
121 }
80 else {
122 else {
81 qCDebug(LOG_GraphPlottablesFactory())
123 qCDebug(LOG_GraphPlottablesFactory())
82 << QObject::tr("Can't create graph plottables : unmanaged data series type");
124 << QObject::tr("Can't create graph plottables : unmanaged data series type");
83 }
125 }
84 }
126 }
85 else {
127 else {
86 qCDebug(LOG_GraphPlottablesFactory())
128 qCDebug(LOG_GraphPlottablesFactory())
87 << QObject::tr("Can't create graph plottables : the variable is null");
129 << QObject::tr("Can't create graph plottables : the variable is null");
88 }
130 }
89
131
90 return result;
132 return result;
91 }
133 }
134
135 void GraphPlottablesFactory::updateData(QVector<QCPAbstractPlottable *> plotableVect,
136 IDataSeries *dataSeries, const SqpDateTime &dateTime)
137 {
138 if (auto scalarSeries = dynamic_cast<ScalarSeries *>(dataSeries)) {
139 if (plotableVect.size() == 1) {
140 updateScalarData(plotableVect.at(0), *scalarSeries, dateTime);
141 }
142 else {
143 qCCritical(LOG_GraphPlottablesFactory()) << QObject::tr(
144 "Can't update Data of a scalarSeries because there is not only one component "
145 "associated");
146 }
147 }
148 else {
149 /// @todo DEBUG
150 }
151 }
@@ -1,122 +1,166
1 #include "Visualization/VisualizationGraphWidget.h"
1 #include "Visualization/VisualizationGraphWidget.h"
2 #include "Visualization/GraphPlottablesFactory.h"
2 #include "Visualization/GraphPlottablesFactory.h"
3 #include "Visualization/IVisualizationWidgetVisitor.h"
3 #include "Visualization/IVisualizationWidgetVisitor.h"
4 #include "ui_VisualizationGraphWidget.h"
4 #include "ui_VisualizationGraphWidget.h"
5
5
6 #include <Data/ArrayData.h>
7 #include <Data/IDataSeries.h>
8 #include <SqpApplication.h>
6 #include <Variable/Variable.h>
9 #include <Variable/Variable.h>
10 #include <Variable/VariableController.h>
11
7 #include <unordered_map>
12 #include <unordered_map>
8
13
9 Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget")
14 Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget")
10
15
11 namespace {
16 namespace {
12
17
13 /// Key pressed to enable zoom on horizontal axis
18 /// Key pressed to enable zoom on horizontal axis
14 const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier;
19 const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier;
15
20
16 /// Key pressed to enable zoom on vertical axis
21 /// Key pressed to enable zoom on vertical axis
17 const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier;
22 const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier;
18
23
19 } // namespace
24 } // namespace
20
25
21 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
26 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
22
27
23 // 1 variable -> n qcpplot
28 // 1 variable -> n qcpplot
24 std::unordered_map<std::shared_ptr<Variable>, QCPAbstractPlottable *> m_VariableToPlotMap;
29 std::unordered_multimap<std::shared_ptr<Variable>, QCPAbstractPlottable *>
30 m_VariableToPlotMultiMap;
25 };
31 };
26
32
27 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent)
33 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent)
28 : QWidget{parent},
34 : QWidget{parent},
29 ui{new Ui::VisualizationGraphWidget},
35 ui{new Ui::VisualizationGraphWidget},
30 impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()}
36 impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()}
31 {
37 {
32 ui->setupUi(this);
38 ui->setupUi(this);
33
39
34 // qcpplot title
40 // qcpplot title
35 ui->widget->plotLayout()->insertRow(0);
41 ui->widget->plotLayout()->insertRow(0);
36 ui->widget->plotLayout()->addElement(0, 0, new QCPTextElement{ui->widget, name});
42 ui->widget->plotLayout()->addElement(0, 0, new QCPTextElement{ui->widget, name});
37
43
38 // Set qcpplot properties :
44 // Set qcpplot properties :
39 // - Drag (on x-axis) and zoom are enabled
45 // - Drag (on x-axis) and zoom are enabled
40 // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation
46 // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation
41 ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
47 ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
42 ui->widget->axisRect()->setRangeDrag(Qt::Horizontal);
48 ui->widget->axisRect()->setRangeDrag(Qt::Horizontal);
43 connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel);
49 connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel);
44 connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>(
50 connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>(
45 &QCPAxis::rangeChanged),
51 &QCPAxis::rangeChanged),
46 this, &VisualizationGraphWidget::onRangeChanged);
52 this, &VisualizationGraphWidget::onRangeChanged);
47 }
53 }
48
54
49
55
50 VisualizationGraphWidget::~VisualizationGraphWidget()
56 VisualizationGraphWidget::~VisualizationGraphWidget()
51 {
57 {
52 delete ui;
58 delete ui;
53 }
59 }
54
60
55 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable)
61 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable)
56 {
62 {
57 // Uses delegate to create the qcpplot components according to the variable
63 // Uses delegate to create the qcpplot components according to the variable
58 auto createdPlottables = GraphPlottablesFactory::create(variable, *ui->widget);
64 auto createdPlottables = GraphPlottablesFactory::create(variable, *ui->widget);
59
65
60 for (auto createdPlottable : qAsConst(createdPlottables)) {
66 for (auto createdPlottable : qAsConst(createdPlottables)) {
61 impl->m_VariableToPlotMap.insert({variable, createdPlottable});
67 impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable});
62 }
68 }
69
70 connect(variable.get(), &Variable::dataCacheUpdated, this,
71 &VisualizationGraphWidget::onDataCacheVariableUpdated);
63 }
72 }
64
73
65 void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor)
74 void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor)
66 {
75 {
67 if (visitor) {
76 if (visitor) {
68 visitor->visit(this);
77 visitor->visit(this);
69 }
78 }
70 else {
79 else {
71 qCCritical(LOG_VisualizationGraphWidget())
80 qCCritical(LOG_VisualizationGraphWidget())
72 << tr("Can't visit widget : the visitor is null");
81 << tr("Can't visit widget : the visitor is null");
73 }
82 }
74 }
83 }
75
84
76 bool VisualizationGraphWidget::canDrop(const Variable &variable) const
85 bool VisualizationGraphWidget::canDrop(const Variable &variable) const
77 {
86 {
78 /// @todo : for the moment, a graph can always accomodate a variable
87 /// @todo : for the moment, a graph can always accomodate a variable
79 Q_UNUSED(variable);
88 Q_UNUSED(variable);
80 return true;
89 return true;
81 }
90 }
82
91
83 void VisualizationGraphWidget::close()
92 void VisualizationGraphWidget::close()
84 {
93 {
85 // The main view cannot be directly closed.
94 // The main view cannot be directly closed.
86 return;
95 return;
87 }
96 }
88
97
89 QString VisualizationGraphWidget::name() const
98 QString VisualizationGraphWidget::name() const
90 {
99 {
91 if (auto title = dynamic_cast<QCPTextElement *>(ui->widget->plotLayout()->elementAt(0))) {
100 if (auto title = dynamic_cast<QCPTextElement *>(ui->widget->plotLayout()->elementAt(0))) {
92 return title->text();
101 return title->text();
93 }
102 }
94 else {
103 else {
95 return QString{};
104 return QString{};
96 }
105 }
97 }
106 }
98
107
99 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2)
108 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2)
100 {
109 {
101 for (auto it = impl->m_VariableToPlotMap.cbegin(); it != impl->m_VariableToPlotMap.cend();
110
102 ++it) {
111 qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged");
103 it->first->onXRangeChanged(SqpDateTime{t2.lower, t2.upper});
112
113 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
114 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
115 auto variable = it->first;
116 auto tolerance = 0.1 * (t2.upper - t2.lower);
117 auto dateTime = SqpDateTime{t2.lower - tolerance, t2.upper + tolerance};
118
119 qCInfo(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged")
120 << variable->dataSeries()->xAxisData()->size();
121 if (!variable->contains(dateTime)) {
122 sqpApp->variableController().requestDataLoading(variable, dateTime);
123 }
104 }
124 }
105 }
125 }
106
126
107 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept
127 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept
108 {
128 {
109 auto zoomOrientations = QFlags<Qt::Orientation>{};
129 auto zoomOrientations = QFlags<Qt::Orientation>{};
110
130
111 // Lambda that enables a zoom orientation if the key modifier related to this orientation has
131 // Lambda that enables a zoom orientation if the key modifier related to this orientation has
112 // been pressed
132 // been pressed
113 auto enableOrientation
133 auto enableOrientation
114 = [&zoomOrientations, event](const auto &orientation, const auto &modifier) {
134 = [&zoomOrientations, event](const auto &orientation, const auto &modifier) {
115 auto orientationEnabled = event->modifiers().testFlag(modifier);
135 auto orientationEnabled = event->modifiers().testFlag(modifier);
116 zoomOrientations.setFlag(orientation, orientationEnabled);
136 zoomOrientations.setFlag(orientation, orientationEnabled);
117 };
137 };
118 enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER);
138 enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER);
119 enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER);
139 enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER);
120
140
121 ui->widget->axisRect()->setRangeZoom(zoomOrientations);
141 ui->widget->axisRect()->setRangeZoom(zoomOrientations);
122 }
142 }
143
144 void VisualizationGraphWidget::onDataCacheVariableUpdated()
145 {
146 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
147 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
148 auto variable = it->first;
149 GraphPlottablesFactory::updateData(QVector<QCPAbstractPlottable *>{} << it->second,
150 variable->dataSeries(), variable->dateTime());
151 }
152 }
153
154 void VisualizationGraphWidget::updateDisplay(std::shared_ptr<Variable> variable)
155 {
156 auto abstractPlotableItPair = impl->m_VariableToPlotMultiMap.equal_range(variable);
157
158 auto abstractPlotableVect = QVector<QCPAbstractPlottable *>{};
159
160 for (auto it = abstractPlotableItPair.first; it != abstractPlotableItPair.second; ++it) {
161 abstractPlotableVect.push_back(it->second);
162 }
163
164 GraphPlottablesFactory::updateData(abstractPlotableVect, variable->dataSeries(),
165 variable->dateTime());
166 }
General Comments 0
You need to be logged in to leave comments. Login now