@@ -1,320 +1,313 | |||||
1 | #include "Visualization/VisualizationGraphWidget.h" |
|
1 | #include "Visualization/VisualizationGraphWidget.h" | |
2 | #include "Visualization/IVisualizationWidgetVisitor.h" |
|
2 | #include "Visualization/IVisualizationWidgetVisitor.h" | |
|
3 | #include "Visualization/VisualizationDefs.h" | |||
3 | #include "Visualization/VisualizationGraphHelper.h" |
|
4 | #include "Visualization/VisualizationGraphHelper.h" | |
4 | #include "Visualization/VisualizationGraphRenderingDelegate.h" |
|
5 | #include "Visualization/VisualizationGraphRenderingDelegate.h" | |
5 | #include "ui_VisualizationGraphWidget.h" |
|
6 | #include "ui_VisualizationGraphWidget.h" | |
6 |
|
7 | |||
7 | #include <Data/ArrayData.h> |
|
8 | #include <Data/ArrayData.h> | |
8 | #include <Data/IDataSeries.h> |
|
9 | #include <Data/IDataSeries.h> | |
9 | #include <Settings/SqpSettingsDefs.h> |
|
10 | #include <Settings/SqpSettingsDefs.h> | |
10 | #include <SqpApplication.h> |
|
11 | #include <SqpApplication.h> | |
11 | #include <Variable/Variable.h> |
|
12 | #include <Variable/Variable.h> | |
12 | #include <Variable/VariableController.h> |
|
13 | #include <Variable/VariableController.h> | |
13 |
|
14 | |||
14 | #include <unordered_map> |
|
15 | #include <unordered_map> | |
15 |
|
16 | |||
16 | Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget") |
|
17 | Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget") | |
17 |
|
18 | |||
18 | namespace { |
|
19 | namespace { | |
19 |
|
20 | |||
20 | /// Key pressed to enable zoom on horizontal axis |
|
21 | /// Key pressed to enable zoom on horizontal axis | |
21 | const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier; |
|
22 | const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier; | |
22 |
|
23 | |||
23 | /// Key pressed to enable zoom on vertical axis |
|
24 | /// Key pressed to enable zoom on vertical axis | |
24 | const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier; |
|
25 | const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier; | |
25 |
|
26 | |||
26 | } // namespace |
|
27 | } // namespace | |
27 |
|
28 | |||
28 | struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { |
|
29 | struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { | |
29 |
|
30 | |||
30 | explicit VisualizationGraphWidgetPrivate() |
|
31 | explicit VisualizationGraphWidgetPrivate() | |
31 | : m_DoAcquisition{true}, m_IsCalibration{false}, m_RenderingDelegate{nullptr} |
|
32 | : m_DoAcquisition{true}, m_IsCalibration{false}, m_RenderingDelegate{nullptr} | |
32 | { |
|
33 | { | |
33 | } |
|
34 | } | |
34 |
|
35 | |||
35 | // 1 variable -> n qcpplot |
|
36 | // 1 variable -> n qcpplot | |
36 |
std:: |
|
37 | std::map<std::shared_ptr<Variable>, PlottablesMap> m_VariableToPlotMultiMap; | |
37 | bool m_DoAcquisition; |
|
38 | bool m_DoAcquisition; | |
38 | bool m_IsCalibration; |
|
39 | bool m_IsCalibration; | |
39 | QCPItemTracer *m_TextTracer; |
|
40 | QCPItemTracer *m_TextTracer; | |
40 | /// Delegate used to attach rendering features to the plot |
|
41 | /// Delegate used to attach rendering features to the plot | |
41 | std::unique_ptr<VisualizationGraphRenderingDelegate> m_RenderingDelegate; |
|
42 | std::unique_ptr<VisualizationGraphRenderingDelegate> m_RenderingDelegate; | |
42 | }; |
|
43 | }; | |
43 |
|
44 | |||
44 | VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent) |
|
45 | VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent) | |
45 | : QWidget{parent}, |
|
46 | : QWidget{parent}, | |
46 | ui{new Ui::VisualizationGraphWidget}, |
|
47 | ui{new Ui::VisualizationGraphWidget}, | |
47 | impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()} |
|
48 | impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()} | |
48 | { |
|
49 | { | |
49 | ui->setupUi(this); |
|
50 | ui->setupUi(this); | |
50 |
|
51 | |||
51 | // The delegate must be initialized after the ui as it uses the plot |
|
52 | // The delegate must be initialized after the ui as it uses the plot | |
52 | impl->m_RenderingDelegate = std::make_unique<VisualizationGraphRenderingDelegate>(*ui->widget); |
|
53 | impl->m_RenderingDelegate = std::make_unique<VisualizationGraphRenderingDelegate>(*ui->widget); | |
53 |
|
54 | |||
54 | ui->graphNameLabel->setText(name); |
|
55 | ui->graphNameLabel->setText(name); | |
55 |
|
56 | |||
56 | // 'Close' options : widget is deleted when closed |
|
57 | // 'Close' options : widget is deleted when closed | |
57 | setAttribute(Qt::WA_DeleteOnClose); |
|
58 | setAttribute(Qt::WA_DeleteOnClose); | |
58 | connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationGraphWidget::close); |
|
59 | connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationGraphWidget::close); | |
59 | ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton)); |
|
60 | ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton)); | |
60 |
|
61 | |||
61 | // Set qcpplot properties : |
|
62 | // Set qcpplot properties : | |
62 | // - Drag (on x-axis) and zoom are enabled |
|
63 | // - Drag (on x-axis) and zoom are enabled | |
63 | // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation |
|
64 | // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation | |
64 | ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); |
|
65 | ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); | |
65 | ui->widget->axisRect()->setRangeDrag(Qt::Horizontal); |
|
66 | ui->widget->axisRect()->setRangeDrag(Qt::Horizontal); | |
66 |
|
67 | |||
67 | connect(ui->widget, &QCustomPlot::mousePress, this, &VisualizationGraphWidget::onMousePress); |
|
68 | connect(ui->widget, &QCustomPlot::mousePress, this, &VisualizationGraphWidget::onMousePress); | |
68 | connect(ui->widget, &QCustomPlot::mouseRelease, this, |
|
69 | connect(ui->widget, &QCustomPlot::mouseRelease, this, | |
69 | &VisualizationGraphWidget::onMouseRelease); |
|
70 | &VisualizationGraphWidget::onMouseRelease); | |
70 | connect(ui->widget, &QCustomPlot::mouseMove, this, &VisualizationGraphWidget::onMouseMove); |
|
71 | connect(ui->widget, &QCustomPlot::mouseMove, this, &VisualizationGraphWidget::onMouseMove); | |
71 | connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel); |
|
72 | connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel); | |
72 | connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>( |
|
73 | connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>( | |
73 | &QCPAxis::rangeChanged), |
|
74 | &QCPAxis::rangeChanged), | |
74 | this, &VisualizationGraphWidget::onRangeChanged, Qt::DirectConnection); |
|
75 | this, &VisualizationGraphWidget::onRangeChanged, Qt::DirectConnection); | |
75 |
|
76 | |||
76 | // Activates menu when right clicking on the graph |
|
77 | // Activates menu when right clicking on the graph | |
77 | ui->widget->setContextMenuPolicy(Qt::CustomContextMenu); |
|
78 | ui->widget->setContextMenuPolicy(Qt::CustomContextMenu); | |
78 | connect(ui->widget, &QCustomPlot::customContextMenuRequested, this, |
|
79 | connect(ui->widget, &QCustomPlot::customContextMenuRequested, this, | |
79 | &VisualizationGraphWidget::onGraphMenuRequested); |
|
80 | &VisualizationGraphWidget::onGraphMenuRequested); | |
80 |
|
81 | |||
81 | connect(this, &VisualizationGraphWidget::requestDataLoading, &sqpApp->variableController(), |
|
82 | connect(this, &VisualizationGraphWidget::requestDataLoading, &sqpApp->variableController(), | |
82 | &VariableController::onRequestDataLoading); |
|
83 | &VariableController::onRequestDataLoading); | |
83 |
|
84 | |||
84 | connect(&sqpApp->variableController(), &VariableController::updateVarDisplaying, this, |
|
85 | connect(&sqpApp->variableController(), &VariableController::updateVarDisplaying, this, | |
85 | &VisualizationGraphWidget::onUpdateVarDisplaying); |
|
86 | &VisualizationGraphWidget::onUpdateVarDisplaying); | |
86 | } |
|
87 | } | |
87 |
|
88 | |||
88 |
|
89 | |||
89 | VisualizationGraphWidget::~VisualizationGraphWidget() |
|
90 | VisualizationGraphWidget::~VisualizationGraphWidget() | |
90 | { |
|
91 | { | |
91 | delete ui; |
|
92 | delete ui; | |
92 | } |
|
93 | } | |
93 |
|
94 | |||
94 | void VisualizationGraphWidget::enableAcquisition(bool enable) |
|
95 | void VisualizationGraphWidget::enableAcquisition(bool enable) | |
95 | { |
|
96 | { | |
96 | impl->m_DoAcquisition = enable; |
|
97 | impl->m_DoAcquisition = enable; | |
97 | } |
|
98 | } | |
98 |
|
99 | |||
99 | void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable, SqpRange range) |
|
100 | void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable, SqpRange range) | |
100 | { |
|
101 | { | |
101 | // Uses delegate to create the qcpplot components according to the variable |
|
102 | // Uses delegate to create the qcpplot components according to the variable | |
102 |
auto createdPlottables = VisualizationGraphHelper::create |
|
103 | auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget); | |
103 |
|
104 | impl->m_VariableToPlotMultiMap.insert({variable, std::move(createdPlottables)}); | ||
104 | for (auto createdPlottable : qAsConst(createdPlottables)) { |
|
|||
105 | impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable}); |
|
|||
106 | } |
|
|||
107 |
|
105 | |||
108 | connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated())); |
|
106 | connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated())); | |
109 |
|
107 | |||
110 | auto varRange = variable->range(); |
|
108 | auto varRange = variable->range(); | |
111 |
|
109 | |||
112 | this->enableAcquisition(false); |
|
110 | this->enableAcquisition(false); | |
113 | this->setGraphRange(range); |
|
111 | this->setGraphRange(range); | |
114 | this->enableAcquisition(true); |
|
112 | this->enableAcquisition(true); | |
115 |
|
113 | |||
116 | emit requestDataLoading(QVector<std::shared_ptr<Variable> >() << variable, range, varRange, |
|
114 | emit requestDataLoading(QVector<std::shared_ptr<Variable> >() << variable, range, varRange, | |
117 | false); |
|
115 | false); | |
118 |
|
116 | |||
119 | emit variableAdded(variable); |
|
117 | emit variableAdded(variable); | |
120 | } |
|
118 | } | |
121 |
|
119 | |||
122 | void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept |
|
120 | void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept | |
123 | { |
|
121 | { | |
124 | // Each component associated to the variable : |
|
122 | // Each component associated to the variable : | |
125 | // - is removed from qcpplot (which deletes it) |
|
123 | // - is removed from qcpplot (which deletes it) | |
126 | // - is no longer referenced in the map |
|
124 | // - is no longer referenced in the map | |
127 |
auto |
|
125 | auto variableIt = impl->m_VariableToPlotMultiMap.find(variable); | |
128 | for (auto it = componentsIt.first; it != componentsIt.second;) { |
|
126 | if (variableIt != impl->m_VariableToPlotMultiMap.cend()) { | |
129 |
|
|
127 | auto &plottablesMap = variableIt->second; | |
130 | it = impl->m_VariableToPlotMultiMap.erase(it); |
|
128 | ||
|
129 | for (auto plottableIt = plottablesMap.cbegin(), plottableEnd = plottablesMap.cend(); | |||
|
130 | plottableIt != plottableEnd;) { | |||
|
131 | ui->widget->removePlottable(plottableIt->second); | |||
|
132 | plottableIt = plottablesMap.erase(plottableIt); | |||
|
133 | } | |||
|
134 | ||||
|
135 | impl->m_VariableToPlotMultiMap.erase(variableIt); | |||
131 | } |
|
136 | } | |
132 |
|
137 | |||
133 | // Updates graph |
|
138 | // Updates graph | |
134 | ui->widget->replot(); |
|
139 | ui->widget->replot(); | |
135 | } |
|
140 | } | |
136 |
|
141 | |||
137 | void VisualizationGraphWidget::setRange(std::shared_ptr<Variable> variable, const SqpRange &range) |
|
142 | void VisualizationGraphWidget::setRange(std::shared_ptr<Variable> variable, const SqpRange &range) | |
138 | { |
|
143 | { | |
139 | // Note: in case of different axes that depends on variable, we could start with a code like |
|
144 | // Note: in case of different axes that depends on variable, we could start with a code like | |
140 | // that: |
|
145 | // that: | |
141 | // auto componentsIt = impl->m_VariableToPlotMultiMap.equal_range(variable); |
|
146 | // auto componentsIt = impl->m_VariableToPlotMultiMap.equal_range(variable); | |
142 | // for (auto it = componentsIt.first; it != componentsIt.second;) { |
|
147 | // for (auto it = componentsIt.first; it != componentsIt.second;) { | |
143 | // } |
|
148 | // } | |
144 | ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd); |
|
149 | ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd); | |
145 | ui->widget->replot(); |
|
150 | ui->widget->replot(); | |
146 | } |
|
151 | } | |
147 |
|
152 | |||
148 | void VisualizationGraphWidget::setYRange(const SqpRange &range) |
|
153 | void VisualizationGraphWidget::setYRange(const SqpRange &range) | |
149 | { |
|
154 | { | |
150 | ui->widget->yAxis->setRange(range.m_TStart, range.m_TEnd); |
|
155 | ui->widget->yAxis->setRange(range.m_TStart, range.m_TEnd); | |
151 | } |
|
156 | } | |
152 |
|
157 | |||
153 | SqpRange VisualizationGraphWidget::graphRange() const noexcept |
|
158 | SqpRange VisualizationGraphWidget::graphRange() const noexcept | |
154 | { |
|
159 | { | |
155 | auto graphRange = ui->widget->xAxis->range(); |
|
160 | auto graphRange = ui->widget->xAxis->range(); | |
156 | return SqpRange{graphRange.lower, graphRange.upper}; |
|
161 | return SqpRange{graphRange.lower, graphRange.upper}; | |
157 | } |
|
162 | } | |
158 |
|
163 | |||
159 | void VisualizationGraphWidget::setGraphRange(const SqpRange &range) |
|
164 | void VisualizationGraphWidget::setGraphRange(const SqpRange &range) | |
160 | { |
|
165 | { | |
161 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange START"); |
|
166 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange START"); | |
162 | ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd); |
|
167 | ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd); | |
163 | ui->widget->replot(); |
|
168 | ui->widget->replot(); | |
164 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange END"); |
|
169 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange END"); | |
165 | } |
|
170 | } | |
166 |
|
171 | |||
167 | void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
172 | void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor) | |
168 | { |
|
173 | { | |
169 | if (visitor) { |
|
174 | if (visitor) { | |
170 | visitor->visit(this); |
|
175 | visitor->visit(this); | |
171 | } |
|
176 | } | |
172 | else { |
|
177 | else { | |
173 | qCCritical(LOG_VisualizationGraphWidget()) |
|
178 | qCCritical(LOG_VisualizationGraphWidget()) | |
174 | << tr("Can't visit widget : the visitor is null"); |
|
179 | << tr("Can't visit widget : the visitor is null"); | |
175 | } |
|
180 | } | |
176 | } |
|
181 | } | |
177 |
|
182 | |||
178 | bool VisualizationGraphWidget::canDrop(const Variable &variable) const |
|
183 | bool VisualizationGraphWidget::canDrop(const Variable &variable) const | |
179 | { |
|
184 | { | |
180 | /// @todo : for the moment, a graph can always accomodate a variable |
|
185 | /// @todo : for the moment, a graph can always accomodate a variable | |
181 | Q_UNUSED(variable); |
|
186 | Q_UNUSED(variable); | |
182 | return true; |
|
187 | return true; | |
183 | } |
|
188 | } | |
184 |
|
189 | |||
185 | bool VisualizationGraphWidget::contains(const Variable &variable) const |
|
190 | bool VisualizationGraphWidget::contains(const Variable &variable) const | |
186 | { |
|
191 | { | |
187 | // Finds the variable among the keys of the map |
|
192 | // Finds the variable among the keys of the map | |
188 | auto variablePtr = &variable; |
|
193 | auto variablePtr = &variable; | |
189 | auto findVariable |
|
194 | auto findVariable | |
190 | = [variablePtr](const auto &entry) { return variablePtr == entry.first.get(); }; |
|
195 | = [variablePtr](const auto &entry) { return variablePtr == entry.first.get(); }; | |
191 |
|
196 | |||
192 | auto end = impl->m_VariableToPlotMultiMap.cend(); |
|
197 | auto end = impl->m_VariableToPlotMultiMap.cend(); | |
193 | auto it = std::find_if(impl->m_VariableToPlotMultiMap.cbegin(), end, findVariable); |
|
198 | auto it = std::find_if(impl->m_VariableToPlotMultiMap.cbegin(), end, findVariable); | |
194 | return it != end; |
|
199 | return it != end; | |
195 | } |
|
200 | } | |
196 |
|
201 | |||
197 | QString VisualizationGraphWidget::name() const |
|
202 | QString VisualizationGraphWidget::name() const | |
198 | { |
|
203 | { | |
199 | return ui->graphNameLabel->text(); |
|
204 | return ui->graphNameLabel->text(); | |
200 | } |
|
205 | } | |
201 |
|
206 | |||
202 | void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept |
|
207 | void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept | |
203 | { |
|
208 | { | |
204 | QMenu graphMenu{}; |
|
209 | QMenu graphMenu{}; | |
205 |
|
210 | |||
206 | // Iterates on variables (unique keys) |
|
211 | // Iterates on variables (unique keys) | |
207 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(), |
|
212 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(), | |
208 | end = impl->m_VariableToPlotMultiMap.cend(); |
|
213 | end = impl->m_VariableToPlotMultiMap.cend(); | |
209 | it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) { |
|
214 | it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) { | |
210 | // 'Remove variable' action |
|
215 | // 'Remove variable' action | |
211 | graphMenu.addAction(tr("Remove variable %1").arg(it->first->name()), |
|
216 | graphMenu.addAction(tr("Remove variable %1").arg(it->first->name()), | |
212 | [ this, var = it->first ]() { removeVariable(var); }); |
|
217 | [ this, var = it->first ]() { removeVariable(var); }); | |
213 | } |
|
218 | } | |
214 |
|
219 | |||
215 | if (!graphMenu.isEmpty()) { |
|
220 | if (!graphMenu.isEmpty()) { | |
216 | graphMenu.exec(mapToGlobal(pos)); |
|
221 | graphMenu.exec(mapToGlobal(pos)); | |
217 | } |
|
222 | } | |
218 | } |
|
223 | } | |
219 |
|
224 | |||
220 | void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2) |
|
225 | void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2) | |
221 | { |
|
226 | { | |
222 | qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: VisualizationGraphWidget::onRangeChanged") |
|
227 | qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: VisualizationGraphWidget::onRangeChanged") | |
223 | << QThread::currentThread()->objectName() << "DoAcqui" |
|
228 | << QThread::currentThread()->objectName() << "DoAcqui" | |
224 | << impl->m_DoAcquisition; |
|
229 | << impl->m_DoAcquisition; | |
225 |
|
230 | |||
226 | auto graphRange = SqpRange{t1.lower, t1.upper}; |
|
231 | auto graphRange = SqpRange{t1.lower, t1.upper}; | |
227 | auto oldGraphRange = SqpRange{t2.lower, t2.upper}; |
|
232 | auto oldGraphRange = SqpRange{t2.lower, t2.upper}; | |
228 |
|
233 | |||
229 | if (impl->m_DoAcquisition) { |
|
234 | if (impl->m_DoAcquisition) { | |
230 | QVector<std::shared_ptr<Variable> > variableUnderGraphVector; |
|
235 | QVector<std::shared_ptr<Variable> > variableUnderGraphVector; | |
231 |
|
236 | |||
232 | for (auto it = impl->m_VariableToPlotMultiMap.begin(), |
|
237 | for (auto it = impl->m_VariableToPlotMultiMap.begin(), | |
233 | end = impl->m_VariableToPlotMultiMap.end(); |
|
238 | end = impl->m_VariableToPlotMultiMap.end(); | |
234 | it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) { |
|
239 | it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) { | |
235 | variableUnderGraphVector.push_back(it->first); |
|
240 | variableUnderGraphVector.push_back(it->first); | |
236 | } |
|
241 | } | |
237 | emit requestDataLoading(std::move(variableUnderGraphVector), graphRange, oldGraphRange, |
|
242 | emit requestDataLoading(std::move(variableUnderGraphVector), graphRange, oldGraphRange, | |
238 | !impl->m_IsCalibration); |
|
243 | !impl->m_IsCalibration); | |
239 |
|
244 | |||
240 | if (!impl->m_IsCalibration) { |
|
245 | if (!impl->m_IsCalibration) { | |
241 | qCDebug(LOG_VisualizationGraphWidget()) |
|
246 | qCDebug(LOG_VisualizationGraphWidget()) | |
242 | << tr("TORM: VisualizationGraphWidget::Synchronize notify !!") |
|
247 | << tr("TORM: VisualizationGraphWidget::Synchronize notify !!") | |
243 | << QThread::currentThread()->objectName() << graphRange << oldGraphRange; |
|
248 | << QThread::currentThread()->objectName() << graphRange << oldGraphRange; | |
244 | emit synchronize(graphRange, oldGraphRange); |
|
249 | emit synchronize(graphRange, oldGraphRange); | |
245 | } |
|
250 | } | |
246 | } |
|
251 | } | |
247 | } |
|
252 | } | |
248 |
|
253 | |||
249 | void VisualizationGraphWidget::onMouseMove(QMouseEvent *event) noexcept |
|
254 | void VisualizationGraphWidget::onMouseMove(QMouseEvent *event) noexcept | |
250 | { |
|
255 | { | |
251 | // Handles plot rendering when mouse is moving |
|
256 | // Handles plot rendering when mouse is moving | |
252 | impl->m_RenderingDelegate->onMouseMove(event); |
|
257 | impl->m_RenderingDelegate->onMouseMove(event); | |
253 | } |
|
258 | } | |
254 |
|
259 | |||
255 | void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept |
|
260 | void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept | |
256 | { |
|
261 | { | |
257 | auto zoomOrientations = QFlags<Qt::Orientation>{}; |
|
262 | auto zoomOrientations = QFlags<Qt::Orientation>{}; | |
258 |
|
263 | |||
259 | // Lambda that enables a zoom orientation if the key modifier related to this orientation |
|
264 | // Lambda that enables a zoom orientation if the key modifier related to this orientation | |
260 | // has |
|
265 | // has | |
261 | // been pressed |
|
266 | // been pressed | |
262 | auto enableOrientation |
|
267 | auto enableOrientation | |
263 | = [&zoomOrientations, event](const auto &orientation, const auto &modifier) { |
|
268 | = [&zoomOrientations, event](const auto &orientation, const auto &modifier) { | |
264 | auto orientationEnabled = event->modifiers().testFlag(modifier); |
|
269 | auto orientationEnabled = event->modifiers().testFlag(modifier); | |
265 | zoomOrientations.setFlag(orientation, orientationEnabled); |
|
270 | zoomOrientations.setFlag(orientation, orientationEnabled); | |
266 | }; |
|
271 | }; | |
267 | enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER); |
|
272 | enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER); | |
268 | enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER); |
|
273 | enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER); | |
269 |
|
274 | |||
270 | ui->widget->axisRect()->setRangeZoom(zoomOrientations); |
|
275 | ui->widget->axisRect()->setRangeZoom(zoomOrientations); | |
271 | } |
|
276 | } | |
272 |
|
277 | |||
273 | void VisualizationGraphWidget::onMousePress(QMouseEvent *event) noexcept |
|
278 | void VisualizationGraphWidget::onMousePress(QMouseEvent *event) noexcept | |
274 | { |
|
279 | { | |
275 | impl->m_IsCalibration = event->modifiers().testFlag(Qt::ControlModifier); |
|
280 | impl->m_IsCalibration = event->modifiers().testFlag(Qt::ControlModifier); | |
276 | } |
|
281 | } | |
277 |
|
282 | |||
278 | void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept |
|
283 | void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept | |
279 | { |
|
284 | { | |
280 | impl->m_IsCalibration = false; |
|
285 | impl->m_IsCalibration = false; | |
281 | } |
|
286 | } | |
282 |
|
287 | |||
283 | void VisualizationGraphWidget::onDataCacheVariableUpdated() |
|
288 | void VisualizationGraphWidget::onDataCacheVariableUpdated() | |
284 | { |
|
289 | { | |
285 | // NOTE: |
|
|||
286 | // We don't want to call the method for each component of a variable unitarily, but for |
|
|||
287 | // all |
|
|||
288 | // its components at once (eg its three components in the case of a vector). |
|
|||
289 |
|
||||
290 | // The unordered_multimap does not do this easily, so the question is whether to: |
|
|||
291 | // - use an ordered_multimap and the algos of std to group the values by key |
|
|||
292 | // - use a map (unique keys) and store as values directly the list of components |
|
|||
293 |
|
||||
294 | auto graphRange = ui->widget->xAxis->range(); |
|
290 | auto graphRange = ui->widget->xAxis->range(); | |
295 | auto dateTime = SqpRange{graphRange.lower, graphRange.upper}; |
|
291 | auto dateTime = SqpRange{graphRange.lower, graphRange.upper}; | |
296 |
|
292 | |||
297 |
for (auto it |
|
293 | for (auto &variableEntry : impl->m_VariableToPlotMultiMap) { | |
298 | it != impl->m_VariableToPlotMultiMap.cend(); ++it) { |
|
294 | auto variable = variableEntry.first; | |
299 | auto variable = it->first; |
|
|||
300 | qCDebug(LOG_VisualizationGraphWidget()) |
|
295 | qCDebug(LOG_VisualizationGraphWidget()) | |
301 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated S" << variable->range(); |
|
296 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated S" << variable->range(); | |
302 | qCDebug(LOG_VisualizationGraphWidget()) |
|
297 | qCDebug(LOG_VisualizationGraphWidget()) | |
303 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated E" << dateTime; |
|
298 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated E" << dateTime; | |
304 | if (dateTime.contains(variable->range()) || dateTime.intersect(variable->range())) { |
|
299 | if (dateTime.contains(variable->range()) || dateTime.intersect(variable->range())) { | |
305 |
|
300 | VisualizationGraphHelper::updateData(variableEntry.second, variable->dataSeries().get(), | ||
306 | VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *>{} << it->second, |
|
301 | variable->range()); | |
307 | variable->dataSeries(), variable->range()); |
|
|||
308 | } |
|
302 | } | |
309 | } |
|
303 | } | |
310 | } |
|
304 | } | |
311 |
|
305 | |||
312 | void VisualizationGraphWidget::onUpdateVarDisplaying(std::shared_ptr<Variable> variable, |
|
306 | void VisualizationGraphWidget::onUpdateVarDisplaying(std::shared_ptr<Variable> variable, | |
313 | const SqpRange &range) |
|
307 | const SqpRange &range) | |
314 | { |
|
308 | { | |
315 |
auto |
|
309 | auto it = impl->m_VariableToPlotMultiMap.find(variable); | |
316 | for (auto it = componentsIt.first; it != componentsIt.second;) { |
|
310 | if (it != impl->m_VariableToPlotMultiMap.end()) { | |
317 | VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *>{} << it->second, |
|
311 | VisualizationGraphHelper::updateData(it->second, variable->dataSeries().get(), range); | |
318 | variable->dataSeries(), range); |
|
|||
319 | } |
|
312 | } | |
320 | } |
|
313 | } |
General Comments 0
You need to be logged in to leave comments.
Login now