@@ -1,43 +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(const QString name = {}, QWidget *parent = 0); |
|
22 | explicit VisualizationGraphWidget(const QString &name = {}, 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 |
|
37 | |||
38 | private slots: |
|
38 | private slots: | |
39 | /// Slot called when a mouse wheel was made, to perform some processing before the zoom is done |
|
39 | /// Slot called when a mouse wheel was made, to perform some processing before the zoom is done | |
40 | void onMouseWheel(QWheelEvent *event) noexcept; |
|
40 | void onMouseWheel(QWheelEvent *event) noexcept; | |
41 | }; |
|
41 | }; | |
42 |
|
42 | |||
43 | #endif // SCIQLOP_VISUALIZATIONGRAPHWIDGET_H |
|
43 | #endif // SCIQLOP_VISUALIZATIONGRAPHWIDGET_H |
@@ -1,95 +1,95 | |||||
1 | #include "Visualization/VisualizationGraphWidget.h" |
|
1 | #include "Visualization/VisualizationGraphWidget.h" | |
2 | #include "Visualization/GraphPlottablesFactory.h" |
|
2 | #include "Visualization/GraphPlottablesFactory.h" | |
3 | #include "ui_VisualizationGraphWidget.h" |
|
3 | #include "ui_VisualizationGraphWidget.h" | |
4 |
|
4 | |||
5 | #include <Variable/Variable.h> |
|
5 | #include <Variable/Variable.h> | |
6 |
|
6 | |||
7 | #include <unordered_map> |
|
7 | #include <unordered_map> | |
8 |
|
8 | |||
9 | namespace { |
|
9 | namespace { | |
10 |
|
10 | |||
11 | /// Key pressed to enable zoom on horizontal axis |
|
11 | /// Key pressed to enable zoom on horizontal axis | |
12 | const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier; |
|
12 | const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier; | |
13 |
|
13 | |||
14 | /// Key pressed to enable zoom on vertical axis |
|
14 | /// Key pressed to enable zoom on vertical axis | |
15 | const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier; |
|
15 | const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier; | |
16 |
|
16 | |||
17 | } // namespace |
|
17 | } // namespace | |
18 |
|
18 | |||
19 | struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { |
|
19 | struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { | |
20 |
|
20 | |||
21 | // 1 variable -> n qcpplot |
|
21 | // 1 variable -> n qcpplot | |
22 | std::unordered_map<std::shared_ptr<Variable>, QCPAbstractPlottable *> m_VariableToPlotMap; |
|
22 | std::unordered_map<std::shared_ptr<Variable>, QCPAbstractPlottable *> m_VariableToPlotMap; | |
23 | }; |
|
23 | }; | |
24 |
|
24 | |||
25 | VisualizationGraphWidget::VisualizationGraphWidget(const QString name, QWidget *parent) |
|
25 | VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, 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 | // qcpplot title |
|
32 | // qcpplot title | |
33 | ui->widget->plotLayout()->insertRow(0); |
|
33 | ui->widget->plotLayout()->insertRow(0); | |
34 | ui->widget->plotLayout()->addElement(0, 0, new QCPTextElement{ui->widget, name}); |
|
34 | ui->widget->plotLayout()->addElement(0, 0, new QCPTextElement{ui->widget, name}); | |
35 |
|
35 | |||
36 | // Set qcpplot properties : |
|
36 | // Set qcpplot properties : | |
37 | // - Drag (on x-axis) and zoom are enabled |
|
37 | // - Drag (on x-axis) and zoom are enabled | |
38 | // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation |
|
38 | // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation | |
39 | ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); |
|
39 | ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); | |
40 | ui->widget->axisRect()->setRangeDrag(Qt::Horizontal); |
|
40 | ui->widget->axisRect()->setRangeDrag(Qt::Horizontal); | |
41 | connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel); |
|
41 | connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel); | |
42 | } |
|
42 | } | |
43 |
|
43 | |||
44 | VisualizationGraphWidget::~VisualizationGraphWidget() |
|
44 | VisualizationGraphWidget::~VisualizationGraphWidget() | |
45 | { |
|
45 | { | |
46 | delete ui; |
|
46 | delete ui; | |
47 | } |
|
47 | } | |
48 |
|
48 | |||
49 | void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable) |
|
49 | void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable) | |
50 | { |
|
50 | { | |
51 | // Uses delegate to create the qcpplot components according to the variable |
|
51 | // Uses delegate to create the qcpplot components according to the variable | |
52 | auto createdPlottables = GraphPlottablesFactory::create(variable, *ui->widget); |
|
52 | auto createdPlottables = GraphPlottablesFactory::create(variable, *ui->widget); | |
53 |
|
53 | |||
54 | for (auto createdPlottable : qAsConst(createdPlottables)) { |
|
54 | for (auto createdPlottable : qAsConst(createdPlottables)) { | |
55 | impl->m_VariableToPlotMap.insert({variable, createdPlottable}); |
|
55 | impl->m_VariableToPlotMap.insert({variable, createdPlottable}); | |
56 | } |
|
56 | } | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | void VisualizationGraphWidget::accept(IVisualizationWidget *visitor) |
|
59 | void VisualizationGraphWidget::accept(IVisualizationWidget *visitor) | |
60 | { |
|
60 | { | |
61 | // TODO: manage the visitor |
|
61 | // TODO: manage the visitor | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | void VisualizationGraphWidget::close() |
|
64 | void VisualizationGraphWidget::close() | |
65 | { |
|
65 | { | |
66 | // The main view cannot be directly closed. |
|
66 | // The main view cannot be directly closed. | |
67 | return; |
|
67 | return; | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | QString VisualizationGraphWidget::name() const |
|
70 | QString VisualizationGraphWidget::name() const | |
71 | { |
|
71 | { | |
72 | if (auto title = dynamic_cast<QCPTextElement *>(ui->widget->plotLayout()->elementAt(0))) { |
|
72 | if (auto title = dynamic_cast<QCPTextElement *>(ui->widget->plotLayout()->elementAt(0))) { | |
73 | return title->text(); |
|
73 | return title->text(); | |
74 | } |
|
74 | } | |
75 | else { |
|
75 | else { | |
76 | return QString{}; |
|
76 | return QString{}; | |
77 | } |
|
77 | } | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept |
|
80 | void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept | |
81 | { |
|
81 | { | |
82 | auto zoomOrientations = QFlags<Qt::Orientation>{}; |
|
82 | auto zoomOrientations = QFlags<Qt::Orientation>{}; | |
83 |
|
83 | |||
84 | // Lambda that enables a zoom orientation if the key modifier related to this orientation has |
|
84 | // Lambda that enables a zoom orientation if the key modifier related to this orientation has | |
85 | // been pressed |
|
85 | // been pressed | |
86 | auto enableOrientation |
|
86 | auto enableOrientation | |
87 | = [&zoomOrientations, event](const auto &orientation, const auto &modifier) { |
|
87 | = [&zoomOrientations, event](const auto &orientation, const auto &modifier) { | |
88 | auto orientationEnabled = event->modifiers().testFlag(modifier); |
|
88 | auto orientationEnabled = event->modifiers().testFlag(modifier); | |
89 | zoomOrientations.setFlag(orientation, orientationEnabled); |
|
89 | zoomOrientations.setFlag(orientation, orientationEnabled); | |
90 | }; |
|
90 | }; | |
91 | enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER); |
|
91 | enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER); | |
92 | enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER); |
|
92 | enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER); | |
93 |
|
93 | |||
94 | ui->widget->axisRect()->setRangeZoom(zoomOrientations); |
|
94 | ui->widget->axisRect()->setRangeZoom(zoomOrientations); | |
95 | } |
|
95 | } |
General Comments 0
You need to be logged in to leave comments.
Login now