@@ -1,39 +1,43 | |||
|
1 | 1 | #ifndef SCIQLOP_VISUALIZATIONZONEWIDGET_H |
|
2 | 2 | #define SCIQLOP_VISUALIZATIONZONEWIDGET_H |
|
3 | 3 | |
|
4 | 4 | #include "Visualization/IVisualizationWidget.h" |
|
5 | 5 | |
|
6 | 6 | #include <QWidget> |
|
7 | 7 | |
|
8 | 8 | namespace Ui { |
|
9 | 9 | class VisualizationZoneWidget; |
|
10 | 10 | } // Ui |
|
11 | 11 | |
|
12 | 12 | class VisualizationGraphWidget; |
|
13 | 13 | |
|
14 | 14 | class VisualizationZoneWidget : public QWidget, public IVisualizationWidget { |
|
15 | 15 | Q_OBJECT |
|
16 | 16 | |
|
17 | 17 | public: |
|
18 | 18 | explicit VisualizationZoneWidget(const QString &name = {}, QWidget *parent = 0); |
|
19 | 19 | virtual ~VisualizationZoneWidget(); |
|
20 | 20 | |
|
21 | 21 | /// Add a graph widget |
|
22 | 22 | void addGraph(VisualizationGraphWidget *graphWidget); |
|
23 | 23 | |
|
24 | /// Create a graph using a Variable | |
|
25 | VisualizationGraphWidget *createGraph(); | |
|
24 | /** | |
|
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 | 31 | /// Remove a graph |
|
28 | 32 | void removeGraph(VisualizationGraphWidget *graph); |
|
29 | 33 | |
|
30 | 34 | // IVisualizationWidget interface |
|
31 | 35 | void accept(IVisualizationWidget *visitor) override; |
|
32 | 36 | void close() override; |
|
33 | 37 | QString name() const override; |
|
34 | 38 | |
|
35 | 39 | private: |
|
36 | 40 | Ui::VisualizationZoneWidget *ui; |
|
37 | 41 | }; |
|
38 | 42 | |
|
39 | 43 | #endif // SCIQLOP_VISUALIZATIONZONEWIDGET_H |
@@ -1,50 +1,71 | |||
|
1 | 1 | #include "Visualization/VisualizationZoneWidget.h" |
|
2 | 2 | #include "ui_VisualizationZoneWidget.h" |
|
3 | 3 | |
|
4 | 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 | 24 | VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent) |
|
7 | 25 | : QWidget{parent}, ui{new Ui::VisualizationZoneWidget} |
|
8 | 26 | { |
|
9 | 27 | ui->setupUi(this); |
|
10 | 28 | |
|
11 | 29 | ui->zoneNameLabel->setText(name); |
|
12 | 30 | } |
|
13 | 31 | |
|
14 | 32 | VisualizationZoneWidget::~VisualizationZoneWidget() |
|
15 | 33 | { |
|
16 | 34 | delete ui; |
|
17 | 35 | } |
|
18 | 36 | |
|
19 | 37 | void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget) |
|
20 | 38 | { |
|
21 | 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{ |
|
|
44 | auto graphWidget = new VisualizationGraphWidget{ | |
|
45 | defaultGraphName(*ui->visualizationZoneFrame->layout()), this}; | |
|
27 | 46 | this->addGraph(graphWidget); |
|
28 | 47 | |
|
48 | graphWidget->addVariable(variable); | |
|
49 | ||
|
29 | 50 | return graphWidget; |
|
30 | 51 | } |
|
31 | 52 | |
|
32 | 53 | void VisualizationZoneWidget::removeGraph(VisualizationGraphWidget *graph) |
|
33 | 54 | { |
|
34 | 55 | } |
|
35 | 56 | |
|
36 | 57 | void VisualizationZoneWidget::accept(IVisualizationWidget *visitor) |
|
37 | 58 | { |
|
38 | 59 | // TODO: manage the visitor |
|
39 | 60 | } |
|
40 | 61 | |
|
41 | 62 | void VisualizationZoneWidget::close() |
|
42 | 63 | { |
|
43 | 64 | // The main view cannot be directly closed. |
|
44 | 65 | return; |
|
45 | 66 | } |
|
46 | 67 | |
|
47 | 68 | QString VisualizationZoneWidget::name() const |
|
48 | 69 | { |
|
49 | 70 | return ui->zoneNameLabel->text(); |
|
50 | 71 | } |
General Comments 0
You need to be logged in to leave comments.
Login now