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