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