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