@@ -1,141 +1,155 | |||||
1 | #ifndef SCIQLOP_VISUALIZATIONGRAPHWIDGET_H |
|
1 | #ifndef SCIQLOP_VISUALIZATIONGRAPHWIDGET_H | |
2 | #define SCIQLOP_VISUALIZATIONGRAPHWIDGET_H |
|
2 | #define SCIQLOP_VISUALIZATIONGRAPHWIDGET_H | |
3 |
|
3 | |||
4 | #include "Visualization/IVisualizationWidget.h" |
|
4 | #include "Visualization/IVisualizationWidget.h" | |
5 | #include "Visualization/VisualizationDragWidget.h" |
|
5 | #include "Visualization/VisualizationDragWidget.h" | |
6 |
|
6 | |||
7 | #include <QLoggingCategory> |
|
7 | #include <QLoggingCategory> | |
8 | #include <QWidget> |
|
8 | #include <QWidget> | |
9 |
|
9 | |||
10 | #include <memory> |
|
10 | #include <memory> | |
11 |
|
11 | |||
12 | #include <Common/spimpl.h> |
|
12 | #include <Common/spimpl.h> | |
13 |
|
13 | |||
14 | Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationGraphWidget) |
|
14 | Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationGraphWidget) | |
15 |
|
15 | |||
16 | class QCPRange; |
|
16 | class QCPRange; | |
17 | class QCustomPlot; |
|
17 | class QCustomPlot; | |
18 | class SqpRange; |
|
18 | class SqpRange; | |
19 | class Variable; |
|
19 | class Variable; | |
20 | class VisualizationWidget; |
|
20 | class VisualizationWidget; | |
21 | class VisualizationZoneWidget; |
|
21 | class VisualizationZoneWidget; | |
22 | class VisualizationSelectionZoneItem; |
|
22 | class VisualizationSelectionZoneItem; | |
23 |
|
23 | |||
24 | namespace Ui { |
|
24 | namespace Ui { | |
25 | class VisualizationGraphWidget; |
|
25 | class VisualizationGraphWidget; | |
26 | } // namespace Ui |
|
26 | } // namespace Ui | |
27 |
|
27 | |||
|
28 | /// Defines options that can be associated with the graph | |||
|
29 | enum GraphFlag { | |||
|
30 | DisableAll = 0x0, ///< Disables acquisition and synchronization | |||
|
31 | EnableAcquisition = 0x1, ///< When this flag is set, the change of the graph's range leads to | |||
|
32 | /// the acquisition of data | |||
|
33 | EnableSynchronization = 0x2, ///< When this flag is set, the change of the graph's range causes | |||
|
34 | /// the call to the synchronization of the graphs contained in the | |||
|
35 | /// same zone of this graph | |||
|
36 | EnableAll = ~DisableAll ///< Enables acquisition and synchronization | |||
|
37 | }; | |||
|
38 | ||||
|
39 | Q_DECLARE_FLAGS(GraphFlags, GraphFlag) | |||
|
40 | Q_DECLARE_OPERATORS_FOR_FLAGS(GraphFlags) | |||
|
41 | ||||
28 | class VisualizationGraphWidget : public VisualizationDragWidget, public IVisualizationWidget { |
|
42 | class VisualizationGraphWidget : public VisualizationDragWidget, public IVisualizationWidget { | |
29 | Q_OBJECT |
|
43 | Q_OBJECT | |
30 |
|
44 | |||
31 | friend class QCustomPlotSynchronizer; |
|
45 | friend class QCustomPlotSynchronizer; | |
32 | friend class VisualizationGraphRenderingDelegate; |
|
46 | friend class VisualizationGraphRenderingDelegate; | |
33 |
|
47 | |||
34 | public: |
|
48 | public: | |
35 | explicit VisualizationGraphWidget(const QString &name = {}, QWidget *parent = 0); |
|
49 | explicit VisualizationGraphWidget(const QString &name = {}, QWidget *parent = 0); | |
36 | virtual ~VisualizationGraphWidget(); |
|
50 | virtual ~VisualizationGraphWidget(); | |
37 |
|
51 | |||
38 | /// Returns the VisualizationZoneWidget which contains the graph or nullptr |
|
52 | /// Returns the VisualizationZoneWidget which contains the graph or nullptr | |
39 | VisualizationZoneWidget *parentZoneWidget() const noexcept; |
|
53 | VisualizationZoneWidget *parentZoneWidget() const noexcept; | |
40 |
|
54 | |||
41 | /// Returns the main VisualizationWidget which contains the graph or nullptr |
|
55 | /// Returns the main VisualizationWidget which contains the graph or nullptr | |
42 | VisualizationWidget *parentVisualizationWidget() const; |
|
56 | VisualizationWidget *parentVisualizationWidget() const; | |
43 |
|
57 | |||
44 | /// If acquisition isn't enable, requestDataLoading signal cannot be emit |
|
58 | /// Sets graph options | |
45 | void enableAcquisition(bool enable); |
|
59 | void setFlags(GraphFlags flags); | |
46 |
|
60 | |||
47 | void addVariable(std::shared_ptr<Variable> variable, SqpRange range); |
|
61 | void addVariable(std::shared_ptr<Variable> variable, SqpRange range); | |
48 |
|
62 | |||
49 | /// Removes a variable from the graph |
|
63 | /// Removes a variable from the graph | |
50 | void removeVariable(std::shared_ptr<Variable> variable) noexcept; |
|
64 | void removeVariable(std::shared_ptr<Variable> variable) noexcept; | |
51 |
|
65 | |||
52 | /// Returns the list of all variables used in the graph |
|
66 | /// Returns the list of all variables used in the graph | |
53 | QList<std::shared_ptr<Variable> > variables() const; |
|
67 | QList<std::shared_ptr<Variable> > variables() const; | |
54 |
|
68 | |||
55 | /// Sets the y-axis range based on the data of a variable |
|
69 | /// Sets the y-axis range based on the data of a variable | |
56 | void setYRange(std::shared_ptr<Variable> variable); |
|
70 | void setYRange(std::shared_ptr<Variable> variable); | |
57 | SqpRange graphRange() const noexcept; |
|
71 | SqpRange graphRange() const noexcept; | |
58 | void setGraphRange(const SqpRange &range); |
|
72 | void setGraphRange(const SqpRange &range); | |
59 |
|
73 | |||
60 | // Zones |
|
74 | // Zones | |
61 | /// Returns the ranges of all the selection zones on the graph |
|
75 | /// Returns the ranges of all the selection zones on the graph | |
62 | QVector<SqpRange> selectionZoneRanges() const; |
|
76 | QVector<SqpRange> selectionZoneRanges() const; | |
63 | /// Adds new selection zones in the graph |
|
77 | /// Adds new selection zones in the graph | |
64 | void addSelectionZones(const QVector<SqpRange> &ranges); |
|
78 | void addSelectionZones(const QVector<SqpRange> &ranges); | |
65 | /// Removes the specified selection zone |
|
79 | /// Removes the specified selection zone | |
66 | void removeSelectionZone(VisualizationSelectionZoneItem *selectionZone); |
|
80 | void removeSelectionZone(VisualizationSelectionZoneItem *selectionZone); | |
67 |
|
81 | |||
68 | /// Undo the last zoom done with a zoom box |
|
82 | /// Undo the last zoom done with a zoom box | |
69 | void undoZoom(); |
|
83 | void undoZoom(); | |
70 |
|
84 | |||
71 | // IVisualizationWidget interface |
|
85 | // IVisualizationWidget interface | |
72 | void accept(IVisualizationWidgetVisitor *visitor) override; |
|
86 | void accept(IVisualizationWidgetVisitor *visitor) override; | |
73 | bool canDrop(const Variable &variable) const override; |
|
87 | bool canDrop(const Variable &variable) const override; | |
74 | bool contains(const Variable &variable) const override; |
|
88 | bool contains(const Variable &variable) const override; | |
75 | QString name() const override; |
|
89 | QString name() const override; | |
76 |
|
90 | |||
77 | // VisualisationDragWidget |
|
91 | // VisualisationDragWidget | |
78 | QMimeData *mimeData(const QPoint &position) const override; |
|
92 | QMimeData *mimeData(const QPoint &position) const override; | |
79 | QPixmap customDragPixmap(const QPoint &dragPosition) override; |
|
93 | QPixmap customDragPixmap(const QPoint &dragPosition) override; | |
80 | bool isDragAllowed() const override; |
|
94 | bool isDragAllowed() const override; | |
81 | void highlightForMerge(bool highlighted) override; |
|
95 | void highlightForMerge(bool highlighted) override; | |
82 |
|
96 | |||
83 | // Cursors |
|
97 | // Cursors | |
84 | /// Adds or moves the vertical cursor at the specified value on the x-axis |
|
98 | /// Adds or moves the vertical cursor at the specified value on the x-axis | |
85 | void addVerticalCursor(double time); |
|
99 | void addVerticalCursor(double time); | |
86 | /// Adds or moves the vertical cursor at the specified value on the x-axis |
|
100 | /// Adds or moves the vertical cursor at the specified value on the x-axis | |
87 | void addVerticalCursorAtViewportPosition(double position); |
|
101 | void addVerticalCursorAtViewportPosition(double position); | |
88 | void removeVerticalCursor(); |
|
102 | void removeVerticalCursor(); | |
89 | /// Adds or moves the vertical cursor at the specified value on the y-axis |
|
103 | /// Adds or moves the vertical cursor at the specified value on the y-axis | |
90 | void addHorizontalCursor(double value); |
|
104 | void addHorizontalCursor(double value); | |
91 | /// Adds or moves the vertical cursor at the specified value on the y-axis |
|
105 | /// Adds or moves the vertical cursor at the specified value on the y-axis | |
92 | void addHorizontalCursorAtViewportPosition(double position); |
|
106 | void addHorizontalCursorAtViewportPosition(double position); | |
93 | void removeHorizontalCursor(); |
|
107 | void removeHorizontalCursor(); | |
94 |
|
108 | |||
95 | signals: |
|
109 | signals: | |
96 | void synchronize(const SqpRange &range, const SqpRange &oldRange); |
|
110 | void synchronize(const SqpRange &range, const SqpRange &oldRange); | |
97 | void requestDataLoading(QVector<std::shared_ptr<Variable> > variable, const SqpRange &range, |
|
111 | void requestDataLoading(QVector<std::shared_ptr<Variable> > variable, const SqpRange &range, | |
98 | bool synchronise); |
|
112 | bool synchronise); | |
99 |
|
113 | |||
100 | /// Signal emitted when the variable is about to be removed from the graph |
|
114 | /// Signal emitted when the variable is about to be removed from the graph | |
101 | void variableAboutToBeRemoved(std::shared_ptr<Variable> var); |
|
115 | void variableAboutToBeRemoved(std::shared_ptr<Variable> var); | |
102 | /// Signal emitted when the variable has been added to the graph |
|
116 | /// Signal emitted when the variable has been added to the graph | |
103 | void variableAdded(std::shared_ptr<Variable> var); |
|
117 | void variableAdded(std::shared_ptr<Variable> var); | |
104 |
|
118 | |||
105 | protected: |
|
119 | protected: | |
106 | void closeEvent(QCloseEvent *event) override; |
|
120 | void closeEvent(QCloseEvent *event) override; | |
107 | void enterEvent(QEvent *event) override; |
|
121 | void enterEvent(QEvent *event) override; | |
108 | void leaveEvent(QEvent *event) override; |
|
122 | void leaveEvent(QEvent *event) override; | |
109 |
|
123 | |||
110 | QCustomPlot &plot() const noexcept; |
|
124 | QCustomPlot &plot() const noexcept; | |
111 |
|
125 | |||
112 | private: |
|
126 | private: | |
113 | Ui::VisualizationGraphWidget *ui; |
|
127 | Ui::VisualizationGraphWidget *ui; | |
114 |
|
128 | |||
115 | class VisualizationGraphWidgetPrivate; |
|
129 | class VisualizationGraphWidgetPrivate; | |
116 | spimpl::unique_impl_ptr<VisualizationGraphWidgetPrivate> impl; |
|
130 | spimpl::unique_impl_ptr<VisualizationGraphWidgetPrivate> impl; | |
117 |
|
131 | |||
118 | private slots: |
|
132 | private slots: | |
119 | /// Slot called when right clicking on the graph (displays a menu) |
|
133 | /// Slot called when right clicking on the graph (displays a menu) | |
120 | void onGraphMenuRequested(const QPoint &pos) noexcept; |
|
134 | void onGraphMenuRequested(const QPoint &pos) noexcept; | |
121 |
|
135 | |||
122 | /// Rescale the X axe to range parameter |
|
136 | /// Rescale the X axe to range parameter | |
123 | void onRangeChanged(const QCPRange &t1, const QCPRange &t2); |
|
137 | void onRangeChanged(const QCPRange &t1, const QCPRange &t2); | |
124 |
|
138 | |||
125 | /// Slot called when a mouse double click was made |
|
139 | /// Slot called when a mouse double click was made | |
126 | void onMouseDoubleClick(QMouseEvent *event) noexcept; |
|
140 | void onMouseDoubleClick(QMouseEvent *event) noexcept; | |
127 | /// Slot called when a mouse move was made |
|
141 | /// Slot called when a mouse move was made | |
128 | void onMouseMove(QMouseEvent *event) noexcept; |
|
142 | void onMouseMove(QMouseEvent *event) noexcept; | |
129 | /// Slot called when a mouse wheel was made, to perform some processing before the zoom is done |
|
143 | /// Slot called when a mouse wheel was made, to perform some processing before the zoom is done | |
130 | void onMouseWheel(QWheelEvent *event) noexcept; |
|
144 | void onMouseWheel(QWheelEvent *event) noexcept; | |
131 | /// Slot called when a mouse press was made, to activate the calibration of a graph |
|
145 | /// Slot called when a mouse press was made, to activate the calibration of a graph | |
132 | void onMousePress(QMouseEvent *event) noexcept; |
|
146 | void onMousePress(QMouseEvent *event) noexcept; | |
133 | /// Slot called when a mouse release was made, to deactivate the calibration of a graph |
|
147 | /// Slot called when a mouse release was made, to deactivate the calibration of a graph | |
134 | void onMouseRelease(QMouseEvent *event) noexcept; |
|
148 | void onMouseRelease(QMouseEvent *event) noexcept; | |
135 |
|
149 | |||
136 | void onDataCacheVariableUpdated(); |
|
150 | void onDataCacheVariableUpdated(); | |
137 |
|
151 | |||
138 | void onUpdateVarDisplaying(std::shared_ptr<Variable> variable, const SqpRange &range); |
|
152 | void onUpdateVarDisplaying(std::shared_ptr<Variable> variable, const SqpRange &range); | |
139 | }; |
|
153 | }; | |
140 |
|
154 | |||
141 | #endif // SCIQLOP_VISUALIZATIONGRAPHWIDGET_H |
|
155 | #endif // SCIQLOP_VISUALIZATIONGRAPHWIDGET_H |
@@ -1,1003 +1,1003 | |||||
1 | #include "Visualization/VisualizationGraphWidget.h" |
|
1 | #include "Visualization/VisualizationGraphWidget.h" | |
2 | #include "Visualization/IVisualizationWidgetVisitor.h" |
|
2 | #include "Visualization/IVisualizationWidgetVisitor.h" | |
3 | #include "Visualization/VisualizationCursorItem.h" |
|
3 | #include "Visualization/VisualizationCursorItem.h" | |
4 | #include "Visualization/VisualizationDefs.h" |
|
4 | #include "Visualization/VisualizationDefs.h" | |
5 | #include "Visualization/VisualizationGraphHelper.h" |
|
5 | #include "Visualization/VisualizationGraphHelper.h" | |
6 | #include "Visualization/VisualizationGraphRenderingDelegate.h" |
|
6 | #include "Visualization/VisualizationGraphRenderingDelegate.h" | |
7 | #include "Visualization/VisualizationMultiZoneSelectionDialog.h" |
|
7 | #include "Visualization/VisualizationMultiZoneSelectionDialog.h" | |
8 | #include "Visualization/VisualizationSelectionZoneItem.h" |
|
8 | #include "Visualization/VisualizationSelectionZoneItem.h" | |
9 | #include "Visualization/VisualizationSelectionZoneManager.h" |
|
9 | #include "Visualization/VisualizationSelectionZoneManager.h" | |
10 | #include "Visualization/VisualizationWidget.h" |
|
10 | #include "Visualization/VisualizationWidget.h" | |
11 | #include "Visualization/VisualizationZoneWidget.h" |
|
11 | #include "Visualization/VisualizationZoneWidget.h" | |
12 | #include "ui_VisualizationGraphWidget.h" |
|
12 | #include "ui_VisualizationGraphWidget.h" | |
13 |
|
13 | |||
14 | #include <Actions/ActionsGuiController.h> |
|
14 | #include <Actions/ActionsGuiController.h> | |
15 | #include <Common/MimeTypesDef.h> |
|
15 | #include <Common/MimeTypesDef.h> | |
16 | #include <Data/ArrayData.h> |
|
16 | #include <Data/ArrayData.h> | |
17 | #include <Data/IDataSeries.h> |
|
17 | #include <Data/IDataSeries.h> | |
18 | #include <Data/SpectrogramSeries.h> |
|
18 | #include <Data/SpectrogramSeries.h> | |
19 | #include <DragAndDrop/DragDropGuiController.h> |
|
19 | #include <DragAndDrop/DragDropGuiController.h> | |
20 | #include <Settings/SqpSettingsDefs.h> |
|
20 | #include <Settings/SqpSettingsDefs.h> | |
21 | #include <SqpApplication.h> |
|
21 | #include <SqpApplication.h> | |
22 | #include <Time/TimeController.h> |
|
22 | #include <Time/TimeController.h> | |
23 | #include <Variable/Variable.h> |
|
23 | #include <Variable/Variable.h> | |
24 | #include <Variable/VariableController.h> |
|
24 | #include <Variable/VariableController.h> | |
25 |
|
25 | |||
26 | #include <unordered_map> |
|
26 | #include <unordered_map> | |
27 |
|
27 | |||
28 | Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget") |
|
28 | Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget") | |
29 |
|
29 | |||
30 | namespace { |
|
30 | namespace { | |
31 |
|
31 | |||
32 | /// Key pressed to enable drag&drop in all modes |
|
32 | /// Key pressed to enable drag&drop in all modes | |
33 | const auto DRAG_DROP_MODIFIER = Qt::AltModifier; |
|
33 | const auto DRAG_DROP_MODIFIER = Qt::AltModifier; | |
34 |
|
34 | |||
35 | /// Key pressed to enable zoom on horizontal axis |
|
35 | /// Key pressed to enable zoom on horizontal axis | |
36 | const auto HORIZONTAL_ZOOM_MODIFIER = Qt::ControlModifier; |
|
36 | const auto HORIZONTAL_ZOOM_MODIFIER = Qt::ControlModifier; | |
37 |
|
37 | |||
38 | /// Key pressed to enable zoom on vertical axis |
|
38 | /// Key pressed to enable zoom on vertical axis | |
39 | const auto VERTICAL_ZOOM_MODIFIER = Qt::ShiftModifier; |
|
39 | const auto VERTICAL_ZOOM_MODIFIER = Qt::ShiftModifier; | |
40 |
|
40 | |||
41 | /// Speed of a step of a wheel event for a pan, in percentage of the axis range |
|
41 | /// Speed of a step of a wheel event for a pan, in percentage of the axis range | |
42 | const auto PAN_SPEED = 5; |
|
42 | const auto PAN_SPEED = 5; | |
43 |
|
43 | |||
44 | /// Key pressed to enable a calibration pan |
|
44 | /// Key pressed to enable a calibration pan | |
45 | const auto VERTICAL_PAN_MODIFIER = Qt::AltModifier; |
|
45 | const auto VERTICAL_PAN_MODIFIER = Qt::AltModifier; | |
46 |
|
46 | |||
47 | /// Key pressed to enable multi selection of selection zones |
|
47 | /// Key pressed to enable multi selection of selection zones | |
48 | const auto MULTI_ZONE_SELECTION_MODIFIER = Qt::ControlModifier; |
|
48 | const auto MULTI_ZONE_SELECTION_MODIFIER = Qt::ControlModifier; | |
49 |
|
49 | |||
50 | /// Minimum size for the zoom box, in percentage of the axis range |
|
50 | /// Minimum size for the zoom box, in percentage of the axis range | |
51 | const auto ZOOM_BOX_MIN_SIZE = 0.8; |
|
51 | const auto ZOOM_BOX_MIN_SIZE = 0.8; | |
52 |
|
52 | |||
53 | /// Format of the dates appearing in the label of a cursor |
|
53 | /// Format of the dates appearing in the label of a cursor | |
54 | const auto CURSOR_LABELS_DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd\nhh:mm:ss:zzz"); |
|
54 | const auto CURSOR_LABELS_DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd\nhh:mm:ss:zzz"); | |
55 |
|
55 | |||
56 | } // namespace |
|
56 | } // namespace | |
57 |
|
57 | |||
58 | struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { |
|
58 | struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { | |
59 |
|
59 | |||
60 | explicit VisualizationGraphWidgetPrivate(const QString &name) |
|
60 | explicit VisualizationGraphWidgetPrivate(const QString &name) | |
61 | : m_Name{name}, |
|
61 | : m_Name{name}, | |
62 | m_DoAcquisition{true}, |
|
62 | m_Flags{GraphFlag::EnableAll}, | |
63 | m_IsCalibration{false}, |
|
63 | m_IsCalibration{false}, | |
64 | m_RenderingDelegate{nullptr} |
|
64 | m_RenderingDelegate{nullptr} | |
65 | { |
|
65 | { | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | void updateData(PlottablesMap &plottables, std::shared_ptr<IDataSeries> dataSeries, |
|
68 | void updateData(PlottablesMap &plottables, std::shared_ptr<IDataSeries> dataSeries, | |
69 | const SqpRange &range) |
|
69 | const SqpRange &range) | |
70 | { |
|
70 | { | |
71 | VisualizationGraphHelper::updateData(plottables, dataSeries, range); |
|
71 | VisualizationGraphHelper::updateData(plottables, dataSeries, range); | |
72 |
|
72 | |||
73 | // Prevents that data has changed to update rendering |
|
73 | // Prevents that data has changed to update rendering | |
74 | m_RenderingDelegate->onPlotUpdated(); |
|
74 | m_RenderingDelegate->onPlotUpdated(); | |
75 | } |
|
75 | } | |
76 |
|
76 | |||
77 | QString m_Name; |
|
77 | QString m_Name; | |
78 | // 1 variable -> n qcpplot |
|
78 | // 1 variable -> n qcpplot | |
79 | std::map<std::shared_ptr<Variable>, PlottablesMap> m_VariableToPlotMultiMap; |
|
79 | std::map<std::shared_ptr<Variable>, PlottablesMap> m_VariableToPlotMultiMap; | |
80 | bool m_DoAcquisition; |
|
80 | GraphFlags m_Flags; | |
81 | bool m_IsCalibration; |
|
81 | bool m_IsCalibration; | |
82 | /// Delegate used to attach rendering features to the plot |
|
82 | /// Delegate used to attach rendering features to the plot | |
83 | std::unique_ptr<VisualizationGraphRenderingDelegate> m_RenderingDelegate; |
|
83 | std::unique_ptr<VisualizationGraphRenderingDelegate> m_RenderingDelegate; | |
84 |
|
84 | |||
85 | QCPItemRect *m_DrawingZoomRect = nullptr; |
|
85 | QCPItemRect *m_DrawingZoomRect = nullptr; | |
86 | QStack<QPair<QCPRange, QCPRange> > m_ZoomStack; |
|
86 | QStack<QPair<QCPRange, QCPRange> > m_ZoomStack; | |
87 |
|
87 | |||
88 | std::unique_ptr<VisualizationCursorItem> m_HorizontalCursor = nullptr; |
|
88 | std::unique_ptr<VisualizationCursorItem> m_HorizontalCursor = nullptr; | |
89 | std::unique_ptr<VisualizationCursorItem> m_VerticalCursor = nullptr; |
|
89 | std::unique_ptr<VisualizationCursorItem> m_VerticalCursor = nullptr; | |
90 |
|
90 | |||
91 | VisualizationSelectionZoneItem *m_DrawingZone = nullptr; |
|
91 | VisualizationSelectionZoneItem *m_DrawingZone = nullptr; | |
92 | VisualizationSelectionZoneItem *m_HoveredZone = nullptr; |
|
92 | VisualizationSelectionZoneItem *m_HoveredZone = nullptr; | |
93 | QVector<VisualizationSelectionZoneItem *> m_SelectionZones; |
|
93 | QVector<VisualizationSelectionZoneItem *> m_SelectionZones; | |
94 |
|
94 | |||
95 | bool m_HasMovedMouse = false; // Indicates if the mouse moved in a releaseMouse even |
|
95 | bool m_HasMovedMouse = false; // Indicates if the mouse moved in a releaseMouse even | |
96 |
|
96 | |||
97 | void startDrawingRect(const QPoint &pos, QCustomPlot &plot) |
|
97 | void startDrawingRect(const QPoint &pos, QCustomPlot &plot) | |
98 | { |
|
98 | { | |
99 | removeDrawingRect(plot); |
|
99 | removeDrawingRect(plot); | |
100 |
|
100 | |||
101 | auto axisPos = posToAxisPos(pos, plot); |
|
101 | auto axisPos = posToAxisPos(pos, plot); | |
102 |
|
102 | |||
103 | m_DrawingZoomRect = new QCPItemRect{&plot}; |
|
103 | m_DrawingZoomRect = new QCPItemRect{&plot}; | |
104 | QPen p; |
|
104 | QPen p; | |
105 | p.setWidth(2); |
|
105 | p.setWidth(2); | |
106 | m_DrawingZoomRect->setPen(p); |
|
106 | m_DrawingZoomRect->setPen(p); | |
107 |
|
107 | |||
108 | m_DrawingZoomRect->topLeft->setCoords(axisPos); |
|
108 | m_DrawingZoomRect->topLeft->setCoords(axisPos); | |
109 | m_DrawingZoomRect->bottomRight->setCoords(axisPos); |
|
109 | m_DrawingZoomRect->bottomRight->setCoords(axisPos); | |
110 | } |
|
110 | } | |
111 |
|
111 | |||
112 | void removeDrawingRect(QCustomPlot &plot) |
|
112 | void removeDrawingRect(QCustomPlot &plot) | |
113 | { |
|
113 | { | |
114 | if (m_DrawingZoomRect) { |
|
114 | if (m_DrawingZoomRect) { | |
115 | plot.removeItem(m_DrawingZoomRect); // the item is deleted by QCustomPlot |
|
115 | plot.removeItem(m_DrawingZoomRect); // the item is deleted by QCustomPlot | |
116 | m_DrawingZoomRect = nullptr; |
|
116 | m_DrawingZoomRect = nullptr; | |
117 | plot.replot(QCustomPlot::rpQueuedReplot); |
|
117 | plot.replot(QCustomPlot::rpQueuedReplot); | |
118 | } |
|
118 | } | |
119 | } |
|
119 | } | |
120 |
|
120 | |||
121 | void startDrawingZone(const QPoint &pos, VisualizationGraphWidget *graph) |
|
121 | void startDrawingZone(const QPoint &pos, VisualizationGraphWidget *graph) | |
122 | { |
|
122 | { | |
123 | endDrawingZone(graph); |
|
123 | endDrawingZone(graph); | |
124 |
|
124 | |||
125 | auto axisPos = posToAxisPos(pos, graph->plot()); |
|
125 | auto axisPos = posToAxisPos(pos, graph->plot()); | |
126 |
|
126 | |||
127 | m_DrawingZone = new VisualizationSelectionZoneItem{&graph->plot()}; |
|
127 | m_DrawingZone = new VisualizationSelectionZoneItem{&graph->plot()}; | |
128 | m_DrawingZone->setRange(axisPos.x(), axisPos.x()); |
|
128 | m_DrawingZone->setRange(axisPos.x(), axisPos.x()); | |
129 | m_DrawingZone->setEditionEnabled(false); |
|
129 | m_DrawingZone->setEditionEnabled(false); | |
130 | } |
|
130 | } | |
131 |
|
131 | |||
132 | void endDrawingZone(VisualizationGraphWidget *graph) |
|
132 | void endDrawingZone(VisualizationGraphWidget *graph) | |
133 | { |
|
133 | { | |
134 | if (m_DrawingZone) { |
|
134 | if (m_DrawingZone) { | |
135 | auto drawingZoneRange = m_DrawingZone->range(); |
|
135 | auto drawingZoneRange = m_DrawingZone->range(); | |
136 | if (qAbs(drawingZoneRange.m_TEnd - drawingZoneRange.m_TStart) > 0) { |
|
136 | if (qAbs(drawingZoneRange.m_TEnd - drawingZoneRange.m_TStart) > 0) { | |
137 | m_DrawingZone->setEditionEnabled(true); |
|
137 | m_DrawingZone->setEditionEnabled(true); | |
138 | addSelectionZone(m_DrawingZone); |
|
138 | addSelectionZone(m_DrawingZone); | |
139 | } |
|
139 | } | |
140 | else { |
|
140 | else { | |
141 | graph->plot().removeItem(m_DrawingZone); // the item is deleted by QCustomPlot |
|
141 | graph->plot().removeItem(m_DrawingZone); // the item is deleted by QCustomPlot | |
142 | } |
|
142 | } | |
143 |
|
143 | |||
144 | graph->plot().replot(QCustomPlot::rpQueuedReplot); |
|
144 | graph->plot().replot(QCustomPlot::rpQueuedReplot); | |
145 | m_DrawingZone = nullptr; |
|
145 | m_DrawingZone = nullptr; | |
146 | } |
|
146 | } | |
147 | } |
|
147 | } | |
148 |
|
148 | |||
149 | void setSelectionZonesEditionEnabled(bool value) |
|
149 | void setSelectionZonesEditionEnabled(bool value) | |
150 | { |
|
150 | { | |
151 | for (auto s : m_SelectionZones) { |
|
151 | for (auto s : m_SelectionZones) { | |
152 | s->setEditionEnabled(value); |
|
152 | s->setEditionEnabled(value); | |
153 | } |
|
153 | } | |
154 | } |
|
154 | } | |
155 |
|
155 | |||
156 | void addSelectionZone(VisualizationSelectionZoneItem *zone) { m_SelectionZones << zone; } |
|
156 | void addSelectionZone(VisualizationSelectionZoneItem *zone) { m_SelectionZones << zone; } | |
157 |
|
157 | |||
158 | VisualizationSelectionZoneItem *selectionZoneAt(const QPoint &pos, |
|
158 | VisualizationSelectionZoneItem *selectionZoneAt(const QPoint &pos, | |
159 | const QCustomPlot &plot) const |
|
159 | const QCustomPlot &plot) const | |
160 | { |
|
160 | { | |
161 | VisualizationSelectionZoneItem *selectionZoneItemUnderCursor = nullptr; |
|
161 | VisualizationSelectionZoneItem *selectionZoneItemUnderCursor = nullptr; | |
162 | auto minDistanceToZone = -1; |
|
162 | auto minDistanceToZone = -1; | |
163 | for (auto zone : m_SelectionZones) { |
|
163 | for (auto zone : m_SelectionZones) { | |
164 | auto distanceToZone = zone->selectTest(pos, false); |
|
164 | auto distanceToZone = zone->selectTest(pos, false); | |
165 | if ((minDistanceToZone < 0 || distanceToZone <= minDistanceToZone) |
|
165 | if ((minDistanceToZone < 0 || distanceToZone <= minDistanceToZone) | |
166 | && distanceToZone >= 0 && distanceToZone < plot.selectionTolerance()) { |
|
166 | && distanceToZone >= 0 && distanceToZone < plot.selectionTolerance()) { | |
167 | selectionZoneItemUnderCursor = zone; |
|
167 | selectionZoneItemUnderCursor = zone; | |
168 | } |
|
168 | } | |
169 | } |
|
169 | } | |
170 |
|
170 | |||
171 | return selectionZoneItemUnderCursor; |
|
171 | return selectionZoneItemUnderCursor; | |
172 | } |
|
172 | } | |
173 |
|
173 | |||
174 | QVector<VisualizationSelectionZoneItem *> selectionZonesAt(const QPoint &pos, |
|
174 | QVector<VisualizationSelectionZoneItem *> selectionZonesAt(const QPoint &pos, | |
175 | const QCustomPlot &plot) const |
|
175 | const QCustomPlot &plot) const | |
176 | { |
|
176 | { | |
177 | QVector<VisualizationSelectionZoneItem *> zones; |
|
177 | QVector<VisualizationSelectionZoneItem *> zones; | |
178 | for (auto zone : m_SelectionZones) { |
|
178 | for (auto zone : m_SelectionZones) { | |
179 | auto distanceToZone = zone->selectTest(pos, false); |
|
179 | auto distanceToZone = zone->selectTest(pos, false); | |
180 | if (distanceToZone >= 0 && distanceToZone < plot.selectionTolerance()) { |
|
180 | if (distanceToZone >= 0 && distanceToZone < plot.selectionTolerance()) { | |
181 | zones << zone; |
|
181 | zones << zone; | |
182 | } |
|
182 | } | |
183 | } |
|
183 | } | |
184 |
|
184 | |||
185 | return zones; |
|
185 | return zones; | |
186 | } |
|
186 | } | |
187 |
|
187 | |||
188 | void moveSelectionZoneOnTop(VisualizationSelectionZoneItem *zone, QCustomPlot &plot) |
|
188 | void moveSelectionZoneOnTop(VisualizationSelectionZoneItem *zone, QCustomPlot &plot) | |
189 | { |
|
189 | { | |
190 | if (!m_SelectionZones.isEmpty() && m_SelectionZones.last() != zone) { |
|
190 | if (!m_SelectionZones.isEmpty() && m_SelectionZones.last() != zone) { | |
191 | zone->moveToTop(); |
|
191 | zone->moveToTop(); | |
192 | m_SelectionZones.removeAll(zone); |
|
192 | m_SelectionZones.removeAll(zone); | |
193 | m_SelectionZones.append(zone); |
|
193 | m_SelectionZones.append(zone); | |
194 | } |
|
194 | } | |
195 | } |
|
195 | } | |
196 |
|
196 | |||
197 | QPointF posToAxisPos(const QPoint &pos, QCustomPlot &plot) const |
|
197 | QPointF posToAxisPos(const QPoint &pos, QCustomPlot &plot) const | |
198 | { |
|
198 | { | |
199 | auto axisX = plot.axisRect()->axis(QCPAxis::atBottom); |
|
199 | auto axisX = plot.axisRect()->axis(QCPAxis::atBottom); | |
200 | auto axisY = plot.axisRect()->axis(QCPAxis::atLeft); |
|
200 | auto axisY = plot.axisRect()->axis(QCPAxis::atLeft); | |
201 | return QPointF{axisX->pixelToCoord(pos.x()), axisY->pixelToCoord(pos.y())}; |
|
201 | return QPointF{axisX->pixelToCoord(pos.x()), axisY->pixelToCoord(pos.y())}; | |
202 | } |
|
202 | } | |
203 |
|
203 | |||
204 | bool pointIsInAxisRect(const QPointF &axisPoint, QCustomPlot &plot) const |
|
204 | bool pointIsInAxisRect(const QPointF &axisPoint, QCustomPlot &plot) const | |
205 | { |
|
205 | { | |
206 | auto axisX = plot.axisRect()->axis(QCPAxis::atBottom); |
|
206 | auto axisX = plot.axisRect()->axis(QCPAxis::atBottom); | |
207 | auto axisY = plot.axisRect()->axis(QCPAxis::atLeft); |
|
207 | auto axisY = plot.axisRect()->axis(QCPAxis::atLeft); | |
208 | return axisX->range().contains(axisPoint.x()) && axisY->range().contains(axisPoint.y()); |
|
208 | return axisX->range().contains(axisPoint.x()) && axisY->range().contains(axisPoint.y()); | |
209 | } |
|
209 | } | |
210 | }; |
|
210 | }; | |
211 |
|
211 | |||
212 | VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent) |
|
212 | VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent) | |
213 | : VisualizationDragWidget{parent}, |
|
213 | : VisualizationDragWidget{parent}, | |
214 | ui{new Ui::VisualizationGraphWidget}, |
|
214 | ui{new Ui::VisualizationGraphWidget}, | |
215 | impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>(name)} |
|
215 | impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>(name)} | |
216 | { |
|
216 | { | |
217 | ui->setupUi(this); |
|
217 | ui->setupUi(this); | |
218 |
|
218 | |||
219 | // 'Close' options : widget is deleted when closed |
|
219 | // 'Close' options : widget is deleted when closed | |
220 | setAttribute(Qt::WA_DeleteOnClose); |
|
220 | setAttribute(Qt::WA_DeleteOnClose); | |
221 |
|
221 | |||
222 | // Set qcpplot properties : |
|
222 | // Set qcpplot properties : | |
223 | // - zoom is enabled |
|
223 | // - zoom is enabled | |
224 | // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation |
|
224 | // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation | |
225 | ui->widget->setInteractions(QCP::iRangeZoom); |
|
225 | ui->widget->setInteractions(QCP::iRangeZoom); | |
226 | ui->widget->axisRect()->setRangeDrag(Qt::Horizontal | Qt::Vertical); |
|
226 | ui->widget->axisRect()->setRangeDrag(Qt::Horizontal | Qt::Vertical); | |
227 |
|
227 | |||
228 | // The delegate must be initialized after the ui as it uses the plot |
|
228 | // The delegate must be initialized after the ui as it uses the plot | |
229 | impl->m_RenderingDelegate = std::make_unique<VisualizationGraphRenderingDelegate>(*this); |
|
229 | impl->m_RenderingDelegate = std::make_unique<VisualizationGraphRenderingDelegate>(*this); | |
230 |
|
230 | |||
231 | // Init the cursors |
|
231 | // Init the cursors | |
232 | impl->m_HorizontalCursor = std::make_unique<VisualizationCursorItem>(&plot()); |
|
232 | impl->m_HorizontalCursor = std::make_unique<VisualizationCursorItem>(&plot()); | |
233 | impl->m_HorizontalCursor->setOrientation(Qt::Horizontal); |
|
233 | impl->m_HorizontalCursor->setOrientation(Qt::Horizontal); | |
234 | impl->m_VerticalCursor = std::make_unique<VisualizationCursorItem>(&plot()); |
|
234 | impl->m_VerticalCursor = std::make_unique<VisualizationCursorItem>(&plot()); | |
235 | impl->m_VerticalCursor->setOrientation(Qt::Vertical); |
|
235 | impl->m_VerticalCursor->setOrientation(Qt::Vertical); | |
236 |
|
236 | |||
237 | connect(ui->widget, &QCustomPlot::mousePress, this, &VisualizationGraphWidget::onMousePress); |
|
237 | connect(ui->widget, &QCustomPlot::mousePress, this, &VisualizationGraphWidget::onMousePress); | |
238 | connect(ui->widget, &QCustomPlot::mouseRelease, this, |
|
238 | connect(ui->widget, &QCustomPlot::mouseRelease, this, | |
239 | &VisualizationGraphWidget::onMouseRelease); |
|
239 | &VisualizationGraphWidget::onMouseRelease); | |
240 | connect(ui->widget, &QCustomPlot::mouseMove, this, &VisualizationGraphWidget::onMouseMove); |
|
240 | connect(ui->widget, &QCustomPlot::mouseMove, this, &VisualizationGraphWidget::onMouseMove); | |
241 | connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel); |
|
241 | connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel); | |
242 | connect(ui->widget, &QCustomPlot::mouseDoubleClick, this, |
|
242 | connect(ui->widget, &QCustomPlot::mouseDoubleClick, this, | |
243 | &VisualizationGraphWidget::onMouseDoubleClick); |
|
243 | &VisualizationGraphWidget::onMouseDoubleClick); | |
244 | connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>( |
|
244 | connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>( | |
245 | &QCPAxis::rangeChanged), |
|
245 | &QCPAxis::rangeChanged), | |
246 | this, &VisualizationGraphWidget::onRangeChanged, Qt::DirectConnection); |
|
246 | this, &VisualizationGraphWidget::onRangeChanged, Qt::DirectConnection); | |
247 |
|
247 | |||
248 | // Activates menu when right clicking on the graph |
|
248 | // Activates menu when right clicking on the graph | |
249 | ui->widget->setContextMenuPolicy(Qt::CustomContextMenu); |
|
249 | ui->widget->setContextMenuPolicy(Qt::CustomContextMenu); | |
250 | connect(ui->widget, &QCustomPlot::customContextMenuRequested, this, |
|
250 | connect(ui->widget, &QCustomPlot::customContextMenuRequested, this, | |
251 | &VisualizationGraphWidget::onGraphMenuRequested); |
|
251 | &VisualizationGraphWidget::onGraphMenuRequested); | |
252 |
|
252 | |||
253 | connect(this, &VisualizationGraphWidget::requestDataLoading, &sqpApp->variableController(), |
|
253 | connect(this, &VisualizationGraphWidget::requestDataLoading, &sqpApp->variableController(), | |
254 | &VariableController::onRequestDataLoading); |
|
254 | &VariableController::onRequestDataLoading); | |
255 |
|
255 | |||
256 | connect(&sqpApp->variableController(), &VariableController::updateVarDisplaying, this, |
|
256 | connect(&sqpApp->variableController(), &VariableController::updateVarDisplaying, this, | |
257 | &VisualizationGraphWidget::onUpdateVarDisplaying); |
|
257 | &VisualizationGraphWidget::onUpdateVarDisplaying); | |
258 |
|
258 | |||
259 | #ifdef Q_OS_MAC |
|
259 | #ifdef Q_OS_MAC | |
260 | plot().setPlottingHint(QCP::phFastPolylines, true); |
|
260 | plot().setPlottingHint(QCP::phFastPolylines, true); | |
261 | #endif |
|
261 | #endif | |
262 | } |
|
262 | } | |
263 |
|
263 | |||
264 |
|
264 | |||
265 | VisualizationGraphWidget::~VisualizationGraphWidget() |
|
265 | VisualizationGraphWidget::~VisualizationGraphWidget() | |
266 | { |
|
266 | { | |
267 | delete ui; |
|
267 | delete ui; | |
268 | } |
|
268 | } | |
269 |
|
269 | |||
270 | VisualizationZoneWidget *VisualizationGraphWidget::parentZoneWidget() const noexcept |
|
270 | VisualizationZoneWidget *VisualizationGraphWidget::parentZoneWidget() const noexcept | |
271 | { |
|
271 | { | |
272 | auto parent = parentWidget(); |
|
272 | auto parent = parentWidget(); | |
273 | while (parent != nullptr && !qobject_cast<VisualizationZoneWidget *>(parent)) { |
|
273 | while (parent != nullptr && !qobject_cast<VisualizationZoneWidget *>(parent)) { | |
274 | parent = parent->parentWidget(); |
|
274 | parent = parent->parentWidget(); | |
275 | } |
|
275 | } | |
276 |
|
276 | |||
277 | return qobject_cast<VisualizationZoneWidget *>(parent); |
|
277 | return qobject_cast<VisualizationZoneWidget *>(parent); | |
278 | } |
|
278 | } | |
279 |
|
279 | |||
280 | VisualizationWidget *VisualizationGraphWidget::parentVisualizationWidget() const |
|
280 | VisualizationWidget *VisualizationGraphWidget::parentVisualizationWidget() const | |
281 | { |
|
281 | { | |
282 | auto parent = parentWidget(); |
|
282 | auto parent = parentWidget(); | |
283 | while (parent != nullptr && !qobject_cast<VisualizationWidget *>(parent)) { |
|
283 | while (parent != nullptr && !qobject_cast<VisualizationWidget *>(parent)) { | |
284 | parent = parent->parentWidget(); |
|
284 | parent = parent->parentWidget(); | |
285 | } |
|
285 | } | |
286 |
|
286 | |||
287 | return qobject_cast<VisualizationWidget *>(parent); |
|
287 | return qobject_cast<VisualizationWidget *>(parent); | |
288 | } |
|
288 | } | |
289 |
|
289 | |||
290 |
void VisualizationGraphWidget:: |
|
290 | void VisualizationGraphWidget::setFlags(GraphFlags flags) | |
291 | { |
|
291 | { | |
292 | impl->m_DoAcquisition = enable; |
|
292 | impl->m_Flags = std::move(flags); | |
293 | } |
|
293 | } | |
294 |
|
294 | |||
295 | void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable, SqpRange range) |
|
295 | void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable, SqpRange range) | |
296 | { |
|
296 | { | |
297 | // Uses delegate to create the qcpplot components according to the variable |
|
297 | // Uses delegate to create the qcpplot components according to the variable | |
298 | auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget); |
|
298 | auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget); | |
299 |
|
299 | |||
300 | if (auto dataSeries = variable->dataSeries()) { |
|
300 | if (auto dataSeries = variable->dataSeries()) { | |
301 | // Set axes properties according to the units of the data series |
|
301 | // Set axes properties according to the units of the data series | |
302 | impl->m_RenderingDelegate->setAxesProperties(dataSeries); |
|
302 | impl->m_RenderingDelegate->setAxesProperties(dataSeries); | |
303 |
|
303 | |||
304 | // Sets rendering properties for the new plottables |
|
304 | // Sets rendering properties for the new plottables | |
305 | // Warning: this method must be called after setAxesProperties(), as it can access to some |
|
305 | // Warning: this method must be called after setAxesProperties(), as it can access to some | |
306 | // axes properties that have to be initialized |
|
306 | // axes properties that have to be initialized | |
307 | impl->m_RenderingDelegate->setPlottablesProperties(dataSeries, createdPlottables); |
|
307 | impl->m_RenderingDelegate->setPlottablesProperties(dataSeries, createdPlottables); | |
308 | } |
|
308 | } | |
309 |
|
309 | |||
310 | impl->m_VariableToPlotMultiMap.insert({variable, std::move(createdPlottables)}); |
|
310 | impl->m_VariableToPlotMultiMap.insert({variable, std::move(createdPlottables)}); | |
311 |
|
311 | |||
312 | connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated())); |
|
312 | connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated())); | |
313 |
|
313 | |||
314 | this->enableAcquisition(false); |
|
314 | this->setFlags(GraphFlag::DisableAll); | |
315 | this->setGraphRange(range); |
|
315 | this->setGraphRange(range); | |
316 | this->enableAcquisition(true); |
|
316 | this->setFlags(GraphFlag::EnableAll); | |
317 |
|
317 | |||
318 | emit requestDataLoading(QVector<std::shared_ptr<Variable> >() << variable, range, false); |
|
318 | emit requestDataLoading(QVector<std::shared_ptr<Variable> >() << variable, range, false); | |
319 |
|
319 | |||
320 | emit variableAdded(variable); |
|
320 | emit variableAdded(variable); | |
321 | } |
|
321 | } | |
322 |
|
322 | |||
323 | void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept |
|
323 | void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept | |
324 | { |
|
324 | { | |
325 | // Each component associated to the variable : |
|
325 | // Each component associated to the variable : | |
326 | // - is removed from qcpplot (which deletes it) |
|
326 | // - is removed from qcpplot (which deletes it) | |
327 | // - is no longer referenced in the map |
|
327 | // - is no longer referenced in the map | |
328 | auto variableIt = impl->m_VariableToPlotMultiMap.find(variable); |
|
328 | auto variableIt = impl->m_VariableToPlotMultiMap.find(variable); | |
329 | if (variableIt != impl->m_VariableToPlotMultiMap.cend()) { |
|
329 | if (variableIt != impl->m_VariableToPlotMultiMap.cend()) { | |
330 | emit variableAboutToBeRemoved(variable); |
|
330 | emit variableAboutToBeRemoved(variable); | |
331 |
|
331 | |||
332 | auto &plottablesMap = variableIt->second; |
|
332 | auto &plottablesMap = variableIt->second; | |
333 |
|
333 | |||
334 | for (auto plottableIt = plottablesMap.cbegin(), plottableEnd = plottablesMap.cend(); |
|
334 | for (auto plottableIt = plottablesMap.cbegin(), plottableEnd = plottablesMap.cend(); | |
335 | plottableIt != plottableEnd;) { |
|
335 | plottableIt != plottableEnd;) { | |
336 | ui->widget->removePlottable(plottableIt->second); |
|
336 | ui->widget->removePlottable(plottableIt->second); | |
337 | plottableIt = plottablesMap.erase(plottableIt); |
|
337 | plottableIt = plottablesMap.erase(plottableIt); | |
338 | } |
|
338 | } | |
339 |
|
339 | |||
340 | impl->m_VariableToPlotMultiMap.erase(variableIt); |
|
340 | impl->m_VariableToPlotMultiMap.erase(variableIt); | |
341 | } |
|
341 | } | |
342 |
|
342 | |||
343 | // Updates graph |
|
343 | // Updates graph | |
344 | ui->widget->replot(); |
|
344 | ui->widget->replot(); | |
345 | } |
|
345 | } | |
346 |
|
346 | |||
347 | QList<std::shared_ptr<Variable> > VisualizationGraphWidget::variables() const |
|
347 | QList<std::shared_ptr<Variable> > VisualizationGraphWidget::variables() const | |
348 | { |
|
348 | { | |
349 | auto variables = QList<std::shared_ptr<Variable> >{}; |
|
349 | auto variables = QList<std::shared_ptr<Variable> >{}; | |
350 | for (auto it = std::cbegin(impl->m_VariableToPlotMultiMap); |
|
350 | for (auto it = std::cbegin(impl->m_VariableToPlotMultiMap); | |
351 | it != std::cend(impl->m_VariableToPlotMultiMap); ++it) { |
|
351 | it != std::cend(impl->m_VariableToPlotMultiMap); ++it) { | |
352 | variables << it->first; |
|
352 | variables << it->first; | |
353 | } |
|
353 | } | |
354 |
|
354 | |||
355 | return variables; |
|
355 | return variables; | |
356 | } |
|
356 | } | |
357 |
|
357 | |||
358 | void VisualizationGraphWidget::setYRange(std::shared_ptr<Variable> variable) |
|
358 | void VisualizationGraphWidget::setYRange(std::shared_ptr<Variable> variable) | |
359 | { |
|
359 | { | |
360 | if (!variable) { |
|
360 | if (!variable) { | |
361 | qCCritical(LOG_VisualizationGraphWidget()) << "Can't set y-axis range: variable is null"; |
|
361 | qCCritical(LOG_VisualizationGraphWidget()) << "Can't set y-axis range: variable is null"; | |
362 | return; |
|
362 | return; | |
363 | } |
|
363 | } | |
364 |
|
364 | |||
365 | VisualizationGraphHelper::setYAxisRange(variable, *ui->widget); |
|
365 | VisualizationGraphHelper::setYAxisRange(variable, *ui->widget); | |
366 | } |
|
366 | } | |
367 |
|
367 | |||
368 | SqpRange VisualizationGraphWidget::graphRange() const noexcept |
|
368 | SqpRange VisualizationGraphWidget::graphRange() const noexcept | |
369 | { |
|
369 | { | |
370 | auto graphRange = ui->widget->xAxis->range(); |
|
370 | auto graphRange = ui->widget->xAxis->range(); | |
371 | return SqpRange{graphRange.lower, graphRange.upper}; |
|
371 | return SqpRange{graphRange.lower, graphRange.upper}; | |
372 | } |
|
372 | } | |
373 |
|
373 | |||
374 | void VisualizationGraphWidget::setGraphRange(const SqpRange &range) |
|
374 | void VisualizationGraphWidget::setGraphRange(const SqpRange &range) | |
375 | { |
|
375 | { | |
376 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange START"); |
|
376 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange START"); | |
377 | ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd); |
|
377 | ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd); | |
378 | ui->widget->replot(); |
|
378 | ui->widget->replot(); | |
379 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange END"); |
|
379 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange END"); | |
380 | } |
|
380 | } | |
381 |
|
381 | |||
382 | QVector<SqpRange> VisualizationGraphWidget::selectionZoneRanges() const |
|
382 | QVector<SqpRange> VisualizationGraphWidget::selectionZoneRanges() const | |
383 | { |
|
383 | { | |
384 | QVector<SqpRange> ranges; |
|
384 | QVector<SqpRange> ranges; | |
385 | for (auto zone : impl->m_SelectionZones) { |
|
385 | for (auto zone : impl->m_SelectionZones) { | |
386 | ranges << zone->range(); |
|
386 | ranges << zone->range(); | |
387 | } |
|
387 | } | |
388 |
|
388 | |||
389 | return ranges; |
|
389 | return ranges; | |
390 | } |
|
390 | } | |
391 |
|
391 | |||
392 | void VisualizationGraphWidget::addSelectionZones(const QVector<SqpRange> &ranges) |
|
392 | void VisualizationGraphWidget::addSelectionZones(const QVector<SqpRange> &ranges) | |
393 | { |
|
393 | { | |
394 | for (const auto &range : ranges) { |
|
394 | for (const auto &range : ranges) { | |
395 | // note: ownership is transfered to QCustomPlot |
|
395 | // note: ownership is transfered to QCustomPlot | |
396 | auto zone = new VisualizationSelectionZoneItem(&plot()); |
|
396 | auto zone = new VisualizationSelectionZoneItem(&plot()); | |
397 | zone->setRange(range.m_TStart, range.m_TEnd); |
|
397 | zone->setRange(range.m_TStart, range.m_TEnd); | |
398 | impl->addSelectionZone(zone); |
|
398 | impl->addSelectionZone(zone); | |
399 | } |
|
399 | } | |
400 |
|
400 | |||
401 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
401 | plot().replot(QCustomPlot::rpQueuedReplot); | |
402 | } |
|
402 | } | |
403 |
|
403 | |||
404 | void VisualizationGraphWidget::removeSelectionZone(VisualizationSelectionZoneItem *selectionZone) |
|
404 | void VisualizationGraphWidget::removeSelectionZone(VisualizationSelectionZoneItem *selectionZone) | |
405 | { |
|
405 | { | |
406 | parentVisualizationWidget()->selectionZoneManager().setSelected(selectionZone, false); |
|
406 | parentVisualizationWidget()->selectionZoneManager().setSelected(selectionZone, false); | |
407 |
|
407 | |||
408 | if (impl->m_HoveredZone == selectionZone) { |
|
408 | if (impl->m_HoveredZone == selectionZone) { | |
409 | impl->m_HoveredZone = nullptr; |
|
409 | impl->m_HoveredZone = nullptr; | |
410 | setCursor(Qt::ArrowCursor); |
|
410 | setCursor(Qt::ArrowCursor); | |
411 | } |
|
411 | } | |
412 |
|
412 | |||
413 | impl->m_SelectionZones.removeAll(selectionZone); |
|
413 | impl->m_SelectionZones.removeAll(selectionZone); | |
414 | plot().removeItem(selectionZone); |
|
414 | plot().removeItem(selectionZone); | |
415 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
415 | plot().replot(QCustomPlot::rpQueuedReplot); | |
416 | } |
|
416 | } | |
417 |
|
417 | |||
418 | void VisualizationGraphWidget::undoZoom() |
|
418 | void VisualizationGraphWidget::undoZoom() | |
419 | { |
|
419 | { | |
420 | auto zoom = impl->m_ZoomStack.pop(); |
|
420 | auto zoom = impl->m_ZoomStack.pop(); | |
421 | auto axisX = plot().axisRect()->axis(QCPAxis::atBottom); |
|
421 | auto axisX = plot().axisRect()->axis(QCPAxis::atBottom); | |
422 | auto axisY = plot().axisRect()->axis(QCPAxis::atLeft); |
|
422 | auto axisY = plot().axisRect()->axis(QCPAxis::atLeft); | |
423 |
|
423 | |||
424 | axisX->setRange(zoom.first); |
|
424 | axisX->setRange(zoom.first); | |
425 | axisY->setRange(zoom.second); |
|
425 | axisY->setRange(zoom.second); | |
426 |
|
426 | |||
427 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
427 | plot().replot(QCustomPlot::rpQueuedReplot); | |
428 | } |
|
428 | } | |
429 |
|
429 | |||
430 | void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
430 | void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor) | |
431 | { |
|
431 | { | |
432 | if (visitor) { |
|
432 | if (visitor) { | |
433 | visitor->visit(this); |
|
433 | visitor->visit(this); | |
434 | } |
|
434 | } | |
435 | else { |
|
435 | else { | |
436 | qCCritical(LOG_VisualizationGraphWidget()) |
|
436 | qCCritical(LOG_VisualizationGraphWidget()) | |
437 | << tr("Can't visit widget : the visitor is null"); |
|
437 | << tr("Can't visit widget : the visitor is null"); | |
438 | } |
|
438 | } | |
439 | } |
|
439 | } | |
440 |
|
440 | |||
441 | bool VisualizationGraphWidget::canDrop(const Variable &variable) const |
|
441 | bool VisualizationGraphWidget::canDrop(const Variable &variable) const | |
442 | { |
|
442 | { | |
443 | auto isSpectrogram = [](const auto &variable) { |
|
443 | auto isSpectrogram = [](const auto &variable) { | |
444 | return std::dynamic_pointer_cast<SpectrogramSeries>(variable.dataSeries()) != nullptr; |
|
444 | return std::dynamic_pointer_cast<SpectrogramSeries>(variable.dataSeries()) != nullptr; | |
445 | }; |
|
445 | }; | |
446 |
|
446 | |||
447 | // - A spectrogram series can't be dropped on graph with existing plottables |
|
447 | // - A spectrogram series can't be dropped on graph with existing plottables | |
448 | // - No data series can be dropped on graph with existing spectrogram series |
|
448 | // - No data series can be dropped on graph with existing spectrogram series | |
449 | return isSpectrogram(variable) |
|
449 | return isSpectrogram(variable) | |
450 | ? impl->m_VariableToPlotMultiMap.empty() |
|
450 | ? impl->m_VariableToPlotMultiMap.empty() | |
451 | : std::none_of( |
|
451 | : std::none_of( | |
452 | impl->m_VariableToPlotMultiMap.cbegin(), impl->m_VariableToPlotMultiMap.cend(), |
|
452 | impl->m_VariableToPlotMultiMap.cbegin(), impl->m_VariableToPlotMultiMap.cend(), | |
453 | [isSpectrogram](const auto &entry) { return isSpectrogram(*entry.first); }); |
|
453 | [isSpectrogram](const auto &entry) { return isSpectrogram(*entry.first); }); | |
454 | } |
|
454 | } | |
455 |
|
455 | |||
456 | bool VisualizationGraphWidget::contains(const Variable &variable) const |
|
456 | bool VisualizationGraphWidget::contains(const Variable &variable) const | |
457 | { |
|
457 | { | |
458 | // Finds the variable among the keys of the map |
|
458 | // Finds the variable among the keys of the map | |
459 | auto variablePtr = &variable; |
|
459 | auto variablePtr = &variable; | |
460 | auto findVariable |
|
460 | auto findVariable | |
461 | = [variablePtr](const auto &entry) { return variablePtr == entry.first.get(); }; |
|
461 | = [variablePtr](const auto &entry) { return variablePtr == entry.first.get(); }; | |
462 |
|
462 | |||
463 | auto end = impl->m_VariableToPlotMultiMap.cend(); |
|
463 | auto end = impl->m_VariableToPlotMultiMap.cend(); | |
464 | auto it = std::find_if(impl->m_VariableToPlotMultiMap.cbegin(), end, findVariable); |
|
464 | auto it = std::find_if(impl->m_VariableToPlotMultiMap.cbegin(), end, findVariable); | |
465 | return it != end; |
|
465 | return it != end; | |
466 | } |
|
466 | } | |
467 |
|
467 | |||
468 | QString VisualizationGraphWidget::name() const |
|
468 | QString VisualizationGraphWidget::name() const | |
469 | { |
|
469 | { | |
470 | return impl->m_Name; |
|
470 | return impl->m_Name; | |
471 | } |
|
471 | } | |
472 |
|
472 | |||
473 | QMimeData *VisualizationGraphWidget::mimeData(const QPoint &position) const |
|
473 | QMimeData *VisualizationGraphWidget::mimeData(const QPoint &position) const | |
474 | { |
|
474 | { | |
475 | auto mimeData = new QMimeData; |
|
475 | auto mimeData = new QMimeData; | |
476 |
|
476 | |||
477 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(position, plot()); |
|
477 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(position, plot()); | |
478 | if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones |
|
478 | if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones | |
479 | && selectionZoneItemUnderCursor) { |
|
479 | && selectionZoneItemUnderCursor) { | |
480 | mimeData->setData(MIME_TYPE_TIME_RANGE, TimeController::mimeDataForTimeRange( |
|
480 | mimeData->setData(MIME_TYPE_TIME_RANGE, TimeController::mimeDataForTimeRange( | |
481 | selectionZoneItemUnderCursor->range())); |
|
481 | selectionZoneItemUnderCursor->range())); | |
482 | mimeData->setData(MIME_TYPE_SELECTION_ZONE, TimeController::mimeDataForTimeRange( |
|
482 | mimeData->setData(MIME_TYPE_SELECTION_ZONE, TimeController::mimeDataForTimeRange( | |
483 | selectionZoneItemUnderCursor->range())); |
|
483 | selectionZoneItemUnderCursor->range())); | |
484 | } |
|
484 | } | |
485 | else { |
|
485 | else { | |
486 | mimeData->setData(MIME_TYPE_GRAPH, QByteArray{}); |
|
486 | mimeData->setData(MIME_TYPE_GRAPH, QByteArray{}); | |
487 |
|
487 | |||
488 | auto timeRangeData = TimeController::mimeDataForTimeRange(graphRange()); |
|
488 | auto timeRangeData = TimeController::mimeDataForTimeRange(graphRange()); | |
489 | mimeData->setData(MIME_TYPE_TIME_RANGE, timeRangeData); |
|
489 | mimeData->setData(MIME_TYPE_TIME_RANGE, timeRangeData); | |
490 | } |
|
490 | } | |
491 |
|
491 | |||
492 | return mimeData; |
|
492 | return mimeData; | |
493 | } |
|
493 | } | |
494 |
|
494 | |||
495 | QPixmap VisualizationGraphWidget::customDragPixmap(const QPoint &dragPosition) |
|
495 | QPixmap VisualizationGraphWidget::customDragPixmap(const QPoint &dragPosition) | |
496 | { |
|
496 | { | |
497 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(dragPosition, plot()); |
|
497 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(dragPosition, plot()); | |
498 | if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones |
|
498 | if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones | |
499 | && selectionZoneItemUnderCursor) { |
|
499 | && selectionZoneItemUnderCursor) { | |
500 |
|
500 | |||
501 | auto zoneTopLeft = selectionZoneItemUnderCursor->topLeft->pixelPosition(); |
|
501 | auto zoneTopLeft = selectionZoneItemUnderCursor->topLeft->pixelPosition(); | |
502 | auto zoneBottomRight = selectionZoneItemUnderCursor->bottomRight->pixelPosition(); |
|
502 | auto zoneBottomRight = selectionZoneItemUnderCursor->bottomRight->pixelPosition(); | |
503 |
|
503 | |||
504 | auto zoneSize = QSizeF{qAbs(zoneBottomRight.x() - zoneTopLeft.x()), |
|
504 | auto zoneSize = QSizeF{qAbs(zoneBottomRight.x() - zoneTopLeft.x()), | |
505 | qAbs(zoneBottomRight.y() - zoneTopLeft.y())} |
|
505 | qAbs(zoneBottomRight.y() - zoneTopLeft.y())} | |
506 | .toSize(); |
|
506 | .toSize(); | |
507 |
|
507 | |||
508 | auto pixmap = QPixmap(zoneSize); |
|
508 | auto pixmap = QPixmap(zoneSize); | |
509 | render(&pixmap, QPoint(), QRegion{QRect{zoneTopLeft.toPoint(), zoneSize}}); |
|
509 | render(&pixmap, QPoint(), QRegion{QRect{zoneTopLeft.toPoint(), zoneSize}}); | |
510 |
|
510 | |||
511 | return pixmap; |
|
511 | return pixmap; | |
512 | } |
|
512 | } | |
513 |
|
513 | |||
514 | return QPixmap(); |
|
514 | return QPixmap(); | |
515 | } |
|
515 | } | |
516 |
|
516 | |||
517 | bool VisualizationGraphWidget::isDragAllowed() const |
|
517 | bool VisualizationGraphWidget::isDragAllowed() const | |
518 | { |
|
518 | { | |
519 | return true; |
|
519 | return true; | |
520 | } |
|
520 | } | |
521 |
|
521 | |||
522 | void VisualizationGraphWidget::highlightForMerge(bool highlighted) |
|
522 | void VisualizationGraphWidget::highlightForMerge(bool highlighted) | |
523 | { |
|
523 | { | |
524 | if (highlighted) { |
|
524 | if (highlighted) { | |
525 | plot().setBackground(QBrush(QColor("#BBD5EE"))); |
|
525 | plot().setBackground(QBrush(QColor("#BBD5EE"))); | |
526 | } |
|
526 | } | |
527 | else { |
|
527 | else { | |
528 | plot().setBackground(QBrush(Qt::white)); |
|
528 | plot().setBackground(QBrush(Qt::white)); | |
529 | } |
|
529 | } | |
530 |
|
530 | |||
531 | plot().update(); |
|
531 | plot().update(); | |
532 | } |
|
532 | } | |
533 |
|
533 | |||
534 | void VisualizationGraphWidget::addVerticalCursor(double time) |
|
534 | void VisualizationGraphWidget::addVerticalCursor(double time) | |
535 | { |
|
535 | { | |
536 | impl->m_VerticalCursor->setPosition(time); |
|
536 | impl->m_VerticalCursor->setPosition(time); | |
537 | impl->m_VerticalCursor->setVisible(true); |
|
537 | impl->m_VerticalCursor->setVisible(true); | |
538 |
|
538 | |||
539 | auto text |
|
539 | auto text | |
540 | = DateUtils::dateTime(time).toString(CURSOR_LABELS_DATETIME_FORMAT).replace(' ', '\n'); |
|
540 | = DateUtils::dateTime(time).toString(CURSOR_LABELS_DATETIME_FORMAT).replace(' ', '\n'); | |
541 | impl->m_VerticalCursor->setLabelText(text); |
|
541 | impl->m_VerticalCursor->setLabelText(text); | |
542 | } |
|
542 | } | |
543 |
|
543 | |||
544 | void VisualizationGraphWidget::addVerticalCursorAtViewportPosition(double position) |
|
544 | void VisualizationGraphWidget::addVerticalCursorAtViewportPosition(double position) | |
545 | { |
|
545 | { | |
546 | impl->m_VerticalCursor->setAbsolutePosition(position); |
|
546 | impl->m_VerticalCursor->setAbsolutePosition(position); | |
547 | impl->m_VerticalCursor->setVisible(true); |
|
547 | impl->m_VerticalCursor->setVisible(true); | |
548 |
|
548 | |||
549 | auto axis = plot().axisRect()->axis(QCPAxis::atBottom); |
|
549 | auto axis = plot().axisRect()->axis(QCPAxis::atBottom); | |
550 | auto text |
|
550 | auto text | |
551 | = DateUtils::dateTime(axis->pixelToCoord(position)).toString(CURSOR_LABELS_DATETIME_FORMAT); |
|
551 | = DateUtils::dateTime(axis->pixelToCoord(position)).toString(CURSOR_LABELS_DATETIME_FORMAT); | |
552 | impl->m_VerticalCursor->setLabelText(text); |
|
552 | impl->m_VerticalCursor->setLabelText(text); | |
553 | } |
|
553 | } | |
554 |
|
554 | |||
555 | void VisualizationGraphWidget::removeVerticalCursor() |
|
555 | void VisualizationGraphWidget::removeVerticalCursor() | |
556 | { |
|
556 | { | |
557 | impl->m_VerticalCursor->setVisible(false); |
|
557 | impl->m_VerticalCursor->setVisible(false); | |
558 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
558 | plot().replot(QCustomPlot::rpQueuedReplot); | |
559 | } |
|
559 | } | |
560 |
|
560 | |||
561 | void VisualizationGraphWidget::addHorizontalCursor(double value) |
|
561 | void VisualizationGraphWidget::addHorizontalCursor(double value) | |
562 | { |
|
562 | { | |
563 | impl->m_HorizontalCursor->setPosition(value); |
|
563 | impl->m_HorizontalCursor->setPosition(value); | |
564 | impl->m_HorizontalCursor->setVisible(true); |
|
564 | impl->m_HorizontalCursor->setVisible(true); | |
565 | impl->m_HorizontalCursor->setLabelText(QString::number(value)); |
|
565 | impl->m_HorizontalCursor->setLabelText(QString::number(value)); | |
566 | } |
|
566 | } | |
567 |
|
567 | |||
568 | void VisualizationGraphWidget::addHorizontalCursorAtViewportPosition(double position) |
|
568 | void VisualizationGraphWidget::addHorizontalCursorAtViewportPosition(double position) | |
569 | { |
|
569 | { | |
570 | impl->m_HorizontalCursor->setAbsolutePosition(position); |
|
570 | impl->m_HorizontalCursor->setAbsolutePosition(position); | |
571 | impl->m_HorizontalCursor->setVisible(true); |
|
571 | impl->m_HorizontalCursor->setVisible(true); | |
572 |
|
572 | |||
573 | auto axis = plot().axisRect()->axis(QCPAxis::atLeft); |
|
573 | auto axis = plot().axisRect()->axis(QCPAxis::atLeft); | |
574 | impl->m_HorizontalCursor->setLabelText(QString::number(axis->pixelToCoord(position))); |
|
574 | impl->m_HorizontalCursor->setLabelText(QString::number(axis->pixelToCoord(position))); | |
575 | } |
|
575 | } | |
576 |
|
576 | |||
577 | void VisualizationGraphWidget::removeHorizontalCursor() |
|
577 | void VisualizationGraphWidget::removeHorizontalCursor() | |
578 | { |
|
578 | { | |
579 | impl->m_HorizontalCursor->setVisible(false); |
|
579 | impl->m_HorizontalCursor->setVisible(false); | |
580 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
580 | plot().replot(QCustomPlot::rpQueuedReplot); | |
581 | } |
|
581 | } | |
582 |
|
582 | |||
583 | void VisualizationGraphWidget::closeEvent(QCloseEvent *event) |
|
583 | void VisualizationGraphWidget::closeEvent(QCloseEvent *event) | |
584 | { |
|
584 | { | |
585 | Q_UNUSED(event); |
|
585 | Q_UNUSED(event); | |
586 |
|
586 | |||
587 | // Prevents that all variables will be removed from graph when it will be closed |
|
587 | // Prevents that all variables will be removed from graph when it will be closed | |
588 | for (auto &variableEntry : impl->m_VariableToPlotMultiMap) { |
|
588 | for (auto &variableEntry : impl->m_VariableToPlotMultiMap) { | |
589 | emit variableAboutToBeRemoved(variableEntry.first); |
|
589 | emit variableAboutToBeRemoved(variableEntry.first); | |
590 | } |
|
590 | } | |
591 | } |
|
591 | } | |
592 |
|
592 | |||
593 | void VisualizationGraphWidget::enterEvent(QEvent *event) |
|
593 | void VisualizationGraphWidget::enterEvent(QEvent *event) | |
594 | { |
|
594 | { | |
595 | Q_UNUSED(event); |
|
595 | Q_UNUSED(event); | |
596 | impl->m_RenderingDelegate->showGraphOverlay(true); |
|
596 | impl->m_RenderingDelegate->showGraphOverlay(true); | |
597 | } |
|
597 | } | |
598 |
|
598 | |||
599 | void VisualizationGraphWidget::leaveEvent(QEvent *event) |
|
599 | void VisualizationGraphWidget::leaveEvent(QEvent *event) | |
600 | { |
|
600 | { | |
601 | Q_UNUSED(event); |
|
601 | Q_UNUSED(event); | |
602 | impl->m_RenderingDelegate->showGraphOverlay(false); |
|
602 | impl->m_RenderingDelegate->showGraphOverlay(false); | |
603 |
|
603 | |||
604 | if (auto parentZone = parentZoneWidget()) { |
|
604 | if (auto parentZone = parentZoneWidget()) { | |
605 | parentZone->notifyMouseLeaveGraph(this); |
|
605 | parentZone->notifyMouseLeaveGraph(this); | |
606 | } |
|
606 | } | |
607 | else { |
|
607 | else { | |
608 | qCWarning(LOG_VisualizationGraphWidget()) << "leaveEvent: No parent zone widget"; |
|
608 | qCWarning(LOG_VisualizationGraphWidget()) << "leaveEvent: No parent zone widget"; | |
609 | } |
|
609 | } | |
610 |
|
610 | |||
611 | if (impl->m_HoveredZone) { |
|
611 | if (impl->m_HoveredZone) { | |
612 | impl->m_HoveredZone->setHovered(false); |
|
612 | impl->m_HoveredZone->setHovered(false); | |
613 | impl->m_HoveredZone = nullptr; |
|
613 | impl->m_HoveredZone = nullptr; | |
614 | } |
|
614 | } | |
615 | } |
|
615 | } | |
616 |
|
616 | |||
617 | QCustomPlot &VisualizationGraphWidget::plot() const noexcept |
|
617 | QCustomPlot &VisualizationGraphWidget::plot() const noexcept | |
618 | { |
|
618 | { | |
619 | return *ui->widget; |
|
619 | return *ui->widget; | |
620 | } |
|
620 | } | |
621 |
|
621 | |||
622 | void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept |
|
622 | void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept | |
623 | { |
|
623 | { | |
624 | QMenu graphMenu{}; |
|
624 | QMenu graphMenu{}; | |
625 |
|
625 | |||
626 | // Iterates on variables (unique keys) |
|
626 | // Iterates on variables (unique keys) | |
627 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(), |
|
627 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(), | |
628 | end = impl->m_VariableToPlotMultiMap.cend(); |
|
628 | end = impl->m_VariableToPlotMultiMap.cend(); | |
629 | it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) { |
|
629 | it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) { | |
630 | // 'Remove variable' action |
|
630 | // 'Remove variable' action | |
631 | graphMenu.addAction(tr("Remove variable %1").arg(it->first->name()), |
|
631 | graphMenu.addAction(tr("Remove variable %1").arg(it->first->name()), | |
632 | [ this, var = it->first ]() { removeVariable(var); }); |
|
632 | [ this, var = it->first ]() { removeVariable(var); }); | |
633 | } |
|
633 | } | |
634 |
|
634 | |||
635 | if (!impl->m_ZoomStack.isEmpty()) { |
|
635 | if (!impl->m_ZoomStack.isEmpty()) { | |
636 | if (!graphMenu.isEmpty()) { |
|
636 | if (!graphMenu.isEmpty()) { | |
637 | graphMenu.addSeparator(); |
|
637 | graphMenu.addSeparator(); | |
638 | } |
|
638 | } | |
639 |
|
639 | |||
640 | graphMenu.addAction(tr("Undo Zoom"), [this]() { undoZoom(); }); |
|
640 | graphMenu.addAction(tr("Undo Zoom"), [this]() { undoZoom(); }); | |
641 | } |
|
641 | } | |
642 |
|
642 | |||
643 | // Selection Zone Actions |
|
643 | // Selection Zone Actions | |
644 | auto selectionZoneItem = impl->selectionZoneAt(pos, plot()); |
|
644 | auto selectionZoneItem = impl->selectionZoneAt(pos, plot()); | |
645 | if (selectionZoneItem) { |
|
645 | if (selectionZoneItem) { | |
646 | auto selectedItems = parentVisualizationWidget()->selectionZoneManager().selectedItems(); |
|
646 | auto selectedItems = parentVisualizationWidget()->selectionZoneManager().selectedItems(); | |
647 | selectedItems.removeAll(selectionZoneItem); |
|
647 | selectedItems.removeAll(selectionZoneItem); | |
648 | selectedItems.prepend(selectionZoneItem); // Put the current selection zone first |
|
648 | selectedItems.prepend(selectionZoneItem); // Put the current selection zone first | |
649 |
|
649 | |||
650 | auto zoneActions = sqpApp->actionsGuiController().selectionZoneActions(); |
|
650 | auto zoneActions = sqpApp->actionsGuiController().selectionZoneActions(); | |
651 | if (!zoneActions.isEmpty() && !graphMenu.isEmpty()) { |
|
651 | if (!zoneActions.isEmpty() && !graphMenu.isEmpty()) { | |
652 | graphMenu.addSeparator(); |
|
652 | graphMenu.addSeparator(); | |
653 | } |
|
653 | } | |
654 |
|
654 | |||
655 | QHash<QString, QMenu *> subMenus; |
|
655 | QHash<QString, QMenu *> subMenus; | |
656 | QHash<QString, bool> subMenusEnabled; |
|
656 | QHash<QString, bool> subMenusEnabled; | |
657 |
|
657 | |||
658 | for (auto zoneAction : zoneActions) { |
|
658 | for (auto zoneAction : zoneActions) { | |
659 |
|
659 | |||
660 | auto isEnabled = zoneAction->isEnabled(selectedItems); |
|
660 | auto isEnabled = zoneAction->isEnabled(selectedItems); | |
661 |
|
661 | |||
662 | auto menu = &graphMenu; |
|
662 | auto menu = &graphMenu; | |
663 | for (auto subMenuName : zoneAction->subMenuList()) { |
|
663 | for (auto subMenuName : zoneAction->subMenuList()) { | |
664 | if (!subMenus.contains(subMenuName)) { |
|
664 | if (!subMenus.contains(subMenuName)) { | |
665 | menu = menu->addMenu(subMenuName); |
|
665 | menu = menu->addMenu(subMenuName); | |
666 | subMenus[subMenuName] = menu; |
|
666 | subMenus[subMenuName] = menu; | |
667 | subMenusEnabled[subMenuName] = isEnabled; |
|
667 | subMenusEnabled[subMenuName] = isEnabled; | |
668 | } |
|
668 | } | |
669 | else { |
|
669 | else { | |
670 | menu = subMenus.value(subMenuName); |
|
670 | menu = subMenus.value(subMenuName); | |
671 | if (isEnabled) { |
|
671 | if (isEnabled) { | |
672 | // The sub menu is enabled if at least one of its actions is enabled |
|
672 | // The sub menu is enabled if at least one of its actions is enabled | |
673 | subMenusEnabled[subMenuName] = true; |
|
673 | subMenusEnabled[subMenuName] = true; | |
674 | } |
|
674 | } | |
675 | } |
|
675 | } | |
676 | } |
|
676 | } | |
677 |
|
677 | |||
678 | auto action = menu->addAction(zoneAction->name()); |
|
678 | auto action = menu->addAction(zoneAction->name()); | |
679 | action->setEnabled(isEnabled); |
|
679 | action->setEnabled(isEnabled); | |
680 | action->setShortcut(zoneAction->displayedShortcut()); |
|
680 | action->setShortcut(zoneAction->displayedShortcut()); | |
681 | QObject::connect(action, &QAction::triggered, |
|
681 | QObject::connect(action, &QAction::triggered, | |
682 | [zoneAction, selectedItems]() { zoneAction->execute(selectedItems); }); |
|
682 | [zoneAction, selectedItems]() { zoneAction->execute(selectedItems); }); | |
683 | } |
|
683 | } | |
684 |
|
684 | |||
685 | for (auto it = subMenus.cbegin(); it != subMenus.cend(); ++it) { |
|
685 | for (auto it = subMenus.cbegin(); it != subMenus.cend(); ++it) { | |
686 | it.value()->setEnabled(subMenusEnabled[it.key()]); |
|
686 | it.value()->setEnabled(subMenusEnabled[it.key()]); | |
687 | } |
|
687 | } | |
688 | } |
|
688 | } | |
689 |
|
689 | |||
690 | if (!graphMenu.isEmpty()) { |
|
690 | if (!graphMenu.isEmpty()) { | |
691 | graphMenu.exec(QCursor::pos()); |
|
691 | graphMenu.exec(QCursor::pos()); | |
692 | } |
|
692 | } | |
693 | } |
|
693 | } | |
694 |
|
694 | |||
695 | void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2) |
|
695 | void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2) | |
696 | { |
|
696 | { | |
697 | qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: VisualizationGraphWidget::onRangeChanged") |
|
697 | qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: VisualizationGraphWidget::onRangeChanged") | |
698 | << QThread::currentThread()->objectName() << "DoAcqui" |
|
698 | << QThread::currentThread()->objectName() << "DoAcqui" | |
699 |
<< impl->m_ |
|
699 | << impl->m_Flags.testFlag(GraphFlag::EnableAcquisition); | |
700 |
|
700 | |||
701 | auto graphRange = SqpRange{t1.lower, t1.upper}; |
|
701 | auto graphRange = SqpRange{t1.lower, t1.upper}; | |
702 | auto oldGraphRange = SqpRange{t2.lower, t2.upper}; |
|
702 | auto oldGraphRange = SqpRange{t2.lower, t2.upper}; | |
703 |
|
703 | |||
704 |
if (impl->m_ |
|
704 | if (impl->m_Flags.testFlag(GraphFlag::EnableAcquisition)) { | |
705 | QVector<std::shared_ptr<Variable> > variableUnderGraphVector; |
|
705 | QVector<std::shared_ptr<Variable> > variableUnderGraphVector; | |
706 |
|
706 | |||
707 | for (auto it = impl->m_VariableToPlotMultiMap.begin(), |
|
707 | for (auto it = impl->m_VariableToPlotMultiMap.begin(), | |
708 | end = impl->m_VariableToPlotMultiMap.end(); |
|
708 | end = impl->m_VariableToPlotMultiMap.end(); | |
709 | it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) { |
|
709 | it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) { | |
710 | variableUnderGraphVector.push_back(it->first); |
|
710 | variableUnderGraphVector.push_back(it->first); | |
711 | } |
|
711 | } | |
712 | emit requestDataLoading(std::move(variableUnderGraphVector), graphRange, |
|
712 | emit requestDataLoading(std::move(variableUnderGraphVector), graphRange, | |
713 | !impl->m_IsCalibration); |
|
713 | !impl->m_IsCalibration); | |
714 |
|
714 | |||
715 | if (!impl->m_IsCalibration) { |
|
715 | if (!impl->m_IsCalibration) { | |
716 | qCDebug(LOG_VisualizationGraphWidget()) |
|
716 | qCDebug(LOG_VisualizationGraphWidget()) | |
717 | << tr("TORM: VisualizationGraphWidget::Synchronize notify !!") |
|
717 | << tr("TORM: VisualizationGraphWidget::Synchronize notify !!") | |
718 | << QThread::currentThread()->objectName() << graphRange << oldGraphRange; |
|
718 | << QThread::currentThread()->objectName() << graphRange << oldGraphRange; | |
719 | emit synchronize(graphRange, oldGraphRange); |
|
719 | emit synchronize(graphRange, oldGraphRange); | |
720 | } |
|
720 | } | |
721 | } |
|
721 | } | |
722 |
|
722 | |||
723 | auto pos = mapFromGlobal(QCursor::pos()); |
|
723 | auto pos = mapFromGlobal(QCursor::pos()); | |
724 | auto axisPos = impl->posToAxisPos(pos, plot()); |
|
724 | auto axisPos = impl->posToAxisPos(pos, plot()); | |
725 | if (auto parentZone = parentZoneWidget()) { |
|
725 | if (auto parentZone = parentZoneWidget()) { | |
726 | if (impl->pointIsInAxisRect(axisPos, plot())) { |
|
726 | if (impl->pointIsInAxisRect(axisPos, plot())) { | |
727 | parentZone->notifyMouseMoveInGraph(pos, axisPos, this); |
|
727 | parentZone->notifyMouseMoveInGraph(pos, axisPos, this); | |
728 | } |
|
728 | } | |
729 | else { |
|
729 | else { | |
730 | parentZone->notifyMouseLeaveGraph(this); |
|
730 | parentZone->notifyMouseLeaveGraph(this); | |
731 | } |
|
731 | } | |
732 | } |
|
732 | } | |
733 | else { |
|
733 | else { | |
734 | qCWarning(LOG_VisualizationGraphWidget()) << "onMouseMove: No parent zone widget"; |
|
734 | qCWarning(LOG_VisualizationGraphWidget()) << "onMouseMove: No parent zone widget"; | |
735 | } |
|
735 | } | |
736 | } |
|
736 | } | |
737 |
|
737 | |||
738 | void VisualizationGraphWidget::onMouseDoubleClick(QMouseEvent *event) noexcept |
|
738 | void VisualizationGraphWidget::onMouseDoubleClick(QMouseEvent *event) noexcept | |
739 | { |
|
739 | { | |
740 | impl->m_RenderingDelegate->onMouseDoubleClick(event); |
|
740 | impl->m_RenderingDelegate->onMouseDoubleClick(event); | |
741 | } |
|
741 | } | |
742 |
|
742 | |||
743 | void VisualizationGraphWidget::onMouseMove(QMouseEvent *event) noexcept |
|
743 | void VisualizationGraphWidget::onMouseMove(QMouseEvent *event) noexcept | |
744 | { |
|
744 | { | |
745 | // Handles plot rendering when mouse is moving |
|
745 | // Handles plot rendering when mouse is moving | |
746 | impl->m_RenderingDelegate->onMouseMove(event); |
|
746 | impl->m_RenderingDelegate->onMouseMove(event); | |
747 |
|
747 | |||
748 | auto axisPos = impl->posToAxisPos(event->pos(), plot()); |
|
748 | auto axisPos = impl->posToAxisPos(event->pos(), plot()); | |
749 |
|
749 | |||
750 | // Zoom box and zone drawing |
|
750 | // Zoom box and zone drawing | |
751 | if (impl->m_DrawingZoomRect) { |
|
751 | if (impl->m_DrawingZoomRect) { | |
752 | impl->m_DrawingZoomRect->bottomRight->setCoords(axisPos); |
|
752 | impl->m_DrawingZoomRect->bottomRight->setCoords(axisPos); | |
753 | } |
|
753 | } | |
754 | else if (impl->m_DrawingZone) { |
|
754 | else if (impl->m_DrawingZone) { | |
755 | impl->m_DrawingZone->setEnd(axisPos.x()); |
|
755 | impl->m_DrawingZone->setEnd(axisPos.x()); | |
756 | } |
|
756 | } | |
757 |
|
757 | |||
758 | // Cursor |
|
758 | // Cursor | |
759 | if (auto parentZone = parentZoneWidget()) { |
|
759 | if (auto parentZone = parentZoneWidget()) { | |
760 | if (impl->pointIsInAxisRect(axisPos, plot())) { |
|
760 | if (impl->pointIsInAxisRect(axisPos, plot())) { | |
761 | parentZone->notifyMouseMoveInGraph(event->pos(), axisPos, this); |
|
761 | parentZone->notifyMouseMoveInGraph(event->pos(), axisPos, this); | |
762 | } |
|
762 | } | |
763 | else { |
|
763 | else { | |
764 | parentZone->notifyMouseLeaveGraph(this); |
|
764 | parentZone->notifyMouseLeaveGraph(this); | |
765 | } |
|
765 | } | |
766 | } |
|
766 | } | |
767 | else { |
|
767 | else { | |
768 | qCWarning(LOG_VisualizationGraphWidget()) << "onMouseMove: No parent zone widget"; |
|
768 | qCWarning(LOG_VisualizationGraphWidget()) << "onMouseMove: No parent zone widget"; | |
769 | } |
|
769 | } | |
770 |
|
770 | |||
771 | // Search for the selection zone under the mouse |
|
771 | // Search for the selection zone under the mouse | |
772 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos(), plot()); |
|
772 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos(), plot()); | |
773 | if (selectionZoneItemUnderCursor && !impl->m_DrawingZone |
|
773 | if (selectionZoneItemUnderCursor && !impl->m_DrawingZone | |
774 | && sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones) { |
|
774 | && sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones) { | |
775 |
|
775 | |||
776 | // Sets the appropriate cursor shape |
|
776 | // Sets the appropriate cursor shape | |
777 | auto cursorShape = selectionZoneItemUnderCursor->curshorShapeForPosition(event->pos()); |
|
777 | auto cursorShape = selectionZoneItemUnderCursor->curshorShapeForPosition(event->pos()); | |
778 | setCursor(cursorShape); |
|
778 | setCursor(cursorShape); | |
779 |
|
779 | |||
780 | // Manages the hovered zone |
|
780 | // Manages the hovered zone | |
781 | if (selectionZoneItemUnderCursor != impl->m_HoveredZone) { |
|
781 | if (selectionZoneItemUnderCursor != impl->m_HoveredZone) { | |
782 | if (impl->m_HoveredZone) { |
|
782 | if (impl->m_HoveredZone) { | |
783 | impl->m_HoveredZone->setHovered(false); |
|
783 | impl->m_HoveredZone->setHovered(false); | |
784 | } |
|
784 | } | |
785 | selectionZoneItemUnderCursor->setHovered(true); |
|
785 | selectionZoneItemUnderCursor->setHovered(true); | |
786 | impl->m_HoveredZone = selectionZoneItemUnderCursor; |
|
786 | impl->m_HoveredZone = selectionZoneItemUnderCursor; | |
787 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
787 | plot().replot(QCustomPlot::rpQueuedReplot); | |
788 | } |
|
788 | } | |
789 | } |
|
789 | } | |
790 | else { |
|
790 | else { | |
791 | // There is no zone under the mouse or the interaction mode is not "selection zones" |
|
791 | // There is no zone under the mouse or the interaction mode is not "selection zones" | |
792 | if (impl->m_HoveredZone) { |
|
792 | if (impl->m_HoveredZone) { | |
793 | impl->m_HoveredZone->setHovered(false); |
|
793 | impl->m_HoveredZone->setHovered(false); | |
794 | impl->m_HoveredZone = nullptr; |
|
794 | impl->m_HoveredZone = nullptr; | |
795 | } |
|
795 | } | |
796 |
|
796 | |||
797 | setCursor(Qt::ArrowCursor); |
|
797 | setCursor(Qt::ArrowCursor); | |
798 | } |
|
798 | } | |
799 |
|
799 | |||
800 | impl->m_HasMovedMouse = true; |
|
800 | impl->m_HasMovedMouse = true; | |
801 | VisualizationDragWidget::mouseMoveEvent(event); |
|
801 | VisualizationDragWidget::mouseMoveEvent(event); | |
802 | } |
|
802 | } | |
803 |
|
803 | |||
804 | void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept |
|
804 | void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept | |
805 | { |
|
805 | { | |
806 | auto value = event->angleDelta().x() + event->angleDelta().y(); |
|
806 | auto value = event->angleDelta().x() + event->angleDelta().y(); | |
807 | if (value != 0) { |
|
807 | if (value != 0) { | |
808 |
|
808 | |||
809 | auto direction = value > 0 ? 1.0 : -1.0; |
|
809 | auto direction = value > 0 ? 1.0 : -1.0; | |
810 | auto isZoomX = event->modifiers().testFlag(HORIZONTAL_ZOOM_MODIFIER); |
|
810 | auto isZoomX = event->modifiers().testFlag(HORIZONTAL_ZOOM_MODIFIER); | |
811 | auto isZoomY = event->modifiers().testFlag(VERTICAL_ZOOM_MODIFIER); |
|
811 | auto isZoomY = event->modifiers().testFlag(VERTICAL_ZOOM_MODIFIER); | |
812 | impl->m_IsCalibration = event->modifiers().testFlag(VERTICAL_PAN_MODIFIER); |
|
812 | impl->m_IsCalibration = event->modifiers().testFlag(VERTICAL_PAN_MODIFIER); | |
813 |
|
813 | |||
814 | auto zoomOrientations = QFlags<Qt::Orientation>{}; |
|
814 | auto zoomOrientations = QFlags<Qt::Orientation>{}; | |
815 | zoomOrientations.setFlag(Qt::Horizontal, isZoomX); |
|
815 | zoomOrientations.setFlag(Qt::Horizontal, isZoomX); | |
816 | zoomOrientations.setFlag(Qt::Vertical, isZoomY); |
|
816 | zoomOrientations.setFlag(Qt::Vertical, isZoomY); | |
817 |
|
817 | |||
818 | ui->widget->axisRect()->setRangeZoom(zoomOrientations); |
|
818 | ui->widget->axisRect()->setRangeZoom(zoomOrientations); | |
819 |
|
819 | |||
820 | if (!isZoomX && !isZoomY) { |
|
820 | if (!isZoomX && !isZoomY) { | |
821 | auto axis = plot().axisRect()->axis(QCPAxis::atBottom); |
|
821 | auto axis = plot().axisRect()->axis(QCPAxis::atBottom); | |
822 | auto diff = direction * (axis->range().size() * (PAN_SPEED / 100.0)); |
|
822 | auto diff = direction * (axis->range().size() * (PAN_SPEED / 100.0)); | |
823 |
|
823 | |||
824 | axis->setRange(axis->range() + diff); |
|
824 | axis->setRange(axis->range() + diff); | |
825 |
|
825 | |||
826 | if (plot().noAntialiasingOnDrag()) { |
|
826 | if (plot().noAntialiasingOnDrag()) { | |
827 | plot().setNotAntialiasedElements(QCP::aeAll); |
|
827 | plot().setNotAntialiasedElements(QCP::aeAll); | |
828 | } |
|
828 | } | |
829 |
|
829 | |||
830 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
830 | plot().replot(QCustomPlot::rpQueuedReplot); | |
831 | } |
|
831 | } | |
832 | } |
|
832 | } | |
833 | } |
|
833 | } | |
834 |
|
834 | |||
835 | void VisualizationGraphWidget::onMousePress(QMouseEvent *event) noexcept |
|
835 | void VisualizationGraphWidget::onMousePress(QMouseEvent *event) noexcept | |
836 | { |
|
836 | { | |
837 | auto isDragDropClick = event->modifiers().testFlag(DRAG_DROP_MODIFIER); |
|
837 | auto isDragDropClick = event->modifiers().testFlag(DRAG_DROP_MODIFIER); | |
838 | auto isSelectionZoneMode |
|
838 | auto isSelectionZoneMode | |
839 | = sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones; |
|
839 | = sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones; | |
840 | auto isLeftClick = event->buttons().testFlag(Qt::LeftButton); |
|
840 | auto isLeftClick = event->buttons().testFlag(Qt::LeftButton); | |
841 |
|
841 | |||
842 | if (!isDragDropClick && isLeftClick) { |
|
842 | if (!isDragDropClick && isLeftClick) { | |
843 | if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::ZoomBox) { |
|
843 | if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::ZoomBox) { | |
844 | // Starts a zoom box |
|
844 | // Starts a zoom box | |
845 | impl->startDrawingRect(event->pos(), plot()); |
|
845 | impl->startDrawingRect(event->pos(), plot()); | |
846 | } |
|
846 | } | |
847 | else if (isSelectionZoneMode && impl->m_DrawingZone == nullptr) { |
|
847 | else if (isSelectionZoneMode && impl->m_DrawingZone == nullptr) { | |
848 | // Starts a new selection zone |
|
848 | // Starts a new selection zone | |
849 | auto zoneAtPos = impl->selectionZoneAt(event->pos(), plot()); |
|
849 | auto zoneAtPos = impl->selectionZoneAt(event->pos(), plot()); | |
850 | if (!zoneAtPos) { |
|
850 | if (!zoneAtPos) { | |
851 | impl->startDrawingZone(event->pos(), this); |
|
851 | impl->startDrawingZone(event->pos(), this); | |
852 | } |
|
852 | } | |
853 | } |
|
853 | } | |
854 | } |
|
854 | } | |
855 |
|
855 | |||
856 | // Allows mouse panning only in default mode |
|
856 | // Allows mouse panning only in default mode | |
857 | plot().setInteraction(QCP::iRangeDrag, sqpApp->plotsInteractionMode() |
|
857 | plot().setInteraction(QCP::iRangeDrag, sqpApp->plotsInteractionMode() | |
858 | == SqpApplication::PlotsInteractionMode::None |
|
858 | == SqpApplication::PlotsInteractionMode::None | |
859 | && !isDragDropClick); |
|
859 | && !isDragDropClick); | |
860 |
|
860 | |||
861 | // Allows zone edition only in selection zone mode without drag&drop |
|
861 | // Allows zone edition only in selection zone mode without drag&drop | |
862 | impl->setSelectionZonesEditionEnabled(isSelectionZoneMode && !isDragDropClick); |
|
862 | impl->setSelectionZonesEditionEnabled(isSelectionZoneMode && !isDragDropClick); | |
863 |
|
863 | |||
864 | // Selection / Deselection |
|
864 | // Selection / Deselection | |
865 | if (isSelectionZoneMode) { |
|
865 | if (isSelectionZoneMode) { | |
866 | auto isMultiSelectionClick = event->modifiers().testFlag(MULTI_ZONE_SELECTION_MODIFIER); |
|
866 | auto isMultiSelectionClick = event->modifiers().testFlag(MULTI_ZONE_SELECTION_MODIFIER); | |
867 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos(), plot()); |
|
867 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos(), plot()); | |
868 |
|
868 | |||
869 |
|
869 | |||
870 | if (selectionZoneItemUnderCursor && !selectionZoneItemUnderCursor->selected() |
|
870 | if (selectionZoneItemUnderCursor && !selectionZoneItemUnderCursor->selected() | |
871 | && !isMultiSelectionClick) { |
|
871 | && !isMultiSelectionClick) { | |
872 | parentVisualizationWidget()->selectionZoneManager().select( |
|
872 | parentVisualizationWidget()->selectionZoneManager().select( | |
873 | {selectionZoneItemUnderCursor}); |
|
873 | {selectionZoneItemUnderCursor}); | |
874 | } |
|
874 | } | |
875 | else if (!selectionZoneItemUnderCursor && !isMultiSelectionClick && isLeftClick) { |
|
875 | else if (!selectionZoneItemUnderCursor && !isMultiSelectionClick && isLeftClick) { | |
876 | parentVisualizationWidget()->selectionZoneManager().clearSelection(); |
|
876 | parentVisualizationWidget()->selectionZoneManager().clearSelection(); | |
877 | } |
|
877 | } | |
878 | else { |
|
878 | else { | |
879 | // No selection change |
|
879 | // No selection change | |
880 | } |
|
880 | } | |
881 |
|
881 | |||
882 | if (selectionZoneItemUnderCursor && isLeftClick) { |
|
882 | if (selectionZoneItemUnderCursor && isLeftClick) { | |
883 | selectionZoneItemUnderCursor->setAssociatedEditedZones( |
|
883 | selectionZoneItemUnderCursor->setAssociatedEditedZones( | |
884 | parentVisualizationWidget()->selectionZoneManager().selectedItems()); |
|
884 | parentVisualizationWidget()->selectionZoneManager().selectedItems()); | |
885 | } |
|
885 | } | |
886 | } |
|
886 | } | |
887 |
|
887 | |||
888 |
|
888 | |||
889 | impl->m_HasMovedMouse = false; |
|
889 | impl->m_HasMovedMouse = false; | |
890 | VisualizationDragWidget::mousePressEvent(event); |
|
890 | VisualizationDragWidget::mousePressEvent(event); | |
891 | } |
|
891 | } | |
892 |
|
892 | |||
893 | void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept |
|
893 | void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept | |
894 | { |
|
894 | { | |
895 | if (impl->m_DrawingZoomRect) { |
|
895 | if (impl->m_DrawingZoomRect) { | |
896 |
|
896 | |||
897 | auto axisX = plot().axisRect()->axis(QCPAxis::atBottom); |
|
897 | auto axisX = plot().axisRect()->axis(QCPAxis::atBottom); | |
898 | auto axisY = plot().axisRect()->axis(QCPAxis::atLeft); |
|
898 | auto axisY = plot().axisRect()->axis(QCPAxis::atLeft); | |
899 |
|
899 | |||
900 | auto newAxisXRange = QCPRange{impl->m_DrawingZoomRect->topLeft->coords().x(), |
|
900 | auto newAxisXRange = QCPRange{impl->m_DrawingZoomRect->topLeft->coords().x(), | |
901 | impl->m_DrawingZoomRect->bottomRight->coords().x()}; |
|
901 | impl->m_DrawingZoomRect->bottomRight->coords().x()}; | |
902 |
|
902 | |||
903 | auto newAxisYRange = QCPRange{impl->m_DrawingZoomRect->topLeft->coords().y(), |
|
903 | auto newAxisYRange = QCPRange{impl->m_DrawingZoomRect->topLeft->coords().y(), | |
904 | impl->m_DrawingZoomRect->bottomRight->coords().y()}; |
|
904 | impl->m_DrawingZoomRect->bottomRight->coords().y()}; | |
905 |
|
905 | |||
906 | impl->removeDrawingRect(plot()); |
|
906 | impl->removeDrawingRect(plot()); | |
907 |
|
907 | |||
908 | if (newAxisXRange.size() > axisX->range().size() * (ZOOM_BOX_MIN_SIZE / 100.0) |
|
908 | if (newAxisXRange.size() > axisX->range().size() * (ZOOM_BOX_MIN_SIZE / 100.0) | |
909 | && newAxisYRange.size() > axisY->range().size() * (ZOOM_BOX_MIN_SIZE / 100.0)) { |
|
909 | && newAxisYRange.size() > axisY->range().size() * (ZOOM_BOX_MIN_SIZE / 100.0)) { | |
910 | impl->m_ZoomStack.push(qMakePair(axisX->range(), axisY->range())); |
|
910 | impl->m_ZoomStack.push(qMakePair(axisX->range(), axisY->range())); | |
911 | axisX->setRange(newAxisXRange); |
|
911 | axisX->setRange(newAxisXRange); | |
912 | axisY->setRange(newAxisYRange); |
|
912 | axisY->setRange(newAxisYRange); | |
913 |
|
913 | |||
914 | plot().replot(QCustomPlot::rpQueuedReplot); |
|
914 | plot().replot(QCustomPlot::rpQueuedReplot); | |
915 | } |
|
915 | } | |
916 | } |
|
916 | } | |
917 |
|
917 | |||
918 | impl->endDrawingZone(this); |
|
918 | impl->endDrawingZone(this); | |
919 |
|
919 | |||
920 | impl->m_IsCalibration = false; |
|
920 | impl->m_IsCalibration = false; | |
921 |
|
921 | |||
922 | // Selection / Deselection |
|
922 | // Selection / Deselection | |
923 | auto isSelectionZoneMode |
|
923 | auto isSelectionZoneMode | |
924 | = sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones; |
|
924 | = sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones; | |
925 | if (isSelectionZoneMode) { |
|
925 | if (isSelectionZoneMode) { | |
926 | auto isMultiSelectionClick = event->modifiers().testFlag(MULTI_ZONE_SELECTION_MODIFIER); |
|
926 | auto isMultiSelectionClick = event->modifiers().testFlag(MULTI_ZONE_SELECTION_MODIFIER); | |
927 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos(), plot()); |
|
927 | auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos(), plot()); | |
928 | if (selectionZoneItemUnderCursor && event->button() == Qt::LeftButton |
|
928 | if (selectionZoneItemUnderCursor && event->button() == Qt::LeftButton | |
929 | && !impl->m_HasMovedMouse) { |
|
929 | && !impl->m_HasMovedMouse) { | |
930 |
|
930 | |||
931 | auto zonesUnderCursor = impl->selectionZonesAt(event->pos(), plot()); |
|
931 | auto zonesUnderCursor = impl->selectionZonesAt(event->pos(), plot()); | |
932 | if (zonesUnderCursor.count() > 1) { |
|
932 | if (zonesUnderCursor.count() > 1) { | |
933 | // There are multiple zones under the mouse. |
|
933 | // There are multiple zones under the mouse. | |
934 | // Performs the selection with a selection dialog. |
|
934 | // Performs the selection with a selection dialog. | |
935 | VisualizationMultiZoneSelectionDialog dialog{this}; |
|
935 | VisualizationMultiZoneSelectionDialog dialog{this}; | |
936 | dialog.setZones(zonesUnderCursor); |
|
936 | dialog.setZones(zonesUnderCursor); | |
937 | dialog.move(mapToGlobal(event->pos() - QPoint(dialog.width() / 2, 20))); |
|
937 | dialog.move(mapToGlobal(event->pos() - QPoint(dialog.width() / 2, 20))); | |
938 | dialog.activateWindow(); |
|
938 | dialog.activateWindow(); | |
939 | dialog.raise(); |
|
939 | dialog.raise(); | |
940 | if (dialog.exec() == QDialog::Accepted) { |
|
940 | if (dialog.exec() == QDialog::Accepted) { | |
941 | auto selection = dialog.selectedZones(); |
|
941 | auto selection = dialog.selectedZones(); | |
942 |
|
942 | |||
943 | if (!isMultiSelectionClick) { |
|
943 | if (!isMultiSelectionClick) { | |
944 | parentVisualizationWidget()->selectionZoneManager().clearSelection(); |
|
944 | parentVisualizationWidget()->selectionZoneManager().clearSelection(); | |
945 | } |
|
945 | } | |
946 |
|
946 | |||
947 | for (auto it = selection.cbegin(); it != selection.cend(); ++it) { |
|
947 | for (auto it = selection.cbegin(); it != selection.cend(); ++it) { | |
948 | auto zone = it.key(); |
|
948 | auto zone = it.key(); | |
949 | auto isSelected = it.value(); |
|
949 | auto isSelected = it.value(); | |
950 | parentVisualizationWidget()->selectionZoneManager().setSelected(zone, |
|
950 | parentVisualizationWidget()->selectionZoneManager().setSelected(zone, | |
951 | isSelected); |
|
951 | isSelected); | |
952 |
|
952 | |||
953 | if (isSelected) { |
|
953 | if (isSelected) { | |
954 | // Puts the zone on top of the stack so it can be moved or resized |
|
954 | // Puts the zone on top of the stack so it can be moved or resized | |
955 | impl->moveSelectionZoneOnTop(zone, plot()); |
|
955 | impl->moveSelectionZoneOnTop(zone, plot()); | |
956 | } |
|
956 | } | |
957 | } |
|
957 | } | |
958 | } |
|
958 | } | |
959 | } |
|
959 | } | |
960 | else { |
|
960 | else { | |
961 | if (!isMultiSelectionClick) { |
|
961 | if (!isMultiSelectionClick) { | |
962 | parentVisualizationWidget()->selectionZoneManager().select( |
|
962 | parentVisualizationWidget()->selectionZoneManager().select( | |
963 | {selectionZoneItemUnderCursor}); |
|
963 | {selectionZoneItemUnderCursor}); | |
964 | impl->moveSelectionZoneOnTop(selectionZoneItemUnderCursor, plot()); |
|
964 | impl->moveSelectionZoneOnTop(selectionZoneItemUnderCursor, plot()); | |
965 | } |
|
965 | } | |
966 | else { |
|
966 | else { | |
967 | parentVisualizationWidget()->selectionZoneManager().setSelected( |
|
967 | parentVisualizationWidget()->selectionZoneManager().setSelected( | |
968 | selectionZoneItemUnderCursor, !selectionZoneItemUnderCursor->selected() |
|
968 | selectionZoneItemUnderCursor, !selectionZoneItemUnderCursor->selected() | |
969 | || event->button() == Qt::RightButton); |
|
969 | || event->button() == Qt::RightButton); | |
970 | } |
|
970 | } | |
971 | } |
|
971 | } | |
972 | } |
|
972 | } | |
973 | else { |
|
973 | else { | |
974 | // No selection change |
|
974 | // No selection change | |
975 | } |
|
975 | } | |
976 | } |
|
976 | } | |
977 | } |
|
977 | } | |
978 |
|
978 | |||
979 | void VisualizationGraphWidget::onDataCacheVariableUpdated() |
|
979 | void VisualizationGraphWidget::onDataCacheVariableUpdated() | |
980 | { |
|
980 | { | |
981 | auto graphRange = ui->widget->xAxis->range(); |
|
981 | auto graphRange = ui->widget->xAxis->range(); | |
982 | auto dateTime = SqpRange{graphRange.lower, graphRange.upper}; |
|
982 | auto dateTime = SqpRange{graphRange.lower, graphRange.upper}; | |
983 |
|
983 | |||
984 | for (auto &variableEntry : impl->m_VariableToPlotMultiMap) { |
|
984 | for (auto &variableEntry : impl->m_VariableToPlotMultiMap) { | |
985 | auto variable = variableEntry.first; |
|
985 | auto variable = variableEntry.first; | |
986 | qCDebug(LOG_VisualizationGraphWidget()) |
|
986 | qCDebug(LOG_VisualizationGraphWidget()) | |
987 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated S" << variable->range(); |
|
987 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated S" << variable->range(); | |
988 | qCDebug(LOG_VisualizationGraphWidget()) |
|
988 | qCDebug(LOG_VisualizationGraphWidget()) | |
989 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated E" << dateTime; |
|
989 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated E" << dateTime; | |
990 | if (dateTime.contains(variable->range()) || dateTime.intersect(variable->range())) { |
|
990 | if (dateTime.contains(variable->range()) || dateTime.intersect(variable->range())) { | |
991 | impl->updateData(variableEntry.second, variable->dataSeries(), variable->range()); |
|
991 | impl->updateData(variableEntry.second, variable->dataSeries(), variable->range()); | |
992 | } |
|
992 | } | |
993 | } |
|
993 | } | |
994 | } |
|
994 | } | |
995 |
|
995 | |||
996 | void VisualizationGraphWidget::onUpdateVarDisplaying(std::shared_ptr<Variable> variable, |
|
996 | void VisualizationGraphWidget::onUpdateVarDisplaying(std::shared_ptr<Variable> variable, | |
997 | const SqpRange &range) |
|
997 | const SqpRange &range) | |
998 | { |
|
998 | { | |
999 | auto it = impl->m_VariableToPlotMultiMap.find(variable); |
|
999 | auto it = impl->m_VariableToPlotMultiMap.find(variable); | |
1000 | if (it != impl->m_VariableToPlotMultiMap.end()) { |
|
1000 | if (it != impl->m_VariableToPlotMultiMap.end()) { | |
1001 | impl->updateData(it->second, variable->dataSeries(), range); |
|
1001 | impl->updateData(it->second, variable->dataSeries(), range); | |
1002 | } |
|
1002 | } | |
1003 | } |
|
1003 | } |
@@ -1,601 +1,601 | |||||
1 | #include "Visualization/VisualizationZoneWidget.h" |
|
1 | #include "Visualization/VisualizationZoneWidget.h" | |
2 |
|
2 | |||
3 | #include "Visualization/IVisualizationWidgetVisitor.h" |
|
3 | #include "Visualization/IVisualizationWidgetVisitor.h" | |
4 | #include "Visualization/QCustomPlotSynchronizer.h" |
|
4 | #include "Visualization/QCustomPlotSynchronizer.h" | |
5 | #include "Visualization/VisualizationGraphWidget.h" |
|
5 | #include "Visualization/VisualizationGraphWidget.h" | |
6 | #include "Visualization/VisualizationWidget.h" |
|
6 | #include "Visualization/VisualizationWidget.h" | |
7 | #include "ui_VisualizationZoneWidget.h" |
|
7 | #include "ui_VisualizationZoneWidget.h" | |
8 |
|
8 | |||
9 | #include "Common/MimeTypesDef.h" |
|
9 | #include "Common/MimeTypesDef.h" | |
10 | #include "Common/VisualizationDef.h" |
|
10 | #include "Common/VisualizationDef.h" | |
11 |
|
11 | |||
12 | #include <Data/SqpRange.h> |
|
12 | #include <Data/SqpRange.h> | |
13 | #include <Time/TimeController.h> |
|
13 | #include <Time/TimeController.h> | |
14 | #include <Variable/Variable.h> |
|
14 | #include <Variable/Variable.h> | |
15 | #include <Variable/VariableController.h> |
|
15 | #include <Variable/VariableController.h> | |
16 |
|
16 | |||
17 | #include <Visualization/operations/FindVariableOperation.h> |
|
17 | #include <Visualization/operations/FindVariableOperation.h> | |
18 |
|
18 | |||
19 | #include <DragAndDrop/DragDropGuiController.h> |
|
19 | #include <DragAndDrop/DragDropGuiController.h> | |
20 | #include <QUuid> |
|
20 | #include <QUuid> | |
21 | #include <SqpApplication.h> |
|
21 | #include <SqpApplication.h> | |
22 | #include <cmath> |
|
22 | #include <cmath> | |
23 |
|
23 | |||
24 | #include <QLayout> |
|
24 | #include <QLayout> | |
25 |
|
25 | |||
26 | Q_LOGGING_CATEGORY(LOG_VisualizationZoneWidget, "VisualizationZoneWidget") |
|
26 | Q_LOGGING_CATEGORY(LOG_VisualizationZoneWidget, "VisualizationZoneWidget") | |
27 |
|
27 | |||
28 | namespace { |
|
28 | namespace { | |
29 |
|
29 | |||
30 | /** |
|
30 | /** | |
31 | * Applies a function to all graphs of the zone represented by its layout |
|
31 | * Applies a function to all graphs of the zone represented by its layout | |
32 | * @param layout the layout that contains graphs |
|
32 | * @param layout the layout that contains graphs | |
33 | * @param fun the function to apply to each graph |
|
33 | * @param fun the function to apply to each graph | |
34 | */ |
|
34 | */ | |
35 | template <typename Fun> |
|
35 | template <typename Fun> | |
36 | void processGraphs(QLayout &layout, Fun fun) |
|
36 | void processGraphs(QLayout &layout, Fun fun) | |
37 | { |
|
37 | { | |
38 | for (auto i = 0; i < layout.count(); ++i) { |
|
38 | for (auto i = 0; i < layout.count(); ++i) { | |
39 | if (auto item = layout.itemAt(i)) { |
|
39 | if (auto item = layout.itemAt(i)) { | |
40 | if (auto visualizationGraphWidget |
|
40 | if (auto visualizationGraphWidget | |
41 | = qobject_cast<VisualizationGraphWidget *>(item->widget())) { |
|
41 | = qobject_cast<VisualizationGraphWidget *>(item->widget())) { | |
42 | fun(*visualizationGraphWidget); |
|
42 | fun(*visualizationGraphWidget); | |
43 | } |
|
43 | } | |
44 | } |
|
44 | } | |
45 | } |
|
45 | } | |
46 | } |
|
46 | } | |
47 |
|
47 | |||
48 | /// Generates a default name for a new graph, according to the number of graphs already displayed in |
|
48 | /// Generates a default name for a new graph, according to the number of graphs already displayed in | |
49 | /// the zone |
|
49 | /// the zone | |
50 | QString defaultGraphName(QLayout &layout) |
|
50 | QString defaultGraphName(QLayout &layout) | |
51 | { |
|
51 | { | |
52 | QSet<QString> existingNames; |
|
52 | QSet<QString> existingNames; | |
53 | processGraphs( |
|
53 | processGraphs( | |
54 | layout, [&existingNames](auto &graphWidget) { existingNames.insert(graphWidget.name()); }); |
|
54 | layout, [&existingNames](auto &graphWidget) { existingNames.insert(graphWidget.name()); }); | |
55 |
|
55 | |||
56 | int zoneNum = 1; |
|
56 | int zoneNum = 1; | |
57 | QString name; |
|
57 | QString name; | |
58 | do { |
|
58 | do { | |
59 | name = QObject::tr("Graph ").append(QString::number(zoneNum)); |
|
59 | name = QObject::tr("Graph ").append(QString::number(zoneNum)); | |
60 | ++zoneNum; |
|
60 | ++zoneNum; | |
61 | } while (existingNames.contains(name)); |
|
61 | } while (existingNames.contains(name)); | |
62 |
|
62 | |||
63 | return name; |
|
63 | return name; | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | } // namespace |
|
66 | } // namespace | |
67 |
|
67 | |||
68 | struct VisualizationZoneWidget::VisualizationZoneWidgetPrivate { |
|
68 | struct VisualizationZoneWidget::VisualizationZoneWidgetPrivate { | |
69 |
|
69 | |||
70 | explicit VisualizationZoneWidgetPrivate() |
|
70 | explicit VisualizationZoneWidgetPrivate() | |
71 | : m_SynchronisationGroupId{QUuid::createUuid()}, |
|
71 | : m_SynchronisationGroupId{QUuid::createUuid()}, | |
72 | m_Synchronizer{std::make_unique<QCustomPlotSynchronizer>()} |
|
72 | m_Synchronizer{std::make_unique<QCustomPlotSynchronizer>()} | |
73 | { |
|
73 | { | |
74 | } |
|
74 | } | |
75 | QUuid m_SynchronisationGroupId; |
|
75 | QUuid m_SynchronisationGroupId; | |
76 | std::unique_ptr<IGraphSynchronizer> m_Synchronizer; |
|
76 | std::unique_ptr<IGraphSynchronizer> m_Synchronizer; | |
77 |
|
77 | |||
78 | void dropGraph(int index, VisualizationZoneWidget *zoneWidget); |
|
78 | void dropGraph(int index, VisualizationZoneWidget *zoneWidget); | |
79 | void dropVariables(const QList<std::shared_ptr<Variable> > &variables, int index, |
|
79 | void dropVariables(const QList<std::shared_ptr<Variable> > &variables, int index, | |
80 | VisualizationZoneWidget *zoneWidget); |
|
80 | VisualizationZoneWidget *zoneWidget); | |
81 | }; |
|
81 | }; | |
82 |
|
82 | |||
83 | VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent) |
|
83 | VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent) | |
84 | : VisualizationDragWidget{parent}, |
|
84 | : VisualizationDragWidget{parent}, | |
85 | ui{new Ui::VisualizationZoneWidget}, |
|
85 | ui{new Ui::VisualizationZoneWidget}, | |
86 | impl{spimpl::make_unique_impl<VisualizationZoneWidgetPrivate>()} |
|
86 | impl{spimpl::make_unique_impl<VisualizationZoneWidgetPrivate>()} | |
87 | { |
|
87 | { | |
88 | ui->setupUi(this); |
|
88 | ui->setupUi(this); | |
89 |
|
89 | |||
90 | ui->zoneNameLabel->setText(name); |
|
90 | ui->zoneNameLabel->setText(name); | |
91 |
|
91 | |||
92 | ui->dragDropContainer->setPlaceHolderType(DragDropGuiController::PlaceHolderType::Graph); |
|
92 | ui->dragDropContainer->setPlaceHolderType(DragDropGuiController::PlaceHolderType::Graph); | |
93 | ui->dragDropContainer->setMimeType(MIME_TYPE_GRAPH, |
|
93 | ui->dragDropContainer->setMimeType(MIME_TYPE_GRAPH, | |
94 | VisualizationDragDropContainer::DropBehavior::Inserted); |
|
94 | VisualizationDragDropContainer::DropBehavior::Inserted); | |
95 | ui->dragDropContainer->setMimeType( |
|
95 | ui->dragDropContainer->setMimeType( | |
96 | MIME_TYPE_VARIABLE_LIST, VisualizationDragDropContainer::DropBehavior::InsertedAndMerged); |
|
96 | MIME_TYPE_VARIABLE_LIST, VisualizationDragDropContainer::DropBehavior::InsertedAndMerged); | |
97 | ui->dragDropContainer->setMimeType(MIME_TYPE_TIME_RANGE, |
|
97 | ui->dragDropContainer->setMimeType(MIME_TYPE_TIME_RANGE, | |
98 | VisualizationDragDropContainer::DropBehavior::Merged); |
|
98 | VisualizationDragDropContainer::DropBehavior::Merged); | |
99 | ui->dragDropContainer->setMimeType(MIME_TYPE_ZONE, |
|
99 | ui->dragDropContainer->setMimeType(MIME_TYPE_ZONE, | |
100 | VisualizationDragDropContainer::DropBehavior::Forbidden); |
|
100 | VisualizationDragDropContainer::DropBehavior::Forbidden); | |
101 | ui->dragDropContainer->setMimeType(MIME_TYPE_SELECTION_ZONE, |
|
101 | ui->dragDropContainer->setMimeType(MIME_TYPE_SELECTION_ZONE, | |
102 | VisualizationDragDropContainer::DropBehavior::Forbidden); |
|
102 | VisualizationDragDropContainer::DropBehavior::Forbidden); | |
103 | ui->dragDropContainer->setAcceptMimeDataFunction([this](auto mimeData) { |
|
103 | ui->dragDropContainer->setAcceptMimeDataFunction([this](auto mimeData) { | |
104 | return sqpApp->dragDropGuiController().checkMimeDataForVisualization(mimeData, |
|
104 | return sqpApp->dragDropGuiController().checkMimeDataForVisualization(mimeData, | |
105 | ui->dragDropContainer); |
|
105 | ui->dragDropContainer); | |
106 | }); |
|
106 | }); | |
107 |
|
107 | |||
108 | auto acceptDragWidgetFun = [](auto dragWidget, auto mimeData) { |
|
108 | auto acceptDragWidgetFun = [](auto dragWidget, auto mimeData) { | |
109 | if (!mimeData) { |
|
109 | if (!mimeData) { | |
110 | return false; |
|
110 | return false; | |
111 | } |
|
111 | } | |
112 |
|
112 | |||
113 | if (mimeData->hasFormat(MIME_TYPE_VARIABLE_LIST)) { |
|
113 | if (mimeData->hasFormat(MIME_TYPE_VARIABLE_LIST)) { | |
114 | auto variables = sqpApp->variableController().variablesForMimeData( |
|
114 | auto variables = sqpApp->variableController().variablesForMimeData( | |
115 | mimeData->data(MIME_TYPE_VARIABLE_LIST)); |
|
115 | mimeData->data(MIME_TYPE_VARIABLE_LIST)); | |
116 |
|
116 | |||
117 | if (variables.count() != 1) { |
|
117 | if (variables.count() != 1) { | |
118 | return false; |
|
118 | return false; | |
119 | } |
|
119 | } | |
120 | auto variable = variables.first(); |
|
120 | auto variable = variables.first(); | |
121 |
|
121 | |||
122 | if (auto graphWidget = dynamic_cast<const VisualizationGraphWidget *>(dragWidget)) { |
|
122 | if (auto graphWidget = dynamic_cast<const VisualizationGraphWidget *>(dragWidget)) { | |
123 | return graphWidget->canDrop(*variable); |
|
123 | return graphWidget->canDrop(*variable); | |
124 | } |
|
124 | } | |
125 | } |
|
125 | } | |
126 |
|
126 | |||
127 | return true; |
|
127 | return true; | |
128 | }; |
|
128 | }; | |
129 | ui->dragDropContainer->setAcceptDragWidgetFunction(acceptDragWidgetFun); |
|
129 | ui->dragDropContainer->setAcceptDragWidgetFunction(acceptDragWidgetFun); | |
130 |
|
130 | |||
131 | connect(ui->dragDropContainer, &VisualizationDragDropContainer::dropOccuredInContainer, this, |
|
131 | connect(ui->dragDropContainer, &VisualizationDragDropContainer::dropOccuredInContainer, this, | |
132 | &VisualizationZoneWidget::dropMimeData); |
|
132 | &VisualizationZoneWidget::dropMimeData); | |
133 | connect(ui->dragDropContainer, &VisualizationDragDropContainer::dropOccuredOnWidget, this, |
|
133 | connect(ui->dragDropContainer, &VisualizationDragDropContainer::dropOccuredOnWidget, this, | |
134 | &VisualizationZoneWidget::dropMimeDataOnGraph); |
|
134 | &VisualizationZoneWidget::dropMimeDataOnGraph); | |
135 |
|
135 | |||
136 | // 'Close' options : widget is deleted when closed |
|
136 | // 'Close' options : widget is deleted when closed | |
137 | setAttribute(Qt::WA_DeleteOnClose); |
|
137 | setAttribute(Qt::WA_DeleteOnClose); | |
138 | connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationZoneWidget::close); |
|
138 | connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationZoneWidget::close); | |
139 | ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton)); |
|
139 | ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton)); | |
140 |
|
140 | |||
141 | // Synchronisation id |
|
141 | // Synchronisation id | |
142 | QMetaObject::invokeMethod(&sqpApp->variableController(), "onAddSynchronizationGroupId", |
|
142 | QMetaObject::invokeMethod(&sqpApp->variableController(), "onAddSynchronizationGroupId", | |
143 | Qt::QueuedConnection, Q_ARG(QUuid, impl->m_SynchronisationGroupId)); |
|
143 | Qt::QueuedConnection, Q_ARG(QUuid, impl->m_SynchronisationGroupId)); | |
144 | } |
|
144 | } | |
145 |
|
145 | |||
146 | VisualizationZoneWidget::~VisualizationZoneWidget() |
|
146 | VisualizationZoneWidget::~VisualizationZoneWidget() | |
147 | { |
|
147 | { | |
148 | delete ui; |
|
148 | delete ui; | |
149 | } |
|
149 | } | |
150 |
|
150 | |||
151 | void VisualizationZoneWidget::setZoneRange(const SqpRange &range) |
|
151 | void VisualizationZoneWidget::setZoneRange(const SqpRange &range) | |
152 | { |
|
152 | { | |
153 | if (auto graph = firstGraph()) { |
|
153 | if (auto graph = firstGraph()) { | |
154 | graph->setGraphRange(range); |
|
154 | graph->setGraphRange(range); | |
155 | } |
|
155 | } | |
156 | else { |
|
156 | else { | |
157 | qCWarning(LOG_VisualizationZoneWidget()) |
|
157 | qCWarning(LOG_VisualizationZoneWidget()) | |
158 | << tr("setZoneRange:Cannot set the range of an empty zone."); |
|
158 | << tr("setZoneRange:Cannot set the range of an empty zone."); | |
159 | } |
|
159 | } | |
160 | } |
|
160 | } | |
161 |
|
161 | |||
162 | void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget) |
|
162 | void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget) | |
163 | { |
|
163 | { | |
164 | // Synchronize new graph with others in the zone |
|
164 | // Synchronize new graph with others in the zone | |
165 | impl->m_Synchronizer->addGraph(*graphWidget); |
|
165 | impl->m_Synchronizer->addGraph(*graphWidget); | |
166 |
|
166 | |||
167 | ui->dragDropContainer->addDragWidget(graphWidget); |
|
167 | ui->dragDropContainer->addDragWidget(graphWidget); | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 | void VisualizationZoneWidget::insertGraph(int index, VisualizationGraphWidget *graphWidget) |
|
170 | void VisualizationZoneWidget::insertGraph(int index, VisualizationGraphWidget *graphWidget) | |
171 | { |
|
171 | { | |
172 | // Synchronize new graph with others in the zone |
|
172 | // Synchronize new graph with others in the zone | |
173 | impl->m_Synchronizer->addGraph(*graphWidget); |
|
173 | impl->m_Synchronizer->addGraph(*graphWidget); | |
174 |
|
174 | |||
175 | ui->dragDropContainer->insertDragWidget(index, graphWidget); |
|
175 | ui->dragDropContainer->insertDragWidget(index, graphWidget); | |
176 | } |
|
176 | } | |
177 |
|
177 | |||
178 | VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable) |
|
178 | VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable) | |
179 | { |
|
179 | { | |
180 | return createGraph(variable, -1); |
|
180 | return createGraph(variable, -1); | |
181 | } |
|
181 | } | |
182 |
|
182 | |||
183 | VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable, |
|
183 | VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable, | |
184 | int index) |
|
184 | int index) | |
185 | { |
|
185 | { | |
186 | auto graphWidget |
|
186 | auto graphWidget | |
187 | = new VisualizationGraphWidget{defaultGraphName(*ui->dragDropContainer->layout()), this}; |
|
187 | = new VisualizationGraphWidget{defaultGraphName(*ui->dragDropContainer->layout()), this}; | |
188 |
|
188 | |||
189 |
|
189 | |||
190 | // Set graph properties |
|
190 | // Set graph properties | |
191 | graphWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); |
|
191 | graphWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); | |
192 | graphWidget->setMinimumHeight(GRAPH_MINIMUM_HEIGHT); |
|
192 | graphWidget->setMinimumHeight(GRAPH_MINIMUM_HEIGHT); | |
193 |
|
193 | |||
194 |
|
194 | |||
195 | // Lambda to synchronize zone widget |
|
195 | // Lambda to synchronize zone widget | |
196 | auto synchronizeZoneWidget = [this, graphWidget](const SqpRange &graphRange, |
|
196 | auto synchronizeZoneWidget = [this, graphWidget](const SqpRange &graphRange, | |
197 | const SqpRange &oldGraphRange) { |
|
197 | const SqpRange &oldGraphRange) { | |
198 |
|
198 | |||
199 | auto zoomType = VariableController::getZoomType(graphRange, oldGraphRange); |
|
199 | auto zoomType = VariableController::getZoomType(graphRange, oldGraphRange); | |
200 | auto frameLayout = ui->dragDropContainer->layout(); |
|
200 | auto frameLayout = ui->dragDropContainer->layout(); | |
201 | for (auto i = 0; i < frameLayout->count(); ++i) { |
|
201 | for (auto i = 0; i < frameLayout->count(); ++i) { | |
202 | auto graphChild |
|
202 | auto graphChild | |
203 | = dynamic_cast<VisualizationGraphWidget *>(frameLayout->itemAt(i)->widget()); |
|
203 | = dynamic_cast<VisualizationGraphWidget *>(frameLayout->itemAt(i)->widget()); | |
204 | if (graphChild && (graphChild != graphWidget)) { |
|
204 | if (graphChild && (graphChild != graphWidget)) { | |
205 |
|
205 | |||
206 | auto graphChildRange = graphChild->graphRange(); |
|
206 | auto graphChildRange = graphChild->graphRange(); | |
207 | switch (zoomType) { |
|
207 | switch (zoomType) { | |
208 | case AcquisitionZoomType::ZoomIn: { |
|
208 | case AcquisitionZoomType::ZoomIn: { | |
209 | auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart; |
|
209 | auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart; | |
210 | auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd; |
|
210 | auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd; | |
211 | graphChildRange.m_TStart += deltaLeft; |
|
211 | graphChildRange.m_TStart += deltaLeft; | |
212 | graphChildRange.m_TEnd -= deltaRight; |
|
212 | graphChildRange.m_TEnd -= deltaRight; | |
213 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomIn"); |
|
213 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomIn"); | |
214 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaLeft") |
|
214 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaLeft") | |
215 | << deltaLeft; |
|
215 | << deltaLeft; | |
216 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaRight") |
|
216 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaRight") | |
217 | << deltaRight; |
|
217 | << deltaRight; | |
218 | qCDebug(LOG_VisualizationZoneWidget()) |
|
218 | qCDebug(LOG_VisualizationZoneWidget()) | |
219 | << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart; |
|
219 | << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart; | |
220 |
|
220 | |||
221 | break; |
|
221 | break; | |
222 | } |
|
222 | } | |
223 |
|
223 | |||
224 | case AcquisitionZoomType::ZoomOut: { |
|
224 | case AcquisitionZoomType::ZoomOut: { | |
225 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomOut"); |
|
225 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomOut"); | |
226 | auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; |
|
226 | auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; | |
227 | auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; |
|
227 | auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; | |
228 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaLeft") |
|
228 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaLeft") | |
229 | << deltaLeft; |
|
229 | << deltaLeft; | |
230 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaRight") |
|
230 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: deltaRight") | |
231 | << deltaRight; |
|
231 | << deltaRight; | |
232 | qCDebug(LOG_VisualizationZoneWidget()) |
|
232 | qCDebug(LOG_VisualizationZoneWidget()) | |
233 | << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart; |
|
233 | << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart; | |
234 | graphChildRange.m_TStart -= deltaLeft; |
|
234 | graphChildRange.m_TStart -= deltaLeft; | |
235 | graphChildRange.m_TEnd += deltaRight; |
|
235 | graphChildRange.m_TEnd += deltaRight; | |
236 | break; |
|
236 | break; | |
237 | } |
|
237 | } | |
238 | case AcquisitionZoomType::PanRight: { |
|
238 | case AcquisitionZoomType::PanRight: { | |
239 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: PanRight"); |
|
239 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: PanRight"); | |
240 | auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart; |
|
240 | auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart; | |
241 | auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; |
|
241 | auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; | |
242 | graphChildRange.m_TStart += deltaLeft; |
|
242 | graphChildRange.m_TStart += deltaLeft; | |
243 | graphChildRange.m_TEnd += deltaRight; |
|
243 | graphChildRange.m_TEnd += deltaRight; | |
244 | qCDebug(LOG_VisualizationZoneWidget()) |
|
244 | qCDebug(LOG_VisualizationZoneWidget()) | |
245 | << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart; |
|
245 | << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart; | |
246 | break; |
|
246 | break; | |
247 | } |
|
247 | } | |
248 | case AcquisitionZoomType::PanLeft: { |
|
248 | case AcquisitionZoomType::PanLeft: { | |
249 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: PanLeft"); |
|
249 | qCDebug(LOG_VisualizationZoneWidget()) << tr("TORM: PanLeft"); | |
250 | auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; |
|
250 | auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; | |
251 | auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd; |
|
251 | auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd; | |
252 | graphChildRange.m_TStart -= deltaLeft; |
|
252 | graphChildRange.m_TStart -= deltaLeft; | |
253 | graphChildRange.m_TEnd -= deltaRight; |
|
253 | graphChildRange.m_TEnd -= deltaRight; | |
254 | break; |
|
254 | break; | |
255 | } |
|
255 | } | |
256 | case AcquisitionZoomType::Unknown: { |
|
256 | case AcquisitionZoomType::Unknown: { | |
257 | qCDebug(LOG_VisualizationZoneWidget()) |
|
257 | qCDebug(LOG_VisualizationZoneWidget()) | |
258 | << tr("Impossible to synchronize: zoom type unknown"); |
|
258 | << tr("Impossible to synchronize: zoom type unknown"); | |
259 | break; |
|
259 | break; | |
260 | } |
|
260 | } | |
261 | default: |
|
261 | default: | |
262 | qCCritical(LOG_VisualizationZoneWidget()) |
|
262 | qCCritical(LOG_VisualizationZoneWidget()) | |
263 | << tr("Impossible to synchronize: zoom type not take into account"); |
|
263 | << tr("Impossible to synchronize: zoom type not take into account"); | |
264 | // No action |
|
264 | // No action | |
265 | break; |
|
265 | break; | |
266 | } |
|
266 | } | |
267 |
graphChild-> |
|
267 | graphChild->setFlags(GraphFlag::DisableAll); | |
268 |
qCDebug(LOG_VisualizationZoneWidget()) |
|
268 | qCDebug(LOG_VisualizationZoneWidget()) | |
269 |
|
|
269 | << tr("TORM: Range before: ") << graphChild->graphRange(); | |
270 |
qCDebug(LOG_VisualizationZoneWidget()) |
|
270 | qCDebug(LOG_VisualizationZoneWidget()) | |
271 | << graphChildRange; |
|
271 | << tr("TORM: Range after : ") << graphChildRange; | |
272 | qCDebug(LOG_VisualizationZoneWidget()) |
|
272 | qCDebug(LOG_VisualizationZoneWidget()) | |
273 | << tr("TORM: child dt") << graphChildRange.m_TEnd - graphChildRange.m_TStart; |
|
273 | << tr("TORM: child dt") << graphChildRange.m_TEnd - graphChildRange.m_TStart; | |
274 | graphChild->setGraphRange(graphChildRange); |
|
274 | graphChild->setGraphRange(graphChildRange); | |
275 |
graphChild-> |
|
275 | graphChild->setFlags(GraphFlag::EnableAll); | |
276 | } |
|
276 | } | |
277 | } |
|
277 | } | |
278 | }; |
|
278 | }; | |
279 |
|
279 | |||
280 | // connection for synchronization |
|
280 | // connection for synchronization | |
281 | connect(graphWidget, &VisualizationGraphWidget::synchronize, synchronizeZoneWidget); |
|
281 | connect(graphWidget, &VisualizationGraphWidget::synchronize, synchronizeZoneWidget); | |
282 | connect(graphWidget, &VisualizationGraphWidget::variableAdded, this, |
|
282 | connect(graphWidget, &VisualizationGraphWidget::variableAdded, this, | |
283 | &VisualizationZoneWidget::onVariableAdded); |
|
283 | &VisualizationZoneWidget::onVariableAdded); | |
284 | connect(graphWidget, &VisualizationGraphWidget::variableAboutToBeRemoved, this, |
|
284 | connect(graphWidget, &VisualizationGraphWidget::variableAboutToBeRemoved, this, | |
285 | &VisualizationZoneWidget::onVariableAboutToBeRemoved); |
|
285 | &VisualizationZoneWidget::onVariableAboutToBeRemoved); | |
286 |
|
286 | |||
287 | auto range = SqpRange{}; |
|
287 | auto range = SqpRange{}; | |
288 | if (auto firstGraph = this->firstGraph()) { |
|
288 | if (auto firstGraph = this->firstGraph()) { | |
289 | // Case of a new graph in a existant zone |
|
289 | // Case of a new graph in a existant zone | |
290 | range = firstGraph->graphRange(); |
|
290 | range = firstGraph->graphRange(); | |
291 | } |
|
291 | } | |
292 | else { |
|
292 | else { | |
293 | // Case of a new graph as the first of the zone |
|
293 | // Case of a new graph as the first of the zone | |
294 | range = variable->range(); |
|
294 | range = variable->range(); | |
295 | } |
|
295 | } | |
296 |
|
296 | |||
297 | this->insertGraph(index, graphWidget); |
|
297 | this->insertGraph(index, graphWidget); | |
298 |
|
298 | |||
299 | graphWidget->addVariable(variable, range); |
|
299 | graphWidget->addVariable(variable, range); | |
300 | graphWidget->setYRange(variable); |
|
300 | graphWidget->setYRange(variable); | |
301 |
|
301 | |||
302 | return graphWidget; |
|
302 | return graphWidget; | |
303 | } |
|
303 | } | |
304 |
|
304 | |||
305 | VisualizationGraphWidget * |
|
305 | VisualizationGraphWidget * | |
306 | VisualizationZoneWidget::createGraph(const QList<std::shared_ptr<Variable> > variables, int index) |
|
306 | VisualizationZoneWidget::createGraph(const QList<std::shared_ptr<Variable> > variables, int index) | |
307 | { |
|
307 | { | |
308 | if (variables.isEmpty()) { |
|
308 | if (variables.isEmpty()) { | |
309 | return nullptr; |
|
309 | return nullptr; | |
310 | } |
|
310 | } | |
311 |
|
311 | |||
312 | auto graphWidget = createGraph(variables.first(), index); |
|
312 | auto graphWidget = createGraph(variables.first(), index); | |
313 | for (auto variableIt = variables.cbegin() + 1; variableIt != variables.cend(); ++variableIt) { |
|
313 | for (auto variableIt = variables.cbegin() + 1; variableIt != variables.cend(); ++variableIt) { | |
314 | graphWidget->addVariable(*variableIt, graphWidget->graphRange()); |
|
314 | graphWidget->addVariable(*variableIt, graphWidget->graphRange()); | |
315 | } |
|
315 | } | |
316 |
|
316 | |||
317 | return graphWidget; |
|
317 | return graphWidget; | |
318 | } |
|
318 | } | |
319 |
|
319 | |||
320 | VisualizationGraphWidget *VisualizationZoneWidget::firstGraph() const |
|
320 | VisualizationGraphWidget *VisualizationZoneWidget::firstGraph() const | |
321 | { |
|
321 | { | |
322 | VisualizationGraphWidget *firstGraph = nullptr; |
|
322 | VisualizationGraphWidget *firstGraph = nullptr; | |
323 | auto layout = ui->dragDropContainer->layout(); |
|
323 | auto layout = ui->dragDropContainer->layout(); | |
324 | if (layout->count() > 0) { |
|
324 | if (layout->count() > 0) { | |
325 | if (auto visualizationGraphWidget |
|
325 | if (auto visualizationGraphWidget | |
326 | = qobject_cast<VisualizationGraphWidget *>(layout->itemAt(0)->widget())) { |
|
326 | = qobject_cast<VisualizationGraphWidget *>(layout->itemAt(0)->widget())) { | |
327 | firstGraph = visualizationGraphWidget; |
|
327 | firstGraph = visualizationGraphWidget; | |
328 | } |
|
328 | } | |
329 | } |
|
329 | } | |
330 |
|
330 | |||
331 | return firstGraph; |
|
331 | return firstGraph; | |
332 | } |
|
332 | } | |
333 |
|
333 | |||
334 | void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
334 | void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor) | |
335 | { |
|
335 | { | |
336 | if (visitor) { |
|
336 | if (visitor) { | |
337 | visitor->visitEnter(this); |
|
337 | visitor->visitEnter(this); | |
338 |
|
338 | |||
339 | // Apply visitor to graph children: widgets different from graphs are not visited (no |
|
339 | // Apply visitor to graph children: widgets different from graphs are not visited (no | |
340 | // action) |
|
340 | // action) | |
341 | processGraphs( |
|
341 | processGraphs( | |
342 | *ui->dragDropContainer->layout(), |
|
342 | *ui->dragDropContainer->layout(), | |
343 | [visitor](VisualizationGraphWidget &graphWidget) { graphWidget.accept(visitor); }); |
|
343 | [visitor](VisualizationGraphWidget &graphWidget) { graphWidget.accept(visitor); }); | |
344 |
|
344 | |||
345 | visitor->visitLeave(this); |
|
345 | visitor->visitLeave(this); | |
346 | } |
|
346 | } | |
347 | else { |
|
347 | else { | |
348 | qCCritical(LOG_VisualizationZoneWidget()) << tr("Can't visit widget : the visitor is null"); |
|
348 | qCCritical(LOG_VisualizationZoneWidget()) << tr("Can't visit widget : the visitor is null"); | |
349 | } |
|
349 | } | |
350 | } |
|
350 | } | |
351 |
|
351 | |||
352 | bool VisualizationZoneWidget::canDrop(const Variable &variable) const |
|
352 | bool VisualizationZoneWidget::canDrop(const Variable &variable) const | |
353 | { |
|
353 | { | |
354 | // A tab can always accomodate a variable |
|
354 | // A tab can always accomodate a variable | |
355 | Q_UNUSED(variable); |
|
355 | Q_UNUSED(variable); | |
356 | return true; |
|
356 | return true; | |
357 | } |
|
357 | } | |
358 |
|
358 | |||
359 | bool VisualizationZoneWidget::contains(const Variable &variable) const |
|
359 | bool VisualizationZoneWidget::contains(const Variable &variable) const | |
360 | { |
|
360 | { | |
361 | Q_UNUSED(variable); |
|
361 | Q_UNUSED(variable); | |
362 | return false; |
|
362 | return false; | |
363 | } |
|
363 | } | |
364 |
|
364 | |||
365 | QString VisualizationZoneWidget::name() const |
|
365 | QString VisualizationZoneWidget::name() const | |
366 | { |
|
366 | { | |
367 | return ui->zoneNameLabel->text(); |
|
367 | return ui->zoneNameLabel->text(); | |
368 | } |
|
368 | } | |
369 |
|
369 | |||
370 | QMimeData *VisualizationZoneWidget::mimeData(const QPoint &position) const |
|
370 | QMimeData *VisualizationZoneWidget::mimeData(const QPoint &position) const | |
371 | { |
|
371 | { | |
372 | Q_UNUSED(position); |
|
372 | Q_UNUSED(position); | |
373 |
|
373 | |||
374 | auto mimeData = new QMimeData; |
|
374 | auto mimeData = new QMimeData; | |
375 | mimeData->setData(MIME_TYPE_ZONE, QByteArray{}); |
|
375 | mimeData->setData(MIME_TYPE_ZONE, QByteArray{}); | |
376 |
|
376 | |||
377 | if (auto firstGraph = this->firstGraph()) { |
|
377 | if (auto firstGraph = this->firstGraph()) { | |
378 | auto timeRangeData = TimeController::mimeDataForTimeRange(firstGraph->graphRange()); |
|
378 | auto timeRangeData = TimeController::mimeDataForTimeRange(firstGraph->graphRange()); | |
379 | mimeData->setData(MIME_TYPE_TIME_RANGE, timeRangeData); |
|
379 | mimeData->setData(MIME_TYPE_TIME_RANGE, timeRangeData); | |
380 | } |
|
380 | } | |
381 |
|
381 | |||
382 | return mimeData; |
|
382 | return mimeData; | |
383 | } |
|
383 | } | |
384 |
|
384 | |||
385 | bool VisualizationZoneWidget::isDragAllowed() const |
|
385 | bool VisualizationZoneWidget::isDragAllowed() const | |
386 | { |
|
386 | { | |
387 | return true; |
|
387 | return true; | |
388 | } |
|
388 | } | |
389 |
|
389 | |||
390 | void VisualizationZoneWidget::notifyMouseMoveInGraph(const QPointF &graphPosition, |
|
390 | void VisualizationZoneWidget::notifyMouseMoveInGraph(const QPointF &graphPosition, | |
391 | const QPointF &plotPosition, |
|
391 | const QPointF &plotPosition, | |
392 | VisualizationGraphWidget *graphWidget) |
|
392 | VisualizationGraphWidget *graphWidget) | |
393 | { |
|
393 | { | |
394 | processGraphs(*ui->dragDropContainer->layout(), [&graphPosition, &plotPosition, &graphWidget]( |
|
394 | processGraphs(*ui->dragDropContainer->layout(), [&graphPosition, &plotPosition, &graphWidget]( | |
395 | VisualizationGraphWidget &processedGraph) { |
|
395 | VisualizationGraphWidget &processedGraph) { | |
396 |
|
396 | |||
397 | switch (sqpApp->plotsCursorMode()) { |
|
397 | switch (sqpApp->plotsCursorMode()) { | |
398 | case SqpApplication::PlotsCursorMode::Vertical: |
|
398 | case SqpApplication::PlotsCursorMode::Vertical: | |
399 | processedGraph.removeHorizontalCursor(); |
|
399 | processedGraph.removeHorizontalCursor(); | |
400 | processedGraph.addVerticalCursorAtViewportPosition(graphPosition.x()); |
|
400 | processedGraph.addVerticalCursorAtViewportPosition(graphPosition.x()); | |
401 | break; |
|
401 | break; | |
402 | case SqpApplication::PlotsCursorMode::Temporal: |
|
402 | case SqpApplication::PlotsCursorMode::Temporal: | |
403 | processedGraph.addVerticalCursor(plotPosition.x()); |
|
403 | processedGraph.addVerticalCursor(plotPosition.x()); | |
404 | processedGraph.removeHorizontalCursor(); |
|
404 | processedGraph.removeHorizontalCursor(); | |
405 | break; |
|
405 | break; | |
406 | case SqpApplication::PlotsCursorMode::Horizontal: |
|
406 | case SqpApplication::PlotsCursorMode::Horizontal: | |
407 | processedGraph.removeVerticalCursor(); |
|
407 | processedGraph.removeVerticalCursor(); | |
408 | if (&processedGraph == graphWidget) { |
|
408 | if (&processedGraph == graphWidget) { | |
409 | processedGraph.addHorizontalCursorAtViewportPosition(graphPosition.y()); |
|
409 | processedGraph.addHorizontalCursorAtViewportPosition(graphPosition.y()); | |
410 | } |
|
410 | } | |
411 | else { |
|
411 | else { | |
412 | processedGraph.removeHorizontalCursor(); |
|
412 | processedGraph.removeHorizontalCursor(); | |
413 | } |
|
413 | } | |
414 | break; |
|
414 | break; | |
415 | case SqpApplication::PlotsCursorMode::Cross: |
|
415 | case SqpApplication::PlotsCursorMode::Cross: | |
416 | if (&processedGraph == graphWidget) { |
|
416 | if (&processedGraph == graphWidget) { | |
417 | processedGraph.addVerticalCursorAtViewportPosition(graphPosition.x()); |
|
417 | processedGraph.addVerticalCursorAtViewportPosition(graphPosition.x()); | |
418 | processedGraph.addHorizontalCursorAtViewportPosition(graphPosition.y()); |
|
418 | processedGraph.addHorizontalCursorAtViewportPosition(graphPosition.y()); | |
419 | } |
|
419 | } | |
420 | else { |
|
420 | else { | |
421 | processedGraph.removeHorizontalCursor(); |
|
421 | processedGraph.removeHorizontalCursor(); | |
422 | processedGraph.removeVerticalCursor(); |
|
422 | processedGraph.removeVerticalCursor(); | |
423 | } |
|
423 | } | |
424 | break; |
|
424 | break; | |
425 | case SqpApplication::PlotsCursorMode::NoCursor: |
|
425 | case SqpApplication::PlotsCursorMode::NoCursor: | |
426 | processedGraph.removeHorizontalCursor(); |
|
426 | processedGraph.removeHorizontalCursor(); | |
427 | processedGraph.removeVerticalCursor(); |
|
427 | processedGraph.removeVerticalCursor(); | |
428 | break; |
|
428 | break; | |
429 | } |
|
429 | } | |
430 |
|
430 | |||
431 |
|
431 | |||
432 | }); |
|
432 | }); | |
433 | } |
|
433 | } | |
434 |
|
434 | |||
435 | void VisualizationZoneWidget::notifyMouseLeaveGraph(VisualizationGraphWidget *graphWidget) |
|
435 | void VisualizationZoneWidget::notifyMouseLeaveGraph(VisualizationGraphWidget *graphWidget) | |
436 | { |
|
436 | { | |
437 | processGraphs(*ui->dragDropContainer->layout(), [](VisualizationGraphWidget &processedGraph) { |
|
437 | processGraphs(*ui->dragDropContainer->layout(), [](VisualizationGraphWidget &processedGraph) { | |
438 | processedGraph.removeHorizontalCursor(); |
|
438 | processedGraph.removeHorizontalCursor(); | |
439 | processedGraph.removeVerticalCursor(); |
|
439 | processedGraph.removeVerticalCursor(); | |
440 | }); |
|
440 | }); | |
441 | } |
|
441 | } | |
442 |
|
442 | |||
443 | void VisualizationZoneWidget::closeEvent(QCloseEvent *event) |
|
443 | void VisualizationZoneWidget::closeEvent(QCloseEvent *event) | |
444 | { |
|
444 | { | |
445 | // Closes graphs in the zone |
|
445 | // Closes graphs in the zone | |
446 | processGraphs(*ui->dragDropContainer->layout(), |
|
446 | processGraphs(*ui->dragDropContainer->layout(), | |
447 | [](VisualizationGraphWidget &graphWidget) { graphWidget.close(); }); |
|
447 | [](VisualizationGraphWidget &graphWidget) { graphWidget.close(); }); | |
448 |
|
448 | |||
449 | // Delete synchronization group from variable controller |
|
449 | // Delete synchronization group from variable controller | |
450 | QMetaObject::invokeMethod(&sqpApp->variableController(), "onRemoveSynchronizationGroupId", |
|
450 | QMetaObject::invokeMethod(&sqpApp->variableController(), "onRemoveSynchronizationGroupId", | |
451 | Qt::QueuedConnection, Q_ARG(QUuid, impl->m_SynchronisationGroupId)); |
|
451 | Qt::QueuedConnection, Q_ARG(QUuid, impl->m_SynchronisationGroupId)); | |
452 |
|
452 | |||
453 | QWidget::closeEvent(event); |
|
453 | QWidget::closeEvent(event); | |
454 | } |
|
454 | } | |
455 |
|
455 | |||
456 | void VisualizationZoneWidget::onVariableAdded(std::shared_ptr<Variable> variable) |
|
456 | void VisualizationZoneWidget::onVariableAdded(std::shared_ptr<Variable> variable) | |
457 | { |
|
457 | { | |
458 | QMetaObject::invokeMethod(&sqpApp->variableController(), "onAddSynchronized", |
|
458 | QMetaObject::invokeMethod(&sqpApp->variableController(), "onAddSynchronized", | |
459 | Qt::QueuedConnection, Q_ARG(std::shared_ptr<Variable>, variable), |
|
459 | Qt::QueuedConnection, Q_ARG(std::shared_ptr<Variable>, variable), | |
460 | Q_ARG(QUuid, impl->m_SynchronisationGroupId)); |
|
460 | Q_ARG(QUuid, impl->m_SynchronisationGroupId)); | |
461 | } |
|
461 | } | |
462 |
|
462 | |||
463 | void VisualizationZoneWidget::onVariableAboutToBeRemoved(std::shared_ptr<Variable> variable) |
|
463 | void VisualizationZoneWidget::onVariableAboutToBeRemoved(std::shared_ptr<Variable> variable) | |
464 | { |
|
464 | { | |
465 | QMetaObject::invokeMethod(&sqpApp->variableController(), "desynchronize", Qt::QueuedConnection, |
|
465 | QMetaObject::invokeMethod(&sqpApp->variableController(), "desynchronize", Qt::QueuedConnection, | |
466 | Q_ARG(std::shared_ptr<Variable>, variable), |
|
466 | Q_ARG(std::shared_ptr<Variable>, variable), | |
467 | Q_ARG(QUuid, impl->m_SynchronisationGroupId)); |
|
467 | Q_ARG(QUuid, impl->m_SynchronisationGroupId)); | |
468 | } |
|
468 | } | |
469 |
|
469 | |||
470 | void VisualizationZoneWidget::dropMimeData(int index, const QMimeData *mimeData) |
|
470 | void VisualizationZoneWidget::dropMimeData(int index, const QMimeData *mimeData) | |
471 | { |
|
471 | { | |
472 | if (mimeData->hasFormat(MIME_TYPE_GRAPH)) { |
|
472 | if (mimeData->hasFormat(MIME_TYPE_GRAPH)) { | |
473 | impl->dropGraph(index, this); |
|
473 | impl->dropGraph(index, this); | |
474 | } |
|
474 | } | |
475 | else if (mimeData->hasFormat(MIME_TYPE_VARIABLE_LIST)) { |
|
475 | else if (mimeData->hasFormat(MIME_TYPE_VARIABLE_LIST)) { | |
476 | auto variables = sqpApp->variableController().variablesForMimeData( |
|
476 | auto variables = sqpApp->variableController().variablesForMimeData( | |
477 | mimeData->data(MIME_TYPE_VARIABLE_LIST)); |
|
477 | mimeData->data(MIME_TYPE_VARIABLE_LIST)); | |
478 | impl->dropVariables(variables, index, this); |
|
478 | impl->dropVariables(variables, index, this); | |
479 | } |
|
479 | } | |
480 | else { |
|
480 | else { | |
481 | qCWarning(LOG_VisualizationZoneWidget()) |
|
481 | qCWarning(LOG_VisualizationZoneWidget()) | |
482 | << tr("VisualizationZoneWidget::dropMimeData, unknown MIME data received."); |
|
482 | << tr("VisualizationZoneWidget::dropMimeData, unknown MIME data received."); | |
483 | } |
|
483 | } | |
484 | } |
|
484 | } | |
485 |
|
485 | |||
486 | void VisualizationZoneWidget::dropMimeDataOnGraph(VisualizationDragWidget *dragWidget, |
|
486 | void VisualizationZoneWidget::dropMimeDataOnGraph(VisualizationDragWidget *dragWidget, | |
487 | const QMimeData *mimeData) |
|
487 | const QMimeData *mimeData) | |
488 | { |
|
488 | { | |
489 | auto graphWidget = qobject_cast<VisualizationGraphWidget *>(dragWidget); |
|
489 | auto graphWidget = qobject_cast<VisualizationGraphWidget *>(dragWidget); | |
490 | if (!graphWidget) { |
|
490 | if (!graphWidget) { | |
491 | qCWarning(LOG_VisualizationZoneWidget()) |
|
491 | qCWarning(LOG_VisualizationZoneWidget()) | |
492 | << tr("VisualizationZoneWidget::dropMimeDataOnGraph, dropping in an unknown widget, " |
|
492 | << tr("VisualizationZoneWidget::dropMimeDataOnGraph, dropping in an unknown widget, " | |
493 | "drop aborted"); |
|
493 | "drop aborted"); | |
494 | Q_ASSERT(false); |
|
494 | Q_ASSERT(false); | |
495 | return; |
|
495 | return; | |
496 | } |
|
496 | } | |
497 |
|
497 | |||
498 | if (mimeData->hasFormat(MIME_TYPE_VARIABLE_LIST)) { |
|
498 | if (mimeData->hasFormat(MIME_TYPE_VARIABLE_LIST)) { | |
499 | auto variables = sqpApp->variableController().variablesForMimeData( |
|
499 | auto variables = sqpApp->variableController().variablesForMimeData( | |
500 | mimeData->data(MIME_TYPE_VARIABLE_LIST)); |
|
500 | mimeData->data(MIME_TYPE_VARIABLE_LIST)); | |
501 | for (const auto &var : variables) { |
|
501 | for (const auto &var : variables) { | |
502 | graphWidget->addVariable(var, graphWidget->graphRange()); |
|
502 | graphWidget->addVariable(var, graphWidget->graphRange()); | |
503 | } |
|
503 | } | |
504 | } |
|
504 | } | |
505 | else if (mimeData->hasFormat(MIME_TYPE_TIME_RANGE)) { |
|
505 | else if (mimeData->hasFormat(MIME_TYPE_TIME_RANGE)) { | |
506 | auto range = TimeController::timeRangeForMimeData(mimeData->data(MIME_TYPE_TIME_RANGE)); |
|
506 | auto range = TimeController::timeRangeForMimeData(mimeData->data(MIME_TYPE_TIME_RANGE)); | |
507 | graphWidget->setGraphRange(range); |
|
507 | graphWidget->setGraphRange(range); | |
508 | } |
|
508 | } | |
509 | else { |
|
509 | else { | |
510 | qCWarning(LOG_VisualizationZoneWidget()) |
|
510 | qCWarning(LOG_VisualizationZoneWidget()) | |
511 | << tr("VisualizationZoneWidget::dropMimeDataOnGraph, unknown MIME data received."); |
|
511 | << tr("VisualizationZoneWidget::dropMimeDataOnGraph, unknown MIME data received."); | |
512 | } |
|
512 | } | |
513 | } |
|
513 | } | |
514 |
|
514 | |||
515 | void VisualizationZoneWidget::VisualizationZoneWidgetPrivate::dropGraph( |
|
515 | void VisualizationZoneWidget::VisualizationZoneWidgetPrivate::dropGraph( | |
516 | int index, VisualizationZoneWidget *zoneWidget) |
|
516 | int index, VisualizationZoneWidget *zoneWidget) | |
517 | { |
|
517 | { | |
518 | auto &helper = sqpApp->dragDropGuiController(); |
|
518 | auto &helper = sqpApp->dragDropGuiController(); | |
519 |
|
519 | |||
520 | auto graphWidget = qobject_cast<VisualizationGraphWidget *>(helper.getCurrentDragWidget()); |
|
520 | auto graphWidget = qobject_cast<VisualizationGraphWidget *>(helper.getCurrentDragWidget()); | |
521 | if (!graphWidget) { |
|
521 | if (!graphWidget) { | |
522 | qCWarning(LOG_VisualizationZoneWidget()) |
|
522 | qCWarning(LOG_VisualizationZoneWidget()) | |
523 | << tr("VisualizationZoneWidget::dropGraph, drop aborted, the dropped graph is not " |
|
523 | << tr("VisualizationZoneWidget::dropGraph, drop aborted, the dropped graph is not " | |
524 | "found or invalid."); |
|
524 | "found or invalid."); | |
525 | Q_ASSERT(false); |
|
525 | Q_ASSERT(false); | |
526 | return; |
|
526 | return; | |
527 | } |
|
527 | } | |
528 |
|
528 | |||
529 | auto parentDragDropContainer |
|
529 | auto parentDragDropContainer | |
530 | = qobject_cast<VisualizationDragDropContainer *>(graphWidget->parentWidget()); |
|
530 | = qobject_cast<VisualizationDragDropContainer *>(graphWidget->parentWidget()); | |
531 | if (!parentDragDropContainer) { |
|
531 | if (!parentDragDropContainer) { | |
532 | qCWarning(LOG_VisualizationZoneWidget()) |
|
532 | qCWarning(LOG_VisualizationZoneWidget()) | |
533 | << tr("VisualizationZoneWidget::dropGraph, drop aborted, the parent container of " |
|
533 | << tr("VisualizationZoneWidget::dropGraph, drop aborted, the parent container of " | |
534 | "the dropped graph is not found."); |
|
534 | "the dropped graph is not found."); | |
535 | Q_ASSERT(false); |
|
535 | Q_ASSERT(false); | |
536 | return; |
|
536 | return; | |
537 | } |
|
537 | } | |
538 |
|
538 | |||
539 | const auto &variables = graphWidget->variables(); |
|
539 | const auto &variables = graphWidget->variables(); | |
540 |
|
540 | |||
541 | if (parentDragDropContainer != zoneWidget->ui->dragDropContainer && !variables.isEmpty()) { |
|
541 | if (parentDragDropContainer != zoneWidget->ui->dragDropContainer && !variables.isEmpty()) { | |
542 | // The drop didn't occur in the same zone |
|
542 | // The drop didn't occur in the same zone | |
543 |
|
543 | |||
544 | // Abort the requests for the variables (if any) |
|
544 | // Abort the requests for the variables (if any) | |
545 | // Commented, because it's not sure if it's needed or not |
|
545 | // Commented, because it's not sure if it's needed or not | |
546 | // for (const auto& var : variables) |
|
546 | // for (const auto& var : variables) | |
547 | //{ |
|
547 | //{ | |
548 | // sqpApp->variableController().onAbortProgressRequested(var); |
|
548 | // sqpApp->variableController().onAbortProgressRequested(var); | |
549 | //} |
|
549 | //} | |
550 |
|
550 | |||
551 | auto previousParentZoneWidget = graphWidget->parentZoneWidget(); |
|
551 | auto previousParentZoneWidget = graphWidget->parentZoneWidget(); | |
552 | auto nbGraph = parentDragDropContainer->countDragWidget(); |
|
552 | auto nbGraph = parentDragDropContainer->countDragWidget(); | |
553 | if (nbGraph == 1) { |
|
553 | if (nbGraph == 1) { | |
554 | // This is the only graph in the previous zone, close the zone |
|
554 | // This is the only graph in the previous zone, close the zone | |
555 | helper.delayedCloseWidget(previousParentZoneWidget); |
|
555 | helper.delayedCloseWidget(previousParentZoneWidget); | |
556 | } |
|
556 | } | |
557 | else { |
|
557 | else { | |
558 | // Close the graph |
|
558 | // Close the graph | |
559 | helper.delayedCloseWidget(graphWidget); |
|
559 | helper.delayedCloseWidget(graphWidget); | |
560 | } |
|
560 | } | |
561 |
|
561 | |||
562 | // Creates the new graph in the zone |
|
562 | // Creates the new graph in the zone | |
563 | auto newGraphWidget = zoneWidget->createGraph(variables, index); |
|
563 | auto newGraphWidget = zoneWidget->createGraph(variables, index); | |
564 | newGraphWidget->addSelectionZones(graphWidget->selectionZoneRanges()); |
|
564 | newGraphWidget->addSelectionZones(graphWidget->selectionZoneRanges()); | |
565 | } |
|
565 | } | |
566 | else { |
|
566 | else { | |
567 | // The drop occurred in the same zone or the graph is empty |
|
567 | // The drop occurred in the same zone or the graph is empty | |
568 | // Simple move of the graph, no variable operation associated |
|
568 | // Simple move of the graph, no variable operation associated | |
569 | parentDragDropContainer->layout()->removeWidget(graphWidget); |
|
569 | parentDragDropContainer->layout()->removeWidget(graphWidget); | |
570 |
|
570 | |||
571 | if (variables.isEmpty() && parentDragDropContainer != zoneWidget->ui->dragDropContainer) { |
|
571 | if (variables.isEmpty() && parentDragDropContainer != zoneWidget->ui->dragDropContainer) { | |
572 | // The graph is empty and dropped in a different zone. |
|
572 | // The graph is empty and dropped in a different zone. | |
573 | // Take the range of the first graph in the zone (if existing). |
|
573 | // Take the range of the first graph in the zone (if existing). | |
574 | auto layout = zoneWidget->ui->dragDropContainer->layout(); |
|
574 | auto layout = zoneWidget->ui->dragDropContainer->layout(); | |
575 | if (layout->count() > 0) { |
|
575 | if (layout->count() > 0) { | |
576 | if (auto visualizationGraphWidget |
|
576 | if (auto visualizationGraphWidget | |
577 | = qobject_cast<VisualizationGraphWidget *>(layout->itemAt(0)->widget())) { |
|
577 | = qobject_cast<VisualizationGraphWidget *>(layout->itemAt(0)->widget())) { | |
578 | graphWidget->setGraphRange(visualizationGraphWidget->graphRange()); |
|
578 | graphWidget->setGraphRange(visualizationGraphWidget->graphRange()); | |
579 | } |
|
579 | } | |
580 | } |
|
580 | } | |
581 | } |
|
581 | } | |
582 |
|
582 | |||
583 | zoneWidget->ui->dragDropContainer->insertDragWidget(index, graphWidget); |
|
583 | zoneWidget->ui->dragDropContainer->insertDragWidget(index, graphWidget); | |
584 | } |
|
584 | } | |
585 | } |
|
585 | } | |
586 |
|
586 | |||
587 | void VisualizationZoneWidget::VisualizationZoneWidgetPrivate::dropVariables( |
|
587 | void VisualizationZoneWidget::VisualizationZoneWidgetPrivate::dropVariables( | |
588 | const QList<std::shared_ptr<Variable> > &variables, int index, |
|
588 | const QList<std::shared_ptr<Variable> > &variables, int index, | |
589 | VisualizationZoneWidget *zoneWidget) |
|
589 | VisualizationZoneWidget *zoneWidget) | |
590 | { |
|
590 | { | |
591 | // Note: the AcceptMimeDataFunction (set on the drop container) ensure there is a single and |
|
591 | // Note: the AcceptMimeDataFunction (set on the drop container) ensure there is a single and | |
592 | // compatible variable here |
|
592 | // compatible variable here | |
593 | if (variables.count() > 1) { |
|
593 | if (variables.count() > 1) { | |
594 | qCWarning(LOG_VisualizationZoneWidget()) |
|
594 | qCWarning(LOG_VisualizationZoneWidget()) | |
595 | << tr("VisualizationZoneWidget::dropVariables, dropping multiple variables, operation " |
|
595 | << tr("VisualizationZoneWidget::dropVariables, dropping multiple variables, operation " | |
596 | "aborted."); |
|
596 | "aborted."); | |
597 | return; |
|
597 | return; | |
598 | } |
|
598 | } | |
599 |
|
599 | |||
600 | zoneWidget->createGraph(variables, index); |
|
600 | zoneWidget->createGraph(variables, index); | |
601 | } |
|
601 | } |
@@ -1,71 +1,71 | |||||
1 | #include "Visualization/operations/RescaleAxeOperation.h" |
|
1 | #include "Visualization/operations/RescaleAxeOperation.h" | |
2 | #include "Visualization/VisualizationGraphWidget.h" |
|
2 | #include "Visualization/VisualizationGraphWidget.h" | |
3 |
|
3 | |||
4 | Q_LOGGING_CATEGORY(LOG_RescaleAxeOperation, "RescaleAxeOperation") |
|
4 | Q_LOGGING_CATEGORY(LOG_RescaleAxeOperation, "RescaleAxeOperation") | |
5 |
|
5 | |||
6 | struct RescaleAxeOperation::RescaleAxeOperationPrivate { |
|
6 | struct RescaleAxeOperation::RescaleAxeOperationPrivate { | |
7 | explicit RescaleAxeOperationPrivate(std::shared_ptr<Variable> variable, const SqpRange &range) |
|
7 | explicit RescaleAxeOperationPrivate(std::shared_ptr<Variable> variable, const SqpRange &range) | |
8 | : m_Variable{variable}, m_Range{range} |
|
8 | : m_Variable{variable}, m_Range{range} | |
9 | { |
|
9 | { | |
10 | } |
|
10 | } | |
11 |
|
11 | |||
12 | std::shared_ptr<Variable> m_Variable; |
|
12 | std::shared_ptr<Variable> m_Variable; | |
13 | SqpRange m_Range; |
|
13 | SqpRange m_Range; | |
14 | }; |
|
14 | }; | |
15 |
|
15 | |||
16 | RescaleAxeOperation::RescaleAxeOperation(std::shared_ptr<Variable> variable, const SqpRange &range) |
|
16 | RescaleAxeOperation::RescaleAxeOperation(std::shared_ptr<Variable> variable, const SqpRange &range) | |
17 | : impl{spimpl::make_unique_impl<RescaleAxeOperationPrivate>(variable, range)} |
|
17 | : impl{spimpl::make_unique_impl<RescaleAxeOperationPrivate>(variable, range)} | |
18 | { |
|
18 | { | |
19 | } |
|
19 | } | |
20 |
|
20 | |||
21 | void RescaleAxeOperation::visitEnter(VisualizationWidget *widget) |
|
21 | void RescaleAxeOperation::visitEnter(VisualizationWidget *widget) | |
22 | { |
|
22 | { | |
23 | // VisualizationWidget is not intended to contain a variable |
|
23 | // VisualizationWidget is not intended to contain a variable | |
24 | Q_UNUSED(widget) |
|
24 | Q_UNUSED(widget) | |
25 | } |
|
25 | } | |
26 |
|
26 | |||
27 | void RescaleAxeOperation::visitLeave(VisualizationWidget *widget) |
|
27 | void RescaleAxeOperation::visitLeave(VisualizationWidget *widget) | |
28 | { |
|
28 | { | |
29 | // VisualizationWidget is not intended to contain a variable |
|
29 | // VisualizationWidget is not intended to contain a variable | |
30 | Q_UNUSED(widget) |
|
30 | Q_UNUSED(widget) | |
31 | } |
|
31 | } | |
32 |
|
32 | |||
33 | void RescaleAxeOperation::visitEnter(VisualizationTabWidget *tabWidget) |
|
33 | void RescaleAxeOperation::visitEnter(VisualizationTabWidget *tabWidget) | |
34 | { |
|
34 | { | |
35 | // VisualizationTabWidget is not intended to contain a variable |
|
35 | // VisualizationTabWidget is not intended to contain a variable | |
36 | Q_UNUSED(tabWidget) |
|
36 | Q_UNUSED(tabWidget) | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | void RescaleAxeOperation::visitLeave(VisualizationTabWidget *tabWidget) |
|
39 | void RescaleAxeOperation::visitLeave(VisualizationTabWidget *tabWidget) | |
40 | { |
|
40 | { | |
41 | // VisualizationTabWidget is not intended to contain a variable |
|
41 | // VisualizationTabWidget is not intended to contain a variable | |
42 | Q_UNUSED(tabWidget) |
|
42 | Q_UNUSED(tabWidget) | |
43 | } |
|
43 | } | |
44 |
|
44 | |||
45 | void RescaleAxeOperation::visitEnter(VisualizationZoneWidget *zoneWidget) |
|
45 | void RescaleAxeOperation::visitEnter(VisualizationZoneWidget *zoneWidget) | |
46 | { |
|
46 | { | |
47 | // VisualizationZoneWidget is not intended to contain a variable |
|
47 | // VisualizationZoneWidget is not intended to contain a variable | |
48 | Q_UNUSED(zoneWidget) |
|
48 | Q_UNUSED(zoneWidget) | |
49 | } |
|
49 | } | |
50 |
|
50 | |||
51 | void RescaleAxeOperation::visitLeave(VisualizationZoneWidget *zoneWidget) |
|
51 | void RescaleAxeOperation::visitLeave(VisualizationZoneWidget *zoneWidget) | |
52 | { |
|
52 | { | |
53 | // VisualizationZoneWidget is not intended to contain a variable |
|
53 | // VisualizationZoneWidget is not intended to contain a variable | |
54 | Q_UNUSED(zoneWidget) |
|
54 | Q_UNUSED(zoneWidget) | |
55 | } |
|
55 | } | |
56 |
|
56 | |||
57 | void RescaleAxeOperation::visit(VisualizationGraphWidget *graphWidget) |
|
57 | void RescaleAxeOperation::visit(VisualizationGraphWidget *graphWidget) | |
58 | { |
|
58 | { | |
59 | if (graphWidget) { |
|
59 | if (graphWidget) { | |
60 | // If the widget contains the variable, rescale it |
|
60 | // If the widget contains the variable, rescale it | |
61 | if (impl->m_Variable && graphWidget->contains(*impl->m_Variable)) { |
|
61 | if (impl->m_Variable && graphWidget->contains(*impl->m_Variable)) { | |
62 |
graphWidget-> |
|
62 | graphWidget->setFlags(GraphFlag::DisableAll); | |
63 | graphWidget->setGraphRange(impl->m_Range); |
|
63 | graphWidget->setGraphRange(impl->m_Range); | |
64 |
graphWidget-> |
|
64 | graphWidget->setFlags(GraphFlag::EnableAll); | |
65 | } |
|
65 | } | |
66 | } |
|
66 | } | |
67 | else { |
|
67 | else { | |
68 | qCCritical(LOG_RescaleAxeOperation(), |
|
68 | qCCritical(LOG_RescaleAxeOperation(), | |
69 | "Can't visit VisualizationGraphWidget : the widget is null"); |
|
69 | "Can't visit VisualizationGraphWidget : the widget is null"); | |
70 | } |
|
70 | } | |
71 | } |
|
71 | } |
General Comments 0
You need to be logged in to leave comments.
Login now