##// END OF EJS Templates
Merge pull request 172 from SCIQLOP-Initialisation develop...
leroux -
r321:b1c50789867a merge
parent child
Show More
@@ -1,44 +1,44
1 #ifndef SCIQLOP_SQPDATETIME_H
1 #ifndef SCIQLOP_SQPDATETIME_H
2 #define SCIQLOP_SQPDATETIME_H
2 #define SCIQLOP_SQPDATETIME_H
3
3
4 #include <QObject>
4 #include <QObject>
5
5
6 #include <QDateTime>
6 #include <QDateTime>
7 #include <QDebug>
7 #include <QDebug>
8
8
9 #include <Common/MetaTypes.h>
9 #include <Common/MetaTypes.h>
10
10
11 /**
11 /**
12 * @brief The SqpDateTime struct holds the information of time parameters
12 * @brief The SqpDateTime struct holds the information of time parameters
13 */
13 */
14 struct SqpDateTime {
14 struct SqpDateTime {
15 /// Start time
15 /// Start time
16 double m_TStart;
16 double m_TStart;
17 /// End time
17 /// End time
18 double m_TEnd;
18 double m_TEnd;
19
19
20 bool contains(const SqpDateTime &dateTime)
20 bool contains(const SqpDateTime &dateTime) const noexcept
21 {
21 {
22 return (m_TStart <= dateTime.m_TStart && m_TEnd >= dateTime.m_TEnd);
22 return (m_TStart <= dateTime.m_TStart && m_TEnd >= dateTime.m_TEnd);
23 }
23 }
24
24
25 bool intersect(const SqpDateTime &dateTime)
25 bool intersect(const SqpDateTime &dateTime) const noexcept
26 {
26 {
27 return (m_TEnd >= dateTime.m_TStart && m_TStart <= dateTime.m_TEnd);
27 return (m_TEnd >= dateTime.m_TStart && m_TStart <= dateTime.m_TEnd);
28 }
28 }
29 };
29 };
30
30
31 inline QDebug operator<<(QDebug d, SqpDateTime obj)
31 inline QDebug operator<<(QDebug d, SqpDateTime obj)
32 {
32 {
33 auto tendDateTimeStart = QDateTime::fromMSecsSinceEpoch(obj.m_TStart * 1000);
33 auto tendDateTimeStart = QDateTime::fromMSecsSinceEpoch(obj.m_TStart * 1000);
34 auto tendDateTimeEnd = QDateTime::fromMSecsSinceEpoch(obj.m_TEnd * 1000);
34 auto tendDateTimeEnd = QDateTime::fromMSecsSinceEpoch(obj.m_TEnd * 1000);
35
35
36 // QDebug << "ts: " << tendDateTimeStart << " te: " << tendDateTimeEnd;
36 // QDebug << "ts: " << tendDateTimeStart << " te: " << tendDateTimeEnd;
37 d << "ts: " << tendDateTimeStart << " te: " << tendDateTimeEnd;
37 d << "ts: " << tendDateTimeStart << " te: " << tendDateTimeEnd;
38 return d;
38 return d;
39 }
39 }
40
40
41 // Required for using shared_ptr in signals/slots
41 // Required for using shared_ptr in signals/slots
42 SCIQLOP_REGISTER_META_TYPE(SQPDATETIME_REGISTRY, SqpDateTime)
42 SCIQLOP_REGISTER_META_TYPE(SQPDATETIME_REGISTRY, SqpDateTime)
43
43
44 #endif // SCIQLOP_SQPDATETIME_H
44 #endif // SCIQLOP_SQPDATETIME_H
@@ -1,54 +1,55
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 #include <QLoggingCategory>
6 #include <QLoggingCategory>
7 #include <QObject>
7 #include <QObject>
8
8
9 #include <Common/MetaTypes.h>
9 #include <Common/MetaTypes.h>
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 : public QObject {
20 class Variable : public QObject {
21
21
22 Q_OBJECT
22 Q_OBJECT
23
23
24 public:
24 public:
25 explicit Variable(const QString &name, const QString &unit, const QString &mission,
25 explicit Variable(const QString &name, const QString &unit, const QString &mission,
26 const SqpDateTime &dateTime);
26 const SqpDateTime &dateTime);
27
27
28 QString name() const noexcept;
28 QString name() const noexcept;
29 QString mission() const noexcept;
29 QString mission() const noexcept;
30 QString unit() const noexcept;
30 QString unit() const noexcept;
31 SqpDateTime dateTime() const noexcept;
31 SqpDateTime dateTime() const noexcept;
32 void setDateTime(const SqpDateTime &dateTime) noexcept;
32 void setDateTime(const SqpDateTime &dateTime) noexcept;
33
33
34 /// @return the data of the variable, nullptr if there is no data
34 /// @return the data of the variable, nullptr if there is no data
35 IDataSeries *dataSeries() const noexcept;
35 IDataSeries *dataSeries() const noexcept;
36
36
37 bool contains(const SqpDateTime &dateTime);
37 bool contains(const SqpDateTime &dateTime) const noexcept;
38 bool intersect(const SqpDateTime &dateTime);
38 bool intersect(const SqpDateTime &dateTime) const noexcept;
39 bool isInside(const SqpDateTime &dateTime) const noexcept;
39
40
40 public slots:
41 public slots:
41 void setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept;
42 void setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept;
42
43
43 signals:
44 signals:
44 void updated();
45 void updated();
45
46
46 private:
47 private:
47 class VariablePrivate;
48 class VariablePrivate;
48 spimpl::unique_impl_ptr<VariablePrivate> impl;
49 spimpl::unique_impl_ptr<VariablePrivate> impl;
49 };
50 };
50
51
51 // Required for using shared_ptr in signals/slots
52 // Required for using shared_ptr in signals/slots
52 SCIQLOP_REGISTER_META_TYPE(VARIABLE_PTR_REGISTRY, std::shared_ptr<Variable>)
53 SCIQLOP_REGISTER_META_TYPE(VARIABLE_PTR_REGISTRY, std::shared_ptr<Variable>)
53
54
54 #endif // SCIQLOP_VARIABLE_H
55 #endif // SCIQLOP_VARIABLE_H
@@ -1,51 +1,49
1 #ifndef SCIQLOP_VARIABLEMODEL_H
1 #ifndef SCIQLOP_VARIABLEMODEL_H
2 #define SCIQLOP_VARIABLEMODEL_H
2 #define SCIQLOP_VARIABLEMODEL_H
3
3
4
4
5 #include <Data/SqpDateTime.h>
5 #include <Data/SqpDateTime.h>
6
6
7 #include <QAbstractTableModel>
7 #include <QAbstractTableModel>
8 #include <QLoggingCategory>
8 #include <QLoggingCategory>
9
9
10 #include <Common/spimpl.h>
10 #include <Common/spimpl.h>
11
11
12 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableModel)
12 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableModel)
13
13
14 class IDataSeries;
14 class IDataSeries;
15 class Variable;
15 class Variable;
16
16
17 /**
17 /**
18 * @brief The VariableModel class aims to hold the variables that have been created in SciQlop
18 * @brief The VariableModel class aims to hold the variables that have been created in SciQlop
19 */
19 */
20 class VariableModel : public QAbstractTableModel {
20 class VariableModel : public QAbstractTableModel {
21 public:
21 public:
22 explicit VariableModel(QObject *parent = nullptr);
22 explicit VariableModel(QObject *parent = nullptr);
23
23
24 /**
24 /**
25 * Creates a new variable in the model
25 * Creates a new variable in the model
26 * @param name the name of the new variable
26 * @param name the name of the new variable
27 * @param dateTime the dateTime of the new variable
27 * @param dateTime the dateTime of the new variable
28 * @param defaultDataSeries the default data of the new variable
29 * @return the pointer to the new variable
28 * @return the pointer to the new variable
30 */
29 */
31 std::shared_ptr<Variable>
30 std::shared_ptr<Variable> createVariable(const QString &name,
32 createVariable(const QString &name, const SqpDateTime &dateTime,
31 const SqpDateTime &dateTime) noexcept;
33 std::shared_ptr<IDataSeries> defaultDataSeries) noexcept;
34
32
35 std::shared_ptr<Variable> variable(int index) const;
33 std::shared_ptr<Variable> variable(int index) const;
36
34
37 // /////////////////////////// //
35 // /////////////////////////// //
38 // QAbstractTableModel methods //
36 // QAbstractTableModel methods //
39 // /////////////////////////// //
37 // /////////////////////////// //
40 virtual int columnCount(const QModelIndex &parent = QModelIndex{}) const override;
38 virtual int columnCount(const QModelIndex &parent = QModelIndex{}) const override;
41 virtual int rowCount(const QModelIndex &parent = QModelIndex{}) const override;
39 virtual int rowCount(const QModelIndex &parent = QModelIndex{}) const override;
42 virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
40 virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
43 virtual QVariant headerData(int section, Qt::Orientation orientation,
41 virtual QVariant headerData(int section, Qt::Orientation orientation,
44 int role = Qt::DisplayRole) const override;
42 int role = Qt::DisplayRole) const override;
45
43
46 private:
44 private:
47 class VariableModelPrivate;
45 class VariableModelPrivate;
48 spimpl::unique_impl_ptr<VariableModelPrivate> impl;
46 spimpl::unique_impl_ptr<VariableModelPrivate> impl;
49 };
47 };
50
48
51 #endif // SCIQLOP_VARIABLEMODEL_H
49 #endif // SCIQLOP_VARIABLEMODEL_H
@@ -1,89 +1,94
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 SqpDateTime Variable::dateTime() const noexcept
48 SqpDateTime Variable::dateTime() const noexcept
49 {
49 {
50 return impl->m_DateTime;
50 return impl->m_DateTime;
51 }
51 }
52
52
53 void Variable::setDateTime(const SqpDateTime &dateTime) noexcept
53 void Variable::setDateTime(const SqpDateTime &dateTime) noexcept
54 {
54 {
55 impl->m_DateTime = dateTime;
55 impl->m_DateTime = dateTime;
56 }
56 }
57
57
58 void Variable::setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept
58 void Variable::setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept
59 {
59 {
60 if (!dataSeries) {
60 if (!dataSeries) {
61 /// @todo ALX : log
61 /// @todo ALX : log
62 return;
62 return;
63 }
63 }
64
64
65 // Inits the data series of the variable
65 // Inits the data series of the variable
66 if (!impl->m_DataSeries) {
66 if (!impl->m_DataSeries) {
67 impl->m_DataSeries = dataSeries->clone();
67 impl->m_DataSeries = dataSeries->clone();
68 }
68 }
69 else {
69 else {
70 impl->m_DataSeries->merge(dataSeries.get());
70 impl->m_DataSeries->merge(dataSeries.get());
71
71
72 emit updated();
72 emit updated();
73 }
73 }
74 }
74 }
75
75
76 IDataSeries *Variable::dataSeries() const noexcept
76 IDataSeries *Variable::dataSeries() const noexcept
77 {
77 {
78 return impl->m_DataSeries.get();
78 return impl->m_DataSeries.get();
79 }
79 }
80
80
81 bool Variable::contains(const SqpDateTime &dateTime)
81 bool Variable::contains(const SqpDateTime &dateTime) const noexcept
82 {
82 {
83 return impl->m_DateTime.contains(dateTime);
83 return impl->m_DateTime.contains(dateTime);
84 }
84 }
85
85
86 bool Variable::intersect(const SqpDateTime &dateTime)
86 bool Variable::intersect(const SqpDateTime &dateTime) const noexcept
87 {
87 {
88 return impl->m_DateTime.intersect(dateTime);
88 return impl->m_DateTime.intersect(dateTime);
89 }
89 }
90
91 bool Variable::isInside(const SqpDateTime &dateTime) const noexcept
92 {
93 return dateTime.contains(SqpDateTime{impl->m_DateTime.m_TStart, impl->m_DateTime.m_TEnd});
94 }
@@ -1,205 +1,204
1 #include "Variable/VariableCacheController.h"
1 #include "Variable/VariableCacheController.h"
2
2
3 #include "Variable/Variable.h"
3 #include "Variable/Variable.h"
4 #include <unordered_map>
4 #include <unordered_map>
5
5
6 Q_LOGGING_CATEGORY(LOG_VariableCacheController, "VariableCacheController")
6 Q_LOGGING_CATEGORY(LOG_VariableCacheController, "VariableCacheController")
7
7
8 struct VariableCacheController::VariableCacheControllerPrivate {
8 struct VariableCacheController::VariableCacheControllerPrivate {
9
9
10 std::unordered_map<std::shared_ptr<Variable>, QVector<SqpDateTime> >
10 std::unordered_map<std::shared_ptr<Variable>, QVector<SqpDateTime> >
11 m_VariableToSqpDateTimeListMap;
11 m_VariableToSqpDateTimeListMap;
12
12
13 void addInCacheDataByEnd(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList,
13 void addInCacheDataByEnd(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList,
14 QVector<SqpDateTime> &notInCache, int cacheIndex,
14 QVector<SqpDateTime> &notInCache, int cacheIndex,
15 double currentTStart);
15 double currentTStart);
16
16
17 void addInCacheDataByStart(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList,
17 void addInCacheDataByStart(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList,
18 QVector<SqpDateTime> &notInCache, int cacheIndex,
18 QVector<SqpDateTime> &notInCache, int cacheIndex,
19 double currentTStart);
19 double currentTStart);
20
20
21
21
22 void addDateTimeRecurse(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList,
22 void addDateTimeRecurse(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList,
23 int cacheIndex);
23 int cacheIndex);
24 };
24 };
25
25
26
26
27 VariableCacheController::VariableCacheController(QObject *parent)
27 VariableCacheController::VariableCacheController(QObject *parent)
28 : QObject{parent}, impl{spimpl::make_unique_impl<VariableCacheControllerPrivate>()}
28 : QObject{parent}, impl{spimpl::make_unique_impl<VariableCacheControllerPrivate>()}
29 {
29 {
30 }
30 }
31
31
32 void VariableCacheController::addDateTime(std::shared_ptr<Variable> variable,
32 void VariableCacheController::addDateTime(std::shared_ptr<Variable> variable,
33 const SqpDateTime &dateTime)
33 const SqpDateTime &dateTime)
34 {
34 {
35 if (variable) {
35 if (variable) {
36 auto findVariableIte = impl->m_VariableToSqpDateTimeListMap.find(variable);
36 auto findVariableIte = impl->m_VariableToSqpDateTimeListMap.find(variable);
37 if (findVariableIte == impl->m_VariableToSqpDateTimeListMap.end()) {
37 if (findVariableIte == impl->m_VariableToSqpDateTimeListMap.end()) {
38 impl->m_VariableToSqpDateTimeListMap[variable].push_back(dateTime);
38 impl->m_VariableToSqpDateTimeListMap[variable].push_back(dateTime);
39 }
39 }
40 else {
40 else {
41
41
42 // addDateTime modify the list<SqpDateTime> of the variable in a way to ensure
42 // addDateTime modify the list<SqpDateTime> of the variable in a way to ensure
43 // that the list is ordered : l(0) < l(1). We assume also a < b
43 // that the list is ordered : l(0) < l(1). We assume also a < b
44 // (with a & b of type SqpDateTime) means ts(b) > te(a)
44 // (with a & b of type SqpDateTime) means ts(b) > te(a)
45
45
46 // The algorithm will try the merge of two interval:
46 // The algorithm will try the merge of two interval:
47 // - dateTime will be compare with the first interval of the list:
47 // - dateTime will be compare with the first interval of the list:
48 // A: if it is inferior, it will be inserted and it's finished.
48 // A: if it is inferior, it will be inserted and it's finished.
49 // B: if it is in intersection, it will be merge then the merged one
49 // B: if it is in intersection, it will be merge then the merged one
50 // will be compared to the next interval. The old one is remove from the list
50 // will be compared to the next interval. The old one is remove from the list
51 // C: if it is superior, we do the same with the next interval of the list
51 // C: if it is superior, we do the same with the next interval of the list
52
52
53 try {
53 try {
54 impl->addDateTimeRecurse(dateTime,
54 impl->addDateTimeRecurse(dateTime,
55 impl->m_VariableToSqpDateTimeListMap.at(variable), 0);
55 impl->m_VariableToSqpDateTimeListMap.at(variable), 0);
56 }
56 }
57 catch (const std::out_of_range &e) {
57 catch (const std::out_of_range &e) {
58 qCWarning(LOG_VariableCacheController()) << e.what();
58 qCWarning(LOG_VariableCacheController()) << "addDateTime" << e.what();
59 }
59 }
60 }
60 }
61 }
61 }
62 }
62 }
63
63
64 QVector<SqpDateTime>
64 QVector<SqpDateTime>
65 VariableCacheController::provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable,
65 VariableCacheController::provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable,
66 const SqpDateTime &dateTime)
66 const SqpDateTime &dateTime)
67 {
67 {
68 auto notInCache = QVector<SqpDateTime>{};
68 auto notInCache = QVector<SqpDateTime>{};
69
69
70 // This algorithm is recursif. The idea is to localise the start time then the end time in the
70 // This algorithm is recursif. The idea is to localise the start time then the end time in the
71 // list of date time request associated to the variable
71 // list of date time request associated to the variable
72 // We assume that the list is ordered in a way that l(0) < l(1). We assume also a < b
72 // We assume that the list is ordered in a way that l(0) < l(1). We assume also a < b
73 // (with a & b of type SqpDateTime) means ts(b) > te(a)
73 // (with a & b of type SqpDateTime) means ts(b) > te(a)
74
74 auto it = impl->m_VariableToSqpDateTimeListMap.find(variable);
75 try {
75 if (it != impl->m_VariableToSqpDateTimeListMap.end()) {
76 impl->addInCacheDataByStart(dateTime, impl->m_VariableToSqpDateTimeListMap.at(variable),
76 impl->addInCacheDataByStart(dateTime, it->second, notInCache, 0, dateTime.m_TStart);
77 notInCache, 0, dateTime.m_TStart);
78 }
77 }
79 catch (const std::out_of_range &e) {
78 else {
80 qCWarning(LOG_VariableCacheController()) << e.what();
79 notInCache << dateTime;
81 }
80 }
82
81
83 return notInCache;
82 return notInCache;
84 }
83 }
85
84
86 QVector<SqpDateTime>
85 QVector<SqpDateTime>
87 VariableCacheController::dateCacheList(std::shared_ptr<Variable> variable) const noexcept
86 VariableCacheController::dateCacheList(std::shared_ptr<Variable> variable) const noexcept
88 {
87 {
89 try {
88 try {
90 return impl->m_VariableToSqpDateTimeListMap.at(variable);
89 return impl->m_VariableToSqpDateTimeListMap.at(variable);
91 }
90 }
92 catch (const std::out_of_range &e) {
91 catch (const std::out_of_range &e) {
93 qCWarning(LOG_VariableCacheController()) << e.what();
92 qCWarning(LOG_VariableCacheController()) << e.what();
94 return QVector<SqpDateTime>{};
93 return QVector<SqpDateTime>{};
95 }
94 }
96 }
95 }
97
96
98 void VariableCacheController::VariableCacheControllerPrivate::addDateTimeRecurse(
97 void VariableCacheController::VariableCacheControllerPrivate::addDateTimeRecurse(
99 const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, int cacheIndex)
98 const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, int cacheIndex)
100 {
99 {
101 const auto dateTimeListSize = dateTimeList.count();
100 const auto dateTimeListSize = dateTimeList.count();
102 if (cacheIndex >= dateTimeListSize) {
101 if (cacheIndex >= dateTimeListSize) {
103 dateTimeList.push_back(dateTime);
102 dateTimeList.push_back(dateTime);
104 // there is no anymore interval to compore, we can just push_back it
103 // there is no anymore interval to compore, we can just push_back it
105 return;
104 return;
106 }
105 }
107
106
108 auto currentDateTime = dateTimeList[cacheIndex];
107 auto currentDateTime = dateTimeList[cacheIndex];
109
108
110 if (dateTime.m_TEnd < currentDateTime.m_TStart) {
109 if (dateTime.m_TEnd < currentDateTime.m_TStart) {
111 // The compared one is < to current one compared, we can insert it
110 // The compared one is < to current one compared, we can insert it
112 dateTimeList.insert(cacheIndex, dateTime);
111 dateTimeList.insert(cacheIndex, dateTime);
113 }
112 }
114 else if (dateTime.m_TStart > currentDateTime.m_TEnd) {
113 else if (dateTime.m_TStart > currentDateTime.m_TEnd) {
115 // The compared one is > to current one compared we can comparet if to the next one
114 // The compared one is > to current one compared we can comparet if to the next one
116 addDateTimeRecurse(dateTime, dateTimeList, ++cacheIndex);
115 addDateTimeRecurse(dateTime, dateTimeList, ++cacheIndex);
117 }
116 }
118 else {
117 else {
119 // Merge cases: we need to merge the two interval, remove the old one from the list then
118 // Merge cases: we need to merge the two interval, remove the old one from the list then
120 // rerun the algo from this index with the merged interval
119 // rerun the algo from this index with the merged interval
121 auto mTStart = std::min(dateTime.m_TStart, currentDateTime.m_TStart);
120 auto mTStart = std::min(dateTime.m_TStart, currentDateTime.m_TStart);
122 auto mTEnd = std::max(dateTime.m_TEnd, currentDateTime.m_TEnd);
121 auto mTEnd = std::max(dateTime.m_TEnd, currentDateTime.m_TEnd);
123 auto mergeDateTime = SqpDateTime{mTStart, mTEnd};
122 auto mergeDateTime = SqpDateTime{mTStart, mTEnd};
124
123
125 dateTimeList.remove(cacheIndex);
124 dateTimeList.remove(cacheIndex);
126 addDateTimeRecurse(mergeDateTime, dateTimeList, cacheIndex);
125 addDateTimeRecurse(mergeDateTime, dateTimeList, cacheIndex);
127 }
126 }
128 }
127 }
129
128
130
129
131 void VariableCacheController::VariableCacheControllerPrivate::addInCacheDataByEnd(
130 void VariableCacheController::VariableCacheControllerPrivate::addInCacheDataByEnd(
132 const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList,
131 const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList,
133 QVector<SqpDateTime> &notInCache, int cacheIndex, double currentTStart)
132 QVector<SqpDateTime> &notInCache, int cacheIndex, double currentTStart)
134 {
133 {
135 const auto dateTimeListSize = dateTimeList.count();
134 const auto dateTimeListSize = dateTimeList.count();
136 if (cacheIndex >= dateTimeListSize) {
135 if (cacheIndex >= dateTimeListSize) {
137 if (currentTStart < dateTime.m_TEnd) {
136 if (currentTStart < dateTime.m_TEnd) {
138
137
139 // te localised after all other interval: The last interval is [currentTsart, te]
138 // te localised after all other interval: The last interval is [currentTsart, te]
140 notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd});
139 notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd});
141 }
140 }
142 return;
141 return;
143 }
142 }
144
143
145 auto currentDateTimeJ = dateTimeList[cacheIndex];
144 auto currentDateTimeJ = dateTimeList[cacheIndex];
146 if (dateTime.m_TEnd <= currentDateTimeJ.m_TStart) {
145 if (dateTime.m_TEnd <= currentDateTimeJ.m_TStart) {
147 // te localised between to interval: The last interval is [currentTsart, te]
146 // te localised between to interval: The last interval is [currentTsart, te]
148 notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd});
147 notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd});
149 }
148 }
150 else {
149 else {
151 notInCache.push_back(SqpDateTime{currentTStart, currentDateTimeJ.m_TStart});
150 notInCache.push_back(SqpDateTime{currentTStart, currentDateTimeJ.m_TStart});
152 if (dateTime.m_TEnd > currentDateTimeJ.m_TEnd) {
151 if (dateTime.m_TEnd > currentDateTimeJ.m_TEnd) {
153 // te not localised before the current interval: we need to look at the next interval
152 // te not localised before the current interval: we need to look at the next interval
154 addInCacheDataByEnd(dateTime, dateTimeList, notInCache, ++cacheIndex,
153 addInCacheDataByEnd(dateTime, dateTimeList, notInCache, ++cacheIndex,
155 currentDateTimeJ.m_TEnd);
154 currentDateTimeJ.m_TEnd);
156 }
155 }
157 }
156 }
158 }
157 }
159
158
160 void VariableCacheController::VariableCacheControllerPrivate::addInCacheDataByStart(
159 void VariableCacheController::VariableCacheControllerPrivate::addInCacheDataByStart(
161 const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList,
160 const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList,
162 QVector<SqpDateTime> &notInCache, int cacheIndex, double currentTStart)
161 QVector<SqpDateTime> &notInCache, int cacheIndex, double currentTStart)
163 {
162 {
164 const auto dateTimeListSize = dateTimeList.count();
163 const auto dateTimeListSize = dateTimeList.count();
165 if (cacheIndex >= dateTimeListSize) {
164 if (cacheIndex >= dateTimeListSize) {
166 // ts localised after all other interval: The last interval is [ts, te]
165 // ts localised after all other interval: The last interval is [ts, te]
167 notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd});
166 notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd});
168 return;
167 return;
169 }
168 }
170
169
171 auto currentDateTimeI = dateTimeList[cacheIndex];
170 auto currentDateTimeI = dateTimeList[cacheIndex];
172 if (currentTStart < currentDateTimeI.m_TStart) {
171 if (currentTStart < currentDateTimeI.m_TStart) {
173
172
174 // ts localised between to interval: let's localized te
173 // ts localised between to interval: let's localized te
175 addInCacheDataByEnd(dateTime, dateTimeList, notInCache, cacheIndex, currentTStart);
174 addInCacheDataByEnd(dateTime, dateTimeList, notInCache, cacheIndex, currentTStart);
176 }
175 }
177 else if (currentTStart < currentDateTimeI.m_TEnd) {
176 else if (currentTStart < currentDateTimeI.m_TEnd) {
178 if (dateTime.m_TEnd > currentDateTimeI.m_TEnd) {
177 if (dateTime.m_TEnd > currentDateTimeI.m_TEnd) {
179 // ts not localised before the current interval: we need to look at the next interval
178 // ts not localised before the current interval: we need to look at the next interval
180 // We can assume now current tstart is the last interval tend, because data between them
179 // We can assume now current tstart is the last interval tend, because data between them
181 // are
180 // are
182 // in the cache
181 // in the cache
183 addInCacheDataByStart(dateTime, dateTimeList, notInCache, ++cacheIndex,
182 addInCacheDataByStart(dateTime, dateTimeList, notInCache, ++cacheIndex,
184 currentDateTimeI.m_TEnd);
183 currentDateTimeI.m_TEnd);
185 }
184 }
186 }
185 }
187 else {
186 else {
188 // ts not localised before the current interval: we need to look at the next interval
187 // ts not localised before the current interval: we need to look at the next interval
189 addInCacheDataByStart(dateTime, dateTimeList, notInCache, ++cacheIndex, currentTStart);
188 addInCacheDataByStart(dateTime, dateTimeList, notInCache, ++cacheIndex, currentTStart);
190 }
189 }
191 }
190 }
192
191
193
192
194 void VariableCacheController::displayCache(std::shared_ptr<Variable> variable) const
193 void VariableCacheController::displayCache(std::shared_ptr<Variable> variable) const
195 {
194 {
196 auto variableDateTimeList = impl->m_VariableToSqpDateTimeListMap.find(variable);
195 auto variableDateTimeList = impl->m_VariableToSqpDateTimeListMap.find(variable);
197 if (variableDateTimeList != impl->m_VariableToSqpDateTimeListMap.end()) {
196 if (variableDateTimeList != impl->m_VariableToSqpDateTimeListMap.end()) {
198 qCInfo(LOG_VariableCacheController()) << tr("VariableCacheController::displayCache")
197 qCInfo(LOG_VariableCacheController()) << tr("VariableCacheController::displayCache")
199 << variableDateTimeList->second;
198 << variableDateTimeList->second;
200 }
199 }
201 else {
200 else {
202 qCWarning(LOG_VariableCacheController())
201 qCWarning(LOG_VariableCacheController())
203 << tr("Cannot display a variable that is not in the cache");
202 << tr("Cannot display a variable that is not in the cache");
204 }
203 }
205 }
204 }
@@ -1,175 +1,177
1 #include <Variable/Variable.h>
1 #include <Variable/Variable.h>
2 #include <Variable/VariableCacheController.h>
2 #include <Variable/VariableCacheController.h>
3 #include <Variable/VariableController.h>
3 #include <Variable/VariableController.h>
4 #include <Variable/VariableModel.h>
4 #include <Variable/VariableModel.h>
5
5
6 #include <Data/DataProviderParameters.h>
6 #include <Data/DataProviderParameters.h>
7 #include <Data/IDataProvider.h>
7 #include <Data/IDataProvider.h>
8 #include <Data/IDataSeries.h>
8 #include <Data/IDataSeries.h>
9 #include <Time/TimeController.h>
9 #include <Time/TimeController.h>
10
10
11 #include <QDateTime>
11 #include <QDateTime>
12 #include <QMutex>
12 #include <QMutex>
13 #include <QThread>
13 #include <QThread>
14 #include <QtCore/QItemSelectionModel>
14 #include <QtCore/QItemSelectionModel>
15
15
16 #include <unordered_map>
16 #include <unordered_map>
17
17
18 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
18 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
19
19
20 namespace {
20 namespace {
21
21
22 /// @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
23 /// will be deleted when the timerange is recovered from SciQlop
23 /// will be deleted when the timerange is recovered from SciQlop
24 std::shared_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider,
24 std::shared_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider,
25 const SqpDateTime &dateTime) noexcept
25 const SqpDateTime &dateTime) noexcept
26 {
26 {
27 auto parameters = DataProviderParameters{dateTime};
27 auto parameters = DataProviderParameters{dateTime};
28
28
29 return provider.retrieveData(parameters);
29 return provider.retrieveData(parameters);
30 }
30 }
31
31
32 } // namespace
32 } // namespace
33
33
34 struct VariableController::VariableControllerPrivate {
34 struct VariableController::VariableControllerPrivate {
35 explicit VariableControllerPrivate(VariableController *parent)
35 explicit VariableControllerPrivate(VariableController *parent)
36 : m_WorkingMutex{},
36 : m_WorkingMutex{},
37 m_VariableModel{new VariableModel{parent}},
37 m_VariableModel{new VariableModel{parent}},
38 m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}},
38 m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}},
39 m_VariableCacheController{std::make_unique<VariableCacheController>()}
39 m_VariableCacheController{std::make_unique<VariableCacheController>()}
40 {
40 {
41 }
41 }
42
42
43 QMutex m_WorkingMutex;
43 QMutex m_WorkingMutex;
44 /// Variable model. The VariableController has the ownership
44 /// Variable model. The VariableController has the ownership
45 VariableModel *m_VariableModel;
45 VariableModel *m_VariableModel;
46 QItemSelectionModel *m_VariableSelectionModel;
46 QItemSelectionModel *m_VariableSelectionModel;
47
47
48
48
49 TimeController *m_TimeController{nullptr};
49 TimeController *m_TimeController{nullptr};
50 std::unique_ptr<VariableCacheController> m_VariableCacheController;
50 std::unique_ptr<VariableCacheController> m_VariableCacheController;
51
51
52 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
52 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
53 m_VariableToProviderMap;
53 m_VariableToProviderMap;
54 };
54 };
55
55
56 VariableController::VariableController(QObject *parent)
56 VariableController::VariableController(QObject *parent)
57 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
57 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
58 {
58 {
59 qCDebug(LOG_VariableController()) << tr("VariableController construction")
59 qCDebug(LOG_VariableController()) << tr("VariableController construction")
60 << QThread::currentThread();
60 << QThread::currentThread();
61 }
61 }
62
62
63 VariableController::~VariableController()
63 VariableController::~VariableController()
64 {
64 {
65 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
65 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
66 << QThread::currentThread();
66 << QThread::currentThread();
67 this->waitForFinish();
67 this->waitForFinish();
68 }
68 }
69
69
70 VariableModel *VariableController::variableModel() noexcept
70 VariableModel *VariableController::variableModel() noexcept
71 {
71 {
72 return impl->m_VariableModel;
72 return impl->m_VariableModel;
73 }
73 }
74
74
75 QItemSelectionModel *VariableController::variableSelectionModel() noexcept
75 QItemSelectionModel *VariableController::variableSelectionModel() noexcept
76 {
76 {
77 return impl->m_VariableSelectionModel;
77 return impl->m_VariableSelectionModel;
78 }
78 }
79
79
80 void VariableController::setTimeController(TimeController *timeController) noexcept
80 void VariableController::setTimeController(TimeController *timeController) noexcept
81 {
81 {
82 impl->m_TimeController = timeController;
82 impl->m_TimeController = timeController;
83 }
83 }
84
84
85 void VariableController::createVariable(const QString &name,
85 void VariableController::createVariable(const QString &name,
86 std::shared_ptr<IDataProvider> provider) noexcept
86 std::shared_ptr<IDataProvider> provider) noexcept
87 {
87 {
88
88
89 if (!impl->m_TimeController) {
89 if (!impl->m_TimeController) {
90 qCCritical(LOG_VariableController())
90 qCCritical(LOG_VariableController())
91 << tr("Impossible to create variable: The time controller is null");
91 << tr("Impossible to create variable: The time controller is null");
92 return;
92 return;
93 }
93 }
94
94
95
95
96 /// @todo : for the moment :
96 /// @todo : for the moment :
97 /// - the provider is only used to retrieve data from the variable for its initialization, but
97 /// - the provider is only used to retrieve data from the variable for its initialization, but
98 /// it will be retained later
98 /// it will be retained later
99 /// - default data are generated for the variable, without taking into account the timerange set
99 /// - default data are generated for the variable, without taking into account the timerange set
100 /// in sciqlop
100 /// in sciqlop
101 auto dateTime = impl->m_TimeController->dateTime();
101 auto dateTime = impl->m_TimeController->dateTime();
102 if (auto newVariable = impl->m_VariableModel->createVariable(
102 if (auto newVariable = impl->m_VariableModel->createVariable(name, dateTime)) {
103 name, dateTime, generateDefaultDataSeries(*provider, dateTime))) {
104
103
105 // store the provider
104 // store the provider
106 impl->m_VariableToProviderMap[newVariable] = provider;
105 impl->m_VariableToProviderMap[newVariable] = provider;
107 connect(provider.get(), &IDataProvider::dataProvided, newVariable.get(),
108 &Variable::setDataSeries);
109
106
107 auto addDateTimeAcquired
108 = [this, newVariable](auto dataSeriesAcquired, auto dateTimeToPutInCache) {
110
109
111 // store in cache
110 impl->m_VariableCacheController->addDateTime(newVariable, dateTimeToPutInCache);
112 impl->m_VariableCacheController->addDateTime(newVariable, dateTime);
111 newVariable->setDataSeries(dataSeriesAcquired);
112
113 };
114
115 connect(provider.get(), &IDataProvider::dataProvided, addDateTimeAcquired);
116 this->onRequestDataLoading(newVariable, dateTime);
113
117
114 // notify the creation
118 // notify the creation
115 emit variableCreated(newVariable);
119 emit variableCreated(newVariable);
116 }
120 }
117 }
121 }
118
122
119 void VariableController::onDateTimeOnSelection(const SqpDateTime &dateTime)
123 void VariableController::onDateTimeOnSelection(const SqpDateTime &dateTime)
120 {
124 {
121 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
125 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
122
126
123 for (const auto &selectedRow : qAsConst(selectedRows)) {
127 for (const auto &selectedRow : qAsConst(selectedRows)) {
124 if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) {
128 if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) {
125 selectedVariable->setDateTime(dateTime);
129 selectedVariable->setDateTime(dateTime);
126 this->onRequestDataLoading(selectedVariable, dateTime);
130 this->onRequestDataLoading(selectedVariable, dateTime);
127 }
131 }
128 }
132 }
129 }
133 }
130
134
131
135
132 void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable,
136 void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable,
133 const SqpDateTime &dateTime)
137 const SqpDateTime &dateTime)
134 {
138 {
135 // we want to load data of the variable for the dateTime.
139 // we want to load data of the variable for the dateTime.
136 // First we check if the cache contains some of them.
140 // First we check if the cache contains some of them.
137 // For the other, we ask the provider to give them.
141 // For the other, we ask the provider to give them.
138 if (variable) {
142 if (variable) {
139
143
140 auto dateTimeListNotInCache
144 auto dateTimeListNotInCache
141 = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime);
145 = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime);
142
146
143 if (!dateTimeListNotInCache.empty()) {
147 if (!dateTimeListNotInCache.empty()) {
144 // Ask the provider for each data on the dateTimeListNotInCache
148 // Ask the provider for each data on the dateTimeListNotInCache
145 impl->m_VariableToProviderMap.at(variable)->requestDataLoading(
149 impl->m_VariableToProviderMap.at(variable)->requestDataLoading(
146 std::move(dateTimeListNotInCache));
150 std::move(dateTimeListNotInCache));
147 // store in cache
148 impl->m_VariableCacheController->addDateTime(variable, dateTime);
149 }
151 }
150 else {
152 else {
151 emit variable->updated();
153 emit variable->updated();
152 }
154 }
153 }
155 }
154 else {
156 else {
155 qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null");
157 qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null");
156 }
158 }
157 }
159 }
158
160
159
161
160 void VariableController::initialize()
162 void VariableController::initialize()
161 {
163 {
162 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
164 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
163 impl->m_WorkingMutex.lock();
165 impl->m_WorkingMutex.lock();
164 qCDebug(LOG_VariableController()) << tr("VariableController init END");
166 qCDebug(LOG_VariableController()) << tr("VariableController init END");
165 }
167 }
166
168
167 void VariableController::finalize()
169 void VariableController::finalize()
168 {
170 {
169 impl->m_WorkingMutex.unlock();
171 impl->m_WorkingMutex.unlock();
170 }
172 }
171
173
172 void VariableController::waitForFinish()
174 void VariableController::waitForFinish()
173 {
175 {
174 QMutexLocker locker{&impl->m_WorkingMutex};
176 QMutexLocker locker{&impl->m_WorkingMutex};
175 }
177 }
@@ -1,155 +1,153
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 #include <QDateTime>
6 #include <QDateTime>
7 #include <QSize>
7 #include <QSize>
8
8
9 Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel")
9 Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel")
10
10
11 namespace {
11 namespace {
12
12
13 // Column indexes
13 // Column indexes
14 const auto NAME_COLUMN = 0;
14 const auto NAME_COLUMN = 0;
15 const auto TSTART_COLUMN = 1;
15 const auto TSTART_COLUMN = 1;
16 const auto TEND_COLUMN = 2;
16 const auto TEND_COLUMN = 2;
17 const auto NB_COLUMNS = 3;
17 const auto NB_COLUMNS = 3;
18
18
19 // Column properties
19 // Column properties
20 const auto DEFAULT_HEIGHT = 25;
20 const auto DEFAULT_HEIGHT = 25;
21 const auto DEFAULT_WIDTH = 100;
21 const auto DEFAULT_WIDTH = 100;
22
22
23 struct ColumnProperties {
23 struct ColumnProperties {
24 ColumnProperties(const QString &name = {}, int width = DEFAULT_WIDTH,
24 ColumnProperties(const QString &name = {}, int width = DEFAULT_WIDTH,
25 int height = DEFAULT_HEIGHT)
25 int height = DEFAULT_HEIGHT)
26 : m_Name{name}, m_Width{width}, m_Height{height}
26 : m_Name{name}, m_Width{width}, m_Height{height}
27 {
27 {
28 }
28 }
29
29
30 QString m_Name;
30 QString m_Name;
31 int m_Width;
31 int m_Width;
32 int m_Height;
32 int m_Height;
33 };
33 };
34
34
35 const auto COLUMN_PROPERTIES
35 const auto COLUMN_PROPERTIES
36 = QHash<int, ColumnProperties>{{NAME_COLUMN, {QObject::tr("Name")}},
36 = QHash<int, ColumnProperties>{{NAME_COLUMN, {QObject::tr("Name")}},
37 {TSTART_COLUMN, {QObject::tr("tStart"), 180}},
37 {TSTART_COLUMN, {QObject::tr("tStart"), 180}},
38 {TEND_COLUMN, {QObject::tr("tEnd"), 180}}};
38 {TEND_COLUMN, {QObject::tr("tEnd"), 180}}};
39
39
40 /// Format for datetimes
40 /// Format for datetimes
41 const auto DATETIME_FORMAT = QStringLiteral("dd/MM/yyyy \nhh:mm:ss:zzz");
41 const auto DATETIME_FORMAT = QStringLiteral("dd/MM/yyyy \nhh:mm:ss:zzz");
42
42
43 } // namespace
43 } // namespace
44
44
45 struct VariableModel::VariableModelPrivate {
45 struct VariableModel::VariableModelPrivate {
46 /// Variables created in SciQlop
46 /// Variables created in SciQlop
47 std::vector<std::shared_ptr<Variable> > m_Variables;
47 std::vector<std::shared_ptr<Variable> > m_Variables;
48 };
48 };
49
49
50 VariableModel::VariableModel(QObject *parent)
50 VariableModel::VariableModel(QObject *parent)
51 : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()}
51 : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()}
52 {
52 {
53 }
53 }
54
54
55 std::shared_ptr<Variable>
55 std::shared_ptr<Variable> VariableModel::createVariable(const QString &name,
56 VariableModel::createVariable(const QString &name, const SqpDateTime &dateTime,
56 const SqpDateTime &dateTime) noexcept
57 std::shared_ptr<IDataSeries> defaultDataSeries) noexcept
58 {
57 {
59 auto insertIndex = rowCount();
58 auto insertIndex = rowCount();
60 beginInsertRows({}, insertIndex, insertIndex);
59 beginInsertRows({}, insertIndex, insertIndex);
61
60
62 /// @todo For the moment, the other data of the variable is initialized with default values
61 /// @todo For the moment, the other data of the variable is initialized with default values
63 auto variable = std::make_shared<Variable>(name, QStringLiteral("unit"),
62 auto variable = std::make_shared<Variable>(name, QStringLiteral("unit"),
64 QStringLiteral("mission"), dateTime);
63 QStringLiteral("mission"), dateTime);
65 variable->setDataSeries(std::move(defaultDataSeries));
66
64
67 impl->m_Variables.push_back(variable);
65 impl->m_Variables.push_back(variable);
68
66
69 endInsertRows();
67 endInsertRows();
70
68
71 return variable;
69 return variable;
72 }
70 }
73
71
74 std::shared_ptr<Variable> VariableModel::variable(int index) const
72 std::shared_ptr<Variable> VariableModel::variable(int index) const
75 {
73 {
76 return (index >= 0 && index < impl->m_Variables.size()) ? impl->m_Variables[index] : nullptr;
74 return (index >= 0 && index < impl->m_Variables.size()) ? impl->m_Variables[index] : nullptr;
77 }
75 }
78
76
79 int VariableModel::columnCount(const QModelIndex &parent) const
77 int VariableModel::columnCount(const QModelIndex &parent) const
80 {
78 {
81 Q_UNUSED(parent);
79 Q_UNUSED(parent);
82
80
83 return NB_COLUMNS;
81 return NB_COLUMNS;
84 }
82 }
85
83
86 int VariableModel::rowCount(const QModelIndex &parent) const
84 int VariableModel::rowCount(const QModelIndex &parent) const
87 {
85 {
88 Q_UNUSED(parent);
86 Q_UNUSED(parent);
89
87
90 return impl->m_Variables.size();
88 return impl->m_Variables.size();
91 }
89 }
92
90
93 QVariant VariableModel::data(const QModelIndex &index, int role) const
91 QVariant VariableModel::data(const QModelIndex &index, int role) const
94 {
92 {
95 if (!index.isValid()) {
93 if (!index.isValid()) {
96 return QVariant{};
94 return QVariant{};
97 }
95 }
98
96
99 if (index.row() < 0 || index.row() >= rowCount()) {
97 if (index.row() < 0 || index.row() >= rowCount()) {
100 return QVariant{};
98 return QVariant{};
101 }
99 }
102
100
103 if (role == Qt::DisplayRole) {
101 if (role == Qt::DisplayRole) {
104 if (auto variable = impl->m_Variables.at(index.row()).get()) {
102 if (auto variable = impl->m_Variables.at(index.row()).get()) {
105 /// Lambda function that builds the variant to return for a time value
103 /// Lambda function that builds the variant to return for a time value
106 auto dateTimeVariant = [](double time) {
104 auto dateTimeVariant = [](double time) {
107 auto dateTime = QDateTime::fromMSecsSinceEpoch(time * 1000.);
105 auto dateTime = QDateTime::fromMSecsSinceEpoch(time * 1000.);
108 return dateTime.toString(DATETIME_FORMAT);
106 return dateTime.toString(DATETIME_FORMAT);
109 };
107 };
110
108
111 switch (index.column()) {
109 switch (index.column()) {
112 case NAME_COLUMN:
110 case NAME_COLUMN:
113 return variable->name();
111 return variable->name();
114 case TSTART_COLUMN:
112 case TSTART_COLUMN:
115 return dateTimeVariant(variable->dateTime().m_TStart);
113 return dateTimeVariant(variable->dateTime().m_TStart);
116 case TEND_COLUMN:
114 case TEND_COLUMN:
117 return dateTimeVariant(variable->dateTime().m_TEnd);
115 return dateTimeVariant(variable->dateTime().m_TEnd);
118 default:
116 default:
119 // No action
117 // No action
120 break;
118 break;
121 }
119 }
122
120
123 qWarning(LOG_VariableModel())
121 qWarning(LOG_VariableModel())
124 << tr("Can't get data (unknown column %1)").arg(index.column());
122 << tr("Can't get data (unknown column %1)").arg(index.column());
125 }
123 }
126 else {
124 else {
127 qWarning(LOG_VariableModel()) << tr("Can't get data (no variable)");
125 qWarning(LOG_VariableModel()) << tr("Can't get data (no variable)");
128 }
126 }
129 }
127 }
130
128
131 return QVariant{};
129 return QVariant{};
132 }
130 }
133
131
134 QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const
132 QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const
135 {
133 {
136 if (role != Qt::DisplayRole && role != Qt::SizeHintRole) {
134 if (role != Qt::DisplayRole && role != Qt::SizeHintRole) {
137 return QVariant{};
135 return QVariant{};
138 }
136 }
139
137
140 if (orientation == Qt::Horizontal) {
138 if (orientation == Qt::Horizontal) {
141 auto propertiesIt = COLUMN_PROPERTIES.find(section);
139 auto propertiesIt = COLUMN_PROPERTIES.find(section);
142 if (propertiesIt != COLUMN_PROPERTIES.cend()) {
140 if (propertiesIt != COLUMN_PROPERTIES.cend()) {
143 // Role is either DisplayRole or SizeHintRole
141 // Role is either DisplayRole or SizeHintRole
144 return (role == Qt::DisplayRole)
142 return (role == Qt::DisplayRole)
145 ? QVariant{propertiesIt->m_Name}
143 ? QVariant{propertiesIt->m_Name}
146 : QVariant{QSize{propertiesIt->m_Width, propertiesIt->m_Height}};
144 : QVariant{QSize{propertiesIt->m_Width, propertiesIt->m_Height}};
147 }
145 }
148 else {
146 else {
149 qWarning(LOG_VariableModel())
147 qWarning(LOG_VariableModel())
150 << tr("Can't get header data (unknown column %1)").arg(section);
148 << tr("Can't get header data (unknown column %1)").arg(section);
151 }
149 }
152 }
150 }
153
151
154 return QVariant{};
152 return QVariant{};
155 }
153 }
@@ -1,63 +1,64
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 SqpDateTime;
16 class SqpDateTime;
17 class Variable;
17 class Variable;
18
18
19 namespace Ui {
19 namespace Ui {
20 class VisualizationGraphWidget;
20 class VisualizationGraphWidget;
21 } // namespace Ui
21 } // namespace Ui
22
22
23 class VisualizationGraphWidget : public QWidget, public IVisualizationWidget {
23 class VisualizationGraphWidget : public QWidget, public IVisualizationWidget {
24 Q_OBJECT
24 Q_OBJECT
25
25
26 public:
26 public:
27 explicit VisualizationGraphWidget(const QString &name = {}, QWidget *parent = 0);
27 explicit VisualizationGraphWidget(const QString &name = {}, QWidget *parent = 0);
28 virtual ~VisualizationGraphWidget();
28 virtual ~VisualizationGraphWidget();
29
29
30 void addVariable(std::shared_ptr<Variable> variable);
30 void addVariable(std::shared_ptr<Variable> variable);
31 void addVariableUsingGraph(std::shared_ptr<Variable> variable);
31 /// Removes a variable from the graph
32 /// Removes a variable from the graph
32 void removeVariable(std::shared_ptr<Variable> variable) noexcept;
33 void removeVariable(std::shared_ptr<Variable> variable) noexcept;
33
34
34 // IVisualizationWidget interface
35 // IVisualizationWidget interface
35 void accept(IVisualizationWidgetVisitor *visitor) override;
36 void accept(IVisualizationWidgetVisitor *visitor) override;
36 bool canDrop(const Variable &variable) const override;
37 bool canDrop(const Variable &variable) const override;
37 QString name() const override;
38 QString name() const override;
38
39
39 void updateDisplay(std::shared_ptr<Variable> variable);
40 void updateDisplay(std::shared_ptr<Variable> variable);
40
41
41 signals:
42 signals:
42 void requestDataLoading(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime);
43 void requestDataLoading(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime);
43
44
44
45
45 private:
46 private:
46 Ui::VisualizationGraphWidget *ui;
47 Ui::VisualizationGraphWidget *ui;
47
48
48 class VisualizationGraphWidgetPrivate;
49 class VisualizationGraphWidgetPrivate;
49 spimpl::unique_impl_ptr<VisualizationGraphWidgetPrivate> impl;
50 spimpl::unique_impl_ptr<VisualizationGraphWidgetPrivate> impl;
50
51
51 private slots:
52 private slots:
52 /// Slot called when right clicking on the graph (displays a menu)
53 /// Slot called when right clicking on the graph (displays a menu)
53 void onGraphMenuRequested(const QPoint &pos) noexcept;
54 void onGraphMenuRequested(const QPoint &pos) noexcept;
54
55
55 void onRangeChanged(const QCPRange &t1, const QCPRange &t2);
56 void onRangeChanged(const QCPRange &t1);
56
57
57 /// Slot called when a mouse wheel was made, to perform some processing before the zoom is done
58 /// Slot called when a mouse wheel was made, to perform some processing before the zoom is done
58 void onMouseWheel(QWheelEvent *event) noexcept;
59 void onMouseWheel(QWheelEvent *event) noexcept;
59
60
60 void onDataCacheVariableUpdated();
61 void onDataCacheVariableUpdated();
61 };
62 };
62
63
63 #endif // SCIQLOP_VISUALIZATIONGRAPHWIDGET_H
64 #endif // SCIQLOP_VISUALIZATIONGRAPHWIDGET_H
@@ -1,153 +1,155
1 #include "Visualization/VisualizationGraphHelper.h"
1 #include "Visualization/VisualizationGraphHelper.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>
8 #include <QElapsedTimer>
9
9
10 Q_LOGGING_CATEGORY(LOG_VisualizationGraphHelper, "VisualizationGraphHelper")
10 Q_LOGGING_CATEGORY(LOG_VisualizationGraphHelper, "VisualizationGraphHelper")
11
11
12 namespace {
12 namespace {
13
13
14 /// Format for datetimes on a axis
14 /// Format for datetimes on a axis
15 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");
16
16
17 /// 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
18 /// non-time data
18 /// non-time data
19 QSharedPointer<QCPAxisTicker> axisTicker(bool isTimeAxis)
19 QSharedPointer<QCPAxisTicker> axisTicker(bool isTimeAxis)
20 {
20 {
21 if (isTimeAxis) {
21 if (isTimeAxis) {
22 auto dateTicker = QSharedPointer<QCPAxisTickerDateTime>::create();
22 auto dateTicker = QSharedPointer<QCPAxisTickerDateTime>::create();
23 dateTicker->setDateTimeFormat(DATETIME_TICKER_FORMAT);
23 dateTicker->setDateTimeFormat(DATETIME_TICKER_FORMAT);
24
24
25 return dateTicker;
25 return dateTicker;
26 }
26 }
27 else {
27 else {
28 // default ticker
28 // default ticker
29 return QSharedPointer<QCPAxisTicker>::create();
29 return QSharedPointer<QCPAxisTicker>::create();
30 }
30 }
31 }
31 }
32
32
33 void updateScalarData(QCPAbstractPlottable *component, ScalarSeries &scalarSeries,
33 void updateScalarData(QCPAbstractPlottable *component, ScalarSeries &scalarSeries,
34 const SqpDateTime &dateTime)
34 const SqpDateTime &dateTime)
35 {
35 {
36 QElapsedTimer timer;
36 QElapsedTimer timer;
37 timer.start();
37 timer.start();
38 if (auto qcpGraph = dynamic_cast<QCPGraph *>(component)) {
38 if (auto qcpGraph = dynamic_cast<QCPGraph *>(component)) {
39 // Clean the graph
39 // Clean the graph
40 // NAIVE approch
40 // NAIVE approch
41 const auto &xData = scalarSeries.xAxisData()->data();
41 const auto &xData = scalarSeries.xAxisData()->data();
42 const auto &valuesData = scalarSeries.valuesData()->data();
42 const auto &valuesData = scalarSeries.valuesData()->data();
43 const auto count = xData.count();
43 const auto count = xData.count();
44 qCInfo(LOG_VisualizationGraphHelper()) << "TORM: Current points in cache" << xData.count();
44 qCInfo(LOG_VisualizationGraphHelper()) << "TORM: Current points in cache" << xData.count();
45
46 auto xValue = QVector<double>(count);
45 auto xValue = QVector<double>(count);
47 auto vValue = QVector<double>(count);
46 auto vValue = QVector<double>(count);
48
47
49 int n = 0;
48 int n = 0;
50 for (auto i = 0; i < count; ++i) {
49 for (auto i = 0; i < count; ++i) {
51 const auto x = xData[i];
50 const auto x = xData[i];
52 if (x >= dateTime.m_TStart && x <= dateTime.m_TEnd) {
51 if (x >= dateTime.m_TStart && x <= dateTime.m_TEnd) {
53 xValue[n] = x;
52 xValue[n] = x;
54 vValue[n] = valuesData[i];
53 vValue[n] = valuesData[i];
55 ++n;
54 ++n;
56 }
55 }
57 }
56 }
58
57
59 xValue.resize(n);
58 xValue.resize(n);
60 vValue.resize(n);
59 vValue.resize(n);
61
60
62 qCInfo(LOG_VisualizationGraphHelper()) << "TORM: Current points displayed"
61 qCInfo(LOG_VisualizationGraphHelper()) << "TORM: Current points displayed"
63 << xValue.count();
62 << xValue.count();
64
63
65 qcpGraph->setData(xValue, vValue);
64 qcpGraph->setData(xValue, vValue);
65
66 // Display all data
67 component->rescaleAxes();
68 component->parentPlot()->replot();
66 }
69 }
67 else {
70 else {
68 /// @todo DEBUG
71 /// @todo DEBUG
69 }
72 }
70 }
73 }
71
74
72 QCPAbstractPlottable *createScalarSeriesComponent(ScalarSeries &scalarSeries, QCustomPlot &plot,
75 QCPAbstractPlottable *createScalarSeriesComponent(ScalarSeries &scalarSeries, QCustomPlot &plot,
73 const SqpDateTime &dateTime)
76 const SqpDateTime &dateTime)
74 {
77 {
75 auto component = plot.addGraph();
78 auto component = plot.addGraph();
76
79
77 if (component) {
80 if (component) {
78 // // Graph data
81 // // Graph data
79 component->setData(scalarSeries.xAxisData()->data(), scalarSeries.valuesData()->data(),
82 component->setData(scalarSeries.xAxisData()->data(), scalarSeries.valuesData()->data(),
80 true);
83 true);
81
84
82 updateScalarData(component, scalarSeries, dateTime);
85 updateScalarData(component, scalarSeries, dateTime);
83
86
84 // Axes properties
87 // Axes properties
85 /// @todo : for the moment, no control is performed on the axes: the units and the tickers
88 /// @todo : for the moment, no control is performed on the axes: the units and the tickers
86 /// are fixed for the default x-axis and y-axis of the plot, and according to the new graph
89 /// are fixed for the default x-axis and y-axis of the plot, and according to the new graph
87
90
88 auto setAxisProperties = [](auto axis, const auto &unit) {
91 auto setAxisProperties = [](auto axis, const auto &unit) {
89 // label (unit name)
92 // label (unit name)
90 axis->setLabel(unit.m_Name);
93 axis->setLabel(unit.m_Name);
91
94
92 // ticker (depending on the type of unit)
95 // ticker (depending on the type of unit)
93 axis->setTicker(axisTicker(unit.m_TimeUnit));
96 axis->setTicker(axisTicker(unit.m_TimeUnit));
94 };
97 };
95 setAxisProperties(plot.xAxis, scalarSeries.xAxisUnit());
98 setAxisProperties(plot.xAxis, scalarSeries.xAxisUnit());
96 setAxisProperties(plot.yAxis, scalarSeries.valuesUnit());
99 setAxisProperties(plot.yAxis, scalarSeries.valuesUnit());
97
100
98 // Display all data
101 // Display all data
99 component->rescaleAxes();
102 component->rescaleAxes();
100
101 plot.replot();
103 plot.replot();
102 }
104 }
103 else {
105 else {
104 qCDebug(LOG_VisualizationGraphHelper())
106 qCDebug(LOG_VisualizationGraphHelper())
105 << QObject::tr("Can't create graph for the scalar series");
107 << QObject::tr("Can't create graph for the scalar series");
106 }
108 }
107
109
108 return component;
110 return component;
109 }
111 }
110
112
111 } // namespace
113 } // namespace
112
114
113 QVector<QCPAbstractPlottable *> VisualizationGraphHelper::create(std::shared_ptr<Variable> variable,
115 QVector<QCPAbstractPlottable *> VisualizationGraphHelper::create(std::shared_ptr<Variable> variable,
114 QCustomPlot &plot) noexcept
116 QCustomPlot &plot) noexcept
115 {
117 {
116 auto result = QVector<QCPAbstractPlottable *>{};
118 auto result = QVector<QCPAbstractPlottable *>{};
117
119
118 if (variable) {
120 if (variable) {
119 // Gets the data series of the variable to call the creation of the right components
121 // Gets the data series of the variable to call the creation of the right components
120 // according to its type
122 // according to its type
121 if (auto scalarSeries = dynamic_cast<ScalarSeries *>(variable->dataSeries())) {
123 if (auto scalarSeries = dynamic_cast<ScalarSeries *>(variable->dataSeries())) {
122 result.append(createScalarSeriesComponent(*scalarSeries, plot, variable->dateTime()));
124 result.append(createScalarSeriesComponent(*scalarSeries, plot, variable->dateTime()));
123 }
125 }
124 else {
126 else {
125 qCDebug(LOG_VisualizationGraphHelper())
127 qCDebug(LOG_VisualizationGraphHelper())
126 << QObject::tr("Can't create graph plottables : unmanaged data series type");
128 << QObject::tr("Can't create graph plottables : unmanaged data series type");
127 }
129 }
128 }
130 }
129 else {
131 else {
130 qCDebug(LOG_VisualizationGraphHelper())
132 qCDebug(LOG_VisualizationGraphHelper())
131 << QObject::tr("Can't create graph plottables : the variable is null");
133 << QObject::tr("Can't create graph plottables : the variable is null");
132 }
134 }
133
135
134 return result;
136 return result;
135 }
137 }
136
138
137 void VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *> plotableVect,
139 void VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *> plotableVect,
138 IDataSeries *dataSeries, const SqpDateTime &dateTime)
140 IDataSeries *dataSeries, const SqpDateTime &dateTime)
139 {
141 {
140 if (auto scalarSeries = dynamic_cast<ScalarSeries *>(dataSeries)) {
142 if (auto scalarSeries = dynamic_cast<ScalarSeries *>(dataSeries)) {
141 if (plotableVect.size() == 1) {
143 if (plotableVect.size() == 1) {
142 updateScalarData(plotableVect.at(0), *scalarSeries, dateTime);
144 updateScalarData(plotableVect.at(0), *scalarSeries, dateTime);
143 }
145 }
144 else {
146 else {
145 qCCritical(LOG_VisualizationGraphHelper()) << QObject::tr(
147 qCCritical(LOG_VisualizationGraphHelper()) << QObject::tr(
146 "Can't update Data of a scalarSeries because there is not only one component "
148 "Can't update Data of a scalarSeries because there is not only one component "
147 "associated");
149 "associated");
148 }
150 }
149 }
151 }
150 else {
152 else {
151 /// @todo DEBUG
153 /// @todo DEBUG
152 }
154 }
153 }
155 }
@@ -1,236 +1,273
1 #include "Visualization/VisualizationGraphWidget.h"
1 #include "Visualization/VisualizationGraphWidget.h"
2 #include "Visualization/IVisualizationWidgetVisitor.h"
2 #include "Visualization/IVisualizationWidgetVisitor.h"
3 #include "Visualization/VisualizationGraphHelper.h"
3 #include "Visualization/VisualizationGraphHelper.h"
4 #include "ui_VisualizationGraphWidget.h"
4 #include "ui_VisualizationGraphWidget.h"
5
5
6 #include <Data/ArrayData.h>
6 #include <Data/ArrayData.h>
7 #include <Data/IDataSeries.h>
7 #include <Data/IDataSeries.h>
8 #include <SqpApplication.h>
8 #include <SqpApplication.h>
9 #include <Variable/Variable.h>
9 #include <Variable/Variable.h>
10 #include <Variable/VariableController.h>
10 #include <Variable/VariableController.h>
11
11
12 #include <unordered_map>
12 #include <unordered_map>
13
13
14 Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget")
14 Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget")
15
15
16 namespace {
16 namespace {
17
17
18 /// Key pressed to enable zoom on horizontal axis
18 /// Key pressed to enable zoom on horizontal axis
19 const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier;
19 const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier;
20
20
21 /// Key pressed to enable zoom on vertical axis
21 /// Key pressed to enable zoom on vertical axis
22 const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier;
22 const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier;
23
23
24 } // namespace
24 } // namespace
25
25
26 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
26 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
27
27
28 // 1 variable -> n qcpplot
28 // 1 variable -> n qcpplot
29 std::multimap<std::shared_ptr<Variable>, QCPAbstractPlottable *> m_VariableToPlotMultiMap;
29 std::multimap<std::shared_ptr<Variable>, QCPAbstractPlottable *> m_VariableToPlotMultiMap;
30 };
30 };
31
31
32 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent)
32 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent)
33 : QWidget{parent},
33 : QWidget{parent},
34 ui{new Ui::VisualizationGraphWidget},
34 ui{new Ui::VisualizationGraphWidget},
35 impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()}
35 impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()}
36 {
36 {
37 ui->setupUi(this);
37 ui->setupUi(this);
38
38
39 ui->graphNameLabel->setText(name);
39 ui->graphNameLabel->setText(name);
40
40
41 // 'Close' options : widget is deleted when closed
41 // 'Close' options : widget is deleted when closed
42 setAttribute(Qt::WA_DeleteOnClose);
42 setAttribute(Qt::WA_DeleteOnClose);
43 connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationGraphWidget::close);
43 connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationGraphWidget::close);
44 ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton));
44 ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton));
45
45
46 // Set qcpplot properties :
46 // Set qcpplot properties :
47 // - Drag (on x-axis) and zoom are enabled
47 // - Drag (on x-axis) and zoom are enabled
48 // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation
48 // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation
49 ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
49 ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
50 ui->widget->axisRect()->setRangeDrag(Qt::Horizontal);
50 ui->widget->axisRect()->setRangeDrag(Qt::Horizontal);
51 connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel);
51 connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel);
52 connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>(
52 connect(ui->widget->xAxis,
53 &QCPAxis::rangeChanged),
53 static_cast<void (QCPAxis::*)(const QCPRange &)>(&QCPAxis::rangeChanged), this,
54 this, &VisualizationGraphWidget::onRangeChanged);
54 &VisualizationGraphWidget::onRangeChanged);
55
55
56 // Activates menu when right clicking on the graph
56 // Activates menu when right clicking on the graph
57 ui->widget->setContextMenuPolicy(Qt::CustomContextMenu);
57 ui->widget->setContextMenuPolicy(Qt::CustomContextMenu);
58 connect(ui->widget, &QCustomPlot::customContextMenuRequested, this,
58 connect(ui->widget, &QCustomPlot::customContextMenuRequested, this,
59 &VisualizationGraphWidget::onGraphMenuRequested);
59 &VisualizationGraphWidget::onGraphMenuRequested);
60
60
61 connect(this, &VisualizationGraphWidget::requestDataLoading, &sqpApp->variableController(),
61 connect(this, &VisualizationGraphWidget::requestDataLoading, &sqpApp->variableController(),
62 &VariableController::onRequestDataLoading);
62 &VariableController::onRequestDataLoading);
63 }
63 }
64
64
65
65
66 VisualizationGraphWidget::~VisualizationGraphWidget()
66 VisualizationGraphWidget::~VisualizationGraphWidget()
67 {
67 {
68 delete ui;
68 delete ui;
69 }
69 }
70
70
71 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable)
71 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable)
72 {
72 {
73 // Uses delegate to create the qcpplot components according to the variable
73 // Uses delegate to create the qcpplot components according to the variable
74 auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget);
74 auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget);
75
75
76 for (auto createdPlottable : qAsConst(createdPlottables)) {
76 for (auto createdPlottable : qAsConst(createdPlottables)) {
77 impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable});
77 impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable});
78 }
78 }
79
79
80 connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated()));
80 connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated()));
81 }
81 }
82
82
83 void VisualizationGraphWidget::addVariableUsingGraph(std::shared_ptr<Variable> variable)
84 {
85
86 // when adding a variable, we need to set its time range to the current graph range
87 auto grapheRange = ui->widget->xAxis->range();
88 auto dateTime = SqpDateTime{grapheRange.lower, grapheRange.upper};
89 variable->setDateTime(dateTime);
90
91 auto variableDateTimeWithTolerance = dateTime;
92
93 // add 10% tolerance for each side
94 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
95 variableDateTimeWithTolerance.m_TStart -= tolerance;
96 variableDateTimeWithTolerance.m_TEnd += tolerance;
97
98 // Uses delegate to create the qcpplot components according to the variable
99 auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget);
100
101 for (auto createdPlottable : qAsConst(createdPlottables)) {
102 impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable});
103 }
104
105 connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated()));
106
107 // CHangement detected, we need to ask controller to request data loading
108 emit requestDataLoading(variable, variableDateTimeWithTolerance);
109 }
110
83 void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept
111 void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept
84 {
112 {
85 // Each component associated to the variable :
113 // Each component associated to the variable :
86 // - is removed from qcpplot (which deletes it)
114 // - is removed from qcpplot (which deletes it)
87 // - is no longer referenced in the map
115 // - is no longer referenced in the map
88 auto componentsIt = impl->m_VariableToPlotMultiMap.equal_range(variable);
116 auto componentsIt = impl->m_VariableToPlotMultiMap.equal_range(variable);
89 for (auto it = componentsIt.first; it != componentsIt.second;) {
117 for (auto it = componentsIt.first; it != componentsIt.second;) {
90 ui->widget->removePlottable(it->second);
118 ui->widget->removePlottable(it->second);
91 it = impl->m_VariableToPlotMultiMap.erase(it);
119 it = impl->m_VariableToPlotMultiMap.erase(it);
92 }
120 }
93
121
94 // Updates graph
122 // Updates graph
95 ui->widget->replot();
123 ui->widget->replot();
96 }
124 }
97
125
98 void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor)
126 void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor)
99 {
127 {
100 if (visitor) {
128 if (visitor) {
101 visitor->visit(this);
129 visitor->visit(this);
102 }
130 }
103 else {
131 else {
104 qCCritical(LOG_VisualizationGraphWidget())
132 qCCritical(LOG_VisualizationGraphWidget())
105 << tr("Can't visit widget : the visitor is null");
133 << tr("Can't visit widget : the visitor is null");
106 }
134 }
107 }
135 }
108
136
109 bool VisualizationGraphWidget::canDrop(const Variable &variable) const
137 bool VisualizationGraphWidget::canDrop(const Variable &variable) const
110 {
138 {
111 /// @todo : for the moment, a graph can always accomodate a variable
139 /// @todo : for the moment, a graph can always accomodate a variable
112 Q_UNUSED(variable);
140 Q_UNUSED(variable);
113 return true;
141 return true;
114 }
142 }
115
143
116 QString VisualizationGraphWidget::name() const
144 QString VisualizationGraphWidget::name() const
117 {
145 {
118 return ui->graphNameLabel->text();
146 return ui->graphNameLabel->text();
119 }
147 }
120
148
121 void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept
149 void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept
122 {
150 {
123 QMenu graphMenu{};
151 QMenu graphMenu{};
124
152
125 // Iterates on variables (unique keys)
153 // Iterates on variables (unique keys)
126 for (auto it = impl->m_VariableToPlotMultiMap.cbegin(),
154 for (auto it = impl->m_VariableToPlotMultiMap.cbegin(),
127 end = impl->m_VariableToPlotMultiMap.cend();
155 end = impl->m_VariableToPlotMultiMap.cend();
128 it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) {
156 it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) {
129 // 'Remove variable' action
157 // 'Remove variable' action
130 graphMenu.addAction(tr("Remove variable %1").arg(it->first->name()),
158 graphMenu.addAction(tr("Remove variable %1").arg(it->first->name()),
131 [ this, var = it->first ]() { removeVariable(var); });
159 [ this, var = it->first ]() { removeVariable(var); });
132 }
160 }
133
161
134 if (!graphMenu.isEmpty()) {
162 if (!graphMenu.isEmpty()) {
135 graphMenu.exec(mapToGlobal(pos));
163 graphMenu.exec(mapToGlobal(pos));
136 }
164 }
137 }
165 }
138
166
139 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2)
167 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1)
140 {
168 {
141
142 qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged");
169 qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged");
143
170
144 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
171 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
145 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
172 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
146
173
147 auto variable = it->first;
174 auto variable = it->first;
148 auto dateTime = SqpDateTime{t2.lower, t2.upper};
175 auto dateTime = SqpDateTime{t1.lower, t1.upper};
149
176
150 if (!variable->contains(dateTime)) {
177 if (!variable->contains(dateTime)) {
151
178
152 auto variableDateTimeWithTolerance = dateTime;
179 auto variableDateTimeWithTolerance = dateTime;
153 if (variable->intersect(dateTime)) {
180 if (!variable->isInside(dateTime)) {
154 auto variableDateTime = variable->dateTime();
181 auto variableDateTime = variable->dateTime();
155 if (variableDateTime.m_TStart < dateTime.m_TStart) {
182 if (variableDateTime.m_TStart < dateTime.m_TStart) {
183 qCDebug(LOG_VisualizationGraphWidget()) << tr("TDetection pan to right:");
156
184
157 auto diffEndToKeepDelta = dateTime.m_TEnd - variableDateTime.m_TEnd;
185 auto diffEndToKeepDelta = dateTime.m_TEnd - variableDateTime.m_TEnd;
158 dateTime.m_TStart = variableDateTime.m_TStart + diffEndToKeepDelta;
186 dateTime.m_TStart = variableDateTime.m_TStart + diffEndToKeepDelta;
159 // Tolerance have to be added to the right
187 // Tolerance have to be added to the right
160 // add 10% tolerance for right (end) side
188 // add 10% tolerance for right (end) side
161 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
189 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
162 variableDateTimeWithTolerance.m_TEnd += tolerance;
190 variableDateTimeWithTolerance.m_TEnd += tolerance;
163 }
191 }
164 if (variableDateTime.m_TEnd > dateTime.m_TEnd) {
192 else if (variableDateTime.m_TEnd > dateTime.m_TEnd) {
193 qCDebug(LOG_VisualizationGraphWidget()) << tr("Detection pan to left: ");
165 auto diffStartToKeepDelta = variableDateTime.m_TStart - dateTime.m_TStart;
194 auto diffStartToKeepDelta = variableDateTime.m_TStart - dateTime.m_TStart;
166 dateTime.m_TEnd = variableDateTime.m_TEnd - diffStartToKeepDelta;
195 dateTime.m_TEnd = variableDateTime.m_TEnd - diffStartToKeepDelta;
167 // Tolerance have to be added to the left
196 // Tolerance have to be added to the left
168 // add 10% tolerance for left (start) side
197 // add 10% tolerance for left (start) side
169 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
198 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
170 variableDateTimeWithTolerance.m_TStart -= tolerance;
199 variableDateTimeWithTolerance.m_TStart -= tolerance;
171 }
200 }
201 else {
202 qCWarning(LOG_VisualizationGraphWidget())
203 << tr("Detection anormal zoom detection: ");
204 }
172 }
205 }
173 else {
206 else {
207 qCDebug(LOG_VisualizationGraphWidget()) << tr("Detection zoom out: ");
174 // add 10% tolerance for each side
208 // add 10% tolerance for each side
175 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
209 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
176 variableDateTimeWithTolerance.m_TStart -= tolerance;
210 variableDateTimeWithTolerance.m_TStart -= tolerance;
177 variableDateTimeWithTolerance.m_TEnd += tolerance;
211 variableDateTimeWithTolerance.m_TEnd += tolerance;
178 }
212 }
179 variable->setDateTime(dateTime);
213 variable->setDateTime(dateTime);
180
214
181 // CHangement detected, we need to ask controller to request data loading
215 // CHangement detected, we need to ask controller to request data loading
182 emit requestDataLoading(variable, variableDateTimeWithTolerance);
216 emit requestDataLoading(variable, variableDateTimeWithTolerance);
183 }
217 }
218 else {
219 qCDebug(LOG_VisualizationGraphWidget()) << tr("Detection zoom in: ");
220 }
184 }
221 }
185 }
222 }
186
223
187 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept
224 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept
188 {
225 {
189 auto zoomOrientations = QFlags<Qt::Orientation>{};
226 auto zoomOrientations = QFlags<Qt::Orientation>{};
190
227
191 // Lambda that enables a zoom orientation if the key modifier related to this orientation
228 // Lambda that enables a zoom orientation if the key modifier related to this orientation
192 // has
229 // has
193 // been pressed
230 // been pressed
194 auto enableOrientation
231 auto enableOrientation
195 = [&zoomOrientations, event](const auto &orientation, const auto &modifier) {
232 = [&zoomOrientations, event](const auto &orientation, const auto &modifier) {
196 auto orientationEnabled = event->modifiers().testFlag(modifier);
233 auto orientationEnabled = event->modifiers().testFlag(modifier);
197 zoomOrientations.setFlag(orientation, orientationEnabled);
234 zoomOrientations.setFlag(orientation, orientationEnabled);
198 };
235 };
199 enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER);
236 enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER);
200 enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER);
237 enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER);
201
238
202 ui->widget->axisRect()->setRangeZoom(zoomOrientations);
239 ui->widget->axisRect()->setRangeZoom(zoomOrientations);
203 }
240 }
204
241
205 void VisualizationGraphWidget::onDataCacheVariableUpdated()
242 void VisualizationGraphWidget::onDataCacheVariableUpdated()
206 {
243 {
207 // NOTE:
244 // NOTE:
208 // We don't want to call the method for each component of a variable unitarily, but for
245 // We don't want to call the method for each component of a variable unitarily, but for
209 // all
246 // all
210 // its components at once (eg its three components in the case of a vector).
247 // its components at once (eg its three components in the case of a vector).
211
248
212 // The unordered_multimap does not do this easily, so the question is whether to:
249 // The unordered_multimap does not do this easily, so the question is whether to:
213 // - use an ordered_multimap and the algos of std to group the values by key
250 // - use an ordered_multimap and the algos of std to group the values by key
214 // - use a map (unique keys) and store as values directly the list of components
251 // - use a map (unique keys) and store as values directly the list of components
215
252
216 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
253 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
217 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
254 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
218 auto variable = it->first;
255 auto variable = it->first;
219 VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *>{} << it->second,
256 VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *>{} << it->second,
220 variable->dataSeries(), variable->dateTime());
257 variable->dataSeries(), variable->dateTime());
221 }
258 }
222 }
259 }
223
260
224 void VisualizationGraphWidget::updateDisplay(std::shared_ptr<Variable> variable)
261 void VisualizationGraphWidget::updateDisplay(std::shared_ptr<Variable> variable)
225 {
262 {
226 auto abstractPlotableItPair = impl->m_VariableToPlotMultiMap.equal_range(variable);
263 auto abstractPlotableItPair = impl->m_VariableToPlotMultiMap.equal_range(variable);
227
264
228 auto abstractPlotableVect = QVector<QCPAbstractPlottable *>{};
265 auto abstractPlotableVect = QVector<QCPAbstractPlottable *>{};
229
266
230 for (auto it = abstractPlotableItPair.first; it != abstractPlotableItPair.second; ++it) {
267 for (auto it = abstractPlotableItPair.first; it != abstractPlotableItPair.second; ++it) {
231 abstractPlotableVect.push_back(it->second);
268 abstractPlotableVect.push_back(it->second);
232 }
269 }
233
270
234 VisualizationGraphHelper::updateData(abstractPlotableVect, variable->dataSeries(),
271 VisualizationGraphHelper::updateData(abstractPlotableVect, variable->dataSeries(),
235 variable->dateTime());
272 variable->dateTime());
236 }
273 }
@@ -1,146 +1,146
1 #include "Visualization/operations/GenerateVariableMenuOperation.h"
1 #include "Visualization/operations/GenerateVariableMenuOperation.h"
2 #include "Visualization/operations/MenuBuilder.h"
2 #include "Visualization/operations/MenuBuilder.h"
3
3
4 #include "Visualization/VisualizationGraphWidget.h"
4 #include "Visualization/VisualizationGraphWidget.h"
5 #include "Visualization/VisualizationTabWidget.h"
5 #include "Visualization/VisualizationTabWidget.h"
6 #include "Visualization/VisualizationZoneWidget.h"
6 #include "Visualization/VisualizationZoneWidget.h"
7
7
8 #include <Variable/Variable.h>
8 #include <Variable/Variable.h>
9
9
10 #include <QMenu>
10 #include <QMenu>
11 #include <QStack>
11 #include <QStack>
12
12
13 Q_LOGGING_CATEGORY(LOG_GenerateVariableMenuOperation, "GenerateVariableMenuOperation")
13 Q_LOGGING_CATEGORY(LOG_GenerateVariableMenuOperation, "GenerateVariableMenuOperation")
14
14
15 struct GenerateVariableMenuOperation::GenerateVariableMenuOperationPrivate {
15 struct GenerateVariableMenuOperation::GenerateVariableMenuOperationPrivate {
16 explicit GenerateVariableMenuOperationPrivate(QMenu *menu, std::shared_ptr<Variable> variable)
16 explicit GenerateVariableMenuOperationPrivate(QMenu *menu, std::shared_ptr<Variable> variable)
17 : m_Variable{variable}, m_MenuBuilder{menu}
17 : m_Variable{variable}, m_MenuBuilder{menu}
18 {
18 {
19 }
19 }
20
20
21 void visitRootEnter()
21 void visitRootEnter()
22 {
22 {
23 // Creates the root menu
23 // Creates the root menu
24 m_MenuBuilder.addMenu(QObject::tr("Plot"));
24 m_MenuBuilder.addMenu(QObject::tr("Plot"));
25 }
25 }
26
26
27 void visitRootLeave()
27 void visitRootLeave()
28 {
28 {
29 // Closes the root menu
29 // Closes the root menu
30 m_MenuBuilder.closeMenu();
30 m_MenuBuilder.closeMenu();
31 }
31 }
32
32
33 void visitNodeEnter(const IVisualizationWidget &container)
33 void visitNodeEnter(const IVisualizationWidget &container)
34 {
34 {
35 // Opens a new menu associated to the node
35 // Opens a new menu associated to the node
36 m_MenuBuilder.addMenu(container.name());
36 m_MenuBuilder.addMenu(container.name());
37 }
37 }
38
38
39 template <typename ActionFun>
39 template <typename ActionFun>
40 void visitNodeLeave(const IVisualizationWidget &container, const QString &actionName,
40 void visitNodeLeave(const IVisualizationWidget &container, const QString &actionName,
41 ActionFun actionFunction)
41 ActionFun actionFunction)
42 {
42 {
43 if (m_Variable && container.canDrop(*m_Variable)) {
43 if (m_Variable && container.canDrop(*m_Variable)) {
44 m_MenuBuilder.addSeparator();
44 m_MenuBuilder.addSeparator();
45 m_MenuBuilder.addAction(actionName, actionFunction);
45 m_MenuBuilder.addAction(actionName, actionFunction);
46 }
46 }
47
47
48 // Closes the menu associated to the node
48 // Closes the menu associated to the node
49 m_MenuBuilder.closeMenu();
49 m_MenuBuilder.closeMenu();
50 }
50 }
51
51
52 template <typename ActionFun>
52 template <typename ActionFun>
53 void visitLeaf(const IVisualizationWidget &container, const QString &actionName,
53 void visitLeaf(const IVisualizationWidget &container, const QString &actionName,
54 ActionFun actionFunction)
54 ActionFun actionFunction)
55 {
55 {
56 if (m_Variable && container.canDrop(*m_Variable)) {
56 if (m_Variable && container.canDrop(*m_Variable)) {
57 m_MenuBuilder.addAction(actionName, actionFunction);
57 m_MenuBuilder.addAction(actionName, actionFunction);
58 }
58 }
59 }
59 }
60
60
61 std::shared_ptr<Variable> m_Variable;
61 std::shared_ptr<Variable> m_Variable;
62 MenuBuilder m_MenuBuilder;
62 MenuBuilder m_MenuBuilder;
63 };
63 };
64
64
65 GenerateVariableMenuOperation::GenerateVariableMenuOperation(QMenu *menu,
65 GenerateVariableMenuOperation::GenerateVariableMenuOperation(QMenu *menu,
66 std::shared_ptr<Variable> variable)
66 std::shared_ptr<Variable> variable)
67 : impl{spimpl::make_unique_impl<GenerateVariableMenuOperationPrivate>(menu, variable)}
67 : impl{spimpl::make_unique_impl<GenerateVariableMenuOperationPrivate>(menu, variable)}
68 {
68 {
69 }
69 }
70
70
71 void GenerateVariableMenuOperation::visitEnter(VisualizationWidget *widget)
71 void GenerateVariableMenuOperation::visitEnter(VisualizationWidget *widget)
72 {
72 {
73 // VisualizationWidget is not intended to accommodate a variable
73 // VisualizationWidget is not intended to accommodate a variable
74 Q_UNUSED(widget)
74 Q_UNUSED(widget)
75
75
76 impl->visitRootEnter();
76 impl->visitRootEnter();
77 }
77 }
78
78
79 void GenerateVariableMenuOperation::visitLeave(VisualizationWidget *widget)
79 void GenerateVariableMenuOperation::visitLeave(VisualizationWidget *widget)
80 {
80 {
81 // VisualizationWidget is not intended to accommodate a variable
81 // VisualizationWidget is not intended to accommodate a variable
82 Q_UNUSED(widget)
82 Q_UNUSED(widget)
83
83
84 impl->visitRootLeave();
84 impl->visitRootLeave();
85 }
85 }
86
86
87 void GenerateVariableMenuOperation::visitEnter(VisualizationTabWidget *tabWidget)
87 void GenerateVariableMenuOperation::visitEnter(VisualizationTabWidget *tabWidget)
88 {
88 {
89 if (tabWidget) {
89 if (tabWidget) {
90 impl->visitNodeEnter(*tabWidget);
90 impl->visitNodeEnter(*tabWidget);
91 }
91 }
92 else {
92 else {
93 qCCritical(LOG_GenerateVariableMenuOperation(),
93 qCCritical(LOG_GenerateVariableMenuOperation(),
94 "Can't visit enter VisualizationTabWidget : the widget is null");
94 "Can't visit enter VisualizationTabWidget : the widget is null");
95 }
95 }
96 }
96 }
97
97
98 void GenerateVariableMenuOperation::visitLeave(VisualizationTabWidget *tabWidget)
98 void GenerateVariableMenuOperation::visitLeave(VisualizationTabWidget *tabWidget)
99 {
99 {
100 if (tabWidget) {
100 if (tabWidget) {
101 impl->visitNodeLeave(
101 impl->visitNodeLeave(
102 *tabWidget, QObject::tr("Open in a new zone"),
102 *tabWidget, QObject::tr("Open in a new zone"),
103 [ var = impl->m_Variable, tabWidget ]() { tabWidget->createZone(var); });
103 [ var = impl->m_Variable, tabWidget ]() { tabWidget->createZone(var); });
104 }
104 }
105 else {
105 else {
106 qCCritical(LOG_GenerateVariableMenuOperation(),
106 qCCritical(LOG_GenerateVariableMenuOperation(),
107 "Can't visit leave VisualizationTabWidget : the widget is null");
107 "Can't visit leave VisualizationTabWidget : the widget is null");
108 }
108 }
109 }
109 }
110
110
111 void GenerateVariableMenuOperation::visitEnter(VisualizationZoneWidget *zoneWidget)
111 void GenerateVariableMenuOperation::visitEnter(VisualizationZoneWidget *zoneWidget)
112 {
112 {
113 if (zoneWidget) {
113 if (zoneWidget) {
114 impl->visitNodeEnter(*zoneWidget);
114 impl->visitNodeEnter(*zoneWidget);
115 }
115 }
116 else {
116 else {
117 qCCritical(LOG_GenerateVariableMenuOperation(),
117 qCCritical(LOG_GenerateVariableMenuOperation(),
118 "Can't visit enter VisualizationZoneWidget : the widget is null");
118 "Can't visit enter VisualizationZoneWidget : the widget is null");
119 }
119 }
120 }
120 }
121
121
122 void GenerateVariableMenuOperation::visitLeave(VisualizationZoneWidget *zoneWidget)
122 void GenerateVariableMenuOperation::visitLeave(VisualizationZoneWidget *zoneWidget)
123 {
123 {
124 if (zoneWidget) {
124 if (zoneWidget) {
125 impl->visitNodeLeave(
125 impl->visitNodeLeave(
126 *zoneWidget, QObject::tr("Open in a new graph"),
126 *zoneWidget, QObject::tr("Open in a new graph"),
127 [ var = impl->m_Variable, zoneWidget ]() { zoneWidget->createGraph(var); });
127 [ var = impl->m_Variable, zoneWidget ]() { zoneWidget->createGraph(var); });
128 }
128 }
129 else {
129 else {
130 qCCritical(LOG_GenerateVariableMenuOperation(),
130 qCCritical(LOG_GenerateVariableMenuOperation(),
131 "Can't visit leave VisualizationZoneWidget : the widget is null");
131 "Can't visit leave VisualizationZoneWidget : the widget is null");
132 }
132 }
133 }
133 }
134
134
135 void GenerateVariableMenuOperation::visit(VisualizationGraphWidget *graphWidget)
135 void GenerateVariableMenuOperation::visit(VisualizationGraphWidget *graphWidget)
136 {
136 {
137 if (graphWidget) {
137 if (graphWidget) {
138 impl->visitLeaf(
138 impl->visitLeaf(
139 *graphWidget, QObject::tr("Open in %1").arg(graphWidget->name()),
139 *graphWidget, QObject::tr("Open in %1").arg(graphWidget->name()),
140 [ var = impl->m_Variable, graphWidget ]() { graphWidget->addVariable(var); });
140 [ var = impl->m_Variable, graphWidget ]() { graphWidget->addVariableUsingGraph(var); });
141 }
141 }
142 else {
142 else {
143 qCCritical(LOG_GenerateVariableMenuOperation(),
143 qCCritical(LOG_GenerateVariableMenuOperation(),
144 "Can't visit VisualizationGraphWidget : the widget is null");
144 "Can't visit VisualizationGraphWidget : the widget is null");
145 }
145 }
146 }
146 }
General Comments 0
You need to be logged in to leave comments. Login now