##// END OF EJS Templates
Removes the default tab from .ui and adds it manually...
Alexandre Leroux -
r199:0f1ccb97ea85
parent child
Show More
@@ -1,118 +1,121
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
59 // Adds default tab
60 addTabView();
58 }
61 }
59
62
60 VisualizationWidget::~VisualizationWidget()
63 VisualizationWidget::~VisualizationWidget()
61 {
64 {
62 delete ui;
65 delete ui;
63 }
66 }
64
67
65 void VisualizationWidget::addTab(VisualizationTabWidget *tabWidget)
68 void VisualizationWidget::addTab(VisualizationTabWidget *tabWidget)
66 {
69 {
67 // 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
68 // lambda function (in the constructor)
71 // lambda function (in the constructor)
69 }
72 }
70
73
71 VisualizationTabWidget *VisualizationWidget::createTab()
74 VisualizationTabWidget *VisualizationWidget::createTab()
72 {
75 {
73 }
76 }
74
77
75 void VisualizationWidget::removeTab(VisualizationTabWidget *tab)
78 void VisualizationWidget::removeTab(VisualizationTabWidget *tab)
76 {
79 {
77 // 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
78 // lambda function (in the constructor)
81 // lambda function (in the constructor)
79 }
82 }
80
83
81 void VisualizationWidget::accept(IVisualizationWidget *visitor)
84 void VisualizationWidget::accept(IVisualizationWidget *visitor)
82 {
85 {
83 // TODO: manage the visitor
86 // TODO: manage the visitor
84 }
87 }
85
88
86 void VisualizationWidget::close()
89 void VisualizationWidget::close()
87 {
90 {
88 // The main view cannot be directly closed.
91 // The main view cannot be directly closed.
89 return;
92 return;
90 }
93 }
91
94
92 QString VisualizationWidget::name() const
95 QString VisualizationWidget::name() const
93 {
96 {
94 return QStringLiteral("MainView");
97 return QStringLiteral("MainView");
95 }
98 }
96
99
97 void VisualizationWidget::displayVariable(std::shared_ptr<Variable> variable) noexcept
100 void VisualizationWidget::displayVariable(std::shared_ptr<Variable> variable) noexcept
98 {
101 {
99 if (auto currentTab = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->currentWidget())) {
102 if (auto currentTab = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->currentWidget())) {
100 if (auto newZone = currentTab->createZone()) {
103 if (auto newZone = currentTab->createZone()) {
101 if (auto newGraph = newZone->createGraph()) {
104 if (auto newGraph = newZone->createGraph()) {
102 newGraph->addVariable(variable);
105 newGraph->addVariable(variable);
103 }
106 }
104 else {
107 else {
105 qCCritical(LOG_VisualizationWidget())
108 qCCritical(LOG_VisualizationWidget())
106 << tr("Can't display the variable : can't create the graph");
109 << tr("Can't display the variable : can't create the graph");
107 }
110 }
108 }
111 }
109 else {
112 else {
110 qCCritical(LOG_VisualizationWidget())
113 qCCritical(LOG_VisualizationWidget())
111 << tr("Can't display the variable : can't create a new zone in the current tab");
114 << tr("Can't display the variable : can't create a new zone in the current tab");
112 }
115 }
113 }
116 }
114 else {
117 else {
115 qCCritical(LOG_VisualizationWidget())
118 qCCritical(LOG_VisualizationWidget())
116 << tr("Can't display the variable : there is no current tab");
119 << tr("Can't display the variable : there is no current tab");
117 }
120 }
118 }
121 }
@@ -1,41 +1,28
1 <?xml version="1.0" encoding="UTF-8"?>
1 <?xml version="1.0" encoding="UTF-8"?>
2 <ui version="4.0">
2 <ui version="4.0">
3 <class>VisualizationWidget</class>
3 <class>VisualizationWidget</class>
4 <widget class="QWidget" name="VisualizationWidget">
4 <widget class="QWidget" name="VisualizationWidget">
5 <property name="geometry">
5 <property name="geometry">
6 <rect>
6 <rect>
7 <x>0</x>
7 <x>0</x>
8 <y>0</y>
8 <y>0</y>
9 <width>400</width>
9 <width>400</width>
10 <height>300</height>
10 <height>300</height>
11 </rect>
11 </rect>
12 </property>
12 </property>
13 <property name="windowTitle">
13 <property name="windowTitle">
14 <string>Form</string>
14 <string>Form</string>
15 </property>
15 </property>
16 <layout class="QVBoxLayout" name="verticalLayout">
16 <layout class="QVBoxLayout" name="verticalLayout">
17 <item>
17 <item>
18 <widget class="QTabWidget" name="tabWidget">
18 <widget class="QTabWidget" name="tabWidget">
19 <property name="currentIndex">
19 <property name="currentIndex">
20 <number>0</number>
20 <number>-1</number>
21 </property>
21 </property>
22 <widget class="VisualizationTabWidget" name="firstView">
23 <attribute name="title">
24 <string>View 1</string>
25 </attribute>
26 </widget>
27 </widget>
22 </widget>
28 </item>
23 </item>
29 </layout>
24 </layout>
30 </widget>
25 </widget>
31 <customwidgets>
32 <customwidget>
33 <class>VisualizationTabWidget</class>
34 <extends>QWidget</extends>
35 <header location="global">Visualization/VisualizationTabWidget.h</header>
36 <container>1</container>
37 </customwidget>
38 </customwidgets>
39 <resources/>
26 <resources/>
40 <connections/>
27 <connections/>
41 </ui>
28 </ui>
General Comments 0
You need to be logged in to leave comments. Login now