@@ -12,11 +12,12 | |||||
12 |
|
12 | |||
13 | #include <Common/spimpl.h> |
|
13 | #include <Common/spimpl.h> | |
14 |
|
14 | |||
|
15 | #include <Data/DateTimeRange.h> | |||
|
16 | ||||
15 | Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationGraphWidget) |
|
17 | Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationGraphWidget) | |
16 |
|
18 | |||
17 | class QCPRange; |
|
19 | class QCPRange; | |
18 | class QCustomPlot; |
|
20 | class QCustomPlot; | |
19 | class DateTimeRange; |
|
|||
20 | class Variable; |
|
21 | class Variable; | |
21 | class VisualizationWidget; |
|
22 | class VisualizationWidget; | |
22 | class VisualizationZoneWidget; |
|
23 | class VisualizationZoneWidget; | |
@@ -70,7 +71,7 public: | |||||
70 | /// Sets the y-axis range based on the data of a variable |
|
71 | /// Sets the y-axis range based on the data of a variable | |
71 | void setYRange(std::shared_ptr<Variable> variable); |
|
72 | void setYRange(std::shared_ptr<Variable> variable); | |
72 | DateTimeRange graphRange() const noexcept; |
|
73 | DateTimeRange graphRange() const noexcept; | |
73 |
void setGraphRange(const DateTimeRange &range, bool updateVar = |
|
74 | void setGraphRange(const DateTimeRange &range, bool updateVar=false, bool forward=false); | |
74 | void setAutoRangeOnVariableInitialization(bool value); |
|
75 | void setAutoRangeOnVariableInitialization(bool value); | |
75 |
|
76 | |||
76 | // Zones |
|
77 | // Zones | |
@@ -89,6 +90,7 public: | |||||
89 | void zoom(double factor, int center, Qt::Orientation orientation, bool forward=true); |
|
90 | void zoom(double factor, int center, Qt::Orientation orientation, bool forward=true); | |
90 | void move(double factor, Qt::Orientation orientation, bool forward=true); |
|
91 | void move(double factor, Qt::Orientation orientation, bool forward=true); | |
91 | void move(double dx, double dy, bool forward=true); |
|
92 | void move(double dx, double dy, bool forward=true); | |
|
93 | void transform(const DateTimeRangeTransformation& tranformation, bool forward=true); | |||
92 |
|
94 | |||
93 | // IVisualizationWidget interface |
|
95 | // IVisualizationWidget interface | |
94 | void accept(IVisualizationWidgetVisitor *visitor) override; |
|
96 | void accept(IVisualizationWidgetVisitor *visitor) override; | |
@@ -127,6 +129,7 signals: | |||||
127 | void zoom_sig(double factor, int center, Qt::Orientation orientation, bool forward=true); |
|
129 | void zoom_sig(double factor, int center, Qt::Orientation orientation, bool forward=true); | |
128 | void move_sig(double factor, Qt::Orientation orientation, bool forward=true); |
|
130 | void move_sig(double factor, Qt::Orientation orientation, bool forward=true); | |
129 | void move_sig(double dx, double dy, bool forward=true); |
|
131 | void move_sig(double dx, double dy, bool forward=true); | |
|
132 | void transform_sig(const DateTimeRangeTransformation& tranformation, bool forward=true); | |||
130 |
|
133 | |||
131 | protected: |
|
134 | protected: | |
132 | void closeEvent(QCloseEvent *event) override; |
|
135 | void closeEvent(QCloseEvent *event) override; | |
@@ -148,7 +151,6 private: | |||||
148 | class VisualizationGraphWidgetPrivate; |
|
151 | class VisualizationGraphWidgetPrivate; | |
149 | spimpl::unique_impl_ptr<VisualizationGraphWidgetPrivate> impl; |
|
152 | spimpl::unique_impl_ptr<VisualizationGraphWidgetPrivate> impl; | |
150 |
|
153 | |||
151 | void _ugly_sync_(const QPoint& pos,const QPointF& axisPos); |
|
|||
152 | private slots: |
|
154 | private slots: | |
153 | /// Slot called when right clicking on the graph (displays a menu) |
|
155 | /// Slot called when right clicking on the graph (displays a menu) | |
154 | void onGraphMenuRequested(const QPoint &pos) noexcept; |
|
156 | void onGraphMenuRequested(const QPoint &pos) noexcept; |
@@ -23,6 +23,7 | |||||
23 | #include <Time/TimeController.h> |
|
23 | #include <Time/TimeController.h> | |
24 | #include <Variable/Variable.h> |
|
24 | #include <Variable/Variable.h> | |
25 | #include <Variable/VariableController2.h> |
|
25 | #include <Variable/VariableController2.h> | |
|
26 | #include <Data/DateTimeRangeHelper.h> | |||
26 |
|
27 | |||
27 | #include <unordered_map> |
|
28 | #include <unordered_map> | |
28 |
|
29 | |||
@@ -293,17 +294,19 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { | |||||
293 | } |
|
294 | } | |
294 | } |
|
295 | } | |
295 |
|
296 | |||
296 | void setRange(const DateTimeRange &newRange) |
|
297 | void setRange(const DateTimeRange &newRange, bool updateVar=true) | |
297 | { |
|
298 | { | |
298 | if (m_Flags.testFlag(GraphFlag::EnableAcquisition)) |
|
299 | this->m_plot->xAxis->setRange(newRange.m_TStart, newRange.m_TEnd); | |
|
300 | if(updateVar) | |||
299 | { |
|
301 | { | |
300 | for (auto it = m_VariableToPlotMultiMap.begin(), |
|
302 | for (auto it = m_VariableToPlotMultiMap.begin(), | |
301 |
|
|
303 | end = m_VariableToPlotMultiMap.end(); | |
302 | it != end; it = m_VariableToPlotMultiMap.upper_bound(it->first)) |
|
304 | it != end; it = m_VariableToPlotMultiMap.upper_bound(it->first)) | |
303 | { |
|
305 | { | |
304 | sqpApp->variableController().asyncChangeRange(it->first, newRange); |
|
306 | sqpApp->variableController().asyncChangeRange(it->first, newRange); | |
305 | } |
|
307 | } | |
306 | } |
|
308 | } | |
|
309 | m_plot->replot(QCustomPlot::rpQueuedReplot); | |||
307 | } |
|
310 | } | |
308 |
|
311 | |||
309 | void setRange(const QCPRange &newRange) |
|
312 | void setRange(const QCPRange &newRange) | |
@@ -312,6 +315,11 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { | |||||
312 | setRange(graphRange); |
|
315 | setRange(graphRange); | |
313 | } |
|
316 | } | |
314 |
|
317 | |||
|
318 | void rescaleY() | |||
|
319 | { | |||
|
320 | m_plot->yAxis->rescale(true); | |||
|
321 | } | |||
|
322 | ||||
315 | std::tuple<double,double> moveGraph(const QPoint& destination) |
|
323 | std::tuple<double,double> moveGraph(const QPoint& destination) | |
316 | { |
|
324 | { | |
317 | auto currentPos = m_plot->mapFromParent(destination); |
|
325 | auto currentPos = m_plot->mapFromParent(destination); | |
@@ -334,7 +342,6 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { | |||||
334 | auto newXRange = xAxis->range(); |
|
342 | auto newXRange = xAxis->range(); | |
335 | auto newYRange = yAxis->range(); |
|
343 | auto newYRange = yAxis->range(); | |
336 | setRange(xAxis->range()); |
|
344 | setRange(xAxis->range()); | |
337 | m_plot->replot(QCustomPlot::rpQueuedReplot); |
|
|||
338 | //m_lastMousePos = currentPos; |
|
345 | //m_lastMousePos = currentPos; | |
339 | return {newXRange.lower - oldXRange.lower, newYRange.lower - oldYRange.lower}; |
|
346 | return {newXRange.lower - oldXRange.lower, newYRange.lower - oldYRange.lower}; | |
340 | } |
|
347 | } | |
@@ -348,6 +355,15 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { | |||||
348 | m_plot->replot(QCustomPlot::rpQueuedReplot); |
|
355 | m_plot->replot(QCustomPlot::rpQueuedReplot); | |
349 | } |
|
356 | } | |
350 |
|
357 | |||
|
358 | void transform(const DateTimeRangeTransformation &tranformation) | |||
|
359 | { | |||
|
360 | auto graphRange = m_plot->xAxis->range(); | |||
|
361 | DateTimeRange range{graphRange.lower, graphRange.upper}; | |||
|
362 | range = range.transform(tranformation); | |||
|
363 | setRange(range); | |||
|
364 | m_plot->replot(QCustomPlot::rpQueuedReplot); | |||
|
365 | } | |||
|
366 | ||||
351 | void move(double dx, double dy) |
|
367 | void move(double dx, double dy) | |
352 | { |
|
368 | { | |
353 | auto xAxis = m_plot->axisRect()->rangeDragAxis(Qt::Horizontal); |
|
369 | auto xAxis = m_plot->axisRect()->rangeDragAxis(Qt::Horizontal); | |
@@ -520,13 +536,16 DateTimeRange VisualizationGraphWidget::graphRange() const noexcept | |||||
520 | return DateTimeRange{graphRange.lower, graphRange.upper}; |
|
536 | return DateTimeRange{graphRange.lower, graphRange.upper}; | |
521 | } |
|
537 | } | |
522 |
|
538 | |||
523 | void VisualizationGraphWidget::setGraphRange(const DateTimeRange &range, bool updateVar) |
|
539 | void VisualizationGraphWidget::setGraphRange(const DateTimeRange &range, bool updateVar, bool forward) | |
524 | { |
|
540 | { | |
525 |
|
541 | auto oldRange = graphRange(); | ||
526 | if(updateVar) |
|
542 | impl->setRange(range, updateVar); | |
527 | impl->setRange(range); |
|
543 | if(forward) | |
528 | impl->m_plot->xAxis->setRange(range.m_TStart, range.m_TEnd); |
|
544 | { | |
529 | impl->m_plot->replot(QCustomPlot::rpQueuedReplot); |
|
545 | auto newRange = graphRange(); | |
|
546 | if(auto tf = DateTimeRangeHelper::computeTransformation(oldRange,newRange)) | |||
|
547 | emit this->transform_sig(tf.value(), false); | |||
|
548 | } | |||
530 |
|
549 | |||
531 | } |
|
550 | } | |
532 |
|
551 | |||
@@ -618,6 +637,13 void VisualizationGraphWidget::move(double dx, double dy, bool forward) | |||||
618 | emit this->move_sig(dx, dy, false); |
|
637 | emit this->move_sig(dx, dy, false); | |
619 | } |
|
638 | } | |
620 |
|
639 | |||
|
640 | void VisualizationGraphWidget::transform(const DateTimeRangeTransformation &tranformation, bool forward) | |||
|
641 | { | |||
|
642 | impl->transform(tranformation); | |||
|
643 | if(forward) | |||
|
644 | emit this->transform_sig(tranformation, false); | |||
|
645 | } | |||
|
646 | ||||
621 | void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
647 | void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor) | |
622 | { |
|
648 | { | |
623 | if (visitor) { |
|
649 | if (visitor) { | |
@@ -871,7 +897,11 void VisualizationGraphWidget::mouseReleaseEvent(QMouseEvent *event) | |||||
871 | { |
|
897 | { | |
872 | if(impl->isDrawingZoomRect()) |
|
898 | if(impl->isDrawingZoomRect()) | |
873 | { |
|
899 | { | |
|
900 | auto oldRange = this->graphRange(); | |||
874 | impl->applyZoomRect(); |
|
901 | impl->applyZoomRect(); | |
|
902 | auto newRange = this->graphRange(); | |||
|
903 | if(auto tf = DateTimeRangeHelper::computeTransformation(oldRange,newRange)) | |||
|
904 | emit this->transform_sig(tf.value(), false); | |||
875 | } |
|
905 | } | |
876 | else if(impl->isDrawingZoneRect()) |
|
906 | else if(impl->isDrawingZoneRect()) | |
877 | { |
|
907 | { | |
@@ -959,7 +989,7 void VisualizationGraphWidget::keyPressEvent(QKeyEvent *event) | |||||
959 | case Qt::Key_Shift: |
|
989 | case Qt::Key_Shift: | |
960 | break; |
|
990 | break; | |
961 | case Qt::Key_M: |
|
991 | case Qt::Key_M: | |
962 |
impl-> |
|
992 | impl->rescaleY(); | |
963 | impl->m_plot->replot(QCustomPlot::rpQueuedReplot); |
|
993 | impl->m_plot->replot(QCustomPlot::rpQueuedReplot); | |
964 | break; |
|
994 | break; | |
965 | case Qt::Key_Left: |
|
995 | case Qt::Key_Left: |
@@ -184,6 +184,7 void VisualizationZoneWidget::insertGraph(int index, VisualizationGraphWidget *g | |||||
184 | { |
|
184 | { | |
185 | auto graph = qobject_cast<VisualizationGraphWidget *>(layout->itemAt(i)->widget()); |
|
185 | auto graph = qobject_cast<VisualizationGraphWidget *>(layout->itemAt(i)->widget()); | |
186 | connect(graphWidget, &VisualizationGraphWidget::zoom_sig, graph, &VisualizationGraphWidget::zoom); |
|
186 | connect(graphWidget, &VisualizationGraphWidget::zoom_sig, graph, &VisualizationGraphWidget::zoom); | |
|
187 | connect(graphWidget, &VisualizationGraphWidget::transform_sig, graph, &VisualizationGraphWidget::transform); | |||
187 |
|
188 | |||
188 | connect(graphWidget, qOverload<double,Qt::Orientation,bool>(&VisualizationGraphWidget::move_sig), |
|
189 | connect(graphWidget, qOverload<double,Qt::Orientation,bool>(&VisualizationGraphWidget::move_sig), | |
189 | graph, qOverload<double,Qt::Orientation,bool>(&VisualizationGraphWidget::move)); |
|
190 | graph, qOverload<double,Qt::Orientation,bool>(&VisualizationGraphWidget::move)); | |
@@ -191,6 +192,7 void VisualizationZoneWidget::insertGraph(int index, VisualizationGraphWidget *g | |||||
191 | graph, qOverload<double,double,bool>(&VisualizationGraphWidget::move)); |
|
192 | graph, qOverload<double,double,bool>(&VisualizationGraphWidget::move)); | |
192 |
|
193 | |||
193 | connect(graph, &VisualizationGraphWidget::zoom_sig, graphWidget, &VisualizationGraphWidget::zoom); |
|
194 | connect(graph, &VisualizationGraphWidget::zoom_sig, graphWidget, &VisualizationGraphWidget::zoom); | |
|
195 | connect(graph, &VisualizationGraphWidget::transform_sig, graphWidget, &VisualizationGraphWidget::transform); | |||
194 |
|
196 | |||
195 | connect(graph, qOverload<double,Qt::Orientation,bool>(&VisualizationGraphWidget::move_sig), |
|
197 | connect(graph, qOverload<double,Qt::Orientation,bool>(&VisualizationGraphWidget::move_sig), | |
196 | graphWidget, qOverload<double,Qt::Orientation,bool>(&VisualizationGraphWidget::move)); |
|
198 | graphWidget, qOverload<double,Qt::Orientation,bool>(&VisualizationGraphWidget::move)); | |
@@ -539,7 +541,7 void VisualizationZoneWidget::dropMimeDataOnGraph(VisualizationDragWidget *dragW | |||||
539 | } |
|
541 | } | |
540 | else if (mimeData->hasFormat(MIME_TYPE_TIME_RANGE)) { |
|
542 | else if (mimeData->hasFormat(MIME_TYPE_TIME_RANGE)) { | |
541 | auto range = TimeController::timeRangeForMimeData(mimeData->data(MIME_TYPE_TIME_RANGE)); |
|
543 | auto range = TimeController::timeRangeForMimeData(mimeData->data(MIME_TYPE_TIME_RANGE)); | |
542 | graphWidget->setGraphRange(range); |
|
544 | graphWidget->setGraphRange(range, true, true); | |
543 | } |
|
545 | } | |
544 | else { |
|
546 | else { | |
545 | qCWarning(LOG_VisualizationZoneWidget()) |
|
547 | qCWarning(LOG_VisualizationZoneWidget()) |
@@ -62,7 +62,7 void RescaleAxeOperation::visit(VisualizationGraphWidget *graphWidget) | |||||
62 | // During rescale, acquisition for the graph is disabled but synchronization is still |
|
62 | // During rescale, acquisition for the graph is disabled but synchronization is still | |
63 | // enabled |
|
63 | // enabled | |
64 | graphWidget->setFlags(GraphFlag::EnableSynchronization); |
|
64 | graphWidget->setFlags(GraphFlag::EnableSynchronization); | |
65 | graphWidget->setGraphRange(impl->m_Range); |
|
65 | graphWidget->setGraphRange(impl->m_Range, true); | |
66 | graphWidget->setFlags(GraphFlag::EnableAll); |
|
66 | graphWidget->setFlags(GraphFlag::EnableAll); | |
67 | } |
|
67 | } | |
68 | } |
|
68 | } |
General Comments 0
You need to be logged in to leave comments.
Login now