##// END OF EJS Templates
Completes the method of creating a zone from a variable
Alexandre Leroux -
r201:e28c6678c3bc
parent child
Show More
@@ -1,44 +1,49
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>
6 #include <Common/spimpl.h>
7
7
8 #include <QWidget>
8 #include <QWidget>
9
9
10 class VisualizationZoneWidget;
10 class VisualizationZoneWidget;
11
11
12 namespace Ui {
12 namespace Ui {
13 class VisualizationTabWidget;
13 class VisualizationTabWidget;
14 } // namespace Ui
14 } // namespace Ui
15
15
16 class VisualizationTabWidget : public QWidget, public IVisualizationWidget {
16 class VisualizationTabWidget : public QWidget, public IVisualizationWidget {
17 Q_OBJECT
17 Q_OBJECT
18
18
19 public:
19 public:
20 explicit VisualizationTabWidget(const QString &name = {}, QWidget *parent = 0);
20 explicit VisualizationTabWidget(const QString &name = {}, QWidget *parent = 0);
21 virtual ~VisualizationTabWidget();
21 virtual ~VisualizationTabWidget();
22
22
23 /// Add a zone widget
23 /// Add a zone widget
24 void addZone(VisualizationZoneWidget *zoneWidget);
24 void addZone(VisualizationZoneWidget *zoneWidget);
25
25
26 /// Create a zone using a Variable
26 /**
27 VisualizationZoneWidget *createZone();
27 * Creates a zone using a variable. The variable will be displayed in a new graph of the new
28 * zone.
29 * @param variable the variable for which to create the zone
30 * @return the pointer to the created zone
31 */
32 VisualizationZoneWidget *createZone(std::shared_ptr<Variable> variable);
28
33
29 /// Remove a zone
34 /// Remove a zone
30 void removeZone(VisualizationZoneWidget *zone);
35 void removeZone(VisualizationZoneWidget *zone);
31
36
32 // IVisualizationWidget interface
37 // IVisualizationWidget interface
33 void accept(IVisualizationWidget *visitor) override;
38 void accept(IVisualizationWidget *visitor) override;
34 void close() override;
39 void close() override;
35 QString name() const override;
40 QString name() const override;
36
41
37 private:
42 private:
38 Ui::VisualizationTabWidget *ui;
43 Ui::VisualizationTabWidget *ui;
39
44
40 class VisualizationTabWidgetPrivate;
45 class VisualizationTabWidgetPrivate;
41 spimpl::unique_impl_ptr<VisualizationTabWidgetPrivate> impl;
46 spimpl::unique_impl_ptr<VisualizationTabWidgetPrivate> impl;
42 };
47 };
43
48
44 #endif // SCIQLOP_VISUALIZATIONTABWIDGET_H
49 #endif // SCIQLOP_VISUALIZATIONTABWIDGET_H
@@ -1,56 +1,77
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 namespace {
7
8 /// Generates a default name for a new zone, according to the number of zones already displayed in
9 /// the tab
10 QString defaultZoneName(const QLayout &layout)
11 {
12 auto count = 0;
13 for (auto i = 0; i < layout.count(); ++i) {
14 if (dynamic_cast<VisualizationZoneWidget *>(layout.itemAt(i)->widget())) {
15 count++;
16 }
17 }
18
19 return QObject::tr("Zone %1").arg(count + 1);
20 }
21
22 } // namespace
23
6 struct VisualizationTabWidget::VisualizationTabWidgetPrivate {
24 struct VisualizationTabWidget::VisualizationTabWidgetPrivate {
7 explicit VisualizationTabWidgetPrivate(const QString &name) : m_Name{name} {}
25 explicit VisualizationTabWidgetPrivate(const QString &name) : m_Name{name} {}
8
26
9 QString m_Name;
27 QString m_Name;
10 };
28 };
11
29
12 VisualizationTabWidget::VisualizationTabWidget(const QString &name, QWidget *parent)
30 VisualizationTabWidget::VisualizationTabWidget(const QString &name, QWidget *parent)
13 : QWidget{parent},
31 : QWidget{parent},
14 ui{new Ui::VisualizationTabWidget},
32 ui{new Ui::VisualizationTabWidget},
15 impl{spimpl::make_unique_impl<VisualizationTabWidgetPrivate>(name)}
33 impl{spimpl::make_unique_impl<VisualizationTabWidgetPrivate>(name)}
16 {
34 {
17 ui->setupUi(this);
35 ui->setupUi(this);
18 }
36 }
19
37
20 VisualizationTabWidget::~VisualizationTabWidget()
38 VisualizationTabWidget::~VisualizationTabWidget()
21 {
39 {
22 delete ui;
40 delete ui;
23 }
41 }
24
42
25 void VisualizationTabWidget::addZone(VisualizationZoneWidget *zoneWidget)
43 void VisualizationTabWidget::addZone(VisualizationZoneWidget *zoneWidget)
26 {
44 {
27 this->layout()->addWidget(zoneWidget);
45 this->layout()->addWidget(zoneWidget);
28 }
46 }
29
47
30 VisualizationZoneWidget *VisualizationTabWidget::createZone()
48 VisualizationZoneWidget *VisualizationTabWidget::createZone(std::shared_ptr<Variable> variable)
31 {
49 {
32 auto zoneWidget = new VisualizationZoneWidget{this};
50 auto zoneWidget = new VisualizationZoneWidget{defaultZoneName(*layout()), this};
33 this->addZone(zoneWidget);
51 this->addZone(zoneWidget);
34
52
53 // Creates a new graph into the zone
54 zoneWidget->createGraph(variable);
55
35 return zoneWidget;
56 return zoneWidget;
36 }
57 }
37
58
38 void VisualizationTabWidget::removeZone(VisualizationZoneWidget *zone)
59 void VisualizationTabWidget::removeZone(VisualizationZoneWidget *zone)
39 {
60 {
40 }
61 }
41
62
42 void VisualizationTabWidget::accept(IVisualizationWidget *visitor)
63 void VisualizationTabWidget::accept(IVisualizationWidget *visitor)
43 {
64 {
44 // TODO: manage the visitor
65 // TODO: manage the visitor
45 }
66 }
46
67
47 void VisualizationTabWidget::close()
68 void VisualizationTabWidget::close()
48 {
69 {
49 // The main view cannot be directly closed.
70 // The main view cannot be directly closed.
50 return;
71 return;
51 }
72 }
52
73
53 QString VisualizationTabWidget::name() const
74 QString VisualizationTabWidget::name() const
54 {
75 {
55 return impl->m_Name;
76 return impl->m_Name;
56 }
77 }
General Comments 0
You need to be logged in to leave comments. Login now