Auto status change to "Under Review"
@@ -27,11 +27,18 public: | |||||
27 | Qt::CursorShape curshorShapeForPosition(const QPoint &position) const; |
|
27 | Qt::CursorShape curshorShapeForPosition(const QPoint &position) const; | |
28 | void setHovered(bool value); |
|
28 | void setHovered(bool value); | |
29 |
|
29 | |||
|
30 | void setAssociatedEditedZones(const QVector<VisualizationSelectionZoneItem *> &associatedZones); | |||
|
31 | ||||
30 | protected: |
|
32 | protected: | |
31 | void mousePressEvent(QMouseEvent *event, const QVariant &details) override; |
|
33 | void mousePressEvent(QMouseEvent *event, const QVariant &details) override; | |
32 | void mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) override; |
|
34 | void mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) override; | |
33 | void mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) override; |
|
35 | void mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) override; | |
34 |
|
36 | |||
|
37 | void resizeLeft(double pixelDiff); | |||
|
38 | void resizeRight(double pixelDiff); | |||
|
39 | void move(double pixelDiff); | |||
|
40 | ||||
|
41 | ||||
35 | private: |
|
42 | private: | |
36 | class VisualizationSelectionZoneItemPrivate; |
|
43 | class VisualizationSelectionZoneItemPrivate; | |
37 | spimpl::unique_impl_ptr<VisualizationSelectionZoneItemPrivate> impl; |
|
44 | spimpl::unique_impl_ptr<VisualizationSelectionZoneItemPrivate> impl; |
@@ -90,6 +90,8 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { | |||||
90 | VisualizationSelectionZoneItem *m_HoveredZone = nullptr; |
|
90 | VisualizationSelectionZoneItem *m_HoveredZone = nullptr; | |
91 | QVector<VisualizationSelectionZoneItem *> m_SelectionZones; |
|
91 | QVector<VisualizationSelectionZoneItem *> m_SelectionZones; | |
92 |
|
92 | |||
|
93 | bool m_HasMovedMouse = false; //Indicates if the mouse moved in a releaseMouse even | |||
|
94 | ||||
93 | void startDrawingRect(const QPoint &pos, QCustomPlot &plot) |
|
95 | void startDrawingRect(const QPoint &pos, QCustomPlot &plot) | |
94 | { |
|
96 | { | |
95 | removeDrawingRect(plot); |
|
97 | removeDrawingRect(plot); | |
@@ -710,6 +712,7 void VisualizationGraphWidget::onMouseMove(QMouseEvent *event) noexcept | |||||
710 | setCursor(Qt::ArrowCursor); |
|
712 | setCursor(Qt::ArrowCursor); | |
711 | } |
|
713 | } | |
712 |
|
714 | |||
|
715 | impl->m_HasMovedMouse = true; | |||
713 | VisualizationDragWidget::mouseMoveEvent(event); |
|
716 | VisualizationDragWidget::mouseMoveEvent(event); | |
714 | } |
|
717 | } | |
715 |
|
718 | |||
@@ -775,20 +778,13 void VisualizationGraphWidget::onMousePress(QMouseEvent *event) noexcept | |||||
775 | // Allows zone edition only in selection zone mode without drag&drop |
|
778 | // Allows zone edition only in selection zone mode without drag&drop | |
776 | impl->setSelectionZonesEditionEnabled(isSelectionZoneMode && !isDragDropClick); |
|
779 | impl->setSelectionZonesEditionEnabled(isSelectionZoneMode && !isDragDropClick); | |
777 |
|
780 | |||
778 |
|
|
781 | // Selection / Deselection | |
779 | if (isSelectionZoneMode) { |
|
782 | if (isSelectionZoneMode) { | |
780 | auto isMultiSelectionClick = event->modifiers().testFlag(MULTI_ZONE_SELECTION_MODIFIER); |
|
783 | auto isMultiSelectionClick = event->modifiers().testFlag(MULTI_ZONE_SELECTION_MODIFIER); | |
781 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos(), plot()); |
|
784 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos(), plot()); | |
782 | if (selectionZoneItemUnderCursor && event->button() == Qt::LeftButton) { |
|
785 | if (selectionZoneItemUnderCursor && event->button() == Qt::LeftButton) { | |
783 | if (!isMultiSelectionClick) { |
|
786 | selectionZoneItemUnderCursor->setAssociatedEditedZones( | |
784 | parentVisualizationWidget()->selectionZoneManager().select( |
|
787 | parentVisualizationWidget()->selectionZoneManager().selectedItems()); | |
785 | {selectionZoneItemUnderCursor}); |
|
|||
786 | } |
|
|||
787 | else { |
|
|||
788 | parentVisualizationWidget()->selectionZoneManager().setSelected( |
|
|||
789 | selectionZoneItemUnderCursor, !selectionZoneItemUnderCursor->selected() |
|
|||
790 | || event->button() == Qt::RightButton); |
|
|||
791 | } |
|
|||
792 | } |
|
788 | } | |
793 | else if (!isMultiSelectionClick && event->button() == Qt::LeftButton) { |
|
789 | else if (!isMultiSelectionClick && event->button() == Qt::LeftButton) { | |
794 | parentVisualizationWidget()->selectionZoneManager().clearSelection(); |
|
790 | parentVisualizationWidget()->selectionZoneManager().clearSelection(); | |
@@ -798,6 +794,8 void VisualizationGraphWidget::onMousePress(QMouseEvent *event) noexcept | |||||
798 | } |
|
794 | } | |
799 | } |
|
795 | } | |
800 |
|
796 | |||
|
797 | ||||
|
798 | impl->m_HasMovedMouse = false; | |||
801 | VisualizationDragWidget::mousePressEvent(event); |
|
799 | VisualizationDragWidget::mousePressEvent(event); | |
802 | } |
|
800 | } | |
803 |
|
801 | |||
@@ -829,6 +827,28 void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept | |||||
829 | impl->endDrawingZone(this); |
|
827 | impl->endDrawingZone(this); | |
830 |
|
828 | |||
831 | impl->m_IsCalibration = false; |
|
829 | impl->m_IsCalibration = false; | |
|
830 | ||||
|
831 | // Selection / Deselection | |||
|
832 | auto isSelectionZoneMode | |||
|
833 | = sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones; | |||
|
834 | if (isSelectionZoneMode) { | |||
|
835 | auto isMultiSelectionClick = event->modifiers().testFlag(MULTI_ZONE_SELECTION_MODIFIER); | |||
|
836 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos(), plot()); | |||
|
837 | if (selectionZoneItemUnderCursor && event->button() == Qt::LeftButton) { | |||
|
838 | if (!isMultiSelectionClick && !impl->m_HasMovedMouse) { | |||
|
839 | parentVisualizationWidget()->selectionZoneManager().select( | |||
|
840 | {selectionZoneItemUnderCursor}); | |||
|
841 | } | |||
|
842 | else if (!impl->m_HasMovedMouse) { | |||
|
843 | parentVisualizationWidget()->selectionZoneManager().setSelected( | |||
|
844 | selectionZoneItemUnderCursor, !selectionZoneItemUnderCursor->selected() | |||
|
845 | || event->button() == Qt::RightButton); | |||
|
846 | } | |||
|
847 | } | |||
|
848 | else { | |||
|
849 | // No selection change | |||
|
850 | } | |||
|
851 | } | |||
832 | } |
|
852 | } | |
833 |
|
853 | |||
834 | void VisualizationGraphWidget::onDataCacheVariableUpdated() |
|
854 | void VisualizationGraphWidget::onDataCacheVariableUpdated() |
@@ -20,6 +20,8 struct VisualizationSelectionZoneItem::VisualizationSelectionZoneItemPrivate { | |||||
20 | enum class EditionMode { NoEdition, ResizeLeft, ResizeRight, Move }; |
|
20 | enum class EditionMode { NoEdition, ResizeLeft, ResizeRight, Move }; | |
21 | EditionMode m_CurrentEditionMode; |
|
21 | EditionMode m_CurrentEditionMode; | |
22 |
|
22 | |||
|
23 | QVector<VisualizationSelectionZoneItem *> m_AssociatedEditedZones; | |||
|
24 | ||||
23 | VisualizationSelectionZoneItemPrivate(QCustomPlot *plot) |
|
25 | VisualizationSelectionZoneItemPrivate(QCustomPlot *plot) | |
24 | : m_Plot(plot), m_Color(Qt::blue), m_CurrentEditionMode(EditionMode::NoEdition) |
|
26 | : m_Plot(plot), m_Color(Qt::blue), m_CurrentEditionMode(EditionMode::NoEdition) | |
25 | { |
|
27 | { | |
@@ -46,6 +48,12 struct VisualizationSelectionZoneItem::VisualizationSelectionZoneItemPrivate { | |||||
46 |
|
48 | |||
47 | return VisualizationSelectionZoneItemPrivate::EditionMode::Move; |
|
49 | return VisualizationSelectionZoneItemPrivate::EditionMode::Move; | |
48 | } |
|
50 | } | |
|
51 | ||||
|
52 | double pixelSizeToAxisXSize(double pixels) | |||
|
53 | { | |||
|
54 | auto axis = m_Plot->axisRect()->axis(QCPAxis::atBottom); | |||
|
55 | return axis->pixelToCoord(pixels) - axis->pixelToCoord(0); | |||
|
56 | } | |||
49 | }; |
|
57 | }; | |
50 |
|
58 | |||
51 | VisualizationSelectionZoneItem::VisualizationSelectionZoneItem(QCustomPlot *plot) |
|
59 | VisualizationSelectionZoneItem::VisualizationSelectionZoneItem(QCustomPlot *plot) | |
@@ -220,6 +228,13 void VisualizationSelectionZoneItem::setHovered(bool value) | |||||
220 | } |
|
228 | } | |
221 | } |
|
229 | } | |
222 |
|
230 | |||
|
231 | void VisualizationSelectionZoneItem::setAssociatedEditedZones( | |||
|
232 | const QVector<VisualizationSelectionZoneItem *> &associatedZones) | |||
|
233 | { | |||
|
234 | impl->m_AssociatedEditedZones = associatedZones; | |||
|
235 | impl->m_AssociatedEditedZones.removeAll(this); | |||
|
236 | } | |||
|
237 | ||||
223 | void VisualizationSelectionZoneItem::mousePressEvent(QMouseEvent *event, const QVariant &details) |
|
238 | void VisualizationSelectionZoneItem::mousePressEvent(QMouseEvent *event, const QVariant &details) | |
224 | { |
|
239 | { | |
225 | if (isEditionEnabled() && event->button() == Qt::LeftButton) { |
|
240 | if (isEditionEnabled() && event->button() == Qt::LeftButton) { | |
@@ -227,6 +242,10 void VisualizationSelectionZoneItem::mousePressEvent(QMouseEvent *event, const Q | |||||
227 |
|
242 | |||
228 | impl->m_MovedOrinalT1 = impl->m_T1; |
|
243 | impl->m_MovedOrinalT1 = impl->m_T1; | |
229 | impl->m_MovedOrinalT2 = impl->m_T2; |
|
244 | impl->m_MovedOrinalT2 = impl->m_T2; | |
|
245 | for (auto associatedZone : impl->m_AssociatedEditedZones) { | |||
|
246 | associatedZone->impl->m_MovedOrinalT1 = associatedZone->impl->m_T1; | |||
|
247 | associatedZone->impl->m_MovedOrinalT2 = associatedZone->impl->m_T2; | |||
|
248 | } | |||
230 | } |
|
249 | } | |
231 | else { |
|
250 | else { | |
232 | impl->m_CurrentEditionMode = VisualizationSelectionZoneItemPrivate::EditionMode::NoEdition; |
|
251 | impl->m_CurrentEditionMode = VisualizationSelectionZoneItemPrivate::EditionMode::NoEdition; | |
@@ -238,21 +257,39 void VisualizationSelectionZoneItem::mouseMoveEvent(QMouseEvent *event, const QP | |||||
238 | { |
|
257 | { | |
239 | if (isEditionEnabled()) { |
|
258 | if (isEditionEnabled()) { | |
240 | auto axis = impl->m_Plot->axisRect()->axis(QCPAxis::atBottom); |
|
259 | auto axis = impl->m_Plot->axisRect()->axis(QCPAxis::atBottom); | |
241 |
auto |
|
260 | auto pixelDiff = event->pos().x() - startPos.x(); | |
|
261 | auto diff = impl->pixelSizeToAxisXSize(pixelDiff); | |||
242 |
|
262 | |||
243 | switch (impl->m_CurrentEditionMode) { |
|
263 | switch (impl->m_CurrentEditionMode) { | |
244 | case VisualizationSelectionZoneItemPrivate::EditionMode::Move: |
|
264 | case VisualizationSelectionZoneItemPrivate::EditionMode::Move: | |
245 | setRange(impl->m_MovedOrinalT1 + diff, impl->m_MovedOrinalT2 + diff); |
|
265 | setRange(impl->m_MovedOrinalT1 + diff, impl->m_MovedOrinalT2 + diff); | |
|
266 | for (auto associatedZone : impl->m_AssociatedEditedZones) { | |||
|
267 | associatedZone->move(pixelDiff); | |||
|
268 | } | |||
246 | break; |
|
269 | break; | |
247 | case VisualizationSelectionZoneItemPrivate::EditionMode::ResizeLeft: |
|
270 | case VisualizationSelectionZoneItemPrivate::EditionMode::ResizeLeft: | |
248 | setStart(impl->m_MovedOrinalT1 + diff); |
|
271 | setStart(impl->m_MovedOrinalT1 + diff); | |
|
272 | for (auto associatedZone : impl->m_AssociatedEditedZones) { | |||
|
273 | impl->m_MovedOrinalT1 < impl->m_MovedOrinalT2 | |||
|
274 | ? associatedZone->resizeLeft(pixelDiff) | |||
|
275 | : associatedZone->resizeRight(pixelDiff); | |||
|
276 | } | |||
249 | break; |
|
277 | break; | |
250 | case VisualizationSelectionZoneItemPrivate::EditionMode::ResizeRight: |
|
278 | case VisualizationSelectionZoneItemPrivate::EditionMode::ResizeRight: | |
251 | setEnd(impl->m_MovedOrinalT2 + diff); |
|
279 | setEnd(impl->m_MovedOrinalT2 + diff); | |
|
280 | for (auto associatedZone : impl->m_AssociatedEditedZones) { | |||
|
281 | impl->m_MovedOrinalT1 < impl->m_MovedOrinalT2 | |||
|
282 | ? associatedZone->resizeRight(pixelDiff) | |||
|
283 | : associatedZone->resizeLeft(pixelDiff); | |||
|
284 | } | |||
252 | break; |
|
285 | break; | |
253 | default: |
|
286 | default: | |
254 | break; |
|
287 | break; | |
255 | } |
|
288 | } | |
|
289 | ||||
|
290 | for (auto associatedZone : impl->m_AssociatedEditedZones) { | |||
|
291 | associatedZone->parentPlot()->replot(); | |||
|
292 | } | |||
256 | } |
|
293 | } | |
257 | else { |
|
294 | else { | |
258 | event->ignore(); |
|
295 | event->ignore(); | |
@@ -267,4 +304,34 void VisualizationSelectionZoneItem::mouseReleaseEvent(QMouseEvent *event, const | |||||
267 | else { |
|
304 | else { | |
268 | event->ignore(); |
|
305 | event->ignore(); | |
269 | } |
|
306 | } | |
|
307 | ||||
|
308 | impl->m_AssociatedEditedZones.clear(); | |||
|
309 | } | |||
|
310 | ||||
|
311 | void VisualizationSelectionZoneItem::resizeLeft(double pixelDiff) | |||
|
312 | { | |||
|
313 | auto diff = impl->pixelSizeToAxisXSize(pixelDiff); | |||
|
314 | if (impl->m_MovedOrinalT1 <= impl->m_MovedOrinalT2) { | |||
|
315 | setStart(impl->m_MovedOrinalT1 + diff); | |||
|
316 | } | |||
|
317 | else { | |||
|
318 | setEnd(impl->m_MovedOrinalT2 + diff); | |||
|
319 | } | |||
|
320 | } | |||
|
321 | ||||
|
322 | void VisualizationSelectionZoneItem::resizeRight(double pixelDiff) | |||
|
323 | { | |||
|
324 | auto diff = impl->pixelSizeToAxisXSize(pixelDiff); | |||
|
325 | if (impl->m_MovedOrinalT1 > impl->m_MovedOrinalT2) { | |||
|
326 | setStart(impl->m_MovedOrinalT1 + diff); | |||
|
327 | } | |||
|
328 | else { | |||
|
329 | setEnd(impl->m_MovedOrinalT2 + diff); | |||
|
330 | } | |||
|
331 | } | |||
|
332 | ||||
|
333 | void VisualizationSelectionZoneItem::move(double pixelDiff) | |||
|
334 | { | |||
|
335 | auto diff = impl->pixelSizeToAxisXSize(pixelDiff); | |||
|
336 | setRange(impl->m_MovedOrinalT1 + diff, impl->m_MovedOrinalT2 + diff); | |||
270 | } |
|
337 | } |
General Comments 3
Status change > Approved
You need to be logged in to leave comments.
Login now