@@ -0,0 +1,19 | |||||
|
1 | #ifndef SCIQLOP_IVARIABLECONTAINER_H | |||
|
2 | #define SCIQLOP_IVARIABLECONTAINER_H | |||
|
3 | ||||
|
4 | class Variable; | |||
|
5 | ||||
|
6 | /** | |||
|
7 | * @brief The IVariableContainer interface represents an UI object that can accommodate a variable | |||
|
8 | */ | |||
|
9 | class IVariableContainer { | |||
|
10 | ||||
|
11 | public: | |||
|
12 | virtual ~IVariableContainer() = default; | |||
|
13 | ||||
|
14 | /// Checks if the container can handle the variable passed in parameter | |||
|
15 | virtual bool canDrop(const Variable &variable) const = 0; | |||
|
16 | }; | |||
|
17 | ||||
|
18 | ||||
|
19 | #endif // SCIQLOP_IVARIABLECONTAINER_H |
@@ -1,25 +1,26 | |||||
1 | #ifndef SCIQLOP_IVISUALIZATIONWIDGET_H |
|
1 | #ifndef SCIQLOP_IVISUALIZATIONWIDGET_H | |
2 | #define SCIQLOP_IVISUALIZATIONWIDGET_H |
|
2 | #define SCIQLOP_IVISUALIZATIONWIDGET_H | |
3 |
|
3 | |||
|
4 | #include "Visualization/IVariableContainer.h" | |||
4 |
|
5 | |||
5 | #include <QString> |
|
6 | #include <QString> | |
6 | #include <memory> |
|
7 | #include <memory> | |
7 |
|
8 | |||
8 | class IVisualizationWidgetVisitor; |
|
9 | class IVisualizationWidgetVisitor; | |
9 |
|
10 | |||
10 | /** |
|
11 | /** | |
11 | * @brief The IVisualizationWidget handles the visualization widget. |
|
12 | * @brief The IVisualizationWidget handles the visualization widget. | |
12 | */ |
|
13 | */ | |
13 | class IVisualizationWidget { |
|
14 | class IVisualizationWidget : public IVariableContainer { | |
14 |
|
15 | |||
15 | public: |
|
16 | public: | |
16 | virtual ~IVisualizationWidget() = default; |
|
17 | virtual ~IVisualizationWidget() = default; | |
17 |
|
18 | |||
18 | /// Initializes the plugin |
|
19 | /// Initializes the plugin | |
19 | virtual void accept(IVisualizationWidgetVisitor *visitor) = 0; |
|
20 | virtual void accept(IVisualizationWidgetVisitor *visitor) = 0; | |
20 | virtual void close() = 0; |
|
21 | virtual void close() = 0; | |
21 | virtual QString name() const = 0; |
|
22 | virtual QString name() const = 0; | |
22 | }; |
|
23 | }; | |
23 |
|
24 | |||
24 |
|
25 | |||
25 | #endif // SCIQLOP_IVISUALIZATIONWIDGET_H |
|
26 | #endif // SCIQLOP_IVISUALIZATIONWIDGET_H |
@@ -1,43 +1,44 | |||||
1 | #ifndef SCIQLOP_VISUALIZATIONGRAPHWIDGET_H |
|
1 | #ifndef SCIQLOP_VISUALIZATIONGRAPHWIDGET_H | |
2 | #define SCIQLOP_VISUALIZATIONGRAPHWIDGET_H |
|
2 | #define SCIQLOP_VISUALIZATIONGRAPHWIDGET_H | |
3 |
|
3 | |||
4 | #include "Visualization/IVisualizationWidget.h" |
|
4 | #include "Visualization/IVisualizationWidget.h" | |
5 |
|
5 | |||
6 | #include <QWidget> |
|
6 | #include <QWidget> | |
7 |
|
7 | |||
8 | #include <memory> |
|
8 | #include <memory> | |
9 |
|
9 | |||
10 | #include <Common/spimpl.h> |
|
10 | #include <Common/spimpl.h> | |
11 |
|
11 | |||
12 | class Variable; |
|
12 | class Variable; | |
13 |
|
13 | |||
14 | namespace Ui { |
|
14 | namespace Ui { | |
15 | class VisualizationGraphWidget; |
|
15 | class VisualizationGraphWidget; | |
16 | } // namespace Ui |
|
16 | } // namespace Ui | |
17 |
|
17 | |||
18 | class VisualizationGraphWidget : public QWidget, public IVisualizationWidget { |
|
18 | class VisualizationGraphWidget : public QWidget, public IVisualizationWidget { | |
19 | Q_OBJECT |
|
19 | Q_OBJECT | |
20 |
|
20 | |||
21 | public: |
|
21 | public: | |
22 | explicit VisualizationGraphWidget(const QString &name = {}, QWidget *parent = 0); |
|
22 | explicit VisualizationGraphWidget(const QString &name = {}, QWidget *parent = 0); | |
23 | virtual ~VisualizationGraphWidget(); |
|
23 | virtual ~VisualizationGraphWidget(); | |
24 |
|
24 | |||
25 | void addVariable(std::shared_ptr<Variable> variable); |
|
25 | void addVariable(std::shared_ptr<Variable> variable); | |
26 |
|
26 | |||
27 | // IVisualizationWidget interface |
|
27 | // IVisualizationWidget interface | |
28 | void accept(IVisualizationWidgetVisitor *visitor) override; |
|
28 | void accept(IVisualizationWidgetVisitor *visitor) override; | |
|
29 | bool canDrop(const Variable &variable) const override; | |||
29 | void close() override; |
|
30 | void close() override; | |
30 | QString name() const; |
|
31 | QString name() const; | |
31 |
|
32 | |||
32 | private: |
|
33 | private: | |
33 | Ui::VisualizationGraphWidget *ui; |
|
34 | Ui::VisualizationGraphWidget *ui; | |
34 |
|
35 | |||
35 | class VisualizationGraphWidgetPrivate; |
|
36 | class VisualizationGraphWidgetPrivate; | |
36 | spimpl::unique_impl_ptr<VisualizationGraphWidgetPrivate> impl; |
|
37 | spimpl::unique_impl_ptr<VisualizationGraphWidgetPrivate> impl; | |
37 |
|
38 | |||
38 | private slots: |
|
39 | private slots: | |
39 | /// Slot called when a mouse wheel was made, to perform some processing before the zoom is done |
|
40 | /// Slot called when a mouse wheel was made, to perform some processing before the zoom is done | |
40 | void onMouseWheel(QWheelEvent *event) noexcept; |
|
41 | void onMouseWheel(QWheelEvent *event) noexcept; | |
41 | }; |
|
42 | }; | |
42 |
|
43 | |||
43 | #endif // SCIQLOP_VISUALIZATIONGRAPHWIDGET_H |
|
44 | #endif // SCIQLOP_VISUALIZATIONGRAPHWIDGET_H |
@@ -1,50 +1,51 | |||||
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 Variable; |
|
10 | class Variable; | |
11 | class VisualizationZoneWidget; |
|
11 | class VisualizationZoneWidget; | |
12 |
|
12 | |||
13 | namespace Ui { |
|
13 | namespace Ui { | |
14 | class VisualizationTabWidget; |
|
14 | class VisualizationTabWidget; | |
15 | } // namespace Ui |
|
15 | } // namespace Ui | |
16 |
|
16 | |||
17 | class VisualizationTabWidget : public QWidget, public IVisualizationWidget { |
|
17 | class VisualizationTabWidget : public QWidget, public IVisualizationWidget { | |
18 | Q_OBJECT |
|
18 | Q_OBJECT | |
19 |
|
19 | |||
20 | public: |
|
20 | public: | |
21 | explicit VisualizationTabWidget(const QString &name = {}, QWidget *parent = 0); |
|
21 | explicit VisualizationTabWidget(const QString &name = {}, QWidget *parent = 0); | |
22 | virtual ~VisualizationTabWidget(); |
|
22 | virtual ~VisualizationTabWidget(); | |
23 |
|
23 | |||
24 | /// Add a zone widget |
|
24 | /// Add a zone widget | |
25 | void addZone(VisualizationZoneWidget *zoneWidget); |
|
25 | void addZone(VisualizationZoneWidget *zoneWidget); | |
26 |
|
26 | |||
27 | /** |
|
27 | /** | |
28 | * Creates a zone using a variable. The variable will be displayed in a new graph of the new |
|
28 | * Creates a zone using a variable. The variable will be displayed in a new graph of the new | |
29 | * zone. |
|
29 | * zone. | |
30 | * @param variable the variable for which to create the zone |
|
30 | * @param variable the variable for which to create the zone | |
31 | * @return the pointer to the created zone |
|
31 | * @return the pointer to the created zone | |
32 | */ |
|
32 | */ | |
33 | VisualizationZoneWidget *createZone(std::shared_ptr<Variable> variable); |
|
33 | VisualizationZoneWidget *createZone(std::shared_ptr<Variable> variable); | |
34 |
|
34 | |||
35 | /// Remove a zone |
|
35 | /// Remove a zone | |
36 | void removeZone(VisualizationZoneWidget *zone); |
|
36 | void removeZone(VisualizationZoneWidget *zone); | |
37 |
|
37 | |||
38 | // IVisualizationWidget interface |
|
38 | // IVisualizationWidget interface | |
39 | void accept(IVisualizationWidgetVisitor *visitor) override; |
|
39 | void accept(IVisualizationWidgetVisitor *visitor) override; | |
|
40 | bool canDrop(const Variable &variable) const override; | |||
40 | void close() override; |
|
41 | void close() override; | |
41 | QString name() const override; |
|
42 | QString name() const override; | |
42 |
|
43 | |||
43 | private: |
|
44 | private: | |
44 | Ui::VisualizationTabWidget *ui; |
|
45 | Ui::VisualizationTabWidget *ui; | |
45 |
|
46 | |||
46 | class VisualizationTabWidgetPrivate; |
|
47 | class VisualizationTabWidgetPrivate; | |
47 | spimpl::unique_impl_ptr<VisualizationTabWidgetPrivate> impl; |
|
48 | spimpl::unique_impl_ptr<VisualizationTabWidgetPrivate> impl; | |
48 | }; |
|
49 | }; | |
49 |
|
50 | |||
50 | #endif // SCIQLOP_VISUALIZATIONTABWIDGET_H |
|
51 | #endif // SCIQLOP_VISUALIZATIONTABWIDGET_H |
@@ -1,52 +1,53 | |||||
1 | #ifndef SCIQLOP_VISUALIZATIONWIDGET_H |
|
1 | #ifndef SCIQLOP_VISUALIZATIONWIDGET_H | |
2 | #define SCIQLOP_VISUALIZATIONWIDGET_H |
|
2 | #define SCIQLOP_VISUALIZATIONWIDGET_H | |
3 |
|
3 | |||
4 | #include "Visualization/IVisualizationWidget.h" |
|
4 | #include "Visualization/IVisualizationWidget.h" | |
5 |
|
5 | |||
6 | #include <QLoggingCategory> |
|
6 | #include <QLoggingCategory> | |
7 | #include <QWidget> |
|
7 | #include <QWidget> | |
8 |
|
8 | |||
9 | class Variable; |
|
9 | class Variable; | |
10 | class VisualizationTabWidget; |
|
10 | class VisualizationTabWidget; | |
11 |
|
11 | |||
12 | Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationWidget) |
|
12 | Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationWidget) | |
13 |
|
13 | |||
14 | namespace Ui { |
|
14 | namespace Ui { | |
15 | class VisualizationWidget; |
|
15 | class VisualizationWidget; | |
16 | } // namespace Ui |
|
16 | } // namespace Ui | |
17 |
|
17 | |||
18 | class VisualizationWidget : public QWidget, public IVisualizationWidget { |
|
18 | class VisualizationWidget : public QWidget, public IVisualizationWidget { | |
19 | Q_OBJECT |
|
19 | Q_OBJECT | |
20 |
|
20 | |||
21 | public: |
|
21 | public: | |
22 | explicit VisualizationWidget(QWidget *parent = 0); |
|
22 | explicit VisualizationWidget(QWidget *parent = 0); | |
23 | virtual ~VisualizationWidget(); |
|
23 | virtual ~VisualizationWidget(); | |
24 |
|
24 | |||
25 | /// Add a zone widget |
|
25 | /// Add a zone widget | |
26 | virtual void addTab(VisualizationTabWidget *tabWidget); |
|
26 | virtual void addTab(VisualizationTabWidget *tabWidget); | |
27 |
|
27 | |||
28 | /// Create a tab using a Variable |
|
28 | /// Create a tab using a Variable | |
29 | VisualizationTabWidget *createTab(); |
|
29 | VisualizationTabWidget *createTab(); | |
30 |
|
30 | |||
31 | /// Remove a tab |
|
31 | /// Remove a tab | |
32 | void removeTab(VisualizationTabWidget *tab); |
|
32 | void removeTab(VisualizationTabWidget *tab); | |
33 |
|
33 | |||
34 | // IVisualizationWidget interface |
|
34 | // IVisualizationWidget interface | |
35 | void accept(IVisualizationWidgetVisitor *visitor) override; |
|
35 | void accept(IVisualizationWidgetVisitor *visitor) override; | |
|
36 | bool canDrop(const Variable &variable) const override; | |||
36 | void close() override; |
|
37 | void close() override; | |
37 | QString name() const; |
|
38 | QString name() const; | |
38 |
|
39 | |||
39 | public slots: |
|
40 | public slots: | |
40 | /** |
|
41 | /** | |
41 | * Displays a variable in a new graph of a new zone of the current tab |
|
42 | * Displays a variable in a new graph of a new zone of the current tab | |
42 | * @param variable the variable to display |
|
43 | * @param variable the variable to display | |
43 | * @todo this is a temporary method that will be replaced by own actions for each type of |
|
44 | * @todo this is a temporary method that will be replaced by own actions for each type of | |
44 | * visualization widget |
|
45 | * visualization widget | |
45 | */ |
|
46 | */ | |
46 | void displayVariable(std::shared_ptr<Variable> variable) noexcept; |
|
47 | void displayVariable(std::shared_ptr<Variable> variable) noexcept; | |
47 |
|
48 | |||
48 | private: |
|
49 | private: | |
49 | Ui::VisualizationWidget *ui; |
|
50 | Ui::VisualizationWidget *ui; | |
50 | }; |
|
51 | }; | |
51 |
|
52 | |||
52 | #endif // VISUALIZATIONWIDGET_H |
|
53 | #endif // VISUALIZATIONWIDGET_H |
@@ -1,44 +1,45 | |||||
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 Variable; |
|
12 | class Variable; | |
13 | class VisualizationGraphWidget; |
|
13 | class VisualizationGraphWidget; | |
14 |
|
14 | |||
15 | class VisualizationZoneWidget : public QWidget, public IVisualizationWidget { |
|
15 | class VisualizationZoneWidget : public QWidget, public IVisualizationWidget { | |
16 | Q_OBJECT |
|
16 | Q_OBJECT | |
17 |
|
17 | |||
18 | public: |
|
18 | public: | |
19 | explicit VisualizationZoneWidget(const QString &name = {}, QWidget *parent = 0); |
|
19 | explicit VisualizationZoneWidget(const QString &name = {}, QWidget *parent = 0); | |
20 | virtual ~VisualizationZoneWidget(); |
|
20 | virtual ~VisualizationZoneWidget(); | |
21 |
|
21 | |||
22 | /// Add a graph widget |
|
22 | /// Add a graph widget | |
23 | void addGraph(VisualizationGraphWidget *graphWidget); |
|
23 | void addGraph(VisualizationGraphWidget *graphWidget); | |
24 |
|
24 | |||
25 | /** |
|
25 | /** | |
26 | * Creates a graph using a variable. The variable will be displayed in the new graph. |
|
26 | * Creates a graph using a variable. The variable will be displayed in the new graph. | |
27 | * @param variable the variable for which to create the graph |
|
27 | * @param variable the variable for which to create the graph | |
28 | * @return the pointer to the created graph |
|
28 | * @return the pointer to the created graph | |
29 | */ |
|
29 | */ | |
30 | VisualizationGraphWidget *createGraph(std::shared_ptr<Variable> variable); |
|
30 | VisualizationGraphWidget *createGraph(std::shared_ptr<Variable> variable); | |
31 |
|
31 | |||
32 | /// Remove a graph |
|
32 | /// Remove a graph | |
33 | void removeGraph(VisualizationGraphWidget *graph); |
|
33 | void removeGraph(VisualizationGraphWidget *graph); | |
34 |
|
34 | |||
35 | // IVisualizationWidget interface |
|
35 | // IVisualizationWidget interface | |
36 | void accept(IVisualizationWidgetVisitor *visitor) override; |
|
36 | void accept(IVisualizationWidgetVisitor *visitor) override; | |
|
37 | bool canDrop(const Variable &variable) const override; | |||
37 | void close() override; |
|
38 | void close() override; | |
38 | QString name() const override; |
|
39 | QString name() const override; | |
39 |
|
40 | |||
40 | private: |
|
41 | private: | |
41 | Ui::VisualizationZoneWidget *ui; |
|
42 | Ui::VisualizationZoneWidget *ui; | |
42 | }; |
|
43 | }; | |
43 |
|
44 | |||
44 | #endif // SCIQLOP_VISUALIZATIONZONEWIDGET_H |
|
45 | #endif // SCIQLOP_VISUALIZATIONZONEWIDGET_H |
@@ -1,98 +1,105 | |||||
1 | #include "Visualization/VisualizationGraphWidget.h" |
|
1 | #include "Visualization/VisualizationGraphWidget.h" | |
2 | #include "Visualization/GraphPlottablesFactory.h" |
|
2 | #include "Visualization/GraphPlottablesFactory.h" | |
3 | #include "Visualization/IVisualizationWidgetVisitor.h" |
|
3 | #include "Visualization/IVisualizationWidgetVisitor.h" | |
4 | #include "ui_VisualizationGraphWidget.h" |
|
4 | #include "ui_VisualizationGraphWidget.h" | |
5 |
|
5 | |||
6 | #include <Variable/Variable.h> |
|
6 | #include <Variable/Variable.h> | |
7 |
|
7 | |||
8 | #include <unordered_map> |
|
8 | #include <unordered_map> | |
9 |
|
9 | |||
10 | namespace { |
|
10 | namespace { | |
11 |
|
11 | |||
12 | /// Key pressed to enable zoom on horizontal axis |
|
12 | /// Key pressed to enable zoom on horizontal axis | |
13 | const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier; |
|
13 | const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier; | |
14 |
|
14 | |||
15 | /// Key pressed to enable zoom on vertical axis |
|
15 | /// Key pressed to enable zoom on vertical axis | |
16 | const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier; |
|
16 | const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier; | |
17 |
|
17 | |||
18 | } // namespace |
|
18 | } // namespace | |
19 |
|
19 | |||
20 | struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { |
|
20 | struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { | |
21 |
|
21 | |||
22 | // 1 variable -> n qcpplot |
|
22 | // 1 variable -> n qcpplot | |
23 | std::unordered_map<std::shared_ptr<Variable>, QCPAbstractPlottable *> m_VariableToPlotMap; |
|
23 | std::unordered_map<std::shared_ptr<Variable>, QCPAbstractPlottable *> m_VariableToPlotMap; | |
24 | }; |
|
24 | }; | |
25 |
|
25 | |||
26 | VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent) |
|
26 | VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent) | |
27 | : QWidget{parent}, |
|
27 | : QWidget{parent}, | |
28 | ui{new Ui::VisualizationGraphWidget}, |
|
28 | ui{new Ui::VisualizationGraphWidget}, | |
29 | impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()} |
|
29 | impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()} | |
30 | { |
|
30 | { | |
31 | ui->setupUi(this); |
|
31 | ui->setupUi(this); | |
32 |
|
32 | |||
33 | // qcpplot title |
|
33 | // qcpplot title | |
34 | ui->widget->plotLayout()->insertRow(0); |
|
34 | ui->widget->plotLayout()->insertRow(0); | |
35 | ui->widget->plotLayout()->addElement(0, 0, new QCPTextElement{ui->widget, name}); |
|
35 | ui->widget->plotLayout()->addElement(0, 0, new QCPTextElement{ui->widget, name}); | |
36 |
|
36 | |||
37 | // Set qcpplot properties : |
|
37 | // Set qcpplot properties : | |
38 | // - Drag (on x-axis) and zoom are enabled |
|
38 | // - Drag (on x-axis) and zoom are enabled | |
39 | // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation |
|
39 | // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation | |
40 | ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); |
|
40 | ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); | |
41 | ui->widget->axisRect()->setRangeDrag(Qt::Horizontal); |
|
41 | ui->widget->axisRect()->setRangeDrag(Qt::Horizontal); | |
42 | connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel); |
|
42 | connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel); | |
43 | } |
|
43 | } | |
44 |
|
44 | |||
45 | VisualizationGraphWidget::~VisualizationGraphWidget() |
|
45 | VisualizationGraphWidget::~VisualizationGraphWidget() | |
46 | { |
|
46 | { | |
47 | delete ui; |
|
47 | delete ui; | |
48 | } |
|
48 | } | |
49 |
|
49 | |||
50 | void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable) |
|
50 | void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable) | |
51 | { |
|
51 | { | |
52 | // Uses delegate to create the qcpplot components according to the variable |
|
52 | // Uses delegate to create the qcpplot components according to the variable | |
53 | auto createdPlottables = GraphPlottablesFactory::create(variable, *ui->widget); |
|
53 | auto createdPlottables = GraphPlottablesFactory::create(variable, *ui->widget); | |
54 |
|
54 | |||
55 | for (auto createdPlottable : qAsConst(createdPlottables)) { |
|
55 | for (auto createdPlottable : qAsConst(createdPlottables)) { | |
56 | impl->m_VariableToPlotMap.insert({variable, createdPlottable}); |
|
56 | impl->m_VariableToPlotMap.insert({variable, createdPlottable}); | |
57 | } |
|
57 | } | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
60 | void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor) | |
61 | { |
|
61 | { | |
62 | if (visitor) { |
|
62 | if (visitor) { | |
63 | visitor->visit(this); |
|
63 | visitor->visit(this); | |
64 | } |
|
64 | } | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
|
67 | bool VisualizationGraphWidget::canDrop(const Variable &variable) const | |||
|
68 | { | |||
|
69 | /// @todo : for the moment, a graph can always accomodate a variable | |||
|
70 | Q_UNUSED(variable); | |||
|
71 | return true; | |||
|
72 | } | |||
|
73 | ||||
67 | void VisualizationGraphWidget::close() |
|
74 | void VisualizationGraphWidget::close() | |
68 | { |
|
75 | { | |
69 | // The main view cannot be directly closed. |
|
76 | // The main view cannot be directly closed. | |
70 | return; |
|
77 | return; | |
71 | } |
|
78 | } | |
72 |
|
79 | |||
73 | QString VisualizationGraphWidget::name() const |
|
80 | QString VisualizationGraphWidget::name() const | |
74 | { |
|
81 | { | |
75 | if (auto title = dynamic_cast<QCPTextElement *>(ui->widget->plotLayout()->elementAt(0))) { |
|
82 | if (auto title = dynamic_cast<QCPTextElement *>(ui->widget->plotLayout()->elementAt(0))) { | |
76 | return title->text(); |
|
83 | return title->text(); | |
77 | } |
|
84 | } | |
78 | else { |
|
85 | else { | |
79 | return QString{}; |
|
86 | return QString{}; | |
80 | } |
|
87 | } | |
81 | } |
|
88 | } | |
82 |
|
89 | |||
83 | void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept |
|
90 | void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept | |
84 | { |
|
91 | { | |
85 | auto zoomOrientations = QFlags<Qt::Orientation>{}; |
|
92 | auto zoomOrientations = QFlags<Qt::Orientation>{}; | |
86 |
|
93 | |||
87 | // Lambda that enables a zoom orientation if the key modifier related to this orientation has |
|
94 | // Lambda that enables a zoom orientation if the key modifier related to this orientation has | |
88 | // been pressed |
|
95 | // been pressed | |
89 | auto enableOrientation |
|
96 | auto enableOrientation | |
90 | = [&zoomOrientations, event](const auto &orientation, const auto &modifier) { |
|
97 | = [&zoomOrientations, event](const auto &orientation, const auto &modifier) { | |
91 | auto orientationEnabled = event->modifiers().testFlag(modifier); |
|
98 | auto orientationEnabled = event->modifiers().testFlag(modifier); | |
92 | zoomOrientations.setFlag(orientation, orientationEnabled); |
|
99 | zoomOrientations.setFlag(orientation, orientationEnabled); | |
93 | }; |
|
100 | }; | |
94 | enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER); |
|
101 | enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER); | |
95 | enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER); |
|
102 | enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER); | |
96 |
|
103 | |||
97 | ui->widget->axisRect()->setRangeZoom(zoomOrientations); |
|
104 | ui->widget->axisRect()->setRangeZoom(zoomOrientations); | |
98 | } |
|
105 | } |
@@ -1,92 +1,99 | |||||
1 | #include "Visualization/VisualizationTabWidget.h" |
|
1 | #include "Visualization/VisualizationTabWidget.h" | |
2 | #include "Visualization/IVisualizationWidgetVisitor.h" |
|
2 | #include "Visualization/IVisualizationWidgetVisitor.h" | |
3 | #include "ui_VisualizationTabWidget.h" |
|
3 | #include "ui_VisualizationTabWidget.h" | |
4 |
|
4 | |||
5 | #include "Visualization/VisualizationZoneWidget.h" |
|
5 | #include "Visualization/VisualizationZoneWidget.h" | |
6 |
|
6 | |||
7 | namespace { |
|
7 | namespace { | |
8 |
|
8 | |||
9 | /// Generates a default name for a new zone, according to the number of zones already displayed in |
|
9 | /// Generates a default name for a new zone, according to the number of zones already displayed in | |
10 | /// the tab |
|
10 | /// the tab | |
11 | QString defaultZoneName(const QLayout &layout) |
|
11 | QString defaultZoneName(const QLayout &layout) | |
12 | { |
|
12 | { | |
13 | auto count = 0; |
|
13 | auto count = 0; | |
14 | for (auto i = 0; i < layout.count(); ++i) { |
|
14 | for (auto i = 0; i < layout.count(); ++i) { | |
15 | if (dynamic_cast<VisualizationZoneWidget *>(layout.itemAt(i)->widget())) { |
|
15 | if (dynamic_cast<VisualizationZoneWidget *>(layout.itemAt(i)->widget())) { | |
16 | count++; |
|
16 | count++; | |
17 | } |
|
17 | } | |
18 | } |
|
18 | } | |
19 |
|
19 | |||
20 | return QObject::tr("Zone %1").arg(count + 1); |
|
20 | return QObject::tr("Zone %1").arg(count + 1); | |
21 | } |
|
21 | } | |
22 |
|
22 | |||
23 | } // namespace |
|
23 | } // namespace | |
24 |
|
24 | |||
25 | struct VisualizationTabWidget::VisualizationTabWidgetPrivate { |
|
25 | struct VisualizationTabWidget::VisualizationTabWidgetPrivate { | |
26 | explicit VisualizationTabWidgetPrivate(const QString &name) : m_Name{name} {} |
|
26 | explicit VisualizationTabWidgetPrivate(const QString &name) : m_Name{name} {} | |
27 |
|
27 | |||
28 | QString m_Name; |
|
28 | QString m_Name; | |
29 | }; |
|
29 | }; | |
30 |
|
30 | |||
31 | VisualizationTabWidget::VisualizationTabWidget(const QString &name, QWidget *parent) |
|
31 | VisualizationTabWidget::VisualizationTabWidget(const QString &name, QWidget *parent) | |
32 | : QWidget{parent}, |
|
32 | : QWidget{parent}, | |
33 | ui{new Ui::VisualizationTabWidget}, |
|
33 | ui{new Ui::VisualizationTabWidget}, | |
34 | impl{spimpl::make_unique_impl<VisualizationTabWidgetPrivate>(name)} |
|
34 | impl{spimpl::make_unique_impl<VisualizationTabWidgetPrivate>(name)} | |
35 | { |
|
35 | { | |
36 | ui->setupUi(this); |
|
36 | ui->setupUi(this); | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | VisualizationTabWidget::~VisualizationTabWidget() |
|
39 | VisualizationTabWidget::~VisualizationTabWidget() | |
40 | { |
|
40 | { | |
41 | delete ui; |
|
41 | delete ui; | |
42 | } |
|
42 | } | |
43 |
|
43 | |||
44 | void VisualizationTabWidget::addZone(VisualizationZoneWidget *zoneWidget) |
|
44 | void VisualizationTabWidget::addZone(VisualizationZoneWidget *zoneWidget) | |
45 | { |
|
45 | { | |
46 | this->layout()->addWidget(zoneWidget); |
|
46 | this->layout()->addWidget(zoneWidget); | |
47 | } |
|
47 | } | |
48 |
|
48 | |||
49 | VisualizationZoneWidget *VisualizationTabWidget::createZone(std::shared_ptr<Variable> variable) |
|
49 | VisualizationZoneWidget *VisualizationTabWidget::createZone(std::shared_ptr<Variable> variable) | |
50 | { |
|
50 | { | |
51 | auto zoneWidget = new VisualizationZoneWidget{defaultZoneName(*layout()), this}; |
|
51 | auto zoneWidget = new VisualizationZoneWidget{defaultZoneName(*layout()), this}; | |
52 | this->addZone(zoneWidget); |
|
52 | this->addZone(zoneWidget); | |
53 |
|
53 | |||
54 | // Creates a new graph into the zone |
|
54 | // Creates a new graph into the zone | |
55 | zoneWidget->createGraph(variable); |
|
55 | zoneWidget->createGraph(variable); | |
56 |
|
56 | |||
57 | return zoneWidget; |
|
57 | return zoneWidget; | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | void VisualizationTabWidget::removeZone(VisualizationZoneWidget *zone) |
|
60 | void VisualizationTabWidget::removeZone(VisualizationZoneWidget *zone) | |
61 | { |
|
61 | { | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | void VisualizationTabWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
64 | void VisualizationTabWidget::accept(IVisualizationWidgetVisitor *visitor) | |
65 | { |
|
65 | { | |
66 | if (visitor) { |
|
66 | if (visitor) { | |
67 | visitor->visitEnter(this); |
|
67 | visitor->visitEnter(this); | |
68 |
|
68 | |||
69 | // Apply visitor to zone children |
|
69 | // Apply visitor to zone children | |
70 | for (auto i = 0; i < layout()->count(); ++i) { |
|
70 | for (auto i = 0; i < layout()->count(); ++i) { | |
71 | if (auto item = layout()->itemAt(i)) { |
|
71 | if (auto item = layout()->itemAt(i)) { | |
72 | if (auto visualizationZoneWidget |
|
72 | if (auto visualizationZoneWidget | |
73 | = dynamic_cast<VisualizationZoneWidget *>(item->widget())) { |
|
73 | = dynamic_cast<VisualizationZoneWidget *>(item->widget())) { | |
74 | visualizationZoneWidget->accept(visitor); |
|
74 | visualizationZoneWidget->accept(visitor); | |
75 | } |
|
75 | } | |
76 | } |
|
76 | } | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
79 | visitor->visitLeave(this); |
|
79 | visitor->visitLeave(this); | |
80 | } |
|
80 | } | |
81 | } |
|
81 | } | |
82 |
|
82 | |||
|
83 | bool VisualizationTabWidget::canDrop(const Variable &variable) const | |||
|
84 | { | |||
|
85 | // A tab can always accomodate a variable | |||
|
86 | Q_UNUSED(variable); | |||
|
87 | return true; | |||
|
88 | } | |||
|
89 | ||||
83 | void VisualizationTabWidget::close() |
|
90 | void VisualizationTabWidget::close() | |
84 | { |
|
91 | { | |
85 | // The main view cannot be directly closed. |
|
92 | // The main view cannot be directly closed. | |
86 | return; |
|
93 | return; | |
87 | } |
|
94 | } | |
88 |
|
95 | |||
89 | QString VisualizationTabWidget::name() const |
|
96 | QString VisualizationTabWidget::name() const | |
90 | { |
|
97 | { | |
91 | return impl->m_Name; |
|
98 | return impl->m_Name; | |
92 | } |
|
99 | } |
@@ -1,125 +1,132 | |||||
1 | #include "Visualization/VisualizationWidget.h" |
|
1 | #include "Visualization/VisualizationWidget.h" | |
2 | #include "Visualization/IVisualizationWidgetVisitor.h" |
|
2 | #include "Visualization/IVisualizationWidgetVisitor.h" | |
3 | #include "Visualization/VisualizationGraphWidget.h" |
|
3 | #include "Visualization/VisualizationGraphWidget.h" | |
4 | #include "Visualization/VisualizationTabWidget.h" |
|
4 | #include "Visualization/VisualizationTabWidget.h" | |
5 | #include "Visualization/VisualizationZoneWidget.h" |
|
5 | #include "Visualization/VisualizationZoneWidget.h" | |
6 | #include "Visualization/qcustomplot.h" |
|
6 | #include "Visualization/qcustomplot.h" | |
7 |
|
7 | |||
8 | #include "ui_VisualizationWidget.h" |
|
8 | #include "ui_VisualizationWidget.h" | |
9 |
|
9 | |||
10 | #include <QToolButton> |
|
10 | #include <QToolButton> | |
11 |
|
11 | |||
12 | Q_LOGGING_CATEGORY(LOG_VisualizationWidget, "VisualizationWidget") |
|
12 | Q_LOGGING_CATEGORY(LOG_VisualizationWidget, "VisualizationWidget") | |
13 |
|
13 | |||
14 | VisualizationWidget::VisualizationWidget(QWidget *parent) |
|
14 | VisualizationWidget::VisualizationWidget(QWidget *parent) | |
15 | : QWidget{parent}, ui{new Ui::VisualizationWidget} |
|
15 | : QWidget{parent}, ui{new Ui::VisualizationWidget} | |
16 | { |
|
16 | { | |
17 | ui->setupUi(this); |
|
17 | ui->setupUi(this); | |
18 |
|
18 | |||
19 | auto addTabViewButton = new QToolButton{ui->tabWidget}; |
|
19 | auto addTabViewButton = new QToolButton{ui->tabWidget}; | |
20 | addTabViewButton->setText(tr("Add View")); |
|
20 | addTabViewButton->setText(tr("Add View")); | |
21 | addTabViewButton->setCursor(Qt::ArrowCursor); |
|
21 | addTabViewButton->setCursor(Qt::ArrowCursor); | |
22 | ui->tabWidget->setCornerWidget(addTabViewButton, Qt::TopRightCorner); |
|
22 | ui->tabWidget->setCornerWidget(addTabViewButton, Qt::TopRightCorner); | |
23 |
|
23 | |||
24 | auto enableMinimumCornerWidgetSize = [this](bool enable) { |
|
24 | auto enableMinimumCornerWidgetSize = [this](bool enable) { | |
25 |
|
25 | |||
26 | auto tabViewCornerWidget = ui->tabWidget->cornerWidget(); |
|
26 | auto tabViewCornerWidget = ui->tabWidget->cornerWidget(); | |
27 | auto width = enable ? tabViewCornerWidget->width() : 0; |
|
27 | auto width = enable ? tabViewCornerWidget->width() : 0; | |
28 | auto height = enable ? tabViewCornerWidget->height() : 0; |
|
28 | auto height = enable ? tabViewCornerWidget->height() : 0; | |
29 | tabViewCornerWidget->setMinimumHeight(height); |
|
29 | tabViewCornerWidget->setMinimumHeight(height); | |
30 | tabViewCornerWidget->setMinimumWidth(width); |
|
30 | tabViewCornerWidget->setMinimumWidth(width); | |
31 | ui->tabWidget->setMinimumHeight(height); |
|
31 | ui->tabWidget->setMinimumHeight(height); | |
32 | ui->tabWidget->setMinimumWidth(width); |
|
32 | ui->tabWidget->setMinimumWidth(width); | |
33 | }; |
|
33 | }; | |
34 |
|
34 | |||
35 | auto addTabView = [this, enableMinimumCornerWidgetSize]() { |
|
35 | auto addTabView = [this, enableMinimumCornerWidgetSize]() { | |
36 | auto widget = new VisualizationTabWidget{QString{"View %1"}.arg(ui->tabWidget->count() + 1), |
|
36 | auto widget = new VisualizationTabWidget{QString{"View %1"}.arg(ui->tabWidget->count() + 1), | |
37 | ui->tabWidget}; |
|
37 | ui->tabWidget}; | |
38 | auto index = ui->tabWidget->addTab(widget, widget->name()); |
|
38 | auto index = ui->tabWidget->addTab(widget, widget->name()); | |
39 | if (ui->tabWidget->count() > 0) { |
|
39 | if (ui->tabWidget->count() > 0) { | |
40 | enableMinimumCornerWidgetSize(false); |
|
40 | enableMinimumCornerWidgetSize(false); | |
41 | } |
|
41 | } | |
42 | qCInfo(LOG_VisualizationWidget()) << tr("add the tab of index %1").arg(index); |
|
42 | qCInfo(LOG_VisualizationWidget()) << tr("add the tab of index %1").arg(index); | |
43 | }; |
|
43 | }; | |
44 |
|
44 | |||
45 | auto removeTabView = [this, enableMinimumCornerWidgetSize](int index) { |
|
45 | auto removeTabView = [this, enableMinimumCornerWidgetSize](int index) { | |
46 | if (ui->tabWidget->count() == 1) { |
|
46 | if (ui->tabWidget->count() == 1) { | |
47 | enableMinimumCornerWidgetSize(true); |
|
47 | enableMinimumCornerWidgetSize(true); | |
48 | } |
|
48 | } | |
49 |
|
49 | |||
50 | ui->tabWidget->removeTab(index); |
|
50 | ui->tabWidget->removeTab(index); | |
51 | qCInfo(LOG_VisualizationWidget()) << tr("remove the tab of index %1").arg(index); |
|
51 | qCInfo(LOG_VisualizationWidget()) << tr("remove the tab of index %1").arg(index); | |
52 |
|
52 | |||
53 | }; |
|
53 | }; | |
54 |
|
54 | |||
55 | ui->tabWidget->setTabsClosable(true); |
|
55 | ui->tabWidget->setTabsClosable(true); | |
56 |
|
56 | |||
57 | connect(addTabViewButton, &QToolButton::clicked, addTabView); |
|
57 | connect(addTabViewButton, &QToolButton::clicked, addTabView); | |
58 | connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView); |
|
58 | connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView); | |
59 |
|
59 | |||
60 | // Adds default tab |
|
60 | // Adds default tab | |
61 | addTabView(); |
|
61 | addTabView(); | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | VisualizationWidget::~VisualizationWidget() |
|
64 | VisualizationWidget::~VisualizationWidget() | |
65 | { |
|
65 | { | |
66 | delete ui; |
|
66 | delete ui; | |
67 | } |
|
67 | } | |
68 |
|
68 | |||
69 | void VisualizationWidget::addTab(VisualizationTabWidget *tabWidget) |
|
69 | void VisualizationWidget::addTab(VisualizationTabWidget *tabWidget) | |
70 | { |
|
70 | { | |
71 | // NOTE: check is this method has to be deleted because of its dupplicated version visible as |
|
71 | // NOTE: check is this method has to be deleted because of its dupplicated version visible as | |
72 | // lambda function (in the constructor) |
|
72 | // lambda function (in the constructor) | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | VisualizationTabWidget *VisualizationWidget::createTab() |
|
75 | VisualizationTabWidget *VisualizationWidget::createTab() | |
76 | { |
|
76 | { | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
79 | void VisualizationWidget::removeTab(VisualizationTabWidget *tab) |
|
79 | void VisualizationWidget::removeTab(VisualizationTabWidget *tab) | |
80 | { |
|
80 | { | |
81 | // NOTE: check is this method has to be deleted because of its dupplicated version visible as |
|
81 | // NOTE: check is this method has to be deleted because of its dupplicated version visible as | |
82 | // lambda function (in the constructor) |
|
82 | // lambda function (in the constructor) | |
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 | void VisualizationWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
85 | void VisualizationWidget::accept(IVisualizationWidgetVisitor *visitor) | |
86 | { |
|
86 | { | |
87 | if (visitor) { |
|
87 | if (visitor) { | |
88 | visitor->visitEnter(this); |
|
88 | visitor->visitEnter(this); | |
89 |
|
89 | |||
90 | // Apply visitor for tab children |
|
90 | // Apply visitor for tab children | |
91 | for (auto i = 0; i < ui->tabWidget->count(); ++i) { |
|
91 | for (auto i = 0; i < ui->tabWidget->count(); ++i) { | |
92 | if (auto visualizationTabWidget |
|
92 | if (auto visualizationTabWidget | |
93 | = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->widget(i))) { |
|
93 | = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->widget(i))) { | |
94 | visualizationTabWidget->accept(visitor); |
|
94 | visualizationTabWidget->accept(visitor); | |
95 | } |
|
95 | } | |
96 | } |
|
96 | } | |
97 |
|
97 | |||
98 | visitor->visitLeave(this); |
|
98 | visitor->visitLeave(this); | |
99 | } |
|
99 | } | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
|
102 | bool VisualizationWidget::canDrop(const Variable &variable) const | |||
|
103 | { | |||
|
104 | // The main widget can never accomodate a variable | |||
|
105 | Q_UNUSED(variable); | |||
|
106 | return false; | |||
|
107 | } | |||
|
108 | ||||
102 | void VisualizationWidget::close() |
|
109 | void VisualizationWidget::close() | |
103 | { |
|
110 | { | |
104 | // The main view cannot be directly closed. |
|
111 | // The main view cannot be directly closed. | |
105 | return; |
|
112 | return; | |
106 | } |
|
113 | } | |
107 |
|
114 | |||
108 | QString VisualizationWidget::name() const |
|
115 | QString VisualizationWidget::name() const | |
109 | { |
|
116 | { | |
110 | return QStringLiteral("MainView"); |
|
117 | return QStringLiteral("MainView"); | |
111 | } |
|
118 | } | |
112 |
|
119 | |||
113 | void VisualizationWidget::displayVariable(std::shared_ptr<Variable> variable) noexcept |
|
120 | void VisualizationWidget::displayVariable(std::shared_ptr<Variable> variable) noexcept | |
114 | { |
|
121 | { | |
115 | if (auto currentTab = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->currentWidget())) { |
|
122 | if (auto currentTab = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->currentWidget())) { | |
116 | if (!currentTab->createZone(variable)) { |
|
123 | if (!currentTab->createZone(variable)) { | |
117 | qCCritical(LOG_VisualizationWidget()) |
|
124 | qCCritical(LOG_VisualizationWidget()) | |
118 | << tr("Can't display the variable : can't create a new zone in the current tab"); |
|
125 | << tr("Can't display the variable : can't create a new zone in the current tab"); | |
119 | } |
|
126 | } | |
120 | } |
|
127 | } | |
121 | else { |
|
128 | else { | |
122 | qCCritical(LOG_VisualizationWidget()) |
|
129 | qCCritical(LOG_VisualizationWidget()) | |
123 | << tr("Can't display the variable : there is no current tab"); |
|
130 | << tr("Can't display the variable : there is no current tab"); | |
124 | } |
|
131 | } | |
125 | } |
|
132 | } |
@@ -1,87 +1,94 | |||||
1 | #include "Visualization/VisualizationZoneWidget.h" |
|
1 | #include "Visualization/VisualizationZoneWidget.h" | |
2 | #include "Visualization/IVisualizationWidgetVisitor.h" |
|
2 | #include "Visualization/IVisualizationWidgetVisitor.h" | |
3 | #include "ui_VisualizationZoneWidget.h" |
|
3 | #include "ui_VisualizationZoneWidget.h" | |
4 |
|
4 | |||
5 | #include "Visualization/VisualizationGraphWidget.h" |
|
5 | #include "Visualization/VisualizationGraphWidget.h" | |
6 |
|
6 | |||
7 | namespace { |
|
7 | namespace { | |
8 |
|
8 | |||
9 | /// Generates a default name for a new graph, according to the number of graphs already displayed in |
|
9 | /// Generates a default name for a new graph, according to the number of graphs already displayed in | |
10 | /// the zone |
|
10 | /// the zone | |
11 | QString defaultGraphName(const QLayout &layout) |
|
11 | QString defaultGraphName(const QLayout &layout) | |
12 | { |
|
12 | { | |
13 | auto count = 0; |
|
13 | auto count = 0; | |
14 | for (auto i = 0; i < layout.count(); ++i) { |
|
14 | for (auto i = 0; i < layout.count(); ++i) { | |
15 | if (dynamic_cast<VisualizationGraphWidget *>(layout.itemAt(i)->widget())) { |
|
15 | if (dynamic_cast<VisualizationGraphWidget *>(layout.itemAt(i)->widget())) { | |
16 | count++; |
|
16 | count++; | |
17 | } |
|
17 | } | |
18 | } |
|
18 | } | |
19 |
|
19 | |||
20 | return QObject::tr("Graph %1").arg(count + 1); |
|
20 | return QObject::tr("Graph %1").arg(count + 1); | |
21 | } |
|
21 | } | |
22 |
|
22 | |||
23 | } // namespace |
|
23 | } // namespace | |
24 |
|
24 | |||
25 | VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent) |
|
25 | VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent) | |
26 | : QWidget{parent}, ui{new Ui::VisualizationZoneWidget} |
|
26 | : QWidget{parent}, ui{new Ui::VisualizationZoneWidget} | |
27 | { |
|
27 | { | |
28 | ui->setupUi(this); |
|
28 | ui->setupUi(this); | |
29 |
|
29 | |||
30 | ui->zoneNameLabel->setText(name); |
|
30 | ui->zoneNameLabel->setText(name); | |
31 | } |
|
31 | } | |
32 |
|
32 | |||
33 | VisualizationZoneWidget::~VisualizationZoneWidget() |
|
33 | VisualizationZoneWidget::~VisualizationZoneWidget() | |
34 | { |
|
34 | { | |
35 | delete ui; |
|
35 | delete ui; | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 | void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget) |
|
38 | void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget) | |
39 | { |
|
39 | { | |
40 | ui->visualizationZoneFrame->layout()->addWidget(graphWidget); |
|
40 | ui->visualizationZoneFrame->layout()->addWidget(graphWidget); | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable) |
|
43 | VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable) | |
44 | { |
|
44 | { | |
45 | auto graphWidget = new VisualizationGraphWidget{ |
|
45 | auto graphWidget = new VisualizationGraphWidget{ | |
46 | defaultGraphName(*ui->visualizationZoneFrame->layout()), this}; |
|
46 | defaultGraphName(*ui->visualizationZoneFrame->layout()), this}; | |
47 | this->addGraph(graphWidget); |
|
47 | this->addGraph(graphWidget); | |
48 |
|
48 | |||
49 | graphWidget->addVariable(variable); |
|
49 | graphWidget->addVariable(variable); | |
50 |
|
50 | |||
51 | return graphWidget; |
|
51 | return graphWidget; | |
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 | void VisualizationZoneWidget::removeGraph(VisualizationGraphWidget *graph) |
|
54 | void VisualizationZoneWidget::removeGraph(VisualizationGraphWidget *graph) | |
55 | { |
|
55 | { | |
56 | } |
|
56 | } | |
57 |
|
57 | |||
58 | void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
58 | void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor) | |
59 | { |
|
59 | { | |
60 | if (visitor) { |
|
60 | if (visitor) { | |
61 | visitor->visitEnter(this); |
|
61 | visitor->visitEnter(this); | |
62 |
|
62 | |||
63 | // Apply visitor to graph children |
|
63 | // Apply visitor to graph children | |
64 | auto layout = ui->visualizationZoneFrame->layout(); |
|
64 | auto layout = ui->visualizationZoneFrame->layout(); | |
65 | for (auto i = 0; i < layout->count(); ++i) { |
|
65 | for (auto i = 0; i < layout->count(); ++i) { | |
66 | if (auto item = layout->itemAt(i)) { |
|
66 | if (auto item = layout->itemAt(i)) { | |
67 | if (auto visualizationGraphWidget |
|
67 | if (auto visualizationGraphWidget | |
68 | = dynamic_cast<VisualizationGraphWidget *>(item->widget())) { |
|
68 | = dynamic_cast<VisualizationGraphWidget *>(item->widget())) { | |
69 | visualizationGraphWidget->accept(visitor); |
|
69 | visualizationGraphWidget->accept(visitor); | |
70 | } |
|
70 | } | |
71 | } |
|
71 | } | |
72 | } |
|
72 | } | |
73 |
|
73 | |||
74 | visitor->visitLeave(this); |
|
74 | visitor->visitLeave(this); | |
75 | } |
|
75 | } | |
76 | } |
|
76 | } | |
77 |
|
77 | |||
|
78 | bool VisualizationZoneWidget::canDrop(const Variable &variable) const | |||
|
79 | { | |||
|
80 | // A tab can always accomodate a variable | |||
|
81 | Q_UNUSED(variable); | |||
|
82 | return true; | |||
|
83 | } | |||
|
84 | ||||
78 | void VisualizationZoneWidget::close() |
|
85 | void VisualizationZoneWidget::close() | |
79 | { |
|
86 | { | |
80 | // The main view cannot be directly closed. |
|
87 | // The main view cannot be directly closed. | |
81 | return; |
|
88 | return; | |
82 | } |
|
89 | } | |
83 |
|
90 | |||
84 | QString VisualizationZoneWidget::name() const |
|
91 | QString VisualizationZoneWidget::name() const | |
85 | { |
|
92 | { | |
86 | return ui->zoneNameLabel->text(); |
|
93 | return ui->zoneNameLabel->text(); | |
87 | } |
|
94 | } |
General Comments 0
You need to be logged in to leave comments.
Login now