##// END OF EJS Templates
Completes the method of creating a zone from a variable
Alexandre Leroux -
r200:faed9e0296f1
parent child
Show More
@@ -1,39 +1,43
1 #ifndef SCIQLOP_VISUALIZATIONZONEWIDGET_H
1 #ifndef SCIQLOP_VISUALIZATIONZONEWIDGET_H
2 #define SCIQLOP_VISUALIZATIONZONEWIDGET_H
2 #define SCIQLOP_VISUALIZATIONZONEWIDGET_H
3
3
4 #include "Visualization/IVisualizationWidget.h"
4 #include "Visualization/IVisualizationWidget.h"
5
5
6 #include <QWidget>
6 #include <QWidget>
7
7
8 namespace Ui {
8 namespace Ui {
9 class VisualizationZoneWidget;
9 class VisualizationZoneWidget;
10 } // Ui
10 } // Ui
11
11
12 class VisualizationGraphWidget;
12 class VisualizationGraphWidget;
13
13
14 class VisualizationZoneWidget : public QWidget, public IVisualizationWidget {
14 class VisualizationZoneWidget : public QWidget, public IVisualizationWidget {
15 Q_OBJECT
15 Q_OBJECT
16
16
17 public:
17 public:
18 explicit VisualizationZoneWidget(const QString &name = {}, QWidget *parent = 0);
18 explicit VisualizationZoneWidget(const QString &name = {}, QWidget *parent = 0);
19 virtual ~VisualizationZoneWidget();
19 virtual ~VisualizationZoneWidget();
20
20
21 /// Add a graph widget
21 /// Add a graph widget
22 void addGraph(VisualizationGraphWidget *graphWidget);
22 void addGraph(VisualizationGraphWidget *graphWidget);
23
23
24 /// Create a graph using a Variable
24 /**
25 VisualizationGraphWidget *createGraph();
25 * Creates a graph using a variable. The variable will be displayed in the new graph.
26 * @param variable the variable for which to create the graph
27 * @return the pointer to the created graph
28 */
29 VisualizationGraphWidget *createGraph(std::shared_ptr<Variable> variable);
26
30
27 /// Remove a graph
31 /// Remove a graph
28 void removeGraph(VisualizationGraphWidget *graph);
32 void removeGraph(VisualizationGraphWidget *graph);
29
33
30 // IVisualizationWidget interface
34 // IVisualizationWidget interface
31 void accept(IVisualizationWidget *visitor) override;
35 void accept(IVisualizationWidget *visitor) override;
32 void close() override;
36 void close() override;
33 QString name() const override;
37 QString name() const override;
34
38
35 private:
39 private:
36 Ui::VisualizationZoneWidget *ui;
40 Ui::VisualizationZoneWidget *ui;
37 };
41 };
38
42
39 #endif // SCIQLOP_VISUALIZATIONZONEWIDGET_H
43 #endif // SCIQLOP_VISUALIZATIONZONEWIDGET_H
@@ -1,50 +1,71
1 #include "Visualization/VisualizationZoneWidget.h"
1 #include "Visualization/VisualizationZoneWidget.h"
2 #include "ui_VisualizationZoneWidget.h"
2 #include "ui_VisualizationZoneWidget.h"
3
3
4 #include "Visualization/VisualizationGraphWidget.h"
4 #include "Visualization/VisualizationGraphWidget.h"
5
5
6 namespace {
7
8 /// Generates a default name for a new graph, according to the number of graphs already displayed in
9 /// the zone
10 QString defaultGraphName(const QLayout &layout)
11 {
12 auto count = 0;
13 for (auto i = 0; i < layout.count(); ++i) {
14 if (dynamic_cast<VisualizationGraphWidget *>(layout.itemAt(i)->widget())) {
15 count++;
16 }
17 }
18
19 return QObject::tr("Graph %1").arg(count + 1);
20 }
21
22 } // namespace
23
6 VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent)
24 VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent)
7 : QWidget{parent}, ui{new Ui::VisualizationZoneWidget}
25 : QWidget{parent}, ui{new Ui::VisualizationZoneWidget}
8 {
26 {
9 ui->setupUi(this);
27 ui->setupUi(this);
10
28
11 ui->zoneNameLabel->setText(name);
29 ui->zoneNameLabel->setText(name);
12 }
30 }
13
31
14 VisualizationZoneWidget::~VisualizationZoneWidget()
32 VisualizationZoneWidget::~VisualizationZoneWidget()
15 {
33 {
16 delete ui;
34 delete ui;
17 }
35 }
18
36
19 void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget)
37 void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget)
20 {
38 {
21 ui->visualizationZoneFrame->layout()->addWidget(graphWidget);
39 ui->visualizationZoneFrame->layout()->addWidget(graphWidget);
22 }
40 }
23
41
24 VisualizationGraphWidget *VisualizationZoneWidget::createGraph()
42 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable)
25 {
43 {
26 auto graphWidget = new VisualizationGraphWidget{this};
44 auto graphWidget = new VisualizationGraphWidget{
45 defaultGraphName(*ui->visualizationZoneFrame->layout()), this};
27 this->addGraph(graphWidget);
46 this->addGraph(graphWidget);
28
47
48 graphWidget->addVariable(variable);
49
29 return graphWidget;
50 return graphWidget;
30 }
51 }
31
52
32 void VisualizationZoneWidget::removeGraph(VisualizationGraphWidget *graph)
53 void VisualizationZoneWidget::removeGraph(VisualizationGraphWidget *graph)
33 {
54 {
34 }
55 }
35
56
36 void VisualizationZoneWidget::accept(IVisualizationWidget *visitor)
57 void VisualizationZoneWidget::accept(IVisualizationWidget *visitor)
37 {
58 {
38 // TODO: manage the visitor
59 // TODO: manage the visitor
39 }
60 }
40
61
41 void VisualizationZoneWidget::close()
62 void VisualizationZoneWidget::close()
42 {
63 {
43 // The main view cannot be directly closed.
64 // The main view cannot be directly closed.
44 return;
65 return;
45 }
66 }
46
67
47 QString VisualizationZoneWidget::name() const
68 QString VisualizationZoneWidget::name() const
48 {
69 {
49 return ui->zoneNameLabel->text();
70 return ui->zoneNameLabel->text();
50 }
71 }
General Comments 0
You need to be logged in to leave comments. Login now