@@ -1,118 +1,121 | |||
|
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 | ||
|
59 | // Adds default tab | |
|
60 | addTabView(); | |
|
58 | 61 | } |
|
59 | 62 | |
|
60 | 63 | VisualizationWidget::~VisualizationWidget() |
|
61 | 64 | { |
|
62 | 65 | delete ui; |
|
63 | 66 | } |
|
64 | 67 | |
|
65 | 68 | void VisualizationWidget::addTab(VisualizationTabWidget *tabWidget) |
|
66 | 69 | { |
|
67 | 70 | // NOTE: check is this method has to be deleted because of its dupplicated version visible as |
|
68 | 71 | // lambda function (in the constructor) |
|
69 | 72 | } |
|
70 | 73 | |
|
71 | 74 | VisualizationTabWidget *VisualizationWidget::createTab() |
|
72 | 75 | { |
|
73 | 76 | } |
|
74 | 77 | |
|
75 | 78 | void VisualizationWidget::removeTab(VisualizationTabWidget *tab) |
|
76 | 79 | { |
|
77 | 80 | // NOTE: check is this method has to be deleted because of its dupplicated version visible as |
|
78 | 81 | // lambda function (in the constructor) |
|
79 | 82 | } |
|
80 | 83 | |
|
81 | 84 | void VisualizationWidget::accept(IVisualizationWidget *visitor) |
|
82 | 85 | { |
|
83 | 86 | // TODO: manage the visitor |
|
84 | 87 | } |
|
85 | 88 | |
|
86 | 89 | void VisualizationWidget::close() |
|
87 | 90 | { |
|
88 | 91 | // The main view cannot be directly closed. |
|
89 | 92 | return; |
|
90 | 93 | } |
|
91 | 94 | |
|
92 | 95 | QString VisualizationWidget::name() const |
|
93 | 96 | { |
|
94 | 97 | return QStringLiteral("MainView"); |
|
95 | 98 | } |
|
96 | 99 | |
|
97 | 100 | void VisualizationWidget::displayVariable(std::shared_ptr<Variable> variable) noexcept |
|
98 | 101 | { |
|
99 | 102 | if (auto currentTab = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->currentWidget())) { |
|
100 | 103 | if (auto newZone = currentTab->createZone()) { |
|
101 | 104 | if (auto newGraph = newZone->createGraph()) { |
|
102 | 105 | newGraph->addVariable(variable); |
|
103 | 106 | } |
|
104 | 107 | else { |
|
105 | 108 | qCCritical(LOG_VisualizationWidget()) |
|
106 | 109 | << tr("Can't display the variable : can't create the graph"); |
|
107 | 110 | } |
|
108 | 111 | } |
|
109 | 112 | else { |
|
110 | 113 | qCCritical(LOG_VisualizationWidget()) |
|
111 | 114 | << tr("Can't display the variable : can't create a new zone in the current tab"); |
|
112 | 115 | } |
|
113 | 116 | } |
|
114 | 117 | else { |
|
115 | 118 | qCCritical(LOG_VisualizationWidget()) |
|
116 | 119 | << tr("Can't display the variable : there is no current tab"); |
|
117 | 120 | } |
|
118 | 121 | } |
@@ -1,41 +1,28 | |||
|
1 | 1 | <?xml version="1.0" encoding="UTF-8"?> |
|
2 | 2 | <ui version="4.0"> |
|
3 | 3 | <class>VisualizationWidget</class> |
|
4 | 4 | <widget class="QWidget" name="VisualizationWidget"> |
|
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"> |
|
17 | 17 | <item> |
|
18 | 18 | <widget class="QTabWidget" name="tabWidget"> |
|
19 | 19 | <property name="currentIndex"> |
|
20 |
<number> |
|
|
20 | <number>-1</number> | |
|
21 | 21 | </property> |
|
22 | <widget class="VisualizationTabWidget" name="firstView"> | |
|
23 | <attribute name="title"> | |
|
24 | <string>View 1</string> | |
|
25 | </attribute> | |
|
26 | </widget> | |
|
27 | 22 | </widget> |
|
28 | 23 | </item> |
|
29 | 24 | </layout> |
|
30 | 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 | 26 | <resources/> |
|
40 | 27 | <connections/> |
|
41 | 28 | </ui> |
General Comments 0
You need to be logged in to leave comments.
Login now