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