##// END OF EJS Templates
Creates a method (slot) in VisualizationWidget to add the plot menu to a variable menu
Alexandre Leroux -
r248:5b41c2a03db2
parent child
Show More
@@ -1,53 +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 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationWidget)
9 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationWidget)
10
10
11 class QMenu;
11 class Variable;
12 class Variable;
12 class VisualizationTabWidget;
13 class VisualizationTabWidget;
13
14
14 namespace Ui {
15 namespace Ui {
15 class VisualizationWidget;
16 class VisualizationWidget;
16 } // namespace Ui
17 } // namespace Ui
17
18
18 class VisualizationWidget : public QWidget, public IVisualizationWidget {
19 class VisualizationWidget : public QWidget, public IVisualizationWidget {
19 Q_OBJECT
20 Q_OBJECT
20
21
21 public:
22 public:
22 explicit VisualizationWidget(QWidget *parent = 0);
23 explicit VisualizationWidget(QWidget *parent = 0);
23 virtual ~VisualizationWidget();
24 virtual ~VisualizationWidget();
24
25
25 /// Add a zone widget
26 /// Add a zone widget
26 virtual void addTab(VisualizationTabWidget *tabWidget);
27 virtual void addTab(VisualizationTabWidget *tabWidget);
27
28
28 /// Create a tab using a Variable
29 /// Create a tab using a Variable
29 VisualizationTabWidget *createTab();
30 VisualizationTabWidget *createTab();
30
31
31 /// Remove a tab
32 /// Remove a tab
32 void removeTab(VisualizationTabWidget *tab);
33 void removeTab(VisualizationTabWidget *tab);
33
34
34 // IVisualizationWidget interface
35 // IVisualizationWidget interface
35 void accept(IVisualizationWidgetVisitor *visitor) override;
36 void accept(IVisualizationWidgetVisitor *visitor) override;
36 bool canDrop(const Variable &variable) const 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 public slots:
41 public slots:
41 /**
42 /**
42 * Displays a variable in a new graph of a new zone of the current tab
43 * Attaches to a menu the menu relating to the visualization of a variable
43 * @param variable the variable to display
44 * @param menu the parent menu of the generated menu
44 * @todo this is a temporary method that will be replaced by own actions for each type of
45 * @param variable the variable for which to generate the menu
45 * visualization widget
46 */
46 */
47 void displayVariable(std::shared_ptr<Variable> variable) noexcept;
47 void attachVariableMenu(QMenu *menu, std::shared_ptr<Variable> variable) noexcept;
48
48
49 private:
49 private:
50 Ui::VisualizationWidget *ui;
50 Ui::VisualizationWidget *ui;
51 };
51 };
52
52
53 #endif // VISUALIZATIONWIDGET_H
53 #endif // VISUALIZATIONWIDGET_H
@@ -1,136 +1,131
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/qcustomplot.h"
7 #include "Visualization/qcustomplot.h"
7
8
8 #include "ui_VisualizationWidget.h"
9 #include "ui_VisualizationWidget.h"
9
10
10 #include <QToolButton>
11 #include <QToolButton>
11
12
12 Q_LOGGING_CATEGORY(LOG_VisualizationWidget, "VisualizationWidget")
13 Q_LOGGING_CATEGORY(LOG_VisualizationWidget, "VisualizationWidget")
13
14
14 VisualizationWidget::VisualizationWidget(QWidget *parent)
15 VisualizationWidget::VisualizationWidget(QWidget *parent)
15 : QWidget{parent}, ui{new Ui::VisualizationWidget}
16 : QWidget{parent}, ui{new Ui::VisualizationWidget}
16 {
17 {
17 ui->setupUi(this);
18 ui->setupUi(this);
18
19
19 auto addTabViewButton = new QToolButton{ui->tabWidget};
20 auto addTabViewButton = new QToolButton{ui->tabWidget};
20 addTabViewButton->setText(tr("Add View"));
21 addTabViewButton->setText(tr("Add View"));
21 addTabViewButton->setCursor(Qt::ArrowCursor);
22 addTabViewButton->setCursor(Qt::ArrowCursor);
22 ui->tabWidget->setCornerWidget(addTabViewButton, Qt::TopRightCorner);
23 ui->tabWidget->setCornerWidget(addTabViewButton, Qt::TopRightCorner);
23
24
24 auto enableMinimumCornerWidgetSize = [this](bool enable) {
25 auto enableMinimumCornerWidgetSize = [this](bool enable) {
25
26
26 auto tabViewCornerWidget = ui->tabWidget->cornerWidget();
27 auto tabViewCornerWidget = ui->tabWidget->cornerWidget();
27 auto width = enable ? tabViewCornerWidget->width() : 0;
28 auto width = enable ? tabViewCornerWidget->width() : 0;
28 auto height = enable ? tabViewCornerWidget->height() : 0;
29 auto height = enable ? tabViewCornerWidget->height() : 0;
29 tabViewCornerWidget->setMinimumHeight(height);
30 tabViewCornerWidget->setMinimumHeight(height);
30 tabViewCornerWidget->setMinimumWidth(width);
31 tabViewCornerWidget->setMinimumWidth(width);
31 ui->tabWidget->setMinimumHeight(height);
32 ui->tabWidget->setMinimumHeight(height);
32 ui->tabWidget->setMinimumWidth(width);
33 ui->tabWidget->setMinimumWidth(width);
33 };
34 };
34
35
35 auto addTabView = [this, enableMinimumCornerWidgetSize]() {
36 auto addTabView = [this, enableMinimumCornerWidgetSize]() {
36 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),
37 ui->tabWidget};
38 ui->tabWidget};
38 auto index = ui->tabWidget->addTab(widget, widget->name());
39 auto index = ui->tabWidget->addTab(widget, widget->name());
39 if (ui->tabWidget->count() > 0) {
40 if (ui->tabWidget->count() > 0) {
40 enableMinimumCornerWidgetSize(false);
41 enableMinimumCornerWidgetSize(false);
41 }
42 }
42 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);
43 };
44 };
44
45
45 auto removeTabView = [this, enableMinimumCornerWidgetSize](int index) {
46 auto removeTabView = [this, enableMinimumCornerWidgetSize](int index) {
46 if (ui->tabWidget->count() == 1) {
47 if (ui->tabWidget->count() == 1) {
47 enableMinimumCornerWidgetSize(true);
48 enableMinimumCornerWidgetSize(true);
48 }
49 }
49
50
50 ui->tabWidget->removeTab(index);
51 ui->tabWidget->removeTab(index);
51 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);
52
53
53 };
54 };
54
55
55 ui->tabWidget->setTabsClosable(true);
56 ui->tabWidget->setTabsClosable(true);
56
57
57 connect(addTabViewButton, &QToolButton::clicked, addTabView);
58 connect(addTabViewButton, &QToolButton::clicked, addTabView);
58 connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView);
59 connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView);
59
60
60 // Adds default tab
61 // Adds default tab
61 addTabView();
62 addTabView();
62 }
63 }
63
64
64 VisualizationWidget::~VisualizationWidget()
65 VisualizationWidget::~VisualizationWidget()
65 {
66 {
66 delete ui;
67 delete ui;
67 }
68 }
68
69
69 void VisualizationWidget::addTab(VisualizationTabWidget *tabWidget)
70 void VisualizationWidget::addTab(VisualizationTabWidget *tabWidget)
70 {
71 {
71 // 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
72 // lambda function (in the constructor)
73 // lambda function (in the constructor)
73 }
74 }
74
75
75 VisualizationTabWidget *VisualizationWidget::createTab()
76 VisualizationTabWidget *VisualizationWidget::createTab()
76 {
77 {
77 }
78 }
78
79
79 void VisualizationWidget::removeTab(VisualizationTabWidget *tab)
80 void VisualizationWidget::removeTab(VisualizationTabWidget *tab)
80 {
81 {
81 // 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
82 // lambda function (in the constructor)
83 // lambda function (in the constructor)
83 }
84 }
84
85
85 void VisualizationWidget::accept(IVisualizationWidgetVisitor *visitor)
86 void VisualizationWidget::accept(IVisualizationWidgetVisitor *visitor)
86 {
87 {
87 if (visitor) {
88 if (visitor) {
88 visitor->visitEnter(this);
89 visitor->visitEnter(this);
89
90
90 // Apply visitor for tab children
91 // Apply visitor for tab children
91 for (auto i = 0; i < ui->tabWidget->count(); ++i) {
92 for (auto i = 0; i < ui->tabWidget->count(); ++i) {
92 // Widgets different from tabs are not visited (no action)
93 // Widgets different from tabs are not visited (no action)
93 if (auto visualizationTabWidget
94 if (auto visualizationTabWidget
94 = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->widget(i))) {
95 = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->widget(i))) {
95 visualizationTabWidget->accept(visitor);
96 visualizationTabWidget->accept(visitor);
96 }
97 }
97 }
98 }
98
99
99 visitor->visitLeave(this);
100 visitor->visitLeave(this);
100 }
101 }
101 else {
102 else {
102 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");
103 }
104 }
104 }
105 }
105
106
106 bool VisualizationWidget::canDrop(const Variable &variable) const
107 bool VisualizationWidget::canDrop(const Variable &variable) const
107 {
108 {
108 // The main widget can never accomodate a variable
109 // The main widget can never accomodate a variable
109 Q_UNUSED(variable);
110 Q_UNUSED(variable);
110 return false;
111 return false;
111 }
112 }
112
113
113 void VisualizationWidget::close()
114 void VisualizationWidget::close()
114 {
115 {
115 // The main view cannot be directly closed.
116 // The main view cannot be directly closed.
116 return;
117 return;
117 }
118 }
118
119
119 QString VisualizationWidget::name() const
120 QString VisualizationWidget::name() const
120 {
121 {
121 return QStringLiteral("MainView");
122 return QStringLiteral("MainView");
122 }
123 }
123
124
124 void VisualizationWidget::displayVariable(std::shared_ptr<Variable> variable) noexcept
125 void VisualizationWidget::attachVariableMenu(QMenu *menu,
126 std::shared_ptr<Variable> variable) noexcept
125 {
127 {
126 if (auto currentTab = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->currentWidget())) {
128 // Generates the actions that make it possible to visualize the variable
127 if (!currentTab->createZone(variable)) {
129 auto generateVariableMenuOperation = GenerateVariableMenuOperation{menu, variable};
128 qCCritical(LOG_VisualizationWidget())
130 accept(&generateVariableMenuOperation);
129 << tr("Can't display the variable : can't create a new zone in the current tab");
130 }
131 }
132 else {
133 qCCritical(LOG_VisualizationWidget())
134 << tr("Can't display the variable : there is no current tab");
135 }
136 }
131 }
General Comments 0
You need to be logged in to leave comments. Login now