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