##// END OF EJS Templates
Deletes close() method defined for a visualization widget...
Alexandre Leroux -
r244:419e3cbb9021
parent child
Show More
@@ -1,26 +1,25
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 #include "Visualization/IVariableContainer.h"
5
5
6 #include <QString>
6 #include <QString>
7 #include <memory>
7 #include <memory>
8
8
9 class IVisualizationWidgetVisitor;
9 class IVisualizationWidgetVisitor;
10
10
11 /**
11 /**
12 * @brief The IVisualizationWidget handles the visualization widget.
12 * @brief The IVisualizationWidget handles the visualization widget.
13 */
13 */
14 class IVisualizationWidget : public IVariableContainer {
14 class IVisualizationWidget : public IVariableContainer {
15
15
16 public:
16 public:
17 virtual ~IVisualizationWidget() = default;
17 virtual ~IVisualizationWidget() = default;
18
18
19 /// Initializes the plugin
19 /// Initializes the plugin
20 virtual void accept(IVisualizationWidgetVisitor *visitor) = 0;
20 virtual void accept(IVisualizationWidgetVisitor *visitor) = 0;
21 virtual void close() = 0;
22 virtual QString name() const = 0;
21 virtual QString name() const = 0;
23 };
22 };
24
23
25
24
26 #endif // SCIQLOP_IVISUALIZATIONWIDGET_H
25 #endif // SCIQLOP_IVISUALIZATIONWIDGET_H
@@ -1,56 +1,55
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 <QLoggingCategory>
6 #include <QLoggingCategory>
7 #include <QWidget>
7 #include <QWidget>
8
8
9 #include <memory>
9 #include <memory>
10
10
11 #include <Common/spimpl.h>
11 #include <Common/spimpl.h>
12
12
13 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationGraphWidget)
13 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationGraphWidget)
14
14
15 class QCPRange;
15 class QCPRange;
16 class Variable;
16 class Variable;
17
17
18 namespace Ui {
18 namespace Ui {
19 class VisualizationGraphWidget;
19 class VisualizationGraphWidget;
20 } // namespace Ui
20 } // namespace Ui
21
21
22 class VisualizationGraphWidget : public QWidget, public IVisualizationWidget {
22 class VisualizationGraphWidget : public QWidget, public IVisualizationWidget {
23 Q_OBJECT
23 Q_OBJECT
24
24
25 public:
25 public:
26 explicit VisualizationGraphWidget(const QString &name = {}, QWidget *parent = 0);
26 explicit VisualizationGraphWidget(const QString &name = {}, QWidget *parent = 0);
27 virtual ~VisualizationGraphWidget();
27 virtual ~VisualizationGraphWidget();
28
28
29 void addVariable(std::shared_ptr<Variable> variable);
29 void addVariable(std::shared_ptr<Variable> variable);
30
30
31 // IVisualizationWidget interface
31 // IVisualizationWidget interface
32 void accept(IVisualizationWidgetVisitor *visitor) override;
32 void accept(IVisualizationWidgetVisitor *visitor) override;
33 bool canDrop(const Variable &variable) const override;
33 bool canDrop(const Variable &variable) const override;
34 void close() override;
35 QString name() const override;
34 QString name() const override;
36
35
37 void updateDisplay(std::shared_ptr<Variable> variable);
36 void updateDisplay(std::shared_ptr<Variable> variable);
38
37
39
38
40 private:
39 private:
41 Ui::VisualizationGraphWidget *ui;
40 Ui::VisualizationGraphWidget *ui;
42
41
43 class VisualizationGraphWidgetPrivate;
42 class VisualizationGraphWidgetPrivate;
44 spimpl::unique_impl_ptr<VisualizationGraphWidgetPrivate> impl;
43 spimpl::unique_impl_ptr<VisualizationGraphWidgetPrivate> impl;
45
44
46 private slots:
45 private slots:
47
46
48 void onRangeChanged(const QCPRange &t1, const QCPRange &t2);
47 void onRangeChanged(const QCPRange &t1, const QCPRange &t2);
49
48
50 /// Slot called when a mouse wheel was made, to perform some processing before the zoom is done
49 /// Slot called when a mouse wheel was made, to perform some processing before the zoom is done
51 void onMouseWheel(QWheelEvent *event) noexcept;
50 void onMouseWheel(QWheelEvent *event) noexcept;
52
51
53 void onDataCacheVariableUpdated();
52 void onDataCacheVariableUpdated();
54 };
53 };
55
54
56 #endif // SCIQLOP_VISUALIZATIONGRAPHWIDGET_H
55 #endif // SCIQLOP_VISUALIZATIONGRAPHWIDGET_H
@@ -1,54 +1,53
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 <QLoggingCategory>
8 #include <QLoggingCategory>
9 #include <QWidget>
9 #include <QWidget>
10
10
11 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationTabWidget)
11 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationTabWidget)
12
12
13 class Variable;
13 class Variable;
14 class VisualizationZoneWidget;
14 class VisualizationZoneWidget;
15
15
16 namespace Ui {
16 namespace Ui {
17 class VisualizationTabWidget;
17 class VisualizationTabWidget;
18 } // namespace Ui
18 } // namespace Ui
19
19
20 class VisualizationTabWidget : public QWidget, public IVisualizationWidget {
20 class VisualizationTabWidget : public QWidget, public IVisualizationWidget {
21 Q_OBJECT
21 Q_OBJECT
22
22
23 public:
23 public:
24 explicit VisualizationTabWidget(const QString &name = {}, QWidget *parent = 0);
24 explicit VisualizationTabWidget(const QString &name = {}, QWidget *parent = 0);
25 virtual ~VisualizationTabWidget();
25 virtual ~VisualizationTabWidget();
26
26
27 /// Add a zone widget
27 /// Add a zone widget
28 void addZone(VisualizationZoneWidget *zoneWidget);
28 void addZone(VisualizationZoneWidget *zoneWidget);
29
29
30 /**
30 /**
31 * Creates a zone using a variable. The variable will be displayed in a new graph of the new
31 * Creates a zone using a variable. The variable will be displayed in a new graph of the new
32 * zone.
32 * zone.
33 * @param variable the variable for which to create the zone
33 * @param variable the variable for which to create the zone
34 * @return the pointer to the created zone
34 * @return the pointer to the created zone
35 */
35 */
36 VisualizationZoneWidget *createZone(std::shared_ptr<Variable> variable);
36 VisualizationZoneWidget *createZone(std::shared_ptr<Variable> variable);
37
37
38 /// Remove a zone
38 /// Remove a zone
39 void removeZone(VisualizationZoneWidget *zone);
39 void removeZone(VisualizationZoneWidget *zone);
40
40
41 // IVisualizationWidget interface
41 // IVisualizationWidget interface
42 void accept(IVisualizationWidgetVisitor *visitor) override;
42 void accept(IVisualizationWidgetVisitor *visitor) override;
43 bool canDrop(const Variable &variable) const override;
43 bool canDrop(const Variable &variable) const override;
44 void close() override;
45 QString name() const override;
44 QString name() const override;
46
45
47 private:
46 private:
48 Ui::VisualizationTabWidget *ui;
47 Ui::VisualizationTabWidget *ui;
49
48
50 class VisualizationTabWidgetPrivate;
49 class VisualizationTabWidgetPrivate;
51 spimpl::unique_impl_ptr<VisualizationTabWidgetPrivate> impl;
50 spimpl::unique_impl_ptr<VisualizationTabWidgetPrivate> impl;
52 };
51 };
53
52
54 #endif // SCIQLOP_VISUALIZATIONTABWIDGET_H
53 #endif // SCIQLOP_VISUALIZATIONTABWIDGET_H
@@ -1,53 +1,52
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 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationWidget)
9 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationWidget)
10
10
11 class QMenu;
11 class QMenu;
12 class Variable;
12 class Variable;
13 class VisualizationTabWidget;
13 class VisualizationTabWidget;
14
14
15 namespace Ui {
15 namespace Ui {
16 class VisualizationWidget;
16 class VisualizationWidget;
17 } // namespace Ui
17 } // namespace Ui
18
18
19 class VisualizationWidget : public QWidget, public IVisualizationWidget {
19 class VisualizationWidget : public QWidget, public IVisualizationWidget {
20 Q_OBJECT
20 Q_OBJECT
21
21
22 public:
22 public:
23 explicit VisualizationWidget(QWidget *parent = 0);
23 explicit VisualizationWidget(QWidget *parent = 0);
24 virtual ~VisualizationWidget();
24 virtual ~VisualizationWidget();
25
25
26 /// Add a zone widget
26 /// Add a zone widget
27 virtual void addTab(VisualizationTabWidget *tabWidget);
27 virtual void addTab(VisualizationTabWidget *tabWidget);
28
28
29 /// Create a tab using a Variable
29 /// Create a tab using a Variable
30 VisualizationTabWidget *createTab();
30 VisualizationTabWidget *createTab();
31
31
32 /// Remove a tab
32 /// Remove a tab
33 void removeTab(VisualizationTabWidget *tab);
33 void removeTab(VisualizationTabWidget *tab);
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 bool canDrop(const Variable &variable) const override;
38 void close() override;
39 QString name() const override;
38 QString name() const override;
40
39
41 public slots:
40 public slots:
42 /**
41 /**
43 * Attaches to a menu the menu relating to the visualization of a variable
42 * Attaches to a menu the menu relating to the visualization of a variable
44 * @param menu the parent menu of the generated menu
43 * @param menu the parent menu of the generated menu
45 * @param variable the variable for which to generate the menu
44 * @param variable the variable for which to generate the menu
46 */
45 */
47 void attachVariableMenu(QMenu *menu, std::shared_ptr<Variable> variable) noexcept;
46 void attachVariableMenu(QMenu *menu, std::shared_ptr<Variable> variable) noexcept;
48
47
49 private:
48 private:
50 Ui::VisualizationWidget *ui;
49 Ui::VisualizationWidget *ui;
51 };
50 };
52
51
53 #endif // VISUALIZATIONWIDGET_H
52 #endif // VISUALIZATIONWIDGET_H
@@ -1,48 +1,47
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 <QLoggingCategory>
6 #include <QLoggingCategory>
7 #include <QWidget>
7 #include <QWidget>
8
8
9 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationZoneWidget)
9 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationZoneWidget)
10
10
11 namespace Ui {
11 namespace Ui {
12 class VisualizationZoneWidget;
12 class VisualizationZoneWidget;
13 } // Ui
13 } // Ui
14
14
15 class Variable;
15 class Variable;
16 class VisualizationGraphWidget;
16 class VisualizationGraphWidget;
17
17
18 class VisualizationZoneWidget : public QWidget, public IVisualizationWidget {
18 class VisualizationZoneWidget : public QWidget, public IVisualizationWidget {
19 Q_OBJECT
19 Q_OBJECT
20
20
21 public:
21 public:
22 explicit VisualizationZoneWidget(const QString &name = {}, QWidget *parent = 0);
22 explicit VisualizationZoneWidget(const QString &name = {}, QWidget *parent = 0);
23 virtual ~VisualizationZoneWidget();
23 virtual ~VisualizationZoneWidget();
24
24
25 /// Add a graph widget
25 /// Add a graph widget
26 void addGraph(VisualizationGraphWidget *graphWidget);
26 void addGraph(VisualizationGraphWidget *graphWidget);
27
27
28 /**
28 /**
29 * Creates a graph using a variable. The variable will be displayed in the new graph.
29 * Creates a graph using a variable. The variable will be displayed in the new graph.
30 * @param variable the variable for which to create the graph
30 * @param variable the variable for which to create the graph
31 * @return the pointer to the created graph
31 * @return the pointer to the created graph
32 */
32 */
33 VisualizationGraphWidget *createGraph(std::shared_ptr<Variable> variable);
33 VisualizationGraphWidget *createGraph(std::shared_ptr<Variable> variable);
34
34
35 /// Remove a graph
35 /// Remove a graph
36 void removeGraph(VisualizationGraphWidget *graph);
36 void removeGraph(VisualizationGraphWidget *graph);
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 bool canDrop(const Variable &variable) const override;
41 void close() override;
42 QString name() const override;
41 QString name() const override;
43
42
44 private:
43 private:
45 Ui::VisualizationZoneWidget *ui;
44 Ui::VisualizationZoneWidget *ui;
46 };
45 };
47
46
48 #endif // SCIQLOP_VISUALIZATIONZONEWIDGET_H
47 #endif // SCIQLOP_VISUALIZATIONZONEWIDGET_H
@@ -1,208 +1,202
1 #include "Visualization/VisualizationGraphWidget.h"
1 #include "Visualization/VisualizationGraphWidget.h"
2 #include "Visualization/IVisualizationWidgetVisitor.h"
2 #include "Visualization/IVisualizationWidgetVisitor.h"
3 #include "Visualization/VisualizationGraphHelper.h"
3 #include "Visualization/VisualizationGraphHelper.h"
4 #include "ui_VisualizationGraphWidget.h"
4 #include "ui_VisualizationGraphWidget.h"
5
5
6 #include <Data/ArrayData.h>
6 #include <Data/ArrayData.h>
7 #include <Data/IDataSeries.h>
7 #include <Data/IDataSeries.h>
8 #include <SqpApplication.h>
8 #include <SqpApplication.h>
9 #include <Variable/Variable.h>
9 #include <Variable/Variable.h>
10 #include <Variable/VariableController.h>
10 #include <Variable/VariableController.h>
11
11
12 #include <unordered_map>
12 #include <unordered_map>
13
13
14 Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget")
14 Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget")
15
15
16 namespace {
16 namespace {
17
17
18 /// Key pressed to enable zoom on horizontal axis
18 /// Key pressed to enable zoom on horizontal axis
19 const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier;
19 const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier;
20
20
21 /// Key pressed to enable zoom on vertical axis
21 /// Key pressed to enable zoom on vertical axis
22 const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier;
22 const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier;
23
23
24 } // namespace
24 } // namespace
25
25
26 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
26 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
27
27
28 // 1 variable -> n qcpplot
28 // 1 variable -> n qcpplot
29 std::unordered_multimap<std::shared_ptr<Variable>, QCPAbstractPlottable *>
29 std::unordered_multimap<std::shared_ptr<Variable>, QCPAbstractPlottable *>
30 m_VariableToPlotMultiMap;
30 m_VariableToPlotMultiMap;
31 };
31 };
32
32
33 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent)
33 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent)
34 : QWidget{parent},
34 : QWidget{parent},
35 ui{new Ui::VisualizationGraphWidget},
35 ui{new Ui::VisualizationGraphWidget},
36 impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()}
36 impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()}
37 {
37 {
38 ui->setupUi(this);
38 ui->setupUi(this);
39
39
40 // qcpplot title
40 // qcpplot title
41 ui->widget->plotLayout()->insertRow(0);
41 ui->widget->plotLayout()->insertRow(0);
42 ui->widget->plotLayout()->addElement(0, 0, new QCPTextElement{ui->widget, name});
42 ui->widget->plotLayout()->addElement(0, 0, new QCPTextElement{ui->widget, name});
43
43
44 // Set qcpplot properties :
44 // Set qcpplot properties :
45 // - Drag (on x-axis) and zoom are enabled
45 // - Drag (on x-axis) and zoom are enabled
46 // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation
46 // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation
47 ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
47 ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
48 ui->widget->axisRect()->setRangeDrag(Qt::Horizontal);
48 ui->widget->axisRect()->setRangeDrag(Qt::Horizontal);
49 connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel);
49 connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel);
50 connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>(
50 connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>(
51 &QCPAxis::rangeChanged),
51 &QCPAxis::rangeChanged),
52 this, &VisualizationGraphWidget::onRangeChanged);
52 this, &VisualizationGraphWidget::onRangeChanged);
53 }
53 }
54
54
55
55
56 VisualizationGraphWidget::~VisualizationGraphWidget()
56 VisualizationGraphWidget::~VisualizationGraphWidget()
57 {
57 {
58 delete ui;
58 delete ui;
59 }
59 }
60
60
61 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable)
61 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable)
62 {
62 {
63 // Uses delegate to create the qcpplot components according to the variable
63 // Uses delegate to create the qcpplot components according to the variable
64 auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget);
64 auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget);
65
65
66 for (auto createdPlottable : qAsConst(createdPlottables)) {
66 for (auto createdPlottable : qAsConst(createdPlottables)) {
67 impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable});
67 impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable});
68 }
68 }
69
69
70 connect(variable.get(), SIGNAL(dataCacheUpdated()), this, SLOT(onDataCacheVariableUpdated()));
70 connect(variable.get(), SIGNAL(dataCacheUpdated()), this, SLOT(onDataCacheVariableUpdated()));
71 }
71 }
72
72
73 void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor)
73 void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor)
74 {
74 {
75 if (visitor) {
75 if (visitor) {
76 visitor->visit(this);
76 visitor->visit(this);
77 }
77 }
78 else {
78 else {
79 qCCritical(LOG_VisualizationGraphWidget())
79 qCCritical(LOG_VisualizationGraphWidget())
80 << tr("Can't visit widget : the visitor is null");
80 << tr("Can't visit widget : the visitor is null");
81 }
81 }
82 }
82 }
83
83
84 bool VisualizationGraphWidget::canDrop(const Variable &variable) const
84 bool VisualizationGraphWidget::canDrop(const Variable &variable) const
85 {
85 {
86 /// @todo : for the moment, a graph can always accomodate a variable
86 /// @todo : for the moment, a graph can always accomodate a variable
87 Q_UNUSED(variable);
87 Q_UNUSED(variable);
88 return true;
88 return true;
89 }
89 }
90
90
91 void VisualizationGraphWidget::close()
92 {
93 // The main view cannot be directly closed.
94 return;
95 }
96
97 QString VisualizationGraphWidget::name() const
91 QString VisualizationGraphWidget::name() const
98 {
92 {
99 if (auto title = dynamic_cast<QCPTextElement *>(ui->widget->plotLayout()->elementAt(0))) {
93 if (auto title = dynamic_cast<QCPTextElement *>(ui->widget->plotLayout()->elementAt(0))) {
100 return title->text();
94 return title->text();
101 }
95 }
102 else {
96 else {
103 return QString{};
97 return QString{};
104 }
98 }
105 }
99 }
106
100
107 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2)
101 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2)
108 {
102 {
109
103
110 qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged");
104 qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged");
111
105
112 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
106 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
113 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
107 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
114
108
115 auto variable = it->first;
109 auto variable = it->first;
116 qCInfo(LOG_VisualizationGraphWidget())
110 qCInfo(LOG_VisualizationGraphWidget())
117 << tr("TORM: VisualizationGraphWidget::onRangeChanged")
111 << tr("TORM: VisualizationGraphWidget::onRangeChanged")
118 << variable->dataSeries()->xAxisData()->size();
112 << variable->dataSeries()->xAxisData()->size();
119 auto dateTime = SqpDateTime{t2.lower, t2.upper};
113 auto dateTime = SqpDateTime{t2.lower, t2.upper};
120
114
121 if (!variable->contains(dateTime)) {
115 if (!variable->contains(dateTime)) {
122
116
123 auto variableDateTimeWithTolerance = dateTime;
117 auto variableDateTimeWithTolerance = dateTime;
124 if (variable->intersect(dateTime)) {
118 if (variable->intersect(dateTime)) {
125 auto variableDateTime = variable->dateTime();
119 auto variableDateTime = variable->dateTime();
126 if (variableDateTime.m_TStart < dateTime.m_TStart) {
120 if (variableDateTime.m_TStart < dateTime.m_TStart) {
127
121
128 auto diffEndToKeepDelta = dateTime.m_TEnd - variableDateTime.m_TEnd;
122 auto diffEndToKeepDelta = dateTime.m_TEnd - variableDateTime.m_TEnd;
129 dateTime.m_TStart = variableDateTime.m_TStart + diffEndToKeepDelta;
123 dateTime.m_TStart = variableDateTime.m_TStart + diffEndToKeepDelta;
130 // Tolerance have to be added to the right
124 // Tolerance have to be added to the right
131 // add 10% tolerance for right (end) side
125 // add 10% tolerance for right (end) side
132 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
126 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
133 variableDateTimeWithTolerance.m_TEnd += tolerance;
127 variableDateTimeWithTolerance.m_TEnd += tolerance;
134 }
128 }
135 if (variableDateTime.m_TEnd > dateTime.m_TEnd) {
129 if (variableDateTime.m_TEnd > dateTime.m_TEnd) {
136 auto diffStartToKeepDelta = dateTime.m_TStart - dateTime.m_TStart;
130 auto diffStartToKeepDelta = dateTime.m_TStart - dateTime.m_TStart;
137 dateTime.m_TEnd = variableDateTime.m_TEnd - diffStartToKeepDelta;
131 dateTime.m_TEnd = variableDateTime.m_TEnd - diffStartToKeepDelta;
138 // Tolerance have to be added to the left
132 // Tolerance have to be added to the left
139 // add 10% tolerance for left (start) side
133 // add 10% tolerance for left (start) side
140 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
134 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
141 variableDateTimeWithTolerance.m_TStart -= tolerance;
135 variableDateTimeWithTolerance.m_TStart -= tolerance;
142 }
136 }
143 }
137 }
144 else {
138 else {
145 // add 10% tolerance for each side
139 // add 10% tolerance for each side
146 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
140 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
147 variableDateTimeWithTolerance.m_TStart -= tolerance;
141 variableDateTimeWithTolerance.m_TStart -= tolerance;
148 variableDateTimeWithTolerance.m_TEnd += tolerance;
142 variableDateTimeWithTolerance.m_TEnd += tolerance;
149 }
143 }
150 variable->setDateTime(dateTime);
144 variable->setDateTime(dateTime);
151
145
152 // CHangement detected, we need to ask controller to request data loading
146 // CHangement detected, we need to ask controller to request data loading
153 sqpApp->variableController().requestDataLoading(variable,
147 sqpApp->variableController().requestDataLoading(variable,
154 variableDateTimeWithTolerance);
148 variableDateTimeWithTolerance);
155 }
149 }
156 }
150 }
157 }
151 }
158
152
159 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept
153 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept
160 {
154 {
161 auto zoomOrientations = QFlags<Qt::Orientation>{};
155 auto zoomOrientations = QFlags<Qt::Orientation>{};
162
156
163 // Lambda that enables a zoom orientation if the key modifier related to this orientation
157 // Lambda that enables a zoom orientation if the key modifier related to this orientation
164 // has
158 // has
165 // been pressed
159 // been pressed
166 auto enableOrientation
160 auto enableOrientation
167 = [&zoomOrientations, event](const auto &orientation, const auto &modifier) {
161 = [&zoomOrientations, event](const auto &orientation, const auto &modifier) {
168 auto orientationEnabled = event->modifiers().testFlag(modifier);
162 auto orientationEnabled = event->modifiers().testFlag(modifier);
169 zoomOrientations.setFlag(orientation, orientationEnabled);
163 zoomOrientations.setFlag(orientation, orientationEnabled);
170 };
164 };
171 enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER);
165 enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER);
172 enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER);
166 enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER);
173
167
174 ui->widget->axisRect()->setRangeZoom(zoomOrientations);
168 ui->widget->axisRect()->setRangeZoom(zoomOrientations);
175 }
169 }
176
170
177 void VisualizationGraphWidget::onDataCacheVariableUpdated()
171 void VisualizationGraphWidget::onDataCacheVariableUpdated()
178 {
172 {
179 // NOTE:
173 // NOTE:
180 // We don't want to call the method for each component of a variable unitarily, but for
174 // We don't want to call the method for each component of a variable unitarily, but for
181 // all
175 // all
182 // its components at once (eg its three components in the case of a vector).
176 // its components at once (eg its three components in the case of a vector).
183
177
184 // The unordered_multimap does not do this easily, so the question is whether to:
178 // The unordered_multimap does not do this easily, so the question is whether to:
185 // - use an ordered_multimap and the algos of std to group the values by key
179 // - use an ordered_multimap and the algos of std to group the values by key
186 // - use a map (unique keys) and store as values directly the list of components
180 // - use a map (unique keys) and store as values directly the list of components
187
181
188 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
182 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
189 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
183 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
190 auto variable = it->first;
184 auto variable = it->first;
191 VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *>{} << it->second,
185 VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *>{} << it->second,
192 variable->dataSeries(), variable->dateTime());
186 variable->dataSeries(), variable->dateTime());
193 }
187 }
194 }
188 }
195
189
196 void VisualizationGraphWidget::updateDisplay(std::shared_ptr<Variable> variable)
190 void VisualizationGraphWidget::updateDisplay(std::shared_ptr<Variable> variable)
197 {
191 {
198 auto abstractPlotableItPair = impl->m_VariableToPlotMultiMap.equal_range(variable);
192 auto abstractPlotableItPair = impl->m_VariableToPlotMultiMap.equal_range(variable);
199
193
200 auto abstractPlotableVect = QVector<QCPAbstractPlottable *>{};
194 auto abstractPlotableVect = QVector<QCPAbstractPlottable *>{};
201
195
202 for (auto it = abstractPlotableItPair.first; it != abstractPlotableItPair.second; ++it) {
196 for (auto it = abstractPlotableItPair.first; it != abstractPlotableItPair.second; ++it) {
203 abstractPlotableVect.push_back(it->second);
197 abstractPlotableVect.push_back(it->second);
204 }
198 }
205
199
206 VisualizationGraphHelper::updateData(abstractPlotableVect, variable->dataSeries(),
200 VisualizationGraphHelper::updateData(abstractPlotableVect, variable->dataSeries(),
207 variable->dateTime());
201 variable->dateTime());
208 }
202 }
@@ -1,105 +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 Q_LOGGING_CATEGORY(LOG_VisualizationTabWidget, "VisualizationTabWidget")
7 Q_LOGGING_CATEGORY(LOG_VisualizationTabWidget, "VisualizationTabWidget")
8
8
9 namespace {
9 namespace {
10
10
11 /// Generates a default name for a new zone, according to the number of zones already displayed in
11 /// Generates a default name for a new zone, according to the number of zones already displayed in
12 /// the tab
12 /// the tab
13 QString defaultZoneName(const QLayout &layout)
13 QString defaultZoneName(const QLayout &layout)
14 {
14 {
15 auto count = 0;
15 auto count = 0;
16 for (auto i = 0; i < layout.count(); ++i) {
16 for (auto i = 0; i < layout.count(); ++i) {
17 if (dynamic_cast<VisualizationZoneWidget *>(layout.itemAt(i)->widget())) {
17 if (dynamic_cast<VisualizationZoneWidget *>(layout.itemAt(i)->widget())) {
18 count++;
18 count++;
19 }
19 }
20 }
20 }
21
21
22 return QObject::tr("Zone %1").arg(count + 1);
22 return QObject::tr("Zone %1").arg(count + 1);
23 }
23 }
24
24
25 } // namespace
25 } // namespace
26
26
27 struct VisualizationTabWidget::VisualizationTabWidgetPrivate {
27 struct VisualizationTabWidget::VisualizationTabWidgetPrivate {
28 explicit VisualizationTabWidgetPrivate(const QString &name) : m_Name{name} {}
28 explicit VisualizationTabWidgetPrivate(const QString &name) : m_Name{name} {}
29
29
30 QString m_Name;
30 QString m_Name;
31 };
31 };
32
32
33 VisualizationTabWidget::VisualizationTabWidget(const QString &name, QWidget *parent)
33 VisualizationTabWidget::VisualizationTabWidget(const QString &name, QWidget *parent)
34 : QWidget{parent},
34 : QWidget{parent},
35 ui{new Ui::VisualizationTabWidget},
35 ui{new Ui::VisualizationTabWidget},
36 impl{spimpl::make_unique_impl<VisualizationTabWidgetPrivate>(name)}
36 impl{spimpl::make_unique_impl<VisualizationTabWidgetPrivate>(name)}
37 {
37 {
38 ui->setupUi(this);
38 ui->setupUi(this);
39 }
39 }
40
40
41 VisualizationTabWidget::~VisualizationTabWidget()
41 VisualizationTabWidget::~VisualizationTabWidget()
42 {
42 {
43 delete ui;
43 delete ui;
44 }
44 }
45
45
46 void VisualizationTabWidget::addZone(VisualizationZoneWidget *zoneWidget)
46 void VisualizationTabWidget::addZone(VisualizationZoneWidget *zoneWidget)
47 {
47 {
48 this->layout()->addWidget(zoneWidget);
48 this->layout()->addWidget(zoneWidget);
49 }
49 }
50
50
51 VisualizationZoneWidget *VisualizationTabWidget::createZone(std::shared_ptr<Variable> variable)
51 VisualizationZoneWidget *VisualizationTabWidget::createZone(std::shared_ptr<Variable> variable)
52 {
52 {
53 auto zoneWidget = new VisualizationZoneWidget{defaultZoneName(*layout()), this};
53 auto zoneWidget = new VisualizationZoneWidget{defaultZoneName(*layout()), this};
54 this->addZone(zoneWidget);
54 this->addZone(zoneWidget);
55
55
56 // Creates a new graph into the zone
56 // Creates a new graph into the zone
57 zoneWidget->createGraph(variable);
57 zoneWidget->createGraph(variable);
58
58
59 return zoneWidget;
59 return zoneWidget;
60 }
60 }
61
61
62 void VisualizationTabWidget::removeZone(VisualizationZoneWidget *zone)
62 void VisualizationTabWidget::removeZone(VisualizationZoneWidget *zone)
63 {
63 {
64 }
64 }
65
65
66 void VisualizationTabWidget::accept(IVisualizationWidgetVisitor *visitor)
66 void VisualizationTabWidget::accept(IVisualizationWidgetVisitor *visitor)
67 {
67 {
68 if (visitor) {
68 if (visitor) {
69 visitor->visitEnter(this);
69 visitor->visitEnter(this);
70
70
71 // Apply visitor to zone children
71 // Apply visitor to zone children
72 for (auto i = 0; i < layout()->count(); ++i) {
72 for (auto i = 0; i < layout()->count(); ++i) {
73 if (auto item = layout()->itemAt(i)) {
73 if (auto item = layout()->itemAt(i)) {
74 // Widgets different from zones are not visited (no action)
74 // Widgets different from zones are not visited (no action)
75 if (auto visualizationZoneWidget
75 if (auto visualizationZoneWidget
76 = dynamic_cast<VisualizationZoneWidget *>(item->widget())) {
76 = dynamic_cast<VisualizationZoneWidget *>(item->widget())) {
77 visualizationZoneWidget->accept(visitor);
77 visualizationZoneWidget->accept(visitor);
78 }
78 }
79 }
79 }
80 }
80 }
81
81
82 visitor->visitLeave(this);
82 visitor->visitLeave(this);
83 }
83 }
84 else {
84 else {
85 qCCritical(LOG_VisualizationTabWidget()) << tr("Can't visit widget : the visitor is null");
85 qCCritical(LOG_VisualizationTabWidget()) << tr("Can't visit widget : the visitor is null");
86 }
86 }
87 }
87 }
88
88
89 bool VisualizationTabWidget::canDrop(const Variable &variable) const
89 bool VisualizationTabWidget::canDrop(const Variable &variable) const
90 {
90 {
91 // A tab can always accomodate a variable
91 // A tab can always accomodate a variable
92 Q_UNUSED(variable);
92 Q_UNUSED(variable);
93 return true;
93 return true;
94 }
94 }
95
95
96 void VisualizationTabWidget::close()
97 {
98 // The main view cannot be directly closed.
99 return;
100 }
101
102 QString VisualizationTabWidget::name() const
96 QString VisualizationTabWidget::name() const
103 {
97 {
104 return impl->m_Name;
98 return impl->m_Name;
105 }
99 }
@@ -1,131 +1,125
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/operations/GenerateVariableMenuOperation.h"
6 #include "Visualization/operations/GenerateVariableMenuOperation.h"
7 #include "Visualization/qcustomplot.h"
7 #include "Visualization/qcustomplot.h"
8
8
9 #include "ui_VisualizationWidget.h"
9 #include "ui_VisualizationWidget.h"
10
10
11 #include <QToolButton>
11 #include <QToolButton>
12
12
13 Q_LOGGING_CATEGORY(LOG_VisualizationWidget, "VisualizationWidget")
13 Q_LOGGING_CATEGORY(LOG_VisualizationWidget, "VisualizationWidget")
14
14
15 VisualizationWidget::VisualizationWidget(QWidget *parent)
15 VisualizationWidget::VisualizationWidget(QWidget *parent)
16 : QWidget{parent}, ui{new Ui::VisualizationWidget}
16 : QWidget{parent}, ui{new Ui::VisualizationWidget}
17 {
17 {
18 ui->setupUi(this);
18 ui->setupUi(this);
19
19
20 auto addTabViewButton = new QToolButton{ui->tabWidget};
20 auto addTabViewButton = new QToolButton{ui->tabWidget};
21 addTabViewButton->setText(tr("Add View"));
21 addTabViewButton->setText(tr("Add View"));
22 addTabViewButton->setCursor(Qt::ArrowCursor);
22 addTabViewButton->setCursor(Qt::ArrowCursor);
23 ui->tabWidget->setCornerWidget(addTabViewButton, Qt::TopRightCorner);
23 ui->tabWidget->setCornerWidget(addTabViewButton, Qt::TopRightCorner);
24
24
25 auto enableMinimumCornerWidgetSize = [this](bool enable) {
25 auto enableMinimumCornerWidgetSize = [this](bool enable) {
26
26
27 auto tabViewCornerWidget = ui->tabWidget->cornerWidget();
27 auto tabViewCornerWidget = ui->tabWidget->cornerWidget();
28 auto width = enable ? tabViewCornerWidget->width() : 0;
28 auto width = enable ? tabViewCornerWidget->width() : 0;
29 auto height = enable ? tabViewCornerWidget->height() : 0;
29 auto height = enable ? tabViewCornerWidget->height() : 0;
30 tabViewCornerWidget->setMinimumHeight(height);
30 tabViewCornerWidget->setMinimumHeight(height);
31 tabViewCornerWidget->setMinimumWidth(width);
31 tabViewCornerWidget->setMinimumWidth(width);
32 ui->tabWidget->setMinimumHeight(height);
32 ui->tabWidget->setMinimumHeight(height);
33 ui->tabWidget->setMinimumWidth(width);
33 ui->tabWidget->setMinimumWidth(width);
34 };
34 };
35
35
36 auto addTabView = [this, enableMinimumCornerWidgetSize]() {
36 auto addTabView = [this, enableMinimumCornerWidgetSize]() {
37 auto widget = new VisualizationTabWidget{QString{"View %1"}.arg(ui->tabWidget->count() + 1),
37 auto widget = new VisualizationTabWidget{QString{"View %1"}.arg(ui->tabWidget->count() + 1),
38 ui->tabWidget};
38 ui->tabWidget};
39 auto index = ui->tabWidget->addTab(widget, widget->name());
39 auto index = ui->tabWidget->addTab(widget, widget->name());
40 if (ui->tabWidget->count() > 0) {
40 if (ui->tabWidget->count() > 0) {
41 enableMinimumCornerWidgetSize(false);
41 enableMinimumCornerWidgetSize(false);
42 }
42 }
43 qCInfo(LOG_VisualizationWidget()) << tr("add the tab of index %1").arg(index);
43 qCInfo(LOG_VisualizationWidget()) << tr("add the tab of index %1").arg(index);
44 };
44 };
45
45
46 auto removeTabView = [this, enableMinimumCornerWidgetSize](int index) {
46 auto removeTabView = [this, enableMinimumCornerWidgetSize](int index) {
47 if (ui->tabWidget->count() == 1) {
47 if (ui->tabWidget->count() == 1) {
48 enableMinimumCornerWidgetSize(true);
48 enableMinimumCornerWidgetSize(true);
49 }
49 }
50
50
51 ui->tabWidget->removeTab(index);
51 ui->tabWidget->removeTab(index);
52 qCInfo(LOG_VisualizationWidget()) << tr("remove the tab of index %1").arg(index);
52 qCInfo(LOG_VisualizationWidget()) << tr("remove the tab of index %1").arg(index);
53
53
54 };
54 };
55
55
56 ui->tabWidget->setTabsClosable(true);
56 ui->tabWidget->setTabsClosable(true);
57
57
58 connect(addTabViewButton, &QToolButton::clicked, addTabView);
58 connect(addTabViewButton, &QToolButton::clicked, addTabView);
59 connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView);
59 connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView);
60
60
61 // Adds default tab
61 // Adds default tab
62 addTabView();
62 addTabView();
63 }
63 }
64
64
65 VisualizationWidget::~VisualizationWidget()
65 VisualizationWidget::~VisualizationWidget()
66 {
66 {
67 delete ui;
67 delete ui;
68 }
68 }
69
69
70 void VisualizationWidget::addTab(VisualizationTabWidget *tabWidget)
70 void VisualizationWidget::addTab(VisualizationTabWidget *tabWidget)
71 {
71 {
72 // NOTE: check is this method has to be deleted because of its dupplicated version visible as
72 // NOTE: check is this method has to be deleted because of its dupplicated version visible as
73 // lambda function (in the constructor)
73 // lambda function (in the constructor)
74 }
74 }
75
75
76 VisualizationTabWidget *VisualizationWidget::createTab()
76 VisualizationTabWidget *VisualizationWidget::createTab()
77 {
77 {
78 }
78 }
79
79
80 void VisualizationWidget::removeTab(VisualizationTabWidget *tab)
80 void VisualizationWidget::removeTab(VisualizationTabWidget *tab)
81 {
81 {
82 // NOTE: check is this method has to be deleted because of its dupplicated version visible as
82 // NOTE: check is this method has to be deleted because of its dupplicated version visible as
83 // lambda function (in the constructor)
83 // lambda function (in the constructor)
84 }
84 }
85
85
86 void VisualizationWidget::accept(IVisualizationWidgetVisitor *visitor)
86 void VisualizationWidget::accept(IVisualizationWidgetVisitor *visitor)
87 {
87 {
88 if (visitor) {
88 if (visitor) {
89 visitor->visitEnter(this);
89 visitor->visitEnter(this);
90
90
91 // Apply visitor for tab children
91 // Apply visitor for tab children
92 for (auto i = 0; i < ui->tabWidget->count(); ++i) {
92 for (auto i = 0; i < ui->tabWidget->count(); ++i) {
93 // Widgets different from tabs are not visited (no action)
93 // Widgets different from tabs are not visited (no action)
94 if (auto visualizationTabWidget
94 if (auto visualizationTabWidget
95 = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->widget(i))) {
95 = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->widget(i))) {
96 visualizationTabWidget->accept(visitor);
96 visualizationTabWidget->accept(visitor);
97 }
97 }
98 }
98 }
99
99
100 visitor->visitLeave(this);
100 visitor->visitLeave(this);
101 }
101 }
102 else {
102 else {
103 qCCritical(LOG_VisualizationWidget()) << tr("Can't visit widget : the visitor is null");
103 qCCritical(LOG_VisualizationWidget()) << tr("Can't visit widget : the visitor is null");
104 }
104 }
105 }
105 }
106
106
107 bool VisualizationWidget::canDrop(const Variable &variable) const
107 bool VisualizationWidget::canDrop(const Variable &variable) const
108 {
108 {
109 // The main widget can never accomodate a variable
109 // The main widget can never accomodate a variable
110 Q_UNUSED(variable);
110 Q_UNUSED(variable);
111 return false;
111 return false;
112 }
112 }
113
113
114 void VisualizationWidget::close()
115 {
116 // The main view cannot be directly closed.
117 return;
118 }
119
120 QString VisualizationWidget::name() const
114 QString VisualizationWidget::name() const
121 {
115 {
122 return QStringLiteral("MainView");
116 return QStringLiteral("MainView");
123 }
117 }
124
118
125 void VisualizationWidget::attachVariableMenu(QMenu *menu,
119 void VisualizationWidget::attachVariableMenu(QMenu *menu,
126 std::shared_ptr<Variable> variable) noexcept
120 std::shared_ptr<Variable> variable) noexcept
127 {
121 {
128 // Generates the actions that make it possible to visualize the variable
122 // Generates the actions that make it possible to visualize the variable
129 auto generateVariableMenuOperation = GenerateVariableMenuOperation{menu, variable};
123 auto generateVariableMenuOperation = GenerateVariableMenuOperation{menu, variable};
130 accept(&generateVariableMenuOperation);
124 accept(&generateVariableMenuOperation);
131 }
125 }
@@ -1,100 +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 Q_LOGGING_CATEGORY(LOG_VisualizationZoneWidget, "VisualizationZoneWidget")
7 Q_LOGGING_CATEGORY(LOG_VisualizationZoneWidget, "VisualizationZoneWidget")
8
8
9 namespace {
9 namespace {
10
10
11 /// Generates a default name for a new graph, according to the number of graphs already displayed in
11 /// Generates a default name for a new graph, according to the number of graphs already displayed in
12 /// the zone
12 /// the zone
13 QString defaultGraphName(const QLayout &layout)
13 QString defaultGraphName(const QLayout &layout)
14 {
14 {
15 auto count = 0;
15 auto count = 0;
16 for (auto i = 0; i < layout.count(); ++i) {
16 for (auto i = 0; i < layout.count(); ++i) {
17 if (dynamic_cast<VisualizationGraphWidget *>(layout.itemAt(i)->widget())) {
17 if (dynamic_cast<VisualizationGraphWidget *>(layout.itemAt(i)->widget())) {
18 count++;
18 count++;
19 }
19 }
20 }
20 }
21
21
22 return QObject::tr("Graph %1").arg(count + 1);
22 return QObject::tr("Graph %1").arg(count + 1);
23 }
23 }
24
24
25 } // namespace
25 } // namespace
26
26
27 VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent)
27 VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent)
28 : QWidget{parent}, ui{new Ui::VisualizationZoneWidget}
28 : QWidget{parent}, ui{new Ui::VisualizationZoneWidget}
29 {
29 {
30 ui->setupUi(this);
30 ui->setupUi(this);
31
31
32 ui->zoneNameLabel->setText(name);
32 ui->zoneNameLabel->setText(name);
33 }
33 }
34
34
35 VisualizationZoneWidget::~VisualizationZoneWidget()
35 VisualizationZoneWidget::~VisualizationZoneWidget()
36 {
36 {
37 delete ui;
37 delete ui;
38 }
38 }
39
39
40 void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget)
40 void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget)
41 {
41 {
42 ui->visualizationZoneFrame->layout()->addWidget(graphWidget);
42 ui->visualizationZoneFrame->layout()->addWidget(graphWidget);
43 }
43 }
44
44
45 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable)
45 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable)
46 {
46 {
47 auto graphWidget = new VisualizationGraphWidget{
47 auto graphWidget = new VisualizationGraphWidget{
48 defaultGraphName(*ui->visualizationZoneFrame->layout()), this};
48 defaultGraphName(*ui->visualizationZoneFrame->layout()), this};
49 this->addGraph(graphWidget);
49 this->addGraph(graphWidget);
50
50
51 graphWidget->addVariable(variable);
51 graphWidget->addVariable(variable);
52
52
53 return graphWidget;
53 return graphWidget;
54 }
54 }
55
55
56 void VisualizationZoneWidget::removeGraph(VisualizationGraphWidget *graph)
56 void VisualizationZoneWidget::removeGraph(VisualizationGraphWidget *graph)
57 {
57 {
58 }
58 }
59
59
60 void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor)
60 void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor)
61 {
61 {
62 if (visitor) {
62 if (visitor) {
63 visitor->visitEnter(this);
63 visitor->visitEnter(this);
64
64
65 // Apply visitor to graph children
65 // Apply visitor to graph children
66 auto layout = ui->visualizationZoneFrame->layout();
66 auto layout = ui->visualizationZoneFrame->layout();
67 for (auto i = 0; i < layout->count(); ++i) {
67 for (auto i = 0; i < layout->count(); ++i) {
68 if (auto item = layout->itemAt(i)) {
68 if (auto item = layout->itemAt(i)) {
69 // Widgets different from graphs are not visited (no action)
69 // Widgets different from graphs are not visited (no action)
70 if (auto visualizationGraphWidget
70 if (auto visualizationGraphWidget
71 = dynamic_cast<VisualizationGraphWidget *>(item->widget())) {
71 = dynamic_cast<VisualizationGraphWidget *>(item->widget())) {
72 visualizationGraphWidget->accept(visitor);
72 visualizationGraphWidget->accept(visitor);
73 }
73 }
74 }
74 }
75 }
75 }
76
76
77 visitor->visitLeave(this);
77 visitor->visitLeave(this);
78 }
78 }
79 else {
79 else {
80 qCCritical(LOG_VisualizationZoneWidget()) << tr("Can't visit widget : the visitor is null");
80 qCCritical(LOG_VisualizationZoneWidget()) << tr("Can't visit widget : the visitor is null");
81 }
81 }
82 }
82 }
83
83
84 bool VisualizationZoneWidget::canDrop(const Variable &variable) const
84 bool VisualizationZoneWidget::canDrop(const Variable &variable) const
85 {
85 {
86 // A tab can always accomodate a variable
86 // A tab can always accomodate a variable
87 Q_UNUSED(variable);
87 Q_UNUSED(variable);
88 return true;
88 return true;
89 }
89 }
90
90
91 void VisualizationZoneWidget::close()
92 {
93 // The main view cannot be directly closed.
94 return;
95 }
96
97 QString VisualizationZoneWidget::name() const
91 QString VisualizationZoneWidget::name() const
98 {
92 {
99 return ui->zoneNameLabel->text();
93 return ui->zoneNameLabel->text();
100 }
94 }
General Comments 0
You need to be logged in to leave comments. Login now