##// END OF EJS Templates
Add comments
Alexandre Leroux -
r220:d787e1653d55
parent child
Show More
@@ -1,104 +1,105
1 1 #include "Visualization/VisualizationTabWidget.h"
2 2 #include "Visualization/IVisualizationWidgetVisitor.h"
3 3 #include "ui_VisualizationTabWidget.h"
4 4
5 5 #include "Visualization/VisualizationZoneWidget.h"
6 6
7 7 Q_LOGGING_CATEGORY(LOG_VisualizationTabWidget, "VisualizationTabWidget")
8 8
9 9 namespace {
10 10
11 11 /// Generates a default name for a new zone, according to the number of zones already displayed in
12 12 /// the tab
13 13 QString defaultZoneName(const QLayout &layout)
14 14 {
15 15 auto count = 0;
16 16 for (auto i = 0; i < layout.count(); ++i) {
17 17 if (dynamic_cast<VisualizationZoneWidget *>(layout.itemAt(i)->widget())) {
18 18 count++;
19 19 }
20 20 }
21 21
22 22 return QObject::tr("Zone %1").arg(count + 1);
23 23 }
24 24
25 25 } // namespace
26 26
27 27 struct VisualizationTabWidget::VisualizationTabWidgetPrivate {
28 28 explicit VisualizationTabWidgetPrivate(const QString &name) : m_Name{name} {}
29 29
30 30 QString m_Name;
31 31 };
32 32
33 33 VisualizationTabWidget::VisualizationTabWidget(const QString &name, QWidget *parent)
34 34 : QWidget{parent},
35 35 ui{new Ui::VisualizationTabWidget},
36 36 impl{spimpl::make_unique_impl<VisualizationTabWidgetPrivate>(name)}
37 37 {
38 38 ui->setupUi(this);
39 39 }
40 40
41 41 VisualizationTabWidget::~VisualizationTabWidget()
42 42 {
43 43 delete ui;
44 44 }
45 45
46 46 void VisualizationTabWidget::addZone(VisualizationZoneWidget *zoneWidget)
47 47 {
48 48 this->layout()->addWidget(zoneWidget);
49 49 }
50 50
51 51 VisualizationZoneWidget *VisualizationTabWidget::createZone(std::shared_ptr<Variable> variable)
52 52 {
53 53 auto zoneWidget = new VisualizationZoneWidget{defaultZoneName(*layout()), this};
54 54 this->addZone(zoneWidget);
55 55
56 56 // Creates a new graph into the zone
57 57 zoneWidget->createGraph(variable);
58 58
59 59 return zoneWidget;
60 60 }
61 61
62 62 void VisualizationTabWidget::removeZone(VisualizationZoneWidget *zone)
63 63 {
64 64 }
65 65
66 66 void VisualizationTabWidget::accept(IVisualizationWidgetVisitor *visitor)
67 67 {
68 68 if (visitor) {
69 69 visitor->visitEnter(this);
70 70
71 71 // Apply visitor to zone children
72 72 for (auto i = 0; i < layout()->count(); ++i) {
73 73 if (auto item = layout()->itemAt(i)) {
74 // Widgets different from zones are not visited (no action)
74 75 if (auto visualizationZoneWidget
75 76 = dynamic_cast<VisualizationZoneWidget *>(item->widget())) {
76 77 visualizationZoneWidget->accept(visitor);
77 78 }
78 79 }
79 80 }
80 81
81 82 visitor->visitLeave(this);
82 83 }
83 84 else {
84 85 qCCritical(LOG_VisualizationTabWidget()) << tr("Can't visit widget : the visitor is null");
85 86 }
86 87 }
87 88
88 89 bool VisualizationTabWidget::canDrop(const Variable &variable) const
89 90 {
90 91 // A tab can always accomodate a variable
91 92 Q_UNUSED(variable);
92 93 return true;
93 94 }
94 95
95 96 void VisualizationTabWidget::close()
96 97 {
97 98 // The main view cannot be directly closed.
98 99 return;
99 100 }
100 101
101 102 QString VisualizationTabWidget::name() const
102 103 {
103 104 return impl->m_Name;
104 105 }
@@ -1,135 +1,136
1 1 #include "Visualization/VisualizationWidget.h"
2 2 #include "Visualization/IVisualizationWidgetVisitor.h"
3 3 #include "Visualization/VisualizationGraphWidget.h"
4 4 #include "Visualization/VisualizationTabWidget.h"
5 5 #include "Visualization/VisualizationZoneWidget.h"
6 6 #include "Visualization/qcustomplot.h"
7 7
8 8 #include "ui_VisualizationWidget.h"
9 9
10 10 #include <QToolButton>
11 11
12 12 Q_LOGGING_CATEGORY(LOG_VisualizationWidget, "VisualizationWidget")
13 13
14 14 VisualizationWidget::VisualizationWidget(QWidget *parent)
15 15 : QWidget{parent}, ui{new Ui::VisualizationWidget}
16 16 {
17 17 ui->setupUi(this);
18 18
19 19 auto addTabViewButton = new QToolButton{ui->tabWidget};
20 20 addTabViewButton->setText(tr("Add View"));
21 21 addTabViewButton->setCursor(Qt::ArrowCursor);
22 22 ui->tabWidget->setCornerWidget(addTabViewButton, Qt::TopRightCorner);
23 23
24 24 auto enableMinimumCornerWidgetSize = [this](bool enable) {
25 25
26 26 auto tabViewCornerWidget = ui->tabWidget->cornerWidget();
27 27 auto width = enable ? tabViewCornerWidget->width() : 0;
28 28 auto height = enable ? tabViewCornerWidget->height() : 0;
29 29 tabViewCornerWidget->setMinimumHeight(height);
30 30 tabViewCornerWidget->setMinimumWidth(width);
31 31 ui->tabWidget->setMinimumHeight(height);
32 32 ui->tabWidget->setMinimumWidth(width);
33 33 };
34 34
35 35 auto addTabView = [this, enableMinimumCornerWidgetSize]() {
36 36 auto widget = new VisualizationTabWidget{QString{"View %1"}.arg(ui->tabWidget->count() + 1),
37 37 ui->tabWidget};
38 38 auto index = ui->tabWidget->addTab(widget, widget->name());
39 39 if (ui->tabWidget->count() > 0) {
40 40 enableMinimumCornerWidgetSize(false);
41 41 }
42 42 qCInfo(LOG_VisualizationWidget()) << tr("add the tab of index %1").arg(index);
43 43 };
44 44
45 45 auto removeTabView = [this, enableMinimumCornerWidgetSize](int index) {
46 46 if (ui->tabWidget->count() == 1) {
47 47 enableMinimumCornerWidgetSize(true);
48 48 }
49 49
50 50 ui->tabWidget->removeTab(index);
51 51 qCInfo(LOG_VisualizationWidget()) << tr("remove the tab of index %1").arg(index);
52 52
53 53 };
54 54
55 55 ui->tabWidget->setTabsClosable(true);
56 56
57 57 connect(addTabViewButton, &QToolButton::clicked, addTabView);
58 58 connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView);
59 59
60 60 // Adds default tab
61 61 addTabView();
62 62 }
63 63
64 64 VisualizationWidget::~VisualizationWidget()
65 65 {
66 66 delete ui;
67 67 }
68 68
69 69 void VisualizationWidget::addTab(VisualizationTabWidget *tabWidget)
70 70 {
71 71 // NOTE: check is this method has to be deleted because of its dupplicated version visible as
72 72 // lambda function (in the constructor)
73 73 }
74 74
75 75 VisualizationTabWidget *VisualizationWidget::createTab()
76 76 {
77 77 }
78 78
79 79 void VisualizationWidget::removeTab(VisualizationTabWidget *tab)
80 80 {
81 81 // NOTE: check is this method has to be deleted because of its dupplicated version visible as
82 82 // lambda function (in the constructor)
83 83 }
84 84
85 85 void VisualizationWidget::accept(IVisualizationWidgetVisitor *visitor)
86 86 {
87 87 if (visitor) {
88 88 visitor->visitEnter(this);
89 89
90 90 // Apply visitor for tab children
91 91 for (auto i = 0; i < ui->tabWidget->count(); ++i) {
92 // Widgets different from tabs are not visited (no action)
92 93 if (auto visualizationTabWidget
93 94 = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->widget(i))) {
94 95 visualizationTabWidget->accept(visitor);
95 96 }
96 97 }
97 98
98 99 visitor->visitLeave(this);
99 100 }
100 101 else {
101 102 qCCritical(LOG_VisualizationWidget()) << tr("Can't visit widget : the visitor is null");
102 103 }
103 104 }
104 105
105 106 bool VisualizationWidget::canDrop(const Variable &variable) const
106 107 {
107 108 // The main widget can never accomodate a variable
108 109 Q_UNUSED(variable);
109 110 return false;
110 111 }
111 112
112 113 void VisualizationWidget::close()
113 114 {
114 115 // The main view cannot be directly closed.
115 116 return;
116 117 }
117 118
118 119 QString VisualizationWidget::name() const
119 120 {
120 121 return QStringLiteral("MainView");
121 122 }
122 123
123 124 void VisualizationWidget::displayVariable(std::shared_ptr<Variable> variable) noexcept
124 125 {
125 126 if (auto currentTab = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->currentWidget())) {
126 127 if (!currentTab->createZone(variable)) {
127 128 qCCritical(LOG_VisualizationWidget())
128 129 << tr("Can't display the variable : can't create a new zone in the current tab");
129 130 }
130 131 }
131 132 else {
132 133 qCCritical(LOG_VisualizationWidget())
133 134 << tr("Can't display the variable : there is no current tab");
134 135 }
135 136 }
@@ -1,99 +1,100
1 1 #include "Visualization/VisualizationZoneWidget.h"
2 2 #include "Visualization/IVisualizationWidgetVisitor.h"
3 3 #include "ui_VisualizationZoneWidget.h"
4 4
5 5 #include "Visualization/VisualizationGraphWidget.h"
6 6
7 7 Q_LOGGING_CATEGORY(LOG_VisualizationZoneWidget, "VisualizationZoneWidget")
8 8
9 9 namespace {
10 10
11 11 /// Generates a default name for a new graph, according to the number of graphs already displayed in
12 12 /// the zone
13 13 QString defaultGraphName(const QLayout &layout)
14 14 {
15 15 auto count = 0;
16 16 for (auto i = 0; i < layout.count(); ++i) {
17 17 if (dynamic_cast<VisualizationGraphWidget *>(layout.itemAt(i)->widget())) {
18 18 count++;
19 19 }
20 20 }
21 21
22 22 return QObject::tr("Graph %1").arg(count + 1);
23 23 }
24 24
25 25 } // namespace
26 26
27 27 VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent)
28 28 : QWidget{parent}, ui{new Ui::VisualizationZoneWidget}
29 29 {
30 30 ui->setupUi(this);
31 31
32 32 ui->zoneNameLabel->setText(name);
33 33 }
34 34
35 35 VisualizationZoneWidget::~VisualizationZoneWidget()
36 36 {
37 37 delete ui;
38 38 }
39 39
40 40 void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget)
41 41 {
42 42 ui->visualizationZoneFrame->layout()->addWidget(graphWidget);
43 43 }
44 44
45 45 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable)
46 46 {
47 47 auto graphWidget = new VisualizationGraphWidget{
48 48 defaultGraphName(*ui->visualizationZoneFrame->layout()), this};
49 49 this->addGraph(graphWidget);
50 50
51 51 graphWidget->addVariable(variable);
52 52
53 53 return graphWidget;
54 54 }
55 55
56 56 void VisualizationZoneWidget::removeGraph(VisualizationGraphWidget *graph)
57 57 {
58 58 }
59 59
60 60 void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor)
61 61 {
62 62 if (visitor) {
63 63 visitor->visitEnter(this);
64 64
65 65 // Apply visitor to graph children
66 66 auto layout = ui->visualizationZoneFrame->layout();
67 67 for (auto i = 0; i < layout->count(); ++i) {
68 68 if (auto item = layout->itemAt(i)) {
69 // Widgets different from graphs are not visited (no action)
69 70 if (auto visualizationGraphWidget
70 71 = dynamic_cast<VisualizationGraphWidget *>(item->widget())) {
71 72 visualizationGraphWidget->accept(visitor);
72 73 }
73 74 }
74 75 }
75 76
76 77 visitor->visitLeave(this);
77 78 }
78 79 else {
79 80 qCCritical(LOG_VisualizationZoneWidget()) << tr("Can't visit widget : the visitor is null");
80 81 }
81 82 }
82 83
83 84 bool VisualizationZoneWidget::canDrop(const Variable &variable) const
84 85 {
85 86 // A tab can always accomodate a variable
86 87 Q_UNUSED(variable);
87 88 return true;
88 89 }
89 90
90 91 void VisualizationZoneWidget::close()
91 92 {
92 93 // The main view cannot be directly closed.
93 94 return;
94 95 }
95 96
96 97 QString VisualizationZoneWidget::name() const
97 98 {
98 99 return ui->zoneNameLabel->text();
99 100 }
General Comments 0
You need to be logged in to leave comments. Login now