##// END OF EJS Templates
Adds name to a graph...
Alexandre Leroux -
r196:8ddc77b998a0
parent child
Show More
@@ -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(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,86 +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(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
33 ui->widget->plotLayout()->insertRow(0);
34 ui->widget->plotLayout()->addElement(0, 0, new QCPTextElement{ui->widget, name});
35
32 // Set qcpplot properties :
36 // Set qcpplot properties :
33 // - Drag (on x-axis) and zoom are enabled
37 // - Drag (on x-axis) and zoom are enabled
34 // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation
38 // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation
35 ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
39 ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
36 ui->widget->axisRect()->setRangeDrag(Qt::Horizontal);
40 ui->widget->axisRect()->setRangeDrag(Qt::Horizontal);
37 connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel);
41 connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel);
38 }
42 }
39
43
40 VisualizationGraphWidget::~VisualizationGraphWidget()
44 VisualizationGraphWidget::~VisualizationGraphWidget()
41 {
45 {
42 delete ui;
46 delete ui;
43 }
47 }
44
48
45 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable)
49 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable)
46 {
50 {
47 // Uses delegate to create the qcpplot components according to the variable
51 // Uses delegate to create the qcpplot components according to the variable
48 auto createdPlottables = GraphPlottablesFactory::create(variable, *ui->widget);
52 auto createdPlottables = GraphPlottablesFactory::create(variable, *ui->widget);
49
53
50 for (auto createdPlottable : qAsConst(createdPlottables)) {
54 for (auto createdPlottable : qAsConst(createdPlottables)) {
51 impl->m_VariableToPlotMap.insert({variable, createdPlottable});
55 impl->m_VariableToPlotMap.insert({variable, createdPlottable});
52 }
56 }
53 }
57 }
54
58
55 void VisualizationGraphWidget::accept(IVisualizationWidget *visitor)
59 void VisualizationGraphWidget::accept(IVisualizationWidget *visitor)
56 {
60 {
57 // TODO: manage the visitor
61 // TODO: manage the visitor
58 }
62 }
59
63
60 void VisualizationGraphWidget::close()
64 void VisualizationGraphWidget::close()
61 {
65 {
62 // The main view cannot be directly closed.
66 // The main view cannot be directly closed.
63 return;
67 return;
64 }
68 }
65
69
66 QString VisualizationGraphWidget::name() const
70 QString VisualizationGraphWidget::name() const
67 {
71 {
68 return QStringLiteral("MainView");
72 if (auto title = dynamic_cast<QCPTextElement *>(ui->widget->plotLayout()->elementAt(0))) {
73 return title->text();
74 }
75 else {
76 return QString{};
77 }
69 }
78 }
70
79
71 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept
80 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept
72 {
81 {
73 auto zoomOrientations = QFlags<Qt::Orientation>{};
82 auto zoomOrientations = QFlags<Qt::Orientation>{};
74
83
75 // 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
76 // been pressed
85 // been pressed
77 auto enableOrientation
86 auto enableOrientation
78 = [&zoomOrientations, event](const auto &orientation, const auto &modifier) {
87 = [&zoomOrientations, event](const auto &orientation, const auto &modifier) {
79 auto orientationEnabled = event->modifiers().testFlag(modifier);
88 auto orientationEnabled = event->modifiers().testFlag(modifier);
80 zoomOrientations.setFlag(orientation, orientationEnabled);
89 zoomOrientations.setFlag(orientation, orientationEnabled);
81 };
90 };
82 enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER);
91 enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER);
83 enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER);
92 enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER);
84
93
85 ui->widget->axisRect()->setRangeZoom(zoomOrientations);
94 ui->widget->axisRect()->setRangeZoom(zoomOrientations);
86 }
95 }
General Comments 0
You need to be logged in to leave comments. Login now