##// END OF EJS Templates
Implements VisualizationWidget::displayVariable() slot
Alexandre Leroux -
r176:a33df991d7dc
parent child
Show More
@@ -1,85 +1,105
1 #include "Visualization/VisualizationWidget.h"
1 #include "Visualization/VisualizationWidget.h"
2 #include "Visualization/VisualizationGraphWidget.h"
2 #include "Visualization/VisualizationTabWidget.h"
3 #include "Visualization/VisualizationTabWidget.h"
4 #include "Visualization/VisualizationZoneWidget.h"
3 #include "Visualization/qcustomplot.h"
5 #include "Visualization/qcustomplot.h"
4
6
5 #include "ui_VisualizationWidget.h"
7 #include "ui_VisualizationWidget.h"
6
8
7 #include <QToolButton>
9 #include <QToolButton>
8
10
9 Q_LOGGING_CATEGORY(LOG_VisualizationWidget, "VisualizationWidget")
11 Q_LOGGING_CATEGORY(LOG_VisualizationWidget, "VisualizationWidget")
10
12
11 VisualizationWidget::VisualizationWidget(QWidget *parent)
13 VisualizationWidget::VisualizationWidget(QWidget *parent)
12 : QWidget{parent}, ui{new Ui::VisualizationWidget}
14 : QWidget{parent}, ui{new Ui::VisualizationWidget}
13 {
15 {
14 ui->setupUi(this);
16 ui->setupUi(this);
15
17
16 auto addTabViewButton = new QToolButton{ui->tabWidget};
18 auto addTabViewButton = new QToolButton{ui->tabWidget};
17 addTabViewButton->setText(tr("Add View"));
19 addTabViewButton->setText(tr("Add View"));
18 addTabViewButton->setCursor(Qt::ArrowCursor);
20 addTabViewButton->setCursor(Qt::ArrowCursor);
19 addTabViewButton->setAutoRaise(true);
21 addTabViewButton->setAutoRaise(true);
20 ui->tabWidget->setCornerWidget(addTabViewButton, Qt::TopRightCorner);
22 ui->tabWidget->setCornerWidget(addTabViewButton, Qt::TopRightCorner);
21 auto width = ui->tabWidget->cornerWidget()->width();
23 auto width = ui->tabWidget->cornerWidget()->width();
22 auto height = ui->tabWidget->cornerWidget()->height();
24 auto height = ui->tabWidget->cornerWidget()->height();
23 addTabViewButton->setMinimumHeight(height);
25 addTabViewButton->setMinimumHeight(height);
24 addTabViewButton->setMinimumWidth(width);
26 addTabViewButton->setMinimumWidth(width);
25 ui->tabWidget->setMinimumHeight(height);
27 ui->tabWidget->setMinimumHeight(height);
26 ui->tabWidget->setMinimumWidth(width);
28 ui->tabWidget->setMinimumWidth(width);
27
29
28 auto addTabView = [&]() {
30 auto addTabView = [&]() {
29 auto index = ui->tabWidget->addTab(new VisualizationTabWidget(ui->tabWidget),
31 auto index = ui->tabWidget->addTab(new VisualizationTabWidget(ui->tabWidget),
30 QString("View %1").arg(ui->tabWidget->count() + 1));
32 QString("View %1").arg(ui->tabWidget->count() + 1));
31 qCInfo(LOG_VisualizationWidget()) << tr("add the tab of index %1").arg(index);
33 qCInfo(LOG_VisualizationWidget()) << tr("add the tab of index %1").arg(index);
32 };
34 };
33
35
34 auto removeTabView = [&](int index) {
36 auto removeTabView = [&](int index) {
35 ui->tabWidget->removeTab(index);
37 ui->tabWidget->removeTab(index);
36 qCInfo(LOG_VisualizationWidget()) << tr("remove the tab of index %1").arg(index);
38 qCInfo(LOG_VisualizationWidget()) << tr("remove the tab of index %1").arg(index);
37 };
39 };
38
40
39 ui->tabWidget->setTabsClosable(true);
41 ui->tabWidget->setTabsClosable(true);
40
42
41 connect(addTabViewButton, &QToolButton::clicked, addTabView);
43 connect(addTabViewButton, &QToolButton::clicked, addTabView);
42 connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView);
44 connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView);
43 }
45 }
44
46
45 VisualizationWidget::~VisualizationWidget()
47 VisualizationWidget::~VisualizationWidget()
46 {
48 {
47 delete ui;
49 delete ui;
48 }
50 }
49
51
50 void VisualizationWidget::addTab(VisualizationTabWidget *tabWidget)
52 void VisualizationWidget::addTab(VisualizationTabWidget *tabWidget)
51 {
53 {
52 // NOTE: check is this method has to be deleted because of its dupplicated version visible as
54 // NOTE: check is this method has to be deleted because of its dupplicated version visible as
53 // lambda function (in the constructor)
55 // lambda function (in the constructor)
54 }
56 }
55
57
56 VisualizationTabWidget *VisualizationWidget::createTab()
58 VisualizationTabWidget *VisualizationWidget::createTab()
57 {
59 {
58 }
60 }
59
61
60 void VisualizationWidget::removeTab(VisualizationTabWidget *tab)
62 void VisualizationWidget::removeTab(VisualizationTabWidget *tab)
61 {
63 {
62 // NOTE: check is this method has to be deleted because of its dupplicated version visible as
64 // NOTE: check is this method has to be deleted because of its dupplicated version visible as
63 // lambda function (in the constructor)
65 // lambda function (in the constructor)
64 }
66 }
65
67
66 void VisualizationWidget::accept(IVisualizationWidget *visitor)
68 void VisualizationWidget::accept(IVisualizationWidget *visitor)
67 {
69 {
68 // TODO: manage the visitor
70 // TODO: manage the visitor
69 }
71 }
70
72
71 void VisualizationWidget::close()
73 void VisualizationWidget::close()
72 {
74 {
73 // The main view cannot be directly closed.
75 // The main view cannot be directly closed.
74 return;
76 return;
75 }
77 }
76
78
77 QString VisualizationWidget::name() const
79 QString VisualizationWidget::name() const
78 {
80 {
79 return QStringLiteral("MainView");
81 return QStringLiteral("MainView");
80 }
82 }
81
83
82 void VisualizationWidget::displayVariable(std::shared_ptr<Variable> variable) noexcept
84 void VisualizationWidget::displayVariable(std::shared_ptr<Variable> variable) noexcept
83 {
85 {
84 /// @todo ALX : add variable in a new graph
86 if (auto currentTab = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->currentWidget())) {
87 if (auto newZone = currentTab->createZone()) {
88 if (auto newGraph = newZone->createGraph()) {
89 newGraph->addVariable(variable);
90 }
91 else {
92 qCDebug(LOG_VisualizationWidget())
93 << tr("Can't display the variable : can't create the graph");
94 }
95 }
96 else {
97 qCDebug(LOG_VisualizationWidget())
98 << tr("Can't display the variable : can't create a new zone in the current tab");
99 }
100 }
101 else {
102 qCDebug(LOG_VisualizationWidget())
103 << tr("Can't display the variable : there is no current tab");
104 }
85 }
105 }
General Comments 0
You need to be logged in to leave comments. Login now