##// END OF EJS Templates
Variable deletion (5)...
Alexandre Leroux -
r334:bd7aec6a1752
parent child
Show More
@@ -1,45 +1,48
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 // IVisualizationWidget interface
26 // IVisualizationWidget interface
27 void accept(IVisualizationWidgetVisitor *visitor) override;
27 void accept(IVisualizationWidgetVisitor *visitor) override;
28 bool canDrop(const Variable &variable) const override;
28 bool canDrop(const Variable &variable) const override;
29 bool contains(const Variable &variable) const override;
29 bool contains(const Variable &variable) const override;
30 QString name() const override;
30 QString name() const override;
31
31
32 public slots:
32 public slots:
33 /**
33 /**
34 * Attaches to a menu the menu relative to the visualization of variables
34 * Attaches to a menu the menu relative to the visualization of variables
35 * @param menu the parent menu of the generated menu
35 * @param menu the parent menu of the generated menu
36 * @param variables the variables for which to generate the menu
36 * @param variables the variables for which to generate the menu
37 */
37 */
38 void attachVariableMenu(QMenu *menu,
38 void attachVariableMenu(QMenu *menu,
39 const QVector<std::shared_ptr<Variable> > &variables) noexcept;
39 const QVector<std::shared_ptr<Variable> > &variables) noexcept;
40
40
41 /// Slot called when a variable is about to be deleted from SciQlop
42 void onVariableAboutToBeDeleted(std::shared_ptr<Variable> variable) noexcept;
43
41 private:
44 private:
42 Ui::VisualizationWidget *ui;
45 Ui::VisualizationWidget *ui;
43 };
46 };
44
47
45 #endif // VISUALIZATIONWIDGET_H
48 #endif // VISUALIZATIONWIDGET_H
@@ -1,135 +1,143
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/operations/RemoveVariableOperation.h"
7 #include "Visualization/qcustomplot.h"
8 #include "Visualization/qcustomplot.h"
8
9
9 #include "ui_VisualizationWidget.h"
10 #include "ui_VisualizationWidget.h"
10
11
11 #include <QToolButton>
12 #include <QToolButton>
12
13
13 Q_LOGGING_CATEGORY(LOG_VisualizationWidget, "VisualizationWidget")
14 Q_LOGGING_CATEGORY(LOG_VisualizationWidget, "VisualizationWidget")
14
15
15 VisualizationWidget::VisualizationWidget(QWidget *parent)
16 VisualizationWidget::VisualizationWidget(QWidget *parent)
16 : QWidget{parent}, ui{new Ui::VisualizationWidget}
17 : QWidget{parent}, ui{new Ui::VisualizationWidget}
17 {
18 {
18 ui->setupUi(this);
19 ui->setupUi(this);
19
20
20 auto addTabViewButton = new QToolButton{ui->tabWidget};
21 auto addTabViewButton = new QToolButton{ui->tabWidget};
21 addTabViewButton->setText(tr("Add View"));
22 addTabViewButton->setText(tr("Add View"));
22 addTabViewButton->setCursor(Qt::ArrowCursor);
23 addTabViewButton->setCursor(Qt::ArrowCursor);
23 ui->tabWidget->setCornerWidget(addTabViewButton, Qt::TopRightCorner);
24 ui->tabWidget->setCornerWidget(addTabViewButton, Qt::TopRightCorner);
24
25
25 auto enableMinimumCornerWidgetSize = [this](bool enable) {
26 auto enableMinimumCornerWidgetSize = [this](bool enable) {
26
27
27 auto tabViewCornerWidget = ui->tabWidget->cornerWidget();
28 auto tabViewCornerWidget = ui->tabWidget->cornerWidget();
28 auto width = enable ? tabViewCornerWidget->width() : 0;
29 auto width = enable ? tabViewCornerWidget->width() : 0;
29 auto height = enable ? tabViewCornerWidget->height() : 0;
30 auto height = enable ? tabViewCornerWidget->height() : 0;
30 tabViewCornerWidget->setMinimumHeight(height);
31 tabViewCornerWidget->setMinimumHeight(height);
31 tabViewCornerWidget->setMinimumWidth(width);
32 tabViewCornerWidget->setMinimumWidth(width);
32 ui->tabWidget->setMinimumHeight(height);
33 ui->tabWidget->setMinimumHeight(height);
33 ui->tabWidget->setMinimumWidth(width);
34 ui->tabWidget->setMinimumWidth(width);
34 };
35 };
35
36
36 auto addTabView = [this, enableMinimumCornerWidgetSize]() {
37 auto addTabView = [this, enableMinimumCornerWidgetSize]() {
37 auto widget = new VisualizationTabWidget{QString{"View %1"}.arg(ui->tabWidget->count() + 1),
38 auto widget = new VisualizationTabWidget{QString{"View %1"}.arg(ui->tabWidget->count() + 1),
38 ui->tabWidget};
39 ui->tabWidget};
39 auto index = ui->tabWidget->addTab(widget, widget->name());
40 auto index = ui->tabWidget->addTab(widget, widget->name());
40 if (ui->tabWidget->count() > 0) {
41 if (ui->tabWidget->count() > 0) {
41 enableMinimumCornerWidgetSize(false);
42 enableMinimumCornerWidgetSize(false);
42 }
43 }
43 qCInfo(LOG_VisualizationWidget()) << tr("add the tab of index %1").arg(index);
44 qCInfo(LOG_VisualizationWidget()) << tr("add the tab of index %1").arg(index);
44 };
45 };
45
46
46 auto removeTabView = [this, enableMinimumCornerWidgetSize](int index) {
47 auto removeTabView = [this, enableMinimumCornerWidgetSize](int index) {
47 if (ui->tabWidget->count() == 1) {
48 if (ui->tabWidget->count() == 1) {
48 enableMinimumCornerWidgetSize(true);
49 enableMinimumCornerWidgetSize(true);
49 }
50 }
50
51
51 // Removes widget from tab and closes it
52 // Removes widget from tab and closes it
52 auto widget = ui->tabWidget->widget(index);
53 auto widget = ui->tabWidget->widget(index);
53 ui->tabWidget->removeTab(index);
54 ui->tabWidget->removeTab(index);
54 if (widget) {
55 if (widget) {
55 widget->close();
56 widget->close();
56 }
57 }
57
58
58 qCInfo(LOG_VisualizationWidget()) << tr("remove the tab of index %1").arg(index);
59 qCInfo(LOG_VisualizationWidget()) << tr("remove the tab of index %1").arg(index);
59
60
60 };
61 };
61
62
62 ui->tabWidget->setTabsClosable(true);
63 ui->tabWidget->setTabsClosable(true);
63
64
64 connect(addTabViewButton, &QToolButton::clicked, addTabView);
65 connect(addTabViewButton, &QToolButton::clicked, addTabView);
65 connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView);
66 connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView);
66
67
67 // Adds default tab
68 // Adds default tab
68 addTabView();
69 addTabView();
69 }
70 }
70
71
71 VisualizationWidget::~VisualizationWidget()
72 VisualizationWidget::~VisualizationWidget()
72 {
73 {
73 delete ui;
74 delete ui;
74 }
75 }
75
76
76 void VisualizationWidget::accept(IVisualizationWidgetVisitor *visitor)
77 void VisualizationWidget::accept(IVisualizationWidgetVisitor *visitor)
77 {
78 {
78 if (visitor) {
79 if (visitor) {
79 visitor->visitEnter(this);
80 visitor->visitEnter(this);
80
81
81 // Apply visitor for tab children
82 // Apply visitor for tab children
82 for (auto i = 0; i < ui->tabWidget->count(); ++i) {
83 for (auto i = 0; i < ui->tabWidget->count(); ++i) {
83 // Widgets different from tabs are not visited (no action)
84 // Widgets different from tabs are not visited (no action)
84 if (auto visualizationTabWidget
85 if (auto visualizationTabWidget
85 = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->widget(i))) {
86 = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->widget(i))) {
86 visualizationTabWidget->accept(visitor);
87 visualizationTabWidget->accept(visitor);
87 }
88 }
88 }
89 }
89
90
90 visitor->visitLeave(this);
91 visitor->visitLeave(this);
91 }
92 }
92 else {
93 else {
93 qCCritical(LOG_VisualizationWidget()) << tr("Can't visit widget : the visitor is null");
94 qCCritical(LOG_VisualizationWidget()) << tr("Can't visit widget : the visitor is null");
94 }
95 }
95 }
96 }
96
97
97 bool VisualizationWidget::canDrop(const Variable &variable) const
98 bool VisualizationWidget::canDrop(const Variable &variable) const
98 {
99 {
99 // The main widget can never accomodate a variable
100 // The main widget can never accomodate a variable
100 Q_UNUSED(variable);
101 Q_UNUSED(variable);
101 return false;
102 return false;
102 }
103 }
103
104
104 bool VisualizationWidget::contains(const Variable &variable) const
105 bool VisualizationWidget::contains(const Variable &variable) const
105 {
106 {
106 Q_UNUSED(variable);
107 Q_UNUSED(variable);
107 return false;
108 return false;
108 }
109 }
109
110
110 QString VisualizationWidget::name() const
111 QString VisualizationWidget::name() const
111 {
112 {
112 return QStringLiteral("MainView");
113 return QStringLiteral("MainView");
113 }
114 }
114
115
115 void VisualizationWidget::attachVariableMenu(
116 void VisualizationWidget::attachVariableMenu(
116 QMenu *menu, const QVector<std::shared_ptr<Variable> > &variables) noexcept
117 QMenu *menu, const QVector<std::shared_ptr<Variable> > &variables) noexcept
117 {
118 {
118 // Menu is generated only if there is a single variable
119 // Menu is generated only if there is a single variable
119 if (variables.size() == 1) {
120 if (variables.size() == 1) {
120 if (auto variable = variables.first()) {
121 if (auto variable = variables.first()) {
121 // Generates the actions that make it possible to visualize the variable
122 // Generates the actions that make it possible to visualize the variable
122 auto generateVariableMenuOperation = GenerateVariableMenuOperation{menu, variable};
123 auto generateVariableMenuOperation = GenerateVariableMenuOperation{menu, variable};
123 accept(&generateVariableMenuOperation);
124 accept(&generateVariableMenuOperation);
124 }
125 }
125 else {
126 else {
126 qCCritical(LOG_VisualizationWidget()) << tr(
127 qCCritical(LOG_VisualizationWidget()) << tr(
127 "Can't generate the menu relative to the visualization: the variable is null");
128 "Can't generate the menu relative to the visualization: the variable is null");
128 }
129 }
129 }
130 }
130 else {
131 else {
131 qCDebug(LOG_VisualizationWidget())
132 qCDebug(LOG_VisualizationWidget())
132 << tr("No generation of the menu related to the visualization: several variables are "
133 << tr("No generation of the menu related to the visualization: several variables are "
133 "selected");
134 "selected");
134 }
135 }
135 }
136 }
137
138 void VisualizationWidget::onVariableAboutToBeDeleted(std::shared_ptr<Variable> variable) noexcept
139 {
140 // Calls the operation of removing all references to the variable in the visualization
141 auto removeVariableOperation = RemoveVariableOperation{variable};
142 accept(&removeVariableOperation);
143 }
General Comments 0
You need to be logged in to leave comments. Login now