@@ -21,8 +21,12 public: | |||||
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); |
@@ -3,6 +3,24 | |||||
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 | { | |
@@ -21,11 +39,14 void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget) | |||||
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{ |
|
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 |
General Comments 0
You need to be logged in to leave comments.
Login now