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