##// END OF EJS Templates
Add lambda in VIsualizationWidget to fix the bug of the corner widget button size...
perrinel -
r186:134da9ef870f
parent child
Show More
@@ -1,105 +1,117
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 addTabViewButton->setAutoRaise(true);
22 21 ui->tabWidget->setCornerWidget(addTabViewButton, Qt::TopRightCorner);
23 auto width = ui->tabWidget->cornerWidget()->width();
24 auto height = ui->tabWidget->cornerWidget()->height();
25 addTabViewButton->setMinimumHeight(height);
26 addTabViewButton->setMinimumWidth(width);
27 ui->tabWidget->setMinimumHeight(height);
28 ui->tabWidget->setMinimumWidth(width);
29
30 auto addTabView = [&]() {
22
23 auto enableMinimunCornerWidgetSize = [this](bool enable) {
24
25 auto tabViewCornerWidget = ui->tabWidget->cornerWidget();
26 auto width = enable ? tabViewCornerWidget->width() : 0;
27 auto height = enable ? tabViewCornerWidget->height() : 0;
28 tabViewCornerWidget->setMinimumHeight(height);
29 tabViewCornerWidget->setMinimumWidth(width);
30 ui->tabWidget->setMinimumHeight(height);
31 ui->tabWidget->setMinimumWidth(width);
32 };
33
34 auto addTabView = [this, enableMinimunCornerWidgetSize]() {
31 35 auto index = ui->tabWidget->addTab(new VisualizationTabWidget(ui->tabWidget),
32 36 QString("View %1").arg(ui->tabWidget->count() + 1));
37 if (ui->tabWidget->count() > 0) {
38 enableMinimunCornerWidgetSize(false);
39 }
33 40 qCInfo(LOG_VisualizationWidget()) << tr("add the tab of index %1").arg(index);
34 41 };
35 42
36 auto removeTabView = [&](int index) {
43 auto removeTabView = [this, enableMinimunCornerWidgetSize](int index) {
44 if (ui->tabWidget->count() == 1) {
45 enableMinimunCornerWidgetSize(true);
46 }
47
37 48 ui->tabWidget->removeTab(index);
38 49 qCInfo(LOG_VisualizationWidget()) << tr("remove the tab of index %1").arg(index);
50
39 51 };
40 52
41 53 ui->tabWidget->setTabsClosable(true);
42 54
43 55 connect(addTabViewButton, &QToolButton::clicked, addTabView);
44 56 connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView);
45 57 }
46 58
47 59 VisualizationWidget::~VisualizationWidget()
48 60 {
49 61 delete ui;
50 62 }
51 63
52 64 void VisualizationWidget::addTab(VisualizationTabWidget *tabWidget)
53 65 {
54 66 // NOTE: check is this method has to be deleted because of its dupplicated version visible as
55 67 // lambda function (in the constructor)
56 68 }
57 69
58 70 VisualizationTabWidget *VisualizationWidget::createTab()
59 71 {
60 72 }
61 73
62 74 void VisualizationWidget::removeTab(VisualizationTabWidget *tab)
63 75 {
64 76 // NOTE: check is this method has to be deleted because of its dupplicated version visible as
65 77 // lambda function (in the constructor)
66 78 }
67 79
68 80 void VisualizationWidget::accept(IVisualizationWidget *visitor)
69 81 {
70 82 // TODO: manage the visitor
71 83 }
72 84
73 85 void VisualizationWidget::close()
74 86 {
75 87 // The main view cannot be directly closed.
76 88 return;
77 89 }
78 90
79 91 QString VisualizationWidget::name() const
80 92 {
81 93 return QStringLiteral("MainView");
82 94 }
83 95
84 96 void VisualizationWidget::displayVariable(std::shared_ptr<Variable> variable) noexcept
85 97 {
86 98 if (auto currentTab = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->currentWidget())) {
87 99 if (auto newZone = currentTab->createZone()) {
88 100 if (auto newGraph = newZone->createGraph()) {
89 101 newGraph->addVariable(variable);
90 102 }
91 103 else {
92 104 qCDebug(LOG_VisualizationWidget())
93 105 << tr("Can't display the variable : can't create the graph");
94 106 }
95 107 }
96 108 else {
97 109 qCDebug(LOG_VisualizationWidget())
98 110 << tr("Can't display the variable : can't create a new zone in the current tab");
99 111 }
100 112 }
101 113 else {
102 114 qCDebug(LOG_VisualizationWidget())
103 115 << tr("Can't display the variable : there is no current tab");
104 116 }
105 117 }
@@ -1,32 +1,50
1 1 <?xml version="1.0" encoding="UTF-8"?>
2 2 <ui version="4.0">
3 3 <class>VisualizationZoneWidget</class>
4 4 <widget class="QWidget" name="VisualizationZoneWidget">
5 5 <property name="geometry">
6 6 <rect>
7 7 <x>0</x>
8 8 <y>0</y>
9 9 <width>400</width>
10 10 <height>300</height>
11 11 </rect>
12 12 </property>
13 13 <property name="windowTitle">
14 14 <string>Form</string>
15 15 </property>
16 16 <layout class="QVBoxLayout" name="verticalLayout_2">
17 <property name="spacing">
18 <number>3</number>
19 </property>
20 <property name="leftMargin">
21 <number>0</number>
22 </property>
23 <property name="topMargin">
24 <number>0</number>
25 </property>
26 <property name="rightMargin">
27 <number>0</number>
28 </property>
29 <property name="bottomMargin">
30 <number>0</number>
31 </property>
17 32 <item>
18 33 <widget class="QFrame" name="visualizationZoneFrame">
19 34 <property name="frameShape">
20 <enum>QFrame::StyledPanel</enum>
35 <enum>QFrame::Box</enum>
21 36 </property>
22 37 <property name="frameShadow">
23 38 <enum>QFrame::Raised</enum>
24 39 </property>
40 <property name="lineWidth">
41 <number>1</number>
42 </property>
25 43 <layout class="QVBoxLayout" name="verticalLayout"/>
26 44 </widget>
27 45 </item>
28 46 </layout>
29 47 </widget>
30 48 <resources/>
31 49 <connections/>
32 50 </ui>
General Comments 0
You need to be logged in to leave comments. Login now