@@ -1,39 +1,43 | |||
|
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 <QWidget> |
|
7 | 7 | |
|
8 | 8 | #include <memory> |
|
9 | 9 | |
|
10 | 10 | #include <Common/spimpl.h> |
|
11 | 11 | |
|
12 | 12 | class Variable; |
|
13 | 13 | |
|
14 | 14 | namespace Ui { |
|
15 | 15 | class VisualizationGraphWidget; |
|
16 | 16 | } // namespace Ui |
|
17 | 17 | |
|
18 | 18 | class VisualizationGraphWidget : public QWidget, public IVisualizationWidget { |
|
19 | 19 | Q_OBJECT |
|
20 | 20 | |
|
21 | 21 | public: |
|
22 | 22 | explicit VisualizationGraphWidget(QWidget *parent = 0); |
|
23 | 23 | virtual ~VisualizationGraphWidget(); |
|
24 | 24 | |
|
25 | 25 | void addVariable(std::shared_ptr<Variable> variable); |
|
26 | 26 | |
|
27 | 27 | // IVisualizationWidget interface |
|
28 | 28 | void accept(IVisualizationWidget *visitor) override; |
|
29 | 29 | void close() override; |
|
30 | 30 | QString name() const; |
|
31 | 31 | |
|
32 | 32 | private: |
|
33 | 33 | Ui::VisualizationGraphWidget *ui; |
|
34 | 34 | |
|
35 | 35 | class VisualizationGraphWidgetPrivate; |
|
36 | 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 | 43 | #endif // SCIQLOP_VISUALIZATIONGRAPHWIDGET_H |
@@ -1,51 +1,80 | |||
|
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 | 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 | 18 | struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { |
|
9 | 19 | |
|
10 | 20 | // 1 variable -> n qcpplot |
|
11 | 21 | std::unordered_map<std::shared_ptr<Variable>, std::unique_ptr<QCPAbstractPlottable> > |
|
12 | 22 | m_VariableToPlotMap; |
|
13 | 23 | }; |
|
14 | 24 | |
|
15 | 25 | VisualizationGraphWidget::VisualizationGraphWidget(QWidget *parent) |
|
16 | 26 | : QWidget{parent}, |
|
17 | 27 | ui{new Ui::VisualizationGraphWidget}, |
|
18 | 28 | impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()} |
|
19 | 29 | { |
|
20 | 30 | ui->setupUi(this); |
|
21 | 31 | |
|
22 | 32 | // Set qcpplot properties : |
|
23 | 33 | // - Drag and zoom are enabled |
|
34 | // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation | |
|
24 | 35 | ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); |
|
36 | connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel); | |
|
25 | 37 | } |
|
26 | 38 | |
|
27 | 39 | VisualizationGraphWidget::~VisualizationGraphWidget() |
|
28 | 40 | { |
|
29 | 41 | delete ui; |
|
30 | 42 | } |
|
31 | 43 | |
|
32 | 44 | void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable) |
|
33 | 45 | { |
|
34 | 46 | // todo: first check is variable contains data then check how many plot have to be created |
|
35 | 47 | } |
|
36 | 48 | |
|
37 | 49 | void VisualizationGraphWidget::accept(IVisualizationWidget *visitor) |
|
38 | 50 | { |
|
39 | 51 | // TODO: manage the visitor |
|
40 | 52 | } |
|
41 | 53 | |
|
42 | 54 | void VisualizationGraphWidget::close() |
|
43 | 55 | { |
|
44 | 56 | // The main view cannot be directly closed. |
|
45 | 57 | return; |
|
46 | 58 | } |
|
47 | 59 | |
|
48 | 60 | QString VisualizationGraphWidget::name() const |
|
49 | 61 | { |
|
50 | 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