Auto status change to "Under Review"
@@ -1,28 +1,23 | |||||
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 | * @brief The SqpDateTime struct holds the information of time parameters |
|
6 | * @brief The SqpDateTime struct holds the information of time parameters | |
7 | */ |
|
7 | */ | |
8 | struct SqpDateTime { |
|
8 | struct SqpDateTime { | |
9 | /// Start time |
|
9 | /// Start time | |
10 | double m_TStart; |
|
10 | double m_TStart; | |
11 | /// End time |
|
11 | /// End time | |
12 | double m_TEnd; |
|
12 | double m_TEnd; | |
13 |
|
13 | |||
14 | bool contains(const SqpDateTime &dateTime) |
|
14 | bool contains(const SqpDateTime &dateTime) | |
15 | { |
|
15 | { | |
16 | return (m_TStart <= dateTime.m_TStart && m_TEnd >= dateTime.m_TEnd); |
|
16 | return (m_TStart <= dateTime.m_TStart && m_TEnd >= dateTime.m_TEnd); | |
17 | } |
|
17 | } | |
18 |
|
||||
19 | bool intersect(const SqpDateTime &dateTime) |
|
|||
20 | { |
|
|||
21 | return (m_TEnd >= dateTime.m_TStart && m_TStart <= dateTime.m_TEnd); |
|
|||
22 | } |
|
|||
23 | }; |
|
18 | }; | |
24 |
|
19 | |||
25 | // Required for using shared_ptr in signals/slots |
|
20 | // Required for using shared_ptr in signals/slots | |
26 | Q_DECLARE_METATYPE(SqpDateTime) |
|
21 | Q_DECLARE_METATYPE(SqpDateTime) | |
27 |
|
22 | |||
28 | #endif // SCIQLOP_SQPDATETIME_H |
|
23 | #endif // SCIQLOP_SQPDATETIME_H |
@@ -1,55 +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 : 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 |
|
32 | |||
33 | /// @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 | |
34 | IDataSeries *dataSeries() const noexcept; |
|
34 | IDataSeries *dataSeries() const noexcept; | |
35 |
|
35 | |||
36 | bool contains(const SqpDateTime &dateTime); |
|
36 | bool contains(const SqpDateTime &dateTime); | |
37 | bool intersect(const SqpDateTime &dateTime); |
|
|||
38 | void setDataSeries(std::unique_ptr<IDataSeries> dataSeries) noexcept; |
|
37 | void setDataSeries(std::unique_ptr<IDataSeries> dataSeries) noexcept; | |
39 |
|
38 | |||
40 | public slots: |
|
39 | public slots: | |
41 | void onAddDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept; |
|
40 | void onAddDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept; | |
42 |
|
41 | |||
43 | signals: |
|
42 | signals: | |
44 | void dataCacheUpdated(); |
|
43 | void dataCacheUpdated(); | |
45 |
|
44 | |||
46 |
|
45 | |||
47 | private: |
|
46 | private: | |
48 | class VariablePrivate; |
|
47 | class VariablePrivate; | |
49 | spimpl::unique_impl_ptr<VariablePrivate> impl; |
|
48 | spimpl::unique_impl_ptr<VariablePrivate> impl; | |
50 | }; |
|
49 | }; | |
51 |
|
50 | |||
52 | // Required for using shared_ptr in signals/slots |
|
51 | // Required for using shared_ptr in signals/slots | |
53 | Q_DECLARE_METATYPE(std::shared_ptr<Variable>) |
|
52 | Q_DECLARE_METATYPE(std::shared_ptr<Variable>) | |
54 |
|
53 | |||
55 | #endif // SCIQLOP_VARIABLE_H |
|
54 | #endif // SCIQLOP_VARIABLE_H |
@@ -1,94 +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 | 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::setDataSeries(std::unique_ptr<IDataSeries> dataSeries) noexcept |
|
53 | void Variable::setDataSeries(std::unique_ptr<IDataSeries> dataSeries) noexcept | |
54 | { |
|
54 | { | |
55 | if (!impl->m_DataSeries) { |
|
55 | if (!impl->m_DataSeries) { | |
56 | impl->m_DataSeries = std::move(dataSeries); |
|
56 | impl->m_DataSeries = std::move(dataSeries); | |
57 | } |
|
57 | } | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | void Variable::onAddDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept |
|
60 | void Variable::onAddDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept | |
61 | { |
|
61 | { | |
62 | if (impl->m_DataSeries) { |
|
62 | if (impl->m_DataSeries) { | |
63 | impl->m_DataSeries->merge(dataSeries.get()); |
|
63 | impl->m_DataSeries->merge(dataSeries.get()); | |
64 |
|
64 | |||
65 | emit dataCacheUpdated(); |
|
65 | emit dataCacheUpdated(); | |
66 | } |
|
66 | } | |
67 | } |
|
67 | } | |
68 |
|
68 | |||
69 | IDataSeries *Variable::dataSeries() const noexcept |
|
69 | IDataSeries *Variable::dataSeries() const noexcept | |
70 | { |
|
70 | { | |
71 | return impl->m_DataSeries.get(); |
|
71 | return impl->m_DataSeries.get(); | |
72 | } |
|
72 | } | |
73 |
|
73 | |||
74 | bool Variable::contains(const SqpDateTime &dateTime) |
|
74 | bool Variable::contains(const SqpDateTime &dateTime) | |
75 | { |
|
75 | { | |
76 | if (!impl->m_DateTime.contains(dateTime)) { |
|
76 | if (!impl->m_DateTime.contains(dateTime)) { | |
77 | // 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. | |
78 | // We have to update it to the new dateTime requested. |
|
78 | // We have to update it to the new dateTime requested. | |
79 | // 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 | |
80 | // provider if necessary. |
|
80 | // provider if necessary. | |
81 | qCInfo(LOG_Variable()) << "NEW DATE NEEDED"; |
|
81 | qCInfo(LOG_Variable()) << "NEW DATE NEEDED"; | |
82 |
|
82 | |||
83 |
|
|
83 | impl->m_DateTime = dateTime; | |
84 |
|
84 | |||
85 | return false; |
|
85 | return false; | |
86 | } |
|
86 | } | |
87 |
|
87 | |||
88 | return true; |
|
88 | return true; | |
89 | } |
|
89 | } | |
90 |
|
||||
91 | bool Variable::intersect(const SqpDateTime &dateTime) |
|
|||
92 | { |
|
|||
93 | return impl->m_DateTime.intersect(dateTime); |
|
|||
94 | } |
|
@@ -1,198 +1,173 | |||||
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::unordered_multimap<std::shared_ptr<Variable>, QCPAbstractPlottable *> |
|
29 | std::unordered_multimap<std::shared_ptr<Variable>, QCPAbstractPlottable *> | |
30 | m_VariableToPlotMultiMap; |
|
30 | m_VariableToPlotMultiMap; | |
31 | }; |
|
31 | }; | |
32 |
|
32 | |||
33 | VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent) |
|
33 | VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent) | |
34 | : QWidget{parent}, |
|
34 | : QWidget{parent}, | |
35 | ui{new Ui::VisualizationGraphWidget}, |
|
35 | ui{new Ui::VisualizationGraphWidget}, | |
36 | impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()} |
|
36 | impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()} | |
37 | { |
|
37 | { | |
38 | ui->setupUi(this); |
|
38 | ui->setupUi(this); | |
39 |
|
39 | |||
40 | // qcpplot title |
|
40 | // qcpplot title | |
41 | ui->widget->plotLayout()->insertRow(0); |
|
41 | ui->widget->plotLayout()->insertRow(0); | |
42 | ui->widget->plotLayout()->addElement(0, 0, new QCPTextElement{ui->widget, name}); |
|
42 | ui->widget->plotLayout()->addElement(0, 0, new QCPTextElement{ui->widget, name}); | |
43 |
|
43 | |||
44 | // Set qcpplot properties : |
|
44 | // Set qcpplot properties : | |
45 | // - Drag (on x-axis) and zoom are enabled |
|
45 | // - Drag (on x-axis) and zoom are enabled | |
46 | // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation |
|
46 | // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation | |
47 | ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); |
|
47 | ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); | |
48 | ui->widget->axisRect()->setRangeDrag(Qt::Horizontal); |
|
48 | ui->widget->axisRect()->setRangeDrag(Qt::Horizontal); | |
49 | connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel); |
|
49 | connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel); | |
50 | 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 &)>( | |
51 | &QCPAxis::rangeChanged), |
|
51 | &QCPAxis::rangeChanged), | |
52 | this, &VisualizationGraphWidget::onRangeChanged); |
|
52 | this, &VisualizationGraphWidget::onRangeChanged); | |
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 |
|
55 | |||
56 | VisualizationGraphWidget::~VisualizationGraphWidget() |
|
56 | VisualizationGraphWidget::~VisualizationGraphWidget() | |
57 | { |
|
57 | { | |
58 | delete ui; |
|
58 | delete ui; | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable) |
|
61 | void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable) | |
62 | { |
|
62 | { | |
63 | // Uses delegate to create the qcpplot components according to the variable |
|
63 | // Uses delegate to create the qcpplot components according to the variable | |
64 | auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget); |
|
64 | auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget); | |
65 |
|
65 | |||
66 | for (auto createdPlottable : qAsConst(createdPlottables)) { |
|
66 | for (auto createdPlottable : qAsConst(createdPlottables)) { | |
67 | impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable}); |
|
67 | impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable}); | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | connect(variable.get(), SIGNAL(dataCacheUpdated()), this, SLOT(onDataCacheVariableUpdated())); |
|
70 | connect(variable.get(), SIGNAL(dataCacheUpdated()), this, SLOT(onDataCacheVariableUpdated())); | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
73 | void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor) | |
74 | { |
|
74 | { | |
75 | if (visitor) { |
|
75 | if (visitor) { | |
76 | visitor->visit(this); |
|
76 | visitor->visit(this); | |
77 | } |
|
77 | } | |
78 | else { |
|
78 | else { | |
79 | qCCritical(LOG_VisualizationGraphWidget()) |
|
79 | qCCritical(LOG_VisualizationGraphWidget()) | |
80 | << tr("Can't visit widget : the visitor is null"); |
|
80 | << tr("Can't visit widget : the visitor is null"); | |
81 | } |
|
81 | } | |
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 | bool VisualizationGraphWidget::canDrop(const Variable &variable) const |
|
84 | bool VisualizationGraphWidget::canDrop(const Variable &variable) const | |
85 | { |
|
85 | { | |
86 | /// @todo : for the moment, a graph can always accomodate a variable |
|
86 | /// @todo : for the moment, a graph can always accomodate a variable | |
87 | Q_UNUSED(variable); |
|
87 | Q_UNUSED(variable); | |
88 | return true; |
|
88 | return true; | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 | void VisualizationGraphWidget::close() |
|
91 | void VisualizationGraphWidget::close() | |
92 | { |
|
92 | { | |
93 | // The main view cannot be directly closed. |
|
93 | // The main view cannot be directly closed. | |
94 | return; |
|
94 | return; | |
95 | } |
|
95 | } | |
96 |
|
96 | |||
97 | QString VisualizationGraphWidget::name() const |
|
97 | QString VisualizationGraphWidget::name() const | |
98 | { |
|
98 | { | |
99 | if (auto title = dynamic_cast<QCPTextElement *>(ui->widget->plotLayout()->elementAt(0))) { |
|
99 | if (auto title = dynamic_cast<QCPTextElement *>(ui->widget->plotLayout()->elementAt(0))) { | |
100 | return title->text(); |
|
100 | return title->text(); | |
101 | } |
|
101 | } | |
102 | else { |
|
102 | else { | |
103 | return QString{}; |
|
103 | return QString{}; | |
104 | } |
|
104 | } | |
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 | void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2) |
|
107 | void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2) | |
108 | { |
|
108 | { | |
109 |
|
109 | |||
110 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged"); |
|
110 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged"); | |
111 |
|
111 | |||
112 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(); |
|
112 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(); | |
113 | it != impl->m_VariableToPlotMultiMap.cend(); ++it) { |
|
113 | it != impl->m_VariableToPlotMultiMap.cend(); ++it) { | |
114 |
|
||||
115 | auto variable = it->first; |
|
114 | auto variable = it->first; | |
116 | qCInfo(LOG_VisualizationGraphWidget()) |
|
115 | auto tolerance = 0.1 * (t2.upper - t2.lower); | |
117 | << tr("TORM: VisualizationGraphWidget::onRangeChanged") |
|
116 | auto dateTime = SqpDateTime{t2.lower - tolerance, t2.upper + tolerance}; | |
118 | << variable->dataSeries()->xAxisData()->size(); |
|
|||
119 | auto dateTime = SqpDateTime{t2.lower, t2.upper}; |
|
|||
120 |
|
117 | |||
|
118 | qCInfo(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged") | |||
|
119 | << variable->dataSeries()->xAxisData()->size(); | |||
121 | if (!variable->contains(dateTime)) { |
|
120 | if (!variable->contains(dateTime)) { | |
122 |
|
||||
123 | if (variable->intersect(dateTime)) { |
|
|||
124 | auto variableDateTime = variable->dateTime(); |
|
|||
125 | if (variableDateTime.m_TStart < dateTime.m_TStart) { |
|
|||
126 | dateTime.m_TStart = variableDateTime.m_TStart; |
|
|||
127 | // add 20% tolerance for left (start) side |
|
|||
128 | auto tolerance = 0.2 * (dateTime.m_TEnd - dateTime.m_TStart); |
|
|||
129 | dateTime.m_TStart -= tolerance; |
|
|||
130 | } |
|
|||
131 |
|
||||
132 | if (variableDateTime.m_TEnd > dateTime.m_TEnd) { |
|
|||
133 | dateTime.m_TEnd = variableDateTime.m_TEnd; |
|
|||
134 | // add 20% tolerance for right (end) side |
|
|||
135 | auto tolerance = 0.2 * (dateTime.m_TEnd - dateTime.m_TStart); |
|
|||
136 | dateTime.m_TEnd += tolerance; |
|
|||
137 | } |
|
|||
138 | } |
|
|||
139 | else { |
|
|||
140 | // add 10% tolerance for each side |
|
|||
141 | auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart); |
|
|||
142 | dateTime.m_TStart -= tolerance; |
|
|||
143 | dateTime.m_TEnd += tolerance; |
|
|||
144 | } |
|
|||
145 | // CHangement detected, we need to |
|
|||
146 | sqpApp->variableController().requestDataLoading(variable, dateTime); |
|
121 | sqpApp->variableController().requestDataLoading(variable, dateTime); | |
147 | } |
|
122 | } | |
148 | } |
|
123 | } | |
149 | } |
|
124 | } | |
150 |
|
125 | |||
151 | void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept |
|
126 | void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept | |
152 | { |
|
127 | { | |
153 | auto zoomOrientations = QFlags<Qt::Orientation>{}; |
|
128 | auto zoomOrientations = QFlags<Qt::Orientation>{}; | |
154 |
|
129 | |||
155 | // Lambda that enables a zoom orientation if the key modifier related to this orientation has |
|
130 | // Lambda that enables a zoom orientation if the key modifier related to this orientation has | |
156 | // been pressed |
|
131 | // been pressed | |
157 | auto enableOrientation |
|
132 | auto enableOrientation | |
158 | = [&zoomOrientations, event](const auto &orientation, const auto &modifier) { |
|
133 | = [&zoomOrientations, event](const auto &orientation, const auto &modifier) { | |
159 | auto orientationEnabled = event->modifiers().testFlag(modifier); |
|
134 | auto orientationEnabled = event->modifiers().testFlag(modifier); | |
160 | zoomOrientations.setFlag(orientation, orientationEnabled); |
|
135 | zoomOrientations.setFlag(orientation, orientationEnabled); | |
161 | }; |
|
136 | }; | |
162 | enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER); |
|
137 | enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER); | |
163 | enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER); |
|
138 | enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER); | |
164 |
|
139 | |||
165 | ui->widget->axisRect()->setRangeZoom(zoomOrientations); |
|
140 | ui->widget->axisRect()->setRangeZoom(zoomOrientations); | |
166 | } |
|
141 | } | |
167 |
|
142 | |||
168 | void VisualizationGraphWidget::onDataCacheVariableUpdated() |
|
143 | void VisualizationGraphWidget::onDataCacheVariableUpdated() | |
169 | { |
|
144 | { | |
170 | // NOTE: |
|
145 | // NOTE: | |
171 | // We don't want to call the method for each component of a variable unitarily, but for all |
|
146 | // We don't want to call the method for each component of a variable unitarily, but for all | |
172 | // its components at once (eg its three components in the case of a vector). |
|
147 | // its components at once (eg its three components in the case of a vector). | |
173 |
|
148 | |||
174 | // The unordered_multimap does not do this easily, so the question is whether to: |
|
149 | // The unordered_multimap does not do this easily, so the question is whether to: | |
175 | // - use an ordered_multimap and the algos of std to group the values by key |
|
150 | // - use an ordered_multimap and the algos of std to group the values by key | |
176 | // - use a map (unique keys) and store as values directly the list of components |
|
151 | // - use a map (unique keys) and store as values directly the list of components | |
177 |
|
152 | |||
178 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(); |
|
153 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(); | |
179 | it != impl->m_VariableToPlotMultiMap.cend(); ++it) { |
|
154 | it != impl->m_VariableToPlotMultiMap.cend(); ++it) { | |
180 | auto variable = it->first; |
|
155 | auto variable = it->first; | |
181 | VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *>{} << it->second, |
|
156 | VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *>{} << it->second, | |
182 | variable->dataSeries(), variable->dateTime()); |
|
157 | variable->dataSeries(), variable->dateTime()); | |
183 | } |
|
158 | } | |
184 | } |
|
159 | } | |
185 |
|
160 | |||
186 | void VisualizationGraphWidget::updateDisplay(std::shared_ptr<Variable> variable) |
|
161 | void VisualizationGraphWidget::updateDisplay(std::shared_ptr<Variable> variable) | |
187 | { |
|
162 | { | |
188 | auto abstractPlotableItPair = impl->m_VariableToPlotMultiMap.equal_range(variable); |
|
163 | auto abstractPlotableItPair = impl->m_VariableToPlotMultiMap.equal_range(variable); | |
189 |
|
164 | |||
190 | auto abstractPlotableVect = QVector<QCPAbstractPlottable *>{}; |
|
165 | auto abstractPlotableVect = QVector<QCPAbstractPlottable *>{}; | |
191 |
|
166 | |||
192 | for (auto it = abstractPlotableItPair.first; it != abstractPlotableItPair.second; ++it) { |
|
167 | for (auto it = abstractPlotableItPair.first; it != abstractPlotableItPair.second; ++it) { | |
193 | abstractPlotableVect.push_back(it->second); |
|
168 | abstractPlotableVect.push_back(it->second); | |
194 | } |
|
169 | } | |
195 |
|
170 | |||
196 | VisualizationGraphHelper::updateData(abstractPlotableVect, variable->dataSeries(), |
|
171 | VisualizationGraphHelper::updateData(abstractPlotableVect, variable->dataSeries(), | |
197 | variable->dateTime()); |
|
172 | variable->dateTime()); | |
198 | } |
|
173 | } |
General Comments 3
Status change > Approved
You need to be logged in to leave comments.
Login now