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