##// END OF EJS Templates
Shows/hides plot overlay when entering/leaving graph
Alexandre Leroux -
r669:f825dcc5246f
parent child
Show More
@@ -1,24 +1,27
1 1 #ifndef SCIQLOP_VISUALIZATIONGRAPHRENDERINGDELEGATE_H
2 2 #define SCIQLOP_VISUALIZATIONGRAPHRENDERINGDELEGATE_H
3 3
4 4 #include <Common/spimpl.h>
5 5
6 6 class QCustomPlot;
7 7 class QMouseEvent;
8 8 class VisualizationGraphWidget;
9 9
10 10 class VisualizationGraphRenderingDelegate {
11 11 public:
12 12 /// Ctor
13 13 /// @param graphWidget the graph widget to which the delegate is associated
14 14 /// @remarks the graph widget must exist throughout the life cycle of the delegate
15 15 explicit VisualizationGraphRenderingDelegate(VisualizationGraphWidget &graphWidget);
16 16
17 17 void onMouseMove(QMouseEvent *event) noexcept;
18 18
19 /// Shows or hides graph overlay (name, close button, etc.)
20 void showGraphOverlay(bool show) noexcept;
21
19 22 private:
20 23 class VisualizationGraphRenderingDelegatePrivate;
21 24 spimpl::unique_impl_ptr<VisualizationGraphRenderingDelegatePrivate> impl;
22 25 };
23 26
24 27 #endif // SCIQLOP_VISUALIZATIONGRAPHRENDERINGDELEGATE_H
@@ -1,90 +1,93
1 1 #ifndef SCIQLOP_VISUALIZATIONGRAPHWIDGET_H
2 2 #define SCIQLOP_VISUALIZATIONGRAPHWIDGET_H
3 3
4 4 #include "Visualization/IVisualizationWidget.h"
5 5
6 6 #include <QLoggingCategory>
7 7 #include <QWidget>
8 8
9 9 #include <memory>
10 10
11 11 #include <Common/spimpl.h>
12 12
13 13 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationGraphWidget)
14 14
15 15 class QCPRange;
16 16 class QCustomPlot;
17 17 class SqpRange;
18 18 class Variable;
19 19
20 20 namespace Ui {
21 21 class VisualizationGraphWidget;
22 22 } // namespace Ui
23 23
24 24 class VisualizationGraphWidget : public QWidget, public IVisualizationWidget {
25 25 Q_OBJECT
26 26
27 27 friend class VisualizationGraphRenderingDelegate;
28 28
29 29 public:
30 30 explicit VisualizationGraphWidget(const QString &name = {}, QWidget *parent = 0);
31 31 virtual ~VisualizationGraphWidget();
32 32
33 33 /// If acquisition isn't enable, requestDataLoading signal cannot be emit
34 34 void enableAcquisition(bool enable);
35 35
36 36 void addVariable(std::shared_ptr<Variable> variable, SqpRange range);
37 37
38 38 /// Removes a variable from the graph
39 39 void removeVariable(std::shared_ptr<Variable> variable) noexcept;
40 40
41 41 void setRange(std::shared_ptr<Variable> variable, const SqpRange &range);
42 42 void setYRange(const SqpRange &range);
43 43 SqpRange graphRange() const noexcept;
44 44 void setGraphRange(const SqpRange &range);
45 45
46 46 // IVisualizationWidget interface
47 47 void accept(IVisualizationWidgetVisitor *visitor) override;
48 48 bool canDrop(const Variable &variable) const override;
49 49 bool contains(const Variable &variable) const override;
50 50 QString name() const override;
51 51
52 52
53 53 signals:
54 54 void synchronize(const SqpRange &range, const SqpRange &oldRange);
55 55 void requestDataLoading(QVector<std::shared_ptr<Variable> > variable, const SqpRange &range,
56 56 const SqpRange &oldRange, bool synchronise);
57 57
58 58 void variableAdded(std::shared_ptr<Variable> var);
59 59
60 protected:
61 void enterEvent(QEvent *event) override;
62 void leaveEvent(QEvent *event) override;
60 63
61 64 QCustomPlot &plot() noexcept;
62 65
63 66 private:
64 67 Ui::VisualizationGraphWidget *ui;
65 68
66 69 class VisualizationGraphWidgetPrivate;
67 70 spimpl::unique_impl_ptr<VisualizationGraphWidgetPrivate> impl;
68 71
69 72 private slots:
70 73 /// Slot called when right clicking on the graph (displays a menu)
71 74 void onGraphMenuRequested(const QPoint &pos) noexcept;
72 75
73 76 /// Rescale the X axe to range parameter
74 77 void onRangeChanged(const QCPRange &t1, const QCPRange &t2);
75 78
76 79 /// Slot called when a mouse move was made
77 80 void onMouseMove(QMouseEvent *event) noexcept;
78 81 /// Slot called when a mouse wheel was made, to perform some processing before the zoom is done
79 82 void onMouseWheel(QWheelEvent *event) noexcept;
80 83 /// Slot called when a mouse press was made, to activate the calibration of a graph
81 84 void onMousePress(QMouseEvent *event) noexcept;
82 85 /// Slot called when a mouse release was made, to deactivate the calibration of a graph
83 86 void onMouseRelease(QMouseEvent *event) noexcept;
84 87
85 88 void onDataCacheVariableUpdated();
86 89
87 90 void onUpdateVarDisplaying(std::shared_ptr<Variable> variable, const SqpRange &range);
88 91 };
89 92
90 93 #endif // SCIQLOP_VISUALIZATIONGRAPHWIDGET_H
@@ -1,162 +1,169
1 1 #include "Visualization/VisualizationGraphRenderingDelegate.h"
2 2 #include "Visualization/VisualizationGraphWidget.h"
3 3 #include "Visualization/qcustomplot.h"
4 4
5 5 #include <Common/DateUtils.h>
6 6
7 7 #include <SqpApplication.h>
8 8
9 9 namespace {
10 10
11 11 const auto DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd hh:mm:ss:zzz");
12 12
13 13 /// Name of the overlay layer in QCustomPlot
14 14 const auto OVERLAY_LAYER = QStringLiteral("overlay");
15 15
16 16 const auto TOOLTIP_FORMAT = QStringLiteral("key: %1\nvalue: %2");
17 17
18 18 /// Offset used to shift the tooltip of the mouse
19 19 const auto TOOLTIP_OFFSET = QPoint{20, 20};
20 20
21 21 /// Tooltip display rectangle (the tooltip is hidden when the mouse leaves this rectangle)
22 22 const auto TOOLTIP_RECT = QRect{10, 10, 10, 10};
23 23
24 24 /// Timeout after which the tooltip is displayed
25 25 const auto TOOLTIP_TIMEOUT = 500;
26 26
27 27 /// Formats a data value according to the axis on which it is present
28 28 QString formatValue(double value, const QCPAxis &axis)
29 29 {
30 30 // If the axis is a time axis, formats the value as a date
31 31 if (auto axisTicker = qSharedPointerDynamicCast<QCPAxisTickerDateTime>(axis.ticker())) {
32 32 return DateUtils::dateTime(value, axisTicker->dateTimeSpec()).toString(DATETIME_FORMAT);
33 33 }
34 34 else {
35 35 return QString::number(value);
36 36 }
37 37 }
38 38
39 39 void initPointTracerStyle(QCPItemTracer &tracer) noexcept
40 40 {
41 41 tracer.setInterpolating(false);
42 42 tracer.setStyle(QCPItemTracer::tsCircle);
43 43 tracer.setSize(3);
44 44 tracer.setPen(QPen(Qt::black));
45 45 tracer.setBrush(Qt::black);
46 46 }
47 47
48 48 void initClosePixmapStyle(QCPItemPixmap &pixmap) noexcept
49 49 {
50 50 // Icon
51 51 pixmap.setPixmap(
52 52 sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton).pixmap(QSize{16, 16}));
53 53
54 54 // Position
55 55 pixmap.topLeft->setType(QCPItemPosition::ptAxisRectRatio);
56 56 pixmap.topLeft->setCoords(1, 0);
57 57 pixmap.setClipToAxisRect(false);
58 58
59 59 // Can be selected
60 60 pixmap.setSelectable(true);
61 61 }
62 62
63 63 void initTitleTextStyle(QCPItemText &text) noexcept
64 64 {
65 65 // Font and background styles
66 66 text.setColor(Qt::gray);
67 67 text.setBrush(Qt::white);
68 68
69 69 // Position
70 70 text.setPositionAlignment(Qt::AlignTop | Qt::AlignLeft);
71 71 text.position->setType(QCPItemPosition::ptAxisRectRatio);
72 72 text.position->setCoords(0.5, 0);
73 73 }
74 74
75 75 } // namespace
76 76
77 77 struct VisualizationGraphRenderingDelegate::VisualizationGraphRenderingDelegatePrivate {
78 78 explicit VisualizationGraphRenderingDelegatePrivate(VisualizationGraphWidget &graphWidget)
79 79 : m_Plot{graphWidget.plot()},
80 80 m_PointTracer{new QCPItemTracer{&m_Plot}},
81 81 m_TracerTimer{},
82 82 m_ClosePixmap{new QCPItemPixmap{&m_Plot}},
83 83 m_TitleText{new QCPItemText{&m_Plot}}
84 84 {
85 85 initPointTracerStyle(*m_PointTracer);
86 86
87 87 m_TracerTimer.setInterval(TOOLTIP_TIMEOUT);
88 88 m_TracerTimer.setSingleShot(true);
89 89
90 90 // Inits "close button" in plot overlay
91 91 m_ClosePixmap->setLayer(OVERLAY_LAYER);
92 92 initClosePixmapStyle(*m_ClosePixmap);
93 93
94 94 // Connects pixmap selection to graph widget closing
95 95 QObject::connect(m_ClosePixmap, &QCPItemPixmap::selectionChanged,
96 96 [&graphWidget](bool selected) {
97 97 if (selected) {
98 98 graphWidget.close();
99 99 }
100 100 });
101 101
102 102 // Inits graph name in plot overlay
103 103 m_TitleText->setLayer(OVERLAY_LAYER);
104 104 m_TitleText->setText(graphWidget.name());
105 105 initTitleTextStyle(*m_TitleText);
106 106 }
107 107
108 108 QCustomPlot &m_Plot;
109 109 QCPItemTracer *m_PointTracer;
110 110 QTimer m_TracerTimer;
111 111 QCPItemPixmap *m_ClosePixmap; /// Graph's close button
112 112 QCPItemText *m_TitleText; /// Graph's title
113 113 };
114 114
115 115 VisualizationGraphRenderingDelegate::VisualizationGraphRenderingDelegate(
116 116 VisualizationGraphWidget &graphWidget)
117 117 : impl{spimpl::make_unique_impl<VisualizationGraphRenderingDelegatePrivate>(graphWidget)}
118 118 {
119 119 }
120 120
121 121 void VisualizationGraphRenderingDelegate::onMouseMove(QMouseEvent *event) noexcept
122 122 {
123 123 // Cancels pending refresh
124 124 impl->m_TracerTimer.disconnect();
125 125
126 126 // Reinits tracers
127 127 impl->m_PointTracer->setGraph(nullptr);
128 128 impl->m_PointTracer->setVisible(false);
129 129 impl->m_Plot.replot();
130 130
131 131 // Gets the graph under the mouse position
132 132 auto eventPos = event->pos();
133 133 if (auto graph = qobject_cast<QCPGraph *>(impl->m_Plot.plottableAt(eventPos))) {
134 134 auto mouseKey = graph->keyAxis()->pixelToCoord(eventPos.x());
135 135 auto graphData = graph->data();
136 136
137 137 // Gets the closest data point to the mouse
138 138 auto graphDataIt = graphData->findBegin(mouseKey);
139 139 if (graphDataIt != graphData->constEnd()) {
140 140 auto key = formatValue(graphDataIt->key, *graph->keyAxis());
141 141 auto value = formatValue(graphDataIt->value, *graph->valueAxis());
142 142
143 143 // Displays point tracer
144 144 impl->m_PointTracer->setGraph(graph);
145 145 impl->m_PointTracer->setGraphKey(graphDataIt->key);
146 146 impl->m_PointTracer->setLayer(
147 147 impl->m_Plot.layer("main")); // Tracer is set on top of the plot's main layer
148 148 impl->m_PointTracer->setVisible(true);
149 149 impl->m_Plot.replot();
150 150
151 151 // Starts timer to show tooltip after timeout
152 152 auto showTooltip = [ tooltip = TOOLTIP_FORMAT.arg(key, value), eventPos, this ]()
153 153 {
154 154 QToolTip::showText(impl->m_Plot.mapToGlobal(eventPos) + TOOLTIP_OFFSET, tooltip,
155 155 &impl->m_Plot, TOOLTIP_RECT);
156 156 };
157 157
158 158 QObject::connect(&impl->m_TracerTimer, &QTimer::timeout, showTooltip);
159 159 impl->m_TracerTimer.start();
160 160 }
161 161 }
162 162 }
163
164 void VisualizationGraphRenderingDelegate::showGraphOverlay(bool show) noexcept
165 {
166 auto overlay = impl->m_Plot.layer(OVERLAY_LAYER);
167 overlay->setVisible(show);
168 overlay->replot();
169 }
@@ -1,318 +1,330
1 1 #include "Visualization/VisualizationGraphWidget.h"
2 2 #include "Visualization/IVisualizationWidgetVisitor.h"
3 3 #include "Visualization/VisualizationDefs.h"
4 4 #include "Visualization/VisualizationGraphHelper.h"
5 5 #include "Visualization/VisualizationGraphRenderingDelegate.h"
6 6 #include "ui_VisualizationGraphWidget.h"
7 7
8 8 #include <Data/ArrayData.h>
9 9 #include <Data/IDataSeries.h>
10 10 #include <Settings/SqpSettingsDefs.h>
11 11 #include <SqpApplication.h>
12 12 #include <Variable/Variable.h>
13 13 #include <Variable/VariableController.h>
14 14
15 15 #include <unordered_map>
16 16
17 17 Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget")
18 18
19 19 namespace {
20 20
21 21 /// Key pressed to enable zoom on horizontal axis
22 22 const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier;
23 23
24 24 /// Key pressed to enable zoom on vertical axis
25 25 const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier;
26 26
27 27 } // namespace
28 28
29 29 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
30 30
31 31 explicit VisualizationGraphWidgetPrivate(const QString &name)
32 32 : m_Name{name},
33 33 m_DoAcquisition{true},
34 34 m_IsCalibration{false},
35 35 m_RenderingDelegate{nullptr}
36 36 {
37 37 }
38 38
39 39 QString m_Name;
40 40 // 1 variable -> n qcpplot
41 41 std::map<std::shared_ptr<Variable>, PlottablesMap> m_VariableToPlotMultiMap;
42 42 bool m_DoAcquisition;
43 43 bool m_IsCalibration;
44 44 QCPItemTracer *m_TextTracer;
45 45 /// Delegate used to attach rendering features to the plot
46 46 std::unique_ptr<VisualizationGraphRenderingDelegate> m_RenderingDelegate;
47 47 };
48 48
49 49 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent)
50 50 : QWidget{parent},
51 51 ui{new Ui::VisualizationGraphWidget},
52 52 impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>(name)}
53 53 {
54 54 ui->setupUi(this);
55 55
56 56 // 'Close' options : widget is deleted when closed
57 57 setAttribute(Qt::WA_DeleteOnClose);
58 58
59 59 // Set qcpplot properties :
60 60 // - Drag (on x-axis) and zoom are enabled
61 61 // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation
62 62 ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectItems);
63 63 ui->widget->axisRect()->setRangeDrag(Qt::Horizontal);
64 64
65 65 // The delegate must be initialized after the ui as it uses the plot
66 66 impl->m_RenderingDelegate = std::make_unique<VisualizationGraphRenderingDelegate>(*this);
67 67
68 68 connect(ui->widget, &QCustomPlot::mousePress, this, &VisualizationGraphWidget::onMousePress);
69 69 connect(ui->widget, &QCustomPlot::mouseRelease, this,
70 70 &VisualizationGraphWidget::onMouseRelease);
71 71 connect(ui->widget, &QCustomPlot::mouseMove, this, &VisualizationGraphWidget::onMouseMove);
72 72 connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel);
73 73 connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>(
74 74 &QCPAxis::rangeChanged),
75 75 this, &VisualizationGraphWidget::onRangeChanged, Qt::DirectConnection);
76 76
77 77 // Activates menu when right clicking on the graph
78 78 ui->widget->setContextMenuPolicy(Qt::CustomContextMenu);
79 79 connect(ui->widget, &QCustomPlot::customContextMenuRequested, this,
80 80 &VisualizationGraphWidget::onGraphMenuRequested);
81 81
82 82 connect(this, &VisualizationGraphWidget::requestDataLoading, &sqpApp->variableController(),
83 83 &VariableController::onRequestDataLoading);
84 84
85 85 connect(&sqpApp->variableController(), &VariableController::updateVarDisplaying, this,
86 86 &VisualizationGraphWidget::onUpdateVarDisplaying);
87 87 }
88 88
89 89
90 90 VisualizationGraphWidget::~VisualizationGraphWidget()
91 91 {
92 92 delete ui;
93 93 }
94 94
95 95 void VisualizationGraphWidget::enableAcquisition(bool enable)
96 96 {
97 97 impl->m_DoAcquisition = enable;
98 98 }
99 99
100 100 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable, SqpRange range)
101 101 {
102 102 // Uses delegate to create the qcpplot components according to the variable
103 103 auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget);
104 104 impl->m_VariableToPlotMultiMap.insert({variable, std::move(createdPlottables)});
105 105
106 106 connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated()));
107 107
108 108 auto varRange = variable->range();
109 109
110 110 this->enableAcquisition(false);
111 111 this->setGraphRange(range);
112 112 this->enableAcquisition(true);
113 113
114 114 emit requestDataLoading(QVector<std::shared_ptr<Variable> >() << variable, range, varRange,
115 115 false);
116 116
117 117 emit variableAdded(variable);
118 118 }
119 119
120 120 void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept
121 121 {
122 122 // Each component associated to the variable :
123 123 // - is removed from qcpplot (which deletes it)
124 124 // - is no longer referenced in the map
125 125 auto variableIt = impl->m_VariableToPlotMultiMap.find(variable);
126 126 if (variableIt != impl->m_VariableToPlotMultiMap.cend()) {
127 127 auto &plottablesMap = variableIt->second;
128 128
129 129 for (auto plottableIt = plottablesMap.cbegin(), plottableEnd = plottablesMap.cend();
130 130 plottableIt != plottableEnd;) {
131 131 ui->widget->removePlottable(plottableIt->second);
132 132 plottableIt = plottablesMap.erase(plottableIt);
133 133 }
134 134
135 135 impl->m_VariableToPlotMultiMap.erase(variableIt);
136 136 }
137 137
138 138 // Updates graph
139 139 ui->widget->replot();
140 140 }
141 141
142 142 void VisualizationGraphWidget::setRange(std::shared_ptr<Variable> variable, const SqpRange &range)
143 143 {
144 144 // Note: in case of different axes that depends on variable, we could start with a code like
145 145 // that:
146 146 // auto componentsIt = impl->m_VariableToPlotMultiMap.equal_range(variable);
147 147 // for (auto it = componentsIt.first; it != componentsIt.second;) {
148 148 // }
149 149 ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd);
150 150 ui->widget->replot();
151 151 }
152 152
153 153 void VisualizationGraphWidget::setYRange(const SqpRange &range)
154 154 {
155 155 ui->widget->yAxis->setRange(range.m_TStart, range.m_TEnd);
156 156 }
157 157
158 158 SqpRange VisualizationGraphWidget::graphRange() const noexcept
159 159 {
160 160 auto graphRange = ui->widget->xAxis->range();
161 161 return SqpRange{graphRange.lower, graphRange.upper};
162 162 }
163 163
164 164 void VisualizationGraphWidget::setGraphRange(const SqpRange &range)
165 165 {
166 166 qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange START");
167 167 ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd);
168 168 ui->widget->replot();
169 169 qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange END");
170 170 }
171 171
172 172 void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor)
173 173 {
174 174 if (visitor) {
175 175 visitor->visit(this);
176 176 }
177 177 else {
178 178 qCCritical(LOG_VisualizationGraphWidget())
179 179 << tr("Can't visit widget : the visitor is null");
180 180 }
181 181 }
182 182
183 183 bool VisualizationGraphWidget::canDrop(const Variable &variable) const
184 184 {
185 185 /// @todo : for the moment, a graph can always accomodate a variable
186 186 Q_UNUSED(variable);
187 187 return true;
188 188 }
189 189
190 190 bool VisualizationGraphWidget::contains(const Variable &variable) const
191 191 {
192 192 // Finds the variable among the keys of the map
193 193 auto variablePtr = &variable;
194 194 auto findVariable
195 195 = [variablePtr](const auto &entry) { return variablePtr == entry.first.get(); };
196 196
197 197 auto end = impl->m_VariableToPlotMultiMap.cend();
198 198 auto it = std::find_if(impl->m_VariableToPlotMultiMap.cbegin(), end, findVariable);
199 199 return it != end;
200 200 }
201 201
202 202 QString VisualizationGraphWidget::name() const
203 203 {
204 204 return impl->m_Name;
205 205 }
206 206
207 void VisualizationGraphWidget::enterEvent(QEvent *event)
208 {
209 Q_UNUSED(event);
210 impl->m_RenderingDelegate->showGraphOverlay(true);
211 }
212
213 void VisualizationGraphWidget::leaveEvent(QEvent *event)
214 {
215 Q_UNUSED(event);
216 impl->m_RenderingDelegate->showGraphOverlay(false);
217 }
218
207 219 QCustomPlot &VisualizationGraphWidget::plot() noexcept
208 220 {
209 221 return *ui->widget;
210 222 }
211 223
212 224 void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept
213 225 {
214 226 QMenu graphMenu{};
215 227
216 228 // Iterates on variables (unique keys)
217 229 for (auto it = impl->m_VariableToPlotMultiMap.cbegin(),
218 230 end = impl->m_VariableToPlotMultiMap.cend();
219 231 it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) {
220 232 // 'Remove variable' action
221 233 graphMenu.addAction(tr("Remove variable %1").arg(it->first->name()),
222 234 [ this, var = it->first ]() { removeVariable(var); });
223 235 }
224 236
225 237 if (!graphMenu.isEmpty()) {
226 238 graphMenu.exec(QCursor::pos());
227 239 }
228 240 }
229 241
230 242 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2)
231 243 {
232 244 qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: VisualizationGraphWidget::onRangeChanged")
233 245 << QThread::currentThread()->objectName() << "DoAcqui"
234 246 << impl->m_DoAcquisition;
235 247
236 248 auto graphRange = SqpRange{t1.lower, t1.upper};
237 249 auto oldGraphRange = SqpRange{t2.lower, t2.upper};
238 250
239 251 if (impl->m_DoAcquisition) {
240 252 QVector<std::shared_ptr<Variable> > variableUnderGraphVector;
241 253
242 254 for (auto it = impl->m_VariableToPlotMultiMap.begin(),
243 255 end = impl->m_VariableToPlotMultiMap.end();
244 256 it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) {
245 257 variableUnderGraphVector.push_back(it->first);
246 258 }
247 259 emit requestDataLoading(std::move(variableUnderGraphVector), graphRange, oldGraphRange,
248 260 !impl->m_IsCalibration);
249 261
250 262 if (!impl->m_IsCalibration) {
251 263 qCDebug(LOG_VisualizationGraphWidget())
252 264 << tr("TORM: VisualizationGraphWidget::Synchronize notify !!")
253 265 << QThread::currentThread()->objectName() << graphRange << oldGraphRange;
254 266 emit synchronize(graphRange, oldGraphRange);
255 267 }
256 268 }
257 269 }
258 270
259 271 void VisualizationGraphWidget::onMouseMove(QMouseEvent *event) noexcept
260 272 {
261 273 // Handles plot rendering when mouse is moving
262 274 impl->m_RenderingDelegate->onMouseMove(event);
263 275 }
264 276
265 277 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept
266 278 {
267 279 auto zoomOrientations = QFlags<Qt::Orientation>{};
268 280
269 281 // Lambda that enables a zoom orientation if the key modifier related to this orientation
270 282 // has
271 283 // been pressed
272 284 auto enableOrientation
273 285 = [&zoomOrientations, event](const auto &orientation, const auto &modifier) {
274 286 auto orientationEnabled = event->modifiers().testFlag(modifier);
275 287 zoomOrientations.setFlag(orientation, orientationEnabled);
276 288 };
277 289 enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER);
278 290 enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER);
279 291
280 292 ui->widget->axisRect()->setRangeZoom(zoomOrientations);
281 293 }
282 294
283 295 void VisualizationGraphWidget::onMousePress(QMouseEvent *event) noexcept
284 296 {
285 297 impl->m_IsCalibration = event->modifiers().testFlag(Qt::ControlModifier);
286 298 }
287 299
288 300 void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept
289 301 {
290 302 impl->m_IsCalibration = false;
291 303 }
292 304
293 305 void VisualizationGraphWidget::onDataCacheVariableUpdated()
294 306 {
295 307 auto graphRange = ui->widget->xAxis->range();
296 308 auto dateTime = SqpRange{graphRange.lower, graphRange.upper};
297 309
298 310 for (auto &variableEntry : impl->m_VariableToPlotMultiMap) {
299 311 auto variable = variableEntry.first;
300 312 qCDebug(LOG_VisualizationGraphWidget())
301 313 << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated S" << variable->range();
302 314 qCDebug(LOG_VisualizationGraphWidget())
303 315 << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated E" << dateTime;
304 316 if (dateTime.contains(variable->range()) || dateTime.intersect(variable->range())) {
305 317 VisualizationGraphHelper::updateData(variableEntry.second, variable->dataSeries(),
306 318 variable->range());
307 319 }
308 320 }
309 321 }
310 322
311 323 void VisualizationGraphWidget::onUpdateVarDisplaying(std::shared_ptr<Variable> variable,
312 324 const SqpRange &range)
313 325 {
314 326 auto it = impl->m_VariableToPlotMultiMap.find(variable);
315 327 if (it != impl->m_VariableToPlotMultiMap.end()) {
316 328 VisualizationGraphHelper::updateData(it->second, variable->dataSeries(), range);
317 329 }
318 330 }
General Comments 0
You need to be logged in to leave comments. Login now