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