@@ -1,96 +1,98 | |||
|
1 | 1 | #include "Visualization/VisualizationGraphWidget.h" |
|
2 | 2 | #include "Visualization/GraphPlottablesFactory.h" |
|
3 | 3 | #include "Visualization/IVisualizationWidgetVisitor.h" |
|
4 | 4 | #include "ui_VisualizationGraphWidget.h" |
|
5 | 5 | |
|
6 | 6 | #include <Variable/Variable.h> |
|
7 | 7 | |
|
8 | 8 | #include <unordered_map> |
|
9 | 9 | |
|
10 | 10 | namespace { |
|
11 | 11 | |
|
12 | 12 | /// Key pressed to enable zoom on horizontal axis |
|
13 | 13 | const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier; |
|
14 | 14 | |
|
15 | 15 | /// Key pressed to enable zoom on vertical axis |
|
16 | 16 | const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier; |
|
17 | 17 | |
|
18 | 18 | } // namespace |
|
19 | 19 | |
|
20 | 20 | struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { |
|
21 | 21 | |
|
22 | 22 | // 1 variable -> n qcpplot |
|
23 | 23 | std::unordered_map<std::shared_ptr<Variable>, QCPAbstractPlottable *> m_VariableToPlotMap; |
|
24 | 24 | }; |
|
25 | 25 | |
|
26 | 26 | VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent) |
|
27 | 27 | : QWidget{parent}, |
|
28 | 28 | ui{new Ui::VisualizationGraphWidget}, |
|
29 | 29 | impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()} |
|
30 | 30 | { |
|
31 | 31 | ui->setupUi(this); |
|
32 | 32 | |
|
33 | 33 | // qcpplot title |
|
34 | 34 | ui->widget->plotLayout()->insertRow(0); |
|
35 | 35 | ui->widget->plotLayout()->addElement(0, 0, new QCPTextElement{ui->widget, name}); |
|
36 | 36 | |
|
37 | 37 | // Set qcpplot properties : |
|
38 | 38 | // - Drag (on x-axis) and zoom are enabled |
|
39 | 39 | // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation |
|
40 | 40 | ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); |
|
41 | 41 | ui->widget->axisRect()->setRangeDrag(Qt::Horizontal); |
|
42 | 42 | connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel); |
|
43 | 43 | } |
|
44 | 44 | |
|
45 | 45 | VisualizationGraphWidget::~VisualizationGraphWidget() |
|
46 | 46 | { |
|
47 | 47 | delete ui; |
|
48 | 48 | } |
|
49 | 49 | |
|
50 | 50 | void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable) |
|
51 | 51 | { |
|
52 | 52 | // Uses delegate to create the qcpplot components according to the variable |
|
53 | 53 | auto createdPlottables = GraphPlottablesFactory::create(variable, *ui->widget); |
|
54 | 54 | |
|
55 | 55 | for (auto createdPlottable : qAsConst(createdPlottables)) { |
|
56 | 56 | impl->m_VariableToPlotMap.insert({variable, createdPlottable}); |
|
57 | 57 | } |
|
58 | 58 | } |
|
59 | 59 | |
|
60 | 60 | void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
61 | 61 | { |
|
62 | // TODO: manage the visitor | |
|
62 | if (visitor) { | |
|
63 | visitor->visit(this); | |
|
64 | } | |
|
63 | 65 | } |
|
64 | 66 | |
|
65 | 67 | void VisualizationGraphWidget::close() |
|
66 | 68 | { |
|
67 | 69 | // The main view cannot be directly closed. |
|
68 | 70 | return; |
|
69 | 71 | } |
|
70 | 72 | |
|
71 | 73 | QString VisualizationGraphWidget::name() const |
|
72 | 74 | { |
|
73 | 75 | if (auto title = dynamic_cast<QCPTextElement *>(ui->widget->plotLayout()->elementAt(0))) { |
|
74 | 76 | return title->text(); |
|
75 | 77 | } |
|
76 | 78 | else { |
|
77 | 79 | return QString{}; |
|
78 | 80 | } |
|
79 | 81 | } |
|
80 | 82 | |
|
81 | 83 | void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept |
|
82 | 84 | { |
|
83 | 85 | auto zoomOrientations = QFlags<Qt::Orientation>{}; |
|
84 | 86 | |
|
85 | 87 | // Lambda that enables a zoom orientation if the key modifier related to this orientation has |
|
86 | 88 | // been pressed |
|
87 | 89 | auto enableOrientation |
|
88 | 90 | = [&zoomOrientations, event](const auto &orientation, const auto &modifier) { |
|
89 | 91 | auto orientationEnabled = event->modifiers().testFlag(modifier); |
|
90 | 92 | zoomOrientations.setFlag(orientation, orientationEnabled); |
|
91 | 93 | }; |
|
92 | 94 | enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER); |
|
93 | 95 | enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER); |
|
94 | 96 | |
|
95 | 97 | ui->widget->axisRect()->setRangeZoom(zoomOrientations); |
|
96 | 98 | } |
@@ -1,78 +1,92 | |||
|
1 | 1 | #include "Visualization/VisualizationTabWidget.h" |
|
2 | 2 | #include "Visualization/IVisualizationWidgetVisitor.h" |
|
3 | 3 | #include "ui_VisualizationTabWidget.h" |
|
4 | 4 | |
|
5 | 5 | #include "Visualization/VisualizationZoneWidget.h" |
|
6 | 6 | |
|
7 | 7 | namespace { |
|
8 | 8 | |
|
9 | 9 | /// Generates a default name for a new zone, according to the number of zones already displayed in |
|
10 | 10 | /// the tab |
|
11 | 11 | QString defaultZoneName(const QLayout &layout) |
|
12 | 12 | { |
|
13 | 13 | auto count = 0; |
|
14 | 14 | for (auto i = 0; i < layout.count(); ++i) { |
|
15 | 15 | if (dynamic_cast<VisualizationZoneWidget *>(layout.itemAt(i)->widget())) { |
|
16 | 16 | count++; |
|
17 | 17 | } |
|
18 | 18 | } |
|
19 | 19 | |
|
20 | 20 | return QObject::tr("Zone %1").arg(count + 1); |
|
21 | 21 | } |
|
22 | 22 | |
|
23 | 23 | } // namespace |
|
24 | 24 | |
|
25 | 25 | struct VisualizationTabWidget::VisualizationTabWidgetPrivate { |
|
26 | 26 | explicit VisualizationTabWidgetPrivate(const QString &name) : m_Name{name} {} |
|
27 | 27 | |
|
28 | 28 | QString m_Name; |
|
29 | 29 | }; |
|
30 | 30 | |
|
31 | 31 | VisualizationTabWidget::VisualizationTabWidget(const QString &name, QWidget *parent) |
|
32 | 32 | : QWidget{parent}, |
|
33 | 33 | ui{new Ui::VisualizationTabWidget}, |
|
34 | 34 | impl{spimpl::make_unique_impl<VisualizationTabWidgetPrivate>(name)} |
|
35 | 35 | { |
|
36 | 36 | ui->setupUi(this); |
|
37 | 37 | } |
|
38 | 38 | |
|
39 | 39 | VisualizationTabWidget::~VisualizationTabWidget() |
|
40 | 40 | { |
|
41 | 41 | delete ui; |
|
42 | 42 | } |
|
43 | 43 | |
|
44 | 44 | void VisualizationTabWidget::addZone(VisualizationZoneWidget *zoneWidget) |
|
45 | 45 | { |
|
46 | 46 | this->layout()->addWidget(zoneWidget); |
|
47 | 47 | } |
|
48 | 48 | |
|
49 | 49 | VisualizationZoneWidget *VisualizationTabWidget::createZone(std::shared_ptr<Variable> variable) |
|
50 | 50 | { |
|
51 | 51 | auto zoneWidget = new VisualizationZoneWidget{defaultZoneName(*layout()), this}; |
|
52 | 52 | this->addZone(zoneWidget); |
|
53 | 53 | |
|
54 | 54 | // Creates a new graph into the zone |
|
55 | 55 | zoneWidget->createGraph(variable); |
|
56 | 56 | |
|
57 | 57 | return zoneWidget; |
|
58 | 58 | } |
|
59 | 59 | |
|
60 | 60 | void VisualizationTabWidget::removeZone(VisualizationZoneWidget *zone) |
|
61 | 61 | { |
|
62 | 62 | } |
|
63 | 63 | |
|
64 | 64 | void VisualizationTabWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
65 | 65 | { |
|
66 | // TODO: manage the visitor | |
|
66 | if (visitor) { | |
|
67 | visitor->visitEnter(this); | |
|
68 | ||
|
69 | // Apply visitor to zone children | |
|
70 | for (auto i = 0; i < layout()->count(); ++i) { | |
|
71 | if (auto item = layout()->itemAt(i)) { | |
|
72 | if (auto visualizationZoneWidget | |
|
73 | = dynamic_cast<VisualizationZoneWidget *>(item->widget())) { | |
|
74 | visualizationZoneWidget->accept(visitor); | |
|
75 | } | |
|
76 | } | |
|
77 | } | |
|
78 | ||
|
79 | visitor->visitLeave(this); | |
|
80 | } | |
|
67 | 81 | } |
|
68 | 82 | |
|
69 | 83 | void VisualizationTabWidget::close() |
|
70 | 84 | { |
|
71 | 85 | // The main view cannot be directly closed. |
|
72 | 86 | return; |
|
73 | 87 | } |
|
74 | 88 | |
|
75 | 89 | QString VisualizationTabWidget::name() const |
|
76 | 90 | { |
|
77 | 91 | return impl->m_Name; |
|
78 | 92 | } |
@@ -1,113 +1,125 | |||
|
1 | 1 | #include "Visualization/VisualizationWidget.h" |
|
2 | 2 | #include "Visualization/IVisualizationWidgetVisitor.h" |
|
3 | 3 | #include "Visualization/VisualizationGraphWidget.h" |
|
4 | 4 | #include "Visualization/VisualizationTabWidget.h" |
|
5 | 5 | #include "Visualization/VisualizationZoneWidget.h" |
|
6 | 6 | #include "Visualization/qcustomplot.h" |
|
7 | 7 | |
|
8 | 8 | #include "ui_VisualizationWidget.h" |
|
9 | 9 | |
|
10 | 10 | #include <QToolButton> |
|
11 | 11 | |
|
12 | 12 | Q_LOGGING_CATEGORY(LOG_VisualizationWidget, "VisualizationWidget") |
|
13 | 13 | |
|
14 | 14 | VisualizationWidget::VisualizationWidget(QWidget *parent) |
|
15 | 15 | : QWidget{parent}, ui{new Ui::VisualizationWidget} |
|
16 | 16 | { |
|
17 | 17 | ui->setupUi(this); |
|
18 | 18 | |
|
19 | 19 | auto addTabViewButton = new QToolButton{ui->tabWidget}; |
|
20 | 20 | addTabViewButton->setText(tr("Add View")); |
|
21 | 21 | addTabViewButton->setCursor(Qt::ArrowCursor); |
|
22 | 22 | ui->tabWidget->setCornerWidget(addTabViewButton, Qt::TopRightCorner); |
|
23 | 23 | |
|
24 | 24 | auto enableMinimumCornerWidgetSize = [this](bool enable) { |
|
25 | 25 | |
|
26 | 26 | auto tabViewCornerWidget = ui->tabWidget->cornerWidget(); |
|
27 | 27 | auto width = enable ? tabViewCornerWidget->width() : 0; |
|
28 | 28 | auto height = enable ? tabViewCornerWidget->height() : 0; |
|
29 | 29 | tabViewCornerWidget->setMinimumHeight(height); |
|
30 | 30 | tabViewCornerWidget->setMinimumWidth(width); |
|
31 | 31 | ui->tabWidget->setMinimumHeight(height); |
|
32 | 32 | ui->tabWidget->setMinimumWidth(width); |
|
33 | 33 | }; |
|
34 | 34 | |
|
35 | 35 | auto addTabView = [this, enableMinimumCornerWidgetSize]() { |
|
36 | 36 | auto widget = new VisualizationTabWidget{QString{"View %1"}.arg(ui->tabWidget->count() + 1), |
|
37 | 37 | ui->tabWidget}; |
|
38 | 38 | auto index = ui->tabWidget->addTab(widget, widget->name()); |
|
39 | 39 | if (ui->tabWidget->count() > 0) { |
|
40 | 40 | enableMinimumCornerWidgetSize(false); |
|
41 | 41 | } |
|
42 | 42 | qCInfo(LOG_VisualizationWidget()) << tr("add the tab of index %1").arg(index); |
|
43 | 43 | }; |
|
44 | 44 | |
|
45 | 45 | auto removeTabView = [this, enableMinimumCornerWidgetSize](int index) { |
|
46 | 46 | if (ui->tabWidget->count() == 1) { |
|
47 | 47 | enableMinimumCornerWidgetSize(true); |
|
48 | 48 | } |
|
49 | 49 | |
|
50 | 50 | ui->tabWidget->removeTab(index); |
|
51 | 51 | qCInfo(LOG_VisualizationWidget()) << tr("remove the tab of index %1").arg(index); |
|
52 | 52 | |
|
53 | 53 | }; |
|
54 | 54 | |
|
55 | 55 | ui->tabWidget->setTabsClosable(true); |
|
56 | 56 | |
|
57 | 57 | connect(addTabViewButton, &QToolButton::clicked, addTabView); |
|
58 | 58 | connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView); |
|
59 | 59 | |
|
60 | 60 | // Adds default tab |
|
61 | 61 | addTabView(); |
|
62 | 62 | } |
|
63 | 63 | |
|
64 | 64 | VisualizationWidget::~VisualizationWidget() |
|
65 | 65 | { |
|
66 | 66 | delete ui; |
|
67 | 67 | } |
|
68 | 68 | |
|
69 | 69 | void VisualizationWidget::addTab(VisualizationTabWidget *tabWidget) |
|
70 | 70 | { |
|
71 | 71 | // NOTE: check is this method has to be deleted because of its dupplicated version visible as |
|
72 | 72 | // lambda function (in the constructor) |
|
73 | 73 | } |
|
74 | 74 | |
|
75 | 75 | VisualizationTabWidget *VisualizationWidget::createTab() |
|
76 | 76 | { |
|
77 | 77 | } |
|
78 | 78 | |
|
79 | 79 | void VisualizationWidget::removeTab(VisualizationTabWidget *tab) |
|
80 | 80 | { |
|
81 | 81 | // NOTE: check is this method has to be deleted because of its dupplicated version visible as |
|
82 | 82 | // lambda function (in the constructor) |
|
83 | 83 | } |
|
84 | 84 | |
|
85 | 85 | void VisualizationWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
86 | 86 | { |
|
87 | // TODO: manage the visitor | |
|
87 | if (visitor) { | |
|
88 | visitor->visitEnter(this); | |
|
89 | ||
|
90 | // Apply visitor for tab children | |
|
91 | for (auto i = 0; i < ui->tabWidget->count(); ++i) { | |
|
92 | if (auto visualizationTabWidget | |
|
93 | = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->widget(i))) { | |
|
94 | visualizationTabWidget->accept(visitor); | |
|
95 | } | |
|
96 | } | |
|
97 | ||
|
98 | visitor->visitLeave(this); | |
|
99 | } | |
|
88 | 100 | } |
|
89 | 101 | |
|
90 | 102 | void VisualizationWidget::close() |
|
91 | 103 | { |
|
92 | 104 | // The main view cannot be directly closed. |
|
93 | 105 | return; |
|
94 | 106 | } |
|
95 | 107 | |
|
96 | 108 | QString VisualizationWidget::name() const |
|
97 | 109 | { |
|
98 | 110 | return QStringLiteral("MainView"); |
|
99 | 111 | } |
|
100 | 112 | |
|
101 | 113 | void VisualizationWidget::displayVariable(std::shared_ptr<Variable> variable) noexcept |
|
102 | 114 | { |
|
103 | 115 | if (auto currentTab = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->currentWidget())) { |
|
104 | 116 | if (!currentTab->createZone(variable)) { |
|
105 | 117 | qCCritical(LOG_VisualizationWidget()) |
|
106 | 118 | << tr("Can't display the variable : can't create a new zone in the current tab"); |
|
107 | 119 | } |
|
108 | 120 | } |
|
109 | 121 | else { |
|
110 | 122 | qCCritical(LOG_VisualizationWidget()) |
|
111 | 123 | << tr("Can't display the variable : there is no current tab"); |
|
112 | 124 | } |
|
113 | 125 | } |
@@ -1,72 +1,87 | |||
|
1 | 1 | #include "Visualization/VisualizationZoneWidget.h" |
|
2 | 2 | #include "Visualization/IVisualizationWidgetVisitor.h" |
|
3 | 3 | #include "ui_VisualizationZoneWidget.h" |
|
4 | 4 | |
|
5 | 5 | #include "Visualization/VisualizationGraphWidget.h" |
|
6 | 6 | |
|
7 | 7 | namespace { |
|
8 | 8 | |
|
9 | 9 | /// Generates a default name for a new graph, according to the number of graphs already displayed in |
|
10 | 10 | /// the zone |
|
11 | 11 | QString defaultGraphName(const QLayout &layout) |
|
12 | 12 | { |
|
13 | 13 | auto count = 0; |
|
14 | 14 | for (auto i = 0; i < layout.count(); ++i) { |
|
15 | 15 | if (dynamic_cast<VisualizationGraphWidget *>(layout.itemAt(i)->widget())) { |
|
16 | 16 | count++; |
|
17 | 17 | } |
|
18 | 18 | } |
|
19 | 19 | |
|
20 | 20 | return QObject::tr("Graph %1").arg(count + 1); |
|
21 | 21 | } |
|
22 | 22 | |
|
23 | 23 | } // namespace |
|
24 | 24 | |
|
25 | 25 | VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent) |
|
26 | 26 | : QWidget{parent}, ui{new Ui::VisualizationZoneWidget} |
|
27 | 27 | { |
|
28 | 28 | ui->setupUi(this); |
|
29 | 29 | |
|
30 | 30 | ui->zoneNameLabel->setText(name); |
|
31 | 31 | } |
|
32 | 32 | |
|
33 | 33 | VisualizationZoneWidget::~VisualizationZoneWidget() |
|
34 | 34 | { |
|
35 | 35 | delete ui; |
|
36 | 36 | } |
|
37 | 37 | |
|
38 | 38 | void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget) |
|
39 | 39 | { |
|
40 | 40 | ui->visualizationZoneFrame->layout()->addWidget(graphWidget); |
|
41 | 41 | } |
|
42 | 42 | |
|
43 | 43 | VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable) |
|
44 | 44 | { |
|
45 | 45 | auto graphWidget = new VisualizationGraphWidget{ |
|
46 | 46 | defaultGraphName(*ui->visualizationZoneFrame->layout()), this}; |
|
47 | 47 | this->addGraph(graphWidget); |
|
48 | 48 | |
|
49 | 49 | graphWidget->addVariable(variable); |
|
50 | 50 | |
|
51 | 51 | return graphWidget; |
|
52 | 52 | } |
|
53 | 53 | |
|
54 | 54 | void VisualizationZoneWidget::removeGraph(VisualizationGraphWidget *graph) |
|
55 | 55 | { |
|
56 | 56 | } |
|
57 | 57 | |
|
58 | 58 | void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
59 | 59 | { |
|
60 | // TODO: manage the visitor | |
|
60 | if (visitor) { | |
|
61 | visitor->visitEnter(this); | |
|
62 | ||
|
63 | // Apply visitor to graph children | |
|
64 | auto layout = ui->visualizationZoneFrame->layout(); | |
|
65 | for (auto i = 0; i < layout->count(); ++i) { | |
|
66 | if (auto item = layout->itemAt(i)) { | |
|
67 | if (auto visualizationGraphWidget | |
|
68 | = dynamic_cast<VisualizationGraphWidget *>(item->widget())) { | |
|
69 | visualizationGraphWidget->accept(visitor); | |
|
70 | } | |
|
71 | } | |
|
72 | } | |
|
73 | ||
|
74 | visitor->visitLeave(this); | |
|
75 | } | |
|
61 | 76 | } |
|
62 | 77 | |
|
63 | 78 | void VisualizationZoneWidget::close() |
|
64 | 79 | { |
|
65 | 80 | // The main view cannot be directly closed. |
|
66 | 81 | return; |
|
67 | 82 | } |
|
68 | 83 | |
|
69 | 84 | QString VisualizationZoneWidget::name() const |
|
70 | 85 | { |
|
71 | 86 | return ui->zoneNameLabel->text(); |
|
72 | 87 | } |
General Comments 0
You need to be logged in to leave comments.
Login now