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

Pull request updated. Auto status change to "Under Review"

Changed commits:
  * 1 added
  * 0 removed

Changed files:
  * M gui/include/Visualization/VisualizationGraphWidget.h
  * M gui/src/Visualization/VisualizationGraphWidget.cpp
Approved
author

Status change > Approved

You need to be logged in to leave comments. Login now