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