@@ -1,53 +1,50 | |||||
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 |
|
|||
39 | void removeZone(VisualizationZoneWidget *zone); |
|
|||
40 |
|
||||
41 | // IVisualizationWidget interface |
|
38 | // IVisualizationWidget interface | |
42 | void accept(IVisualizationWidgetVisitor *visitor) override; |
|
39 | void accept(IVisualizationWidgetVisitor *visitor) override; | |
43 | bool canDrop(const Variable &variable) const override; |
|
40 | bool canDrop(const Variable &variable) const override; | |
44 | QString name() const override; |
|
41 | QString name() const override; | |
45 |
|
42 | |||
46 | private: |
|
43 | private: | |
47 | Ui::VisualizationTabWidget *ui; |
|
44 | Ui::VisualizationTabWidget *ui; | |
48 |
|
45 | |||
49 | class VisualizationTabWidgetPrivate; |
|
46 | class VisualizationTabWidgetPrivate; | |
50 | spimpl::unique_impl_ptr<VisualizationTabWidgetPrivate> impl; |
|
47 | spimpl::unique_impl_ptr<VisualizationTabWidgetPrivate> impl; | |
51 | }; |
|
48 | }; | |
52 |
|
49 | |||
53 | #endif // SCIQLOP_VISUALIZATIONTABWIDGET_H |
|
50 | #endif // SCIQLOP_VISUALIZATIONTABWIDGET_H |
@@ -1,52 +1,43 | |||||
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 |
|
|||
27 | virtual void addTab(VisualizationTabWidget *tabWidget); |
|
|||
28 |
|
||||
29 | /// Create a tab using a Variable |
|
|||
30 | VisualizationTabWidget *createTab(); |
|
|||
31 |
|
||||
32 | /// Remove a tab |
|
|||
33 | void removeTab(VisualizationTabWidget *tab); |
|
|||
34 |
|
||||
35 | // IVisualizationWidget interface |
|
26 | // IVisualizationWidget interface | |
36 | void accept(IVisualizationWidgetVisitor *visitor) override; |
|
27 | void accept(IVisualizationWidgetVisitor *visitor) override; | |
37 | bool canDrop(const Variable &variable) const override; |
|
28 | bool canDrop(const Variable &variable) const override; | |
38 | QString name() const override; |
|
29 | QString name() const override; | |
39 |
|
30 | |||
40 | public slots: |
|
31 | public slots: | |
41 | /** |
|
32 | /** | |
42 | * Attaches to a menu the menu relating to the visualization of a variable |
|
33 | * Attaches to a menu the menu relating to the visualization of a variable | |
43 | * @param menu the parent menu of the generated menu |
|
34 | * @param menu the parent menu of the generated menu | |
44 | * @param variable the variable for which to generate the menu |
|
35 | * @param variable the variable for which to generate the menu | |
45 | */ |
|
36 | */ | |
46 | void attachVariableMenu(QMenu *menu, std::shared_ptr<Variable> variable) noexcept; |
|
37 | void attachVariableMenu(QMenu *menu, std::shared_ptr<Variable> variable) noexcept; | |
47 |
|
38 | |||
48 | private: |
|
39 | private: | |
49 | Ui::VisualizationWidget *ui; |
|
40 | Ui::VisualizationWidget *ui; | |
50 | }; |
|
41 | }; | |
51 |
|
42 | |||
52 | #endif // VISUALIZATIONWIDGET_H |
|
43 | #endif // VISUALIZATIONWIDGET_H |
@@ -1,47 +1,44 | |||||
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 |
|
|||
36 | void removeGraph(VisualizationGraphWidget *graph); |
|
|||
37 |
|
||||
38 | // IVisualizationWidget interface |
|
35 | // IVisualizationWidget interface | |
39 | void accept(IVisualizationWidgetVisitor *visitor) override; |
|
36 | void accept(IVisualizationWidgetVisitor *visitor) override; | |
40 | bool canDrop(const Variable &variable) const override; |
|
37 | bool canDrop(const Variable &variable) const override; | |
41 | QString name() const override; |
|
38 | QString name() const override; | |
42 |
|
39 | |||
43 | private: |
|
40 | private: | |
44 | Ui::VisualizationZoneWidget *ui; |
|
41 | Ui::VisualizationZoneWidget *ui; | |
45 | }; |
|
42 | }; | |
46 |
|
43 | |||
47 | #endif // SCIQLOP_VISUALIZATIONZONEWIDGET_H |
|
44 | #endif // SCIQLOP_VISUALIZATIONZONEWIDGET_H |
@@ -1,102 +1,98 | |||||
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 | // Widget is deleted when closed |
|
40 | // Widget is deleted when closed | |
41 | setAttribute(Qt::WA_DeleteOnClose); |
|
41 | setAttribute(Qt::WA_DeleteOnClose); | |
42 | } |
|
42 | } | |
43 |
|
43 | |||
44 | VisualizationTabWidget::~VisualizationTabWidget() |
|
44 | VisualizationTabWidget::~VisualizationTabWidget() | |
45 | { |
|
45 | { | |
46 | delete ui; |
|
46 | delete ui; | |
47 | } |
|
47 | } | |
48 |
|
48 | |||
49 | void VisualizationTabWidget::addZone(VisualizationZoneWidget *zoneWidget) |
|
49 | void VisualizationTabWidget::addZone(VisualizationZoneWidget *zoneWidget) | |
50 | { |
|
50 | { | |
51 | this->layout()->addWidget(zoneWidget); |
|
51 | this->layout()->addWidget(zoneWidget); | |
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 | VisualizationZoneWidget *VisualizationTabWidget::createZone(std::shared_ptr<Variable> variable) |
|
54 | VisualizationZoneWidget *VisualizationTabWidget::createZone(std::shared_ptr<Variable> variable) | |
55 | { |
|
55 | { | |
56 | auto zoneWidget = new VisualizationZoneWidget{defaultZoneName(*layout()), this}; |
|
56 | auto zoneWidget = new VisualizationZoneWidget{defaultZoneName(*layout()), this}; | |
57 | this->addZone(zoneWidget); |
|
57 | this->addZone(zoneWidget); | |
58 |
|
58 | |||
59 | // Creates a new graph into the zone |
|
59 | // Creates a new graph into the zone | |
60 | zoneWidget->createGraph(variable); |
|
60 | zoneWidget->createGraph(variable); | |
61 |
|
61 | |||
62 | return zoneWidget; |
|
62 | return zoneWidget; | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | void VisualizationTabWidget::removeZone(VisualizationZoneWidget *zone) |
|
|||
66 | { |
|
|||
67 | } |
|
|||
68 |
|
||||
69 | void VisualizationTabWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
65 | void VisualizationTabWidget::accept(IVisualizationWidgetVisitor *visitor) | |
70 | { |
|
66 | { | |
71 | if (visitor) { |
|
67 | if (visitor) { | |
72 | visitor->visitEnter(this); |
|
68 | visitor->visitEnter(this); | |
73 |
|
69 | |||
74 | // Apply visitor to zone children |
|
70 | // Apply visitor to zone children | |
75 | for (auto i = 0; i < layout()->count(); ++i) { |
|
71 | for (auto i = 0; i < layout()->count(); ++i) { | |
76 | if (auto item = layout()->itemAt(i)) { |
|
72 | if (auto item = layout()->itemAt(i)) { | |
77 | // Widgets different from zones are not visited (no action) |
|
73 | // Widgets different from zones are not visited (no action) | |
78 | if (auto visualizationZoneWidget |
|
74 | if (auto visualizationZoneWidget | |
79 | = dynamic_cast<VisualizationZoneWidget *>(item->widget())) { |
|
75 | = dynamic_cast<VisualizationZoneWidget *>(item->widget())) { | |
80 | visualizationZoneWidget->accept(visitor); |
|
76 | visualizationZoneWidget->accept(visitor); | |
81 | } |
|
77 | } | |
82 | } |
|
78 | } | |
83 | } |
|
79 | } | |
84 |
|
80 | |||
85 | visitor->visitLeave(this); |
|
81 | visitor->visitLeave(this); | |
86 | } |
|
82 | } | |
87 | else { |
|
83 | else { | |
88 | qCCritical(LOG_VisualizationTabWidget()) << tr("Can't visit widget : the visitor is null"); |
|
84 | qCCritical(LOG_VisualizationTabWidget()) << tr("Can't visit widget : the visitor is null"); | |
89 | } |
|
85 | } | |
90 | } |
|
86 | } | |
91 |
|
87 | |||
92 | bool VisualizationTabWidget::canDrop(const Variable &variable) const |
|
88 | bool VisualizationTabWidget::canDrop(const Variable &variable) const | |
93 | { |
|
89 | { | |
94 | // A tab can always accomodate a variable |
|
90 | // A tab can always accomodate a variable | |
95 | Q_UNUSED(variable); |
|
91 | Q_UNUSED(variable); | |
96 | return true; |
|
92 | return true; | |
97 | } |
|
93 | } | |
98 |
|
94 | |||
99 | QString VisualizationTabWidget::name() const |
|
95 | QString VisualizationTabWidget::name() const | |
100 | { |
|
96 | { | |
101 | return impl->m_Name; |
|
97 | return impl->m_Name; | |
102 | } |
|
98 | } |
@@ -1,131 +1,115 | |||||
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 | // Removes widget from tab and closes it |
|
51 | // Removes widget from tab and closes it | |
52 | auto widget = ui->tabWidget->widget(index); |
|
52 | auto widget = ui->tabWidget->widget(index); | |
53 | ui->tabWidget->removeTab(index); |
|
53 | ui->tabWidget->removeTab(index); | |
54 | if (widget) { |
|
54 | if (widget) { | |
55 | widget->close(); |
|
55 | widget->close(); | |
56 | } |
|
56 | } | |
57 |
|
57 | |||
58 | qCInfo(LOG_VisualizationWidget()) << tr("remove the tab of index %1").arg(index); |
|
58 | qCInfo(LOG_VisualizationWidget()) << tr("remove the tab of index %1").arg(index); | |
59 |
|
59 | |||
60 | }; |
|
60 | }; | |
61 |
|
61 | |||
62 | ui->tabWidget->setTabsClosable(true); |
|
62 | ui->tabWidget->setTabsClosable(true); | |
63 |
|
63 | |||
64 | connect(addTabViewButton, &QToolButton::clicked, addTabView); |
|
64 | connect(addTabViewButton, &QToolButton::clicked, addTabView); | |
65 | connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView); |
|
65 | connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView); | |
66 |
|
66 | |||
67 | // Adds default tab |
|
67 | // Adds default tab | |
68 | addTabView(); |
|
68 | addTabView(); | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | VisualizationWidget::~VisualizationWidget() |
|
71 | VisualizationWidget::~VisualizationWidget() | |
72 | { |
|
72 | { | |
73 | delete ui; |
|
73 | delete ui; | |
74 | } |
|
74 | } | |
75 |
|
75 | |||
76 | void VisualizationWidget::addTab(VisualizationTabWidget *tabWidget) |
|
|||
77 | { |
|
|||
78 | // NOTE: check is this method has to be deleted because of its dupplicated version visible as |
|
|||
79 | // lambda function (in the constructor) |
|
|||
80 | } |
|
|||
81 |
|
||||
82 | VisualizationTabWidget *VisualizationWidget::createTab() |
|
|||
83 | { |
|
|||
84 | } |
|
|||
85 |
|
||||
86 | void VisualizationWidget::removeTab(VisualizationTabWidget *tab) |
|
|||
87 | { |
|
|||
88 | // NOTE: check is this method has to be deleted because of its dupplicated version visible as |
|
|||
89 | // lambda function (in the constructor) |
|
|||
90 | } |
|
|||
91 |
|
||||
92 | void VisualizationWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
76 | void VisualizationWidget::accept(IVisualizationWidgetVisitor *visitor) | |
93 | { |
|
77 | { | |
94 | if (visitor) { |
|
78 | if (visitor) { | |
95 | visitor->visitEnter(this); |
|
79 | visitor->visitEnter(this); | |
96 |
|
80 | |||
97 | // Apply visitor for tab children |
|
81 | // Apply visitor for tab children | |
98 | for (auto i = 0; i < ui->tabWidget->count(); ++i) { |
|
82 | for (auto i = 0; i < ui->tabWidget->count(); ++i) { | |
99 | // Widgets different from tabs are not visited (no action) |
|
83 | // Widgets different from tabs are not visited (no action) | |
100 | if (auto visualizationTabWidget |
|
84 | if (auto visualizationTabWidget | |
101 | = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->widget(i))) { |
|
85 | = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->widget(i))) { | |
102 | visualizationTabWidget->accept(visitor); |
|
86 | visualizationTabWidget->accept(visitor); | |
103 | } |
|
87 | } | |
104 | } |
|
88 | } | |
105 |
|
89 | |||
106 | visitor->visitLeave(this); |
|
90 | visitor->visitLeave(this); | |
107 | } |
|
91 | } | |
108 | else { |
|
92 | else { | |
109 | qCCritical(LOG_VisualizationWidget()) << tr("Can't visit widget : the visitor is null"); |
|
93 | qCCritical(LOG_VisualizationWidget()) << tr("Can't visit widget : the visitor is null"); | |
110 | } |
|
94 | } | |
111 | } |
|
95 | } | |
112 |
|
96 | |||
113 | bool VisualizationWidget::canDrop(const Variable &variable) const |
|
97 | bool VisualizationWidget::canDrop(const Variable &variable) const | |
114 | { |
|
98 | { | |
115 | // The main widget can never accomodate a variable |
|
99 | // The main widget can never accomodate a variable | |
116 | Q_UNUSED(variable); |
|
100 | Q_UNUSED(variable); | |
117 | return false; |
|
101 | return false; | |
118 | } |
|
102 | } | |
119 |
|
103 | |||
120 | QString VisualizationWidget::name() const |
|
104 | QString VisualizationWidget::name() const | |
121 | { |
|
105 | { | |
122 | return QStringLiteral("MainView"); |
|
106 | return QStringLiteral("MainView"); | |
123 | } |
|
107 | } | |
124 |
|
108 | |||
125 | void VisualizationWidget::attachVariableMenu(QMenu *menu, |
|
109 | void VisualizationWidget::attachVariableMenu(QMenu *menu, | |
126 | std::shared_ptr<Variable> variable) noexcept |
|
110 | std::shared_ptr<Variable> variable) noexcept | |
127 | { |
|
111 | { | |
128 | // Generates the actions that make it possible to visualize the variable |
|
112 | // Generates the actions that make it possible to visualize the variable | |
129 | auto generateVariableMenuOperation = GenerateVariableMenuOperation{menu, variable}; |
|
113 | auto generateVariableMenuOperation = GenerateVariableMenuOperation{menu, variable}; | |
130 | accept(&generateVariableMenuOperation); |
|
114 | accept(&generateVariableMenuOperation); | |
131 | } |
|
115 | } |
@@ -1,101 +1,97 | |||||
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 | #include <SqpApplication.h> |
|
7 | #include <SqpApplication.h> | |
8 |
|
8 | |||
9 | Q_LOGGING_CATEGORY(LOG_VisualizationZoneWidget, "VisualizationZoneWidget") |
|
9 | Q_LOGGING_CATEGORY(LOG_VisualizationZoneWidget, "VisualizationZoneWidget") | |
10 |
|
10 | |||
11 | namespace { |
|
11 | namespace { | |
12 |
|
12 | |||
13 | /// Generates a default name for a new graph, according to the number of graphs already displayed in |
|
13 | /// Generates a default name for a new graph, according to the number of graphs already displayed in | |
14 | /// the zone |
|
14 | /// the zone | |
15 | QString defaultGraphName(const QLayout &layout) |
|
15 | QString defaultGraphName(const QLayout &layout) | |
16 | { |
|
16 | { | |
17 | auto count = 0; |
|
17 | auto count = 0; | |
18 | for (auto i = 0; i < layout.count(); ++i) { |
|
18 | for (auto i = 0; i < layout.count(); ++i) { | |
19 | if (dynamic_cast<VisualizationGraphWidget *>(layout.itemAt(i)->widget())) { |
|
19 | if (dynamic_cast<VisualizationGraphWidget *>(layout.itemAt(i)->widget())) { | |
20 | count++; |
|
20 | count++; | |
21 | } |
|
21 | } | |
22 | } |
|
22 | } | |
23 |
|
23 | |||
24 | return QObject::tr("Graph %1").arg(count + 1); |
|
24 | return QObject::tr("Graph %1").arg(count + 1); | |
25 | } |
|
25 | } | |
26 |
|
26 | |||
27 | } // namespace |
|
27 | } // namespace | |
28 |
|
28 | |||
29 | VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent) |
|
29 | VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent) | |
30 | : QWidget{parent}, ui{new Ui::VisualizationZoneWidget} |
|
30 | : QWidget{parent}, ui{new Ui::VisualizationZoneWidget} | |
31 | { |
|
31 | { | |
32 | ui->setupUi(this); |
|
32 | ui->setupUi(this); | |
33 |
|
33 | |||
34 | ui->zoneNameLabel->setText(name); |
|
34 | ui->zoneNameLabel->setText(name); | |
35 |
|
35 | |||
36 | // 'Close' options : widget is deleted when closed |
|
36 | // 'Close' options : widget is deleted when closed | |
37 | setAttribute(Qt::WA_DeleteOnClose); |
|
37 | setAttribute(Qt::WA_DeleteOnClose); | |
38 | connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationZoneWidget::close); |
|
38 | connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationZoneWidget::close); | |
39 | ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton)); |
|
39 | ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton)); | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | VisualizationZoneWidget::~VisualizationZoneWidget() |
|
42 | VisualizationZoneWidget::~VisualizationZoneWidget() | |
43 | { |
|
43 | { | |
44 | delete ui; |
|
44 | delete ui; | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget) |
|
47 | void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget) | |
48 | { |
|
48 | { | |
49 | ui->visualizationZoneFrame->layout()->addWidget(graphWidget); |
|
49 | ui->visualizationZoneFrame->layout()->addWidget(graphWidget); | |
50 | } |
|
50 | } | |
51 |
|
51 | |||
52 | VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable) |
|
52 | VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable) | |
53 | { |
|
53 | { | |
54 | auto graphWidget = new VisualizationGraphWidget{ |
|
54 | auto graphWidget = new VisualizationGraphWidget{ | |
55 | defaultGraphName(*ui->visualizationZoneFrame->layout()), this}; |
|
55 | defaultGraphName(*ui->visualizationZoneFrame->layout()), this}; | |
56 | this->addGraph(graphWidget); |
|
56 | this->addGraph(graphWidget); | |
57 |
|
57 | |||
58 | graphWidget->addVariable(variable); |
|
58 | graphWidget->addVariable(variable); | |
59 |
|
59 | |||
60 | return graphWidget; |
|
60 | return graphWidget; | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | void VisualizationZoneWidget::removeGraph(VisualizationGraphWidget *graph) |
|
|||
64 | { |
|
|||
65 | } |
|
|||
66 |
|
||||
67 | void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
63 | void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor) | |
68 | { |
|
64 | { | |
69 | if (visitor) { |
|
65 | if (visitor) { | |
70 | visitor->visitEnter(this); |
|
66 | visitor->visitEnter(this); | |
71 |
|
67 | |||
72 | // Apply visitor to graph children |
|
68 | // Apply visitor to graph children | |
73 | auto layout = ui->visualizationZoneFrame->layout(); |
|
69 | auto layout = ui->visualizationZoneFrame->layout(); | |
74 | for (auto i = 0; i < layout->count(); ++i) { |
|
70 | for (auto i = 0; i < layout->count(); ++i) { | |
75 | if (auto item = layout->itemAt(i)) { |
|
71 | if (auto item = layout->itemAt(i)) { | |
76 | // Widgets different from graphs are not visited (no action) |
|
72 | // Widgets different from graphs are not visited (no action) | |
77 | if (auto visualizationGraphWidget |
|
73 | if (auto visualizationGraphWidget | |
78 | = dynamic_cast<VisualizationGraphWidget *>(item->widget())) { |
|
74 | = dynamic_cast<VisualizationGraphWidget *>(item->widget())) { | |
79 | visualizationGraphWidget->accept(visitor); |
|
75 | visualizationGraphWidget->accept(visitor); | |
80 | } |
|
76 | } | |
81 | } |
|
77 | } | |
82 | } |
|
78 | } | |
83 |
|
79 | |||
84 | visitor->visitLeave(this); |
|
80 | visitor->visitLeave(this); | |
85 | } |
|
81 | } | |
86 | else { |
|
82 | else { | |
87 | qCCritical(LOG_VisualizationZoneWidget()) << tr("Can't visit widget : the visitor is null"); |
|
83 | qCCritical(LOG_VisualizationZoneWidget()) << tr("Can't visit widget : the visitor is null"); | |
88 | } |
|
84 | } | |
89 | } |
|
85 | } | |
90 |
|
86 | |||
91 | bool VisualizationZoneWidget::canDrop(const Variable &variable) const |
|
87 | bool VisualizationZoneWidget::canDrop(const Variable &variable) const | |
92 | { |
|
88 | { | |
93 | // A tab can always accomodate a variable |
|
89 | // A tab can always accomodate a variable | |
94 | Q_UNUSED(variable); |
|
90 | Q_UNUSED(variable); | |
95 | return true; |
|
91 | return true; | |
96 | } |
|
92 | } | |
97 |
|
93 | |||
98 | QString VisualizationZoneWidget::name() const |
|
94 | QString VisualizationZoneWidget::name() const | |
99 | { |
|
95 | { | |
100 | return ui->zoneNameLabel->text(); |
|
96 | return ui->zoneNameLabel->text(); | |
101 | } |
|
97 | } |
General Comments 0
You need to be logged in to leave comments.
Login now