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