@@ -1,85 +1,105 | |||
|
1 | 1 | #include "Visualization/VisualizationWidget.h" |
|
2 | #include "Visualization/VisualizationGraphWidget.h" | |
|
2 | 3 | #include "Visualization/VisualizationTabWidget.h" |
|
4 | #include "Visualization/VisualizationZoneWidget.h" | |
|
3 | 5 | #include "Visualization/qcustomplot.h" |
|
4 | 6 | |
|
5 | 7 | #include "ui_VisualizationWidget.h" |
|
6 | 8 | |
|
7 | 9 | #include <QToolButton> |
|
8 | 10 | |
|
9 | 11 | Q_LOGGING_CATEGORY(LOG_VisualizationWidget, "VisualizationWidget") |
|
10 | 12 | |
|
11 | 13 | VisualizationWidget::VisualizationWidget(QWidget *parent) |
|
12 | 14 | : QWidget{parent}, ui{new Ui::VisualizationWidget} |
|
13 | 15 | { |
|
14 | 16 | ui->setupUi(this); |
|
15 | 17 | |
|
16 | 18 | auto addTabViewButton = new QToolButton{ui->tabWidget}; |
|
17 | 19 | addTabViewButton->setText(tr("Add View")); |
|
18 | 20 | addTabViewButton->setCursor(Qt::ArrowCursor); |
|
19 | 21 | addTabViewButton->setAutoRaise(true); |
|
20 | 22 | ui->tabWidget->setCornerWidget(addTabViewButton, Qt::TopRightCorner); |
|
21 | 23 | auto width = ui->tabWidget->cornerWidget()->width(); |
|
22 | 24 | auto height = ui->tabWidget->cornerWidget()->height(); |
|
23 | 25 | addTabViewButton->setMinimumHeight(height); |
|
24 | 26 | addTabViewButton->setMinimumWidth(width); |
|
25 | 27 | ui->tabWidget->setMinimumHeight(height); |
|
26 | 28 | ui->tabWidget->setMinimumWidth(width); |
|
27 | 29 | |
|
28 | 30 | auto addTabView = [&]() { |
|
29 | 31 | auto index = ui->tabWidget->addTab(new VisualizationTabWidget(ui->tabWidget), |
|
30 | 32 | QString("View %1").arg(ui->tabWidget->count() + 1)); |
|
31 | 33 | qCInfo(LOG_VisualizationWidget()) << tr("add the tab of index %1").arg(index); |
|
32 | 34 | }; |
|
33 | 35 | |
|
34 | 36 | auto removeTabView = [&](int index) { |
|
35 | 37 | ui->tabWidget->removeTab(index); |
|
36 | 38 | qCInfo(LOG_VisualizationWidget()) << tr("remove the tab of index %1").arg(index); |
|
37 | 39 | }; |
|
38 | 40 | |
|
39 | 41 | ui->tabWidget->setTabsClosable(true); |
|
40 | 42 | |
|
41 | 43 | connect(addTabViewButton, &QToolButton::clicked, addTabView); |
|
42 | 44 | connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView); |
|
43 | 45 | } |
|
44 | 46 | |
|
45 | 47 | VisualizationWidget::~VisualizationWidget() |
|
46 | 48 | { |
|
47 | 49 | delete ui; |
|
48 | 50 | } |
|
49 | 51 | |
|
50 | 52 | void VisualizationWidget::addTab(VisualizationTabWidget *tabWidget) |
|
51 | 53 | { |
|
52 | 54 | // NOTE: check is this method has to be deleted because of its dupplicated version visible as |
|
53 | 55 | // lambda function (in the constructor) |
|
54 | 56 | } |
|
55 | 57 | |
|
56 | 58 | VisualizationTabWidget *VisualizationWidget::createTab() |
|
57 | 59 | { |
|
58 | 60 | } |
|
59 | 61 | |
|
60 | 62 | void VisualizationWidget::removeTab(VisualizationTabWidget *tab) |
|
61 | 63 | { |
|
62 | 64 | // NOTE: check is this method has to be deleted because of its dupplicated version visible as |
|
63 | 65 | // lambda function (in the constructor) |
|
64 | 66 | } |
|
65 | 67 | |
|
66 | 68 | void VisualizationWidget::accept(IVisualizationWidget *visitor) |
|
67 | 69 | { |
|
68 | 70 | // TODO: manage the visitor |
|
69 | 71 | } |
|
70 | 72 | |
|
71 | 73 | void VisualizationWidget::close() |
|
72 | 74 | { |
|
73 | 75 | // The main view cannot be directly closed. |
|
74 | 76 | return; |
|
75 | 77 | } |
|
76 | 78 | |
|
77 | 79 | QString VisualizationWidget::name() const |
|
78 | 80 | { |
|
79 | 81 | return QStringLiteral("MainView"); |
|
80 | 82 | } |
|
81 | 83 | |
|
82 | 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