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