##// END OF EJS Templates
Handles key modifiers for zoom...
Alexandre Leroux -
r166:765885a6f6ff
parent child
Show More
@@ -1,39 +1,43
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
5
6 #include <QWidget>
6 #include <QWidget>
7
7
8 #include <memory>
8 #include <memory>
9
9
10 #include <Common/spimpl.h>
10 #include <Common/spimpl.h>
11
11
12 class Variable;
12 class Variable;
13
13
14 namespace Ui {
14 namespace Ui {
15 class VisualizationGraphWidget;
15 class VisualizationGraphWidget;
16 } // namespace Ui
16 } // namespace Ui
17
17
18 class VisualizationGraphWidget : public QWidget, public IVisualizationWidget {
18 class VisualizationGraphWidget : public QWidget, public IVisualizationWidget {
19 Q_OBJECT
19 Q_OBJECT
20
20
21 public:
21 public:
22 explicit VisualizationGraphWidget(QWidget *parent = 0);
22 explicit VisualizationGraphWidget(QWidget *parent = 0);
23 virtual ~VisualizationGraphWidget();
23 virtual ~VisualizationGraphWidget();
24
24
25 void addVariable(std::shared_ptr<Variable> variable);
25 void addVariable(std::shared_ptr<Variable> variable);
26
26
27 // IVisualizationWidget interface
27 // IVisualizationWidget interface
28 void accept(IVisualizationWidget *visitor) override;
28 void accept(IVisualizationWidget *visitor) override;
29 void close() override;
29 void close() override;
30 QString name() const;
30 QString name() const;
31
31
32 private:
32 private:
33 Ui::VisualizationGraphWidget *ui;
33 Ui::VisualizationGraphWidget *ui;
34
34
35 class VisualizationGraphWidgetPrivate;
35 class VisualizationGraphWidgetPrivate;
36 spimpl::unique_impl_ptr<VisualizationGraphWidgetPrivate> impl;
36 spimpl::unique_impl_ptr<VisualizationGraphWidgetPrivate> impl;
37
38 private slots:
39 /// Slot called when a mouse wheel was made, to perform some processing before the zoom is done
40 void onMouseWheel(QWheelEvent *event) noexcept;
37 };
41 };
38
42
39 #endif // SCIQLOP_VISUALIZATIONGRAPHWIDGET_H
43 #endif // SCIQLOP_VISUALIZATIONGRAPHWIDGET_H
@@ -1,51 +1,80
1 #include "Visualization/VisualizationGraphWidget.h"
1 #include "Visualization/VisualizationGraphWidget.h"
2 #include "ui_VisualizationGraphWidget.h"
2 #include "ui_VisualizationGraphWidget.h"
3
3
4 #include <Variable/Variable.h>
4 #include <Variable/Variable.h>
5
5
6 #include <unordered_map>
6 #include <unordered_map>
7
7
8 namespace {
9
10 /// Key pressed to enable zoom on horizontal axis
11 const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier;
12
13 /// Key pressed to enable zoom on vertical axis
14 const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier;
15
16 } // namespace
17
8 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
18 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
9
19
10 // 1 variable -> n qcpplot
20 // 1 variable -> n qcpplot
11 std::unordered_map<std::shared_ptr<Variable>, std::unique_ptr<QCPAbstractPlottable> >
21 std::unordered_map<std::shared_ptr<Variable>, std::unique_ptr<QCPAbstractPlottable> >
12 m_VariableToPlotMap;
22 m_VariableToPlotMap;
13 };
23 };
14
24
15 VisualizationGraphWidget::VisualizationGraphWidget(QWidget *parent)
25 VisualizationGraphWidget::VisualizationGraphWidget(QWidget *parent)
16 : QWidget{parent},
26 : QWidget{parent},
17 ui{new Ui::VisualizationGraphWidget},
27 ui{new Ui::VisualizationGraphWidget},
18 impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()}
28 impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()}
19 {
29 {
20 ui->setupUi(this);
30 ui->setupUi(this);
21
31
22 // Set qcpplot properties :
32 // Set qcpplot properties :
23 // - Drag and zoom are enabled
33 // - Drag and zoom are enabled
34 // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation
24 ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
35 ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
36 connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel);
25 }
37 }
26
38
27 VisualizationGraphWidget::~VisualizationGraphWidget()
39 VisualizationGraphWidget::~VisualizationGraphWidget()
28 {
40 {
29 delete ui;
41 delete ui;
30 }
42 }
31
43
32 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable)
44 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable)
33 {
45 {
34 // todo: first check is variable contains data then check how many plot have to be created
46 // todo: first check is variable contains data then check how many plot have to be created
35 }
47 }
36
48
37 void VisualizationGraphWidget::accept(IVisualizationWidget *visitor)
49 void VisualizationGraphWidget::accept(IVisualizationWidget *visitor)
38 {
50 {
39 // TODO: manage the visitor
51 // TODO: manage the visitor
40 }
52 }
41
53
42 void VisualizationGraphWidget::close()
54 void VisualizationGraphWidget::close()
43 {
55 {
44 // The main view cannot be directly closed.
56 // The main view cannot be directly closed.
45 return;
57 return;
46 }
58 }
47
59
48 QString VisualizationGraphWidget::name() const
60 QString VisualizationGraphWidget::name() const
49 {
61 {
50 return QStringLiteral("MainView");
62 return QStringLiteral("MainView");
51 }
63 }
64
65 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept
66 {
67 auto zoomOrientations = QFlags<Qt::Orientation>{};
68
69 // Lambda that enables a zoom orientation if the key modifier related to this orientation has
70 // been pressed
71 auto enableOrientation
72 = [&zoomOrientations, event](const auto &orientation, const auto &modifier) {
73 auto orientationEnabled = event->modifiers().testFlag(modifier);
74 zoomOrientations.setFlag(orientation, orientationEnabled);
75 };
76 enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER);
77 enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER);
78
79 ui->widget->axisRect()->setRangeZoom(zoomOrientations);
80 }
General Comments 0
You need to be logged in to leave comments. Login now