##// END OF EJS Templates
Adds a name for a tab...
Alexandre Leroux -
r198:2c59e95cf3ce
parent child
Show More
@@ -1,39 +1,44
1 #ifndef SCIQLOP_VISUALIZATIONTABWIDGET_H
1 #ifndef SCIQLOP_VISUALIZATIONTABWIDGET_H
2 #define SCIQLOP_VISUALIZATIONTABWIDGET_H
2 #define SCIQLOP_VISUALIZATIONTABWIDGET_H
3
3
4 #include "Visualization/IVisualizationWidget.h"
4 #include "Visualization/IVisualizationWidget.h"
5
5
6 #include <Common/spimpl.h>
7
6 #include <QWidget>
8 #include <QWidget>
7
9
8 class VisualizationZoneWidget;
10 class VisualizationZoneWidget;
9
11
10 namespace Ui {
12 namespace Ui {
11 class VisualizationTabWidget;
13 class VisualizationTabWidget;
12 } // namespace Ui
14 } // namespace Ui
13
15
14 class VisualizationTabWidget : public QWidget, public IVisualizationWidget {
16 class VisualizationTabWidget : public QWidget, public IVisualizationWidget {
15 Q_OBJECT
17 Q_OBJECT
16
18
17 public:
19 public:
18 explicit VisualizationTabWidget(QWidget *parent = 0);
20 explicit VisualizationTabWidget(const QString &name = {}, QWidget *parent = 0);
19 virtual ~VisualizationTabWidget();
21 virtual ~VisualizationTabWidget();
20
22
21 /// Add a zone widget
23 /// Add a zone widget
22 void addZone(VisualizationZoneWidget *zoneWidget);
24 void addZone(VisualizationZoneWidget *zoneWidget);
23
25
24 /// Create a zone using a Variable
26 /// Create a zone using a Variable
25 VisualizationZoneWidget *createZone();
27 VisualizationZoneWidget *createZone();
26
28
27 /// Remove a zone
29 /// Remove a zone
28 void removeZone(VisualizationZoneWidget *zone);
30 void removeZone(VisualizationZoneWidget *zone);
29
31
30 // IVisualizationWidget interface
32 // IVisualizationWidget interface
31 void accept(IVisualizationWidget *visitor) override;
33 void accept(IVisualizationWidget *visitor) override;
32 void close() override;
34 void close() override;
33 QString name() const override;
35 QString name() const override;
34
36
35 private:
37 private:
36 Ui::VisualizationTabWidget *ui;
38 Ui::VisualizationTabWidget *ui;
39
40 class VisualizationTabWidgetPrivate;
41 spimpl::unique_impl_ptr<VisualizationTabWidgetPrivate> impl;
37 };
42 };
38
43
39 #endif // SCIQLOP_VISUALIZATIONTABWIDGET_H
44 #endif // SCIQLOP_VISUALIZATIONTABWIDGET_H
@@ -1,49 +1,56
1 #include "Visualization/VisualizationTabWidget.h"
1 #include "Visualization/VisualizationTabWidget.h"
2 #include "ui_VisualizationTabWidget.h"
2 #include "ui_VisualizationTabWidget.h"
3
3
4 #include "Visualization/VisualizationZoneWidget.h"
4 #include "Visualization/VisualizationZoneWidget.h"
5
5
6 struct VisualizationTabWidget::VisualizationTabWidgetPrivate {
7 explicit VisualizationTabWidgetPrivate(const QString &name) : m_Name{name} {}
6
8
7 VisualizationTabWidget::VisualizationTabWidget(QWidget *parent)
9 QString m_Name;
8 : QWidget{parent}, ui{new Ui::VisualizationTabWidget}
10 };
11
12 VisualizationTabWidget::VisualizationTabWidget(const QString &name, QWidget *parent)
13 : QWidget{parent},
14 ui{new Ui::VisualizationTabWidget},
15 impl{spimpl::make_unique_impl<VisualizationTabWidgetPrivate>(name)}
9 {
16 {
10 ui->setupUi(this);
17 ui->setupUi(this);
11 }
18 }
12
19
13 VisualizationTabWidget::~VisualizationTabWidget()
20 VisualizationTabWidget::~VisualizationTabWidget()
14 {
21 {
15 delete ui;
22 delete ui;
16 }
23 }
17
24
18 void VisualizationTabWidget::addZone(VisualizationZoneWidget *zoneWidget)
25 void VisualizationTabWidget::addZone(VisualizationZoneWidget *zoneWidget)
19 {
26 {
20 this->layout()->addWidget(zoneWidget);
27 this->layout()->addWidget(zoneWidget);
21 }
28 }
22
29
23 VisualizationZoneWidget *VisualizationTabWidget::createZone()
30 VisualizationZoneWidget *VisualizationTabWidget::createZone()
24 {
31 {
25 auto zoneWidget = new VisualizationZoneWidget{this};
32 auto zoneWidget = new VisualizationZoneWidget{this};
26 this->addZone(zoneWidget);
33 this->addZone(zoneWidget);
27
34
28 return zoneWidget;
35 return zoneWidget;
29 }
36 }
30
37
31 void VisualizationTabWidget::removeZone(VisualizationZoneWidget *zone)
38 void VisualizationTabWidget::removeZone(VisualizationZoneWidget *zone)
32 {
39 {
33 }
40 }
34
41
35 void VisualizationTabWidget::accept(IVisualizationWidget *visitor)
42 void VisualizationTabWidget::accept(IVisualizationWidget *visitor)
36 {
43 {
37 // TODO: manage the visitor
44 // TODO: manage the visitor
38 }
45 }
39
46
40 void VisualizationTabWidget::close()
47 void VisualizationTabWidget::close()
41 {
48 {
42 // The main view cannot be directly closed.
49 // The main view cannot be directly closed.
43 return;
50 return;
44 }
51 }
45
52
46 QString VisualizationTabWidget::name() const
53 QString VisualizationTabWidget::name() const
47 {
54 {
48 return QStringLiteral("MainView");
55 return impl->m_Name;
49 }
56 }
@@ -1,117 +1,118
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 index = ui->tabWidget->addTab(new VisualizationTabWidget(ui->tabWidget),
35 auto widget = new VisualizationTabWidget{QString{"View %1"}.arg(ui->tabWidget->count() + 1),
36 QString("View %1").arg(ui->tabWidget->count() + 1));
36 ui->tabWidget};
37 auto index = ui->tabWidget->addTab(widget, widget->name());
37 if (ui->tabWidget->count() > 0) {
38 if (ui->tabWidget->count() > 0) {
38 enableMinimumCornerWidgetSize(false);
39 enableMinimumCornerWidgetSize(false);
39 }
40 }
40 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);
41 };
42 };
42
43
43 auto removeTabView = [this, enableMinimumCornerWidgetSize](int index) {
44 auto removeTabView = [this, enableMinimumCornerWidgetSize](int index) {
44 if (ui->tabWidget->count() == 1) {
45 if (ui->tabWidget->count() == 1) {
45 enableMinimumCornerWidgetSize(true);
46 enableMinimumCornerWidgetSize(true);
46 }
47 }
47
48
48 ui->tabWidget->removeTab(index);
49 ui->tabWidget->removeTab(index);
49 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);
50
51
51 };
52 };
52
53
53 ui->tabWidget->setTabsClosable(true);
54 ui->tabWidget->setTabsClosable(true);
54
55
55 connect(addTabViewButton, &QToolButton::clicked, addTabView);
56 connect(addTabViewButton, &QToolButton::clicked, addTabView);
56 connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView);
57 connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView);
57 }
58 }
58
59
59 VisualizationWidget::~VisualizationWidget()
60 VisualizationWidget::~VisualizationWidget()
60 {
61 {
61 delete ui;
62 delete ui;
62 }
63 }
63
64
64 void VisualizationWidget::addTab(VisualizationTabWidget *tabWidget)
65 void VisualizationWidget::addTab(VisualizationTabWidget *tabWidget)
65 {
66 {
66 // NOTE: check is this method has to be deleted because of its dupplicated version visible as
67 // NOTE: check is this method has to be deleted because of its dupplicated version visible as
67 // lambda function (in the constructor)
68 // lambda function (in the constructor)
68 }
69 }
69
70
70 VisualizationTabWidget *VisualizationWidget::createTab()
71 VisualizationTabWidget *VisualizationWidget::createTab()
71 {
72 {
72 }
73 }
73
74
74 void VisualizationWidget::removeTab(VisualizationTabWidget *tab)
75 void VisualizationWidget::removeTab(VisualizationTabWidget *tab)
75 {
76 {
76 // NOTE: check is this method has to be deleted because of its dupplicated version visible as
77 // NOTE: check is this method has to be deleted because of its dupplicated version visible as
77 // lambda function (in the constructor)
78 // lambda function (in the constructor)
78 }
79 }
79
80
80 void VisualizationWidget::accept(IVisualizationWidget *visitor)
81 void VisualizationWidget::accept(IVisualizationWidget *visitor)
81 {
82 {
82 // TODO: manage the visitor
83 // TODO: manage the visitor
83 }
84 }
84
85
85 void VisualizationWidget::close()
86 void VisualizationWidget::close()
86 {
87 {
87 // The main view cannot be directly closed.
88 // The main view cannot be directly closed.
88 return;
89 return;
89 }
90 }
90
91
91 QString VisualizationWidget::name() const
92 QString VisualizationWidget::name() const
92 {
93 {
93 return QStringLiteral("MainView");
94 return QStringLiteral("MainView");
94 }
95 }
95
96
96 void VisualizationWidget::displayVariable(std::shared_ptr<Variable> variable) noexcept
97 void VisualizationWidget::displayVariable(std::shared_ptr<Variable> variable) noexcept
97 {
98 {
98 if (auto currentTab = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->currentWidget())) {
99 if (auto currentTab = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->currentWidget())) {
99 if (auto newZone = currentTab->createZone()) {
100 if (auto newZone = currentTab->createZone()) {
100 if (auto newGraph = newZone->createGraph()) {
101 if (auto newGraph = newZone->createGraph()) {
101 newGraph->addVariable(variable);
102 newGraph->addVariable(variable);
102 }
103 }
103 else {
104 else {
104 qCCritical(LOG_VisualizationWidget())
105 qCCritical(LOG_VisualizationWidget())
105 << tr("Can't display the variable : can't create the graph");
106 << tr("Can't display the variable : can't create the graph");
106 }
107 }
107 }
108 }
108 else {
109 else {
109 qCCritical(LOG_VisualizationWidget())
110 qCCritical(LOG_VisualizationWidget())
110 << tr("Can't display the variable : can't create a new zone in the current tab");
111 << tr("Can't display the variable : can't create a new zone in the current tab");
111 }
112 }
112 }
113 }
113 else {
114 else {
114 qCCritical(LOG_VisualizationWidget())
115 qCCritical(LOG_VisualizationWidget())
115 << tr("Can't display the variable : there is no current tab");
116 << tr("Can't display the variable : there is no current tab");
116 }
117 }
117 }
118 }
General Comments 0
You need to be logged in to leave comments. Login now