@@ -62,6 +62,7 signals: | |||
|
62 | 62 | void variableAdded(std::shared_ptr<Variable> var); |
|
63 | 63 | |
|
64 | 64 | protected: |
|
65 | void closeEvent(QCloseEvent *event) override; | |
|
65 | 66 | void enterEvent(QEvent *event) override; |
|
66 | 67 | void leaveEvent(QEvent *event) override; |
|
67 | 68 |
@@ -41,6 +41,9 public: | |||
|
41 | 41 | bool contains(const Variable &variable) const override; |
|
42 | 42 | QString name() const override; |
|
43 | 43 | |
|
44 | protected: | |
|
45 | void closeEvent(QCloseEvent *event) override; | |
|
46 | ||
|
44 | 47 | private: |
|
45 | 48 | /// @return the layout of tab in which zones are added |
|
46 | 49 | QLayout &tabLayout() const noexcept; |
@@ -44,6 +44,9 public slots: | |||
|
44 | 44 | |
|
45 | 45 | void onRangeChanged(std::shared_ptr<Variable> variable, const SqpRange &range) noexcept; |
|
46 | 46 | |
|
47 | protected: | |
|
48 | void closeEvent(QCloseEvent *event) override; | |
|
49 | ||
|
47 | 50 | private: |
|
48 | 51 | Ui::VisualizationWidget *ui; |
|
49 | 52 | }; |
@@ -42,6 +42,9 public: | |||
|
42 | 42 | bool contains(const Variable &variable) const override; |
|
43 | 43 | QString name() const override; |
|
44 | 44 | |
|
45 | protected: | |
|
46 | void closeEvent(QCloseEvent *event) override; | |
|
47 | ||
|
45 | 48 | private: |
|
46 | 49 | Ui::VisualizationZoneWidget *ui; |
|
47 | 50 |
@@ -220,6 +220,16 QString VisualizationGraphWidget::name() const | |||
|
220 | 220 | return impl->m_Name; |
|
221 | 221 | } |
|
222 | 222 | |
|
223 | void VisualizationGraphWidget::closeEvent(QCloseEvent *event) | |
|
224 | { | |
|
225 | Q_UNUSED(event); | |
|
226 | ||
|
227 | // Prevents that all variables will be removed from graph when it will be closed | |
|
228 | for (auto &variableEntry : impl->m_VariableToPlotMultiMap) { | |
|
229 | emit variableAboutToBeRemoved(variableEntry.first); | |
|
230 | } | |
|
231 | } | |
|
232 | ||
|
223 | 233 | void VisualizationGraphWidget::enterEvent(QEvent *event) |
|
224 | 234 | { |
|
225 | 235 | Q_UNUSED(event); |
@@ -22,6 +22,24 QString defaultZoneName(const QLayout &layout) | |||
|
22 | 22 | return QObject::tr("Zone %1").arg(count + 1); |
|
23 | 23 | } |
|
24 | 24 | |
|
25 | /** | |
|
26 | * Applies a function to all zones of the tab represented by its layout | |
|
27 | * @param layout the layout that contains zones | |
|
28 | * @param fun the function to apply to each zone | |
|
29 | */ | |
|
30 | template <typename Fun> | |
|
31 | void processZones(QLayout &layout, Fun fun) | |
|
32 | { | |
|
33 | for (auto i = 0; i < layout.count(); ++i) { | |
|
34 | if (auto item = layout.itemAt(i)) { | |
|
35 | if (auto visualizationZoneWidget | |
|
36 | = dynamic_cast<VisualizationZoneWidget *>(item->widget())) { | |
|
37 | fun(*visualizationZoneWidget); | |
|
38 | } | |
|
39 | } | |
|
40 | } | |
|
41 | } | |
|
42 | ||
|
25 | 43 | } // namespace |
|
26 | 44 | |
|
27 | 45 | struct VisualizationTabWidget::VisualizationTabWidgetPrivate { |
@@ -67,17 +85,10 void VisualizationTabWidget::accept(IVisualizationWidgetVisitor *visitor) | |||
|
67 | 85 | if (visitor) { |
|
68 | 86 | visitor->visitEnter(this); |
|
69 | 87 | |
|
70 | // Apply visitor to zone children | |
|
71 | auto &layout = tabLayout(); | |
|
72 | for (auto i = 0; i < layout.count(); ++i) { | |
|
73 | if (auto item = layout.itemAt(i)) { | |
|
74 | // Widgets different from zones are not visited (no action) | |
|
75 | if (auto visualizationZoneWidget | |
|
76 | = dynamic_cast<VisualizationZoneWidget *>(item->widget())) { | |
|
77 | visualizationZoneWidget->accept(visitor); | |
|
78 | } | |
|
79 | } | |
|
80 | } | |
|
88 | // Apply visitor to zone children: widgets different from zones are not visited (no action) | |
|
89 | processZones(tabLayout(), [visitor](VisualizationZoneWidget &zoneWidget) { | |
|
90 | zoneWidget.accept(visitor); | |
|
91 | }); | |
|
81 | 92 | |
|
82 | 93 | visitor->visitLeave(this); |
|
83 | 94 | } |
@@ -104,6 +115,14 QString VisualizationTabWidget::name() const | |||
|
104 | 115 | return impl->m_Name; |
|
105 | 116 | } |
|
106 | 117 | |
|
118 | void VisualizationTabWidget::closeEvent(QCloseEvent *event) | |
|
119 | { | |
|
120 | // Closes zones in the tab | |
|
121 | processZones(tabLayout(), [](VisualizationZoneWidget &zoneWidget) { zoneWidget.close(); }); | |
|
122 | ||
|
123 | QWidget::closeEvent(event); | |
|
124 | } | |
|
125 | ||
|
107 | 126 | QLayout &VisualizationTabWidget::tabLayout() const noexcept |
|
108 | 127 | { |
|
109 | 128 | return *ui->scrollAreaWidgetContents->layout(); |
@@ -157,3 +157,16 void VisualizationWidget::onRangeChanged(std::shared_ptr<Variable> variable, | |||
|
157 | 157 | auto rescaleVariableOperation = RescaleAxeOperation{variable, range}; |
|
158 | 158 | accept(&rescaleVariableOperation); |
|
159 | 159 | } |
|
160 | ||
|
161 | void VisualizationWidget::closeEvent(QCloseEvent *event) | |
|
162 | { | |
|
163 | // Closes tabs in the widget | |
|
164 | for (auto i = 0; i < ui->tabWidget->count(); ++i) { | |
|
165 | if (auto visualizationTabWidget | |
|
166 | = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->widget(i))) { | |
|
167 | visualizationTabWidget->close(); | |
|
168 | } | |
|
169 | } | |
|
170 | ||
|
171 | QWidget::closeEvent(event); | |
|
172 | } |
@@ -34,6 +34,24 QString defaultGraphName(const QLayout &layout) | |||
|
34 | 34 | return QObject::tr("Graph %1").arg(count + 1); |
|
35 | 35 | } |
|
36 | 36 | |
|
37 | /** | |
|
38 | * Applies a function to all graphs of the zone represented by its layout | |
|
39 | * @param layout the layout that contains graphs | |
|
40 | * @param fun the function to apply to each graph | |
|
41 | */ | |
|
42 | template <typename Fun> | |
|
43 | void processGraphs(QLayout &layout, Fun fun) | |
|
44 | { | |
|
45 | for (auto i = 0; i < layout.count(); ++i) { | |
|
46 | if (auto item = layout.itemAt(i)) { | |
|
47 | if (auto visualizationGraphWidget | |
|
48 | = dynamic_cast<VisualizationGraphWidget *>(item->widget())) { | |
|
49 | fun(*visualizationGraphWidget); | |
|
50 | } | |
|
51 | } | |
|
52 | } | |
|
53 | } | |
|
54 | ||
|
37 | 55 | } // namespace |
|
38 | 56 | |
|
39 | 57 | struct VisualizationZoneWidget::VisualizationZoneWidgetPrivate { |
@@ -225,17 +243,11 void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor) | |||
|
225 | 243 | if (visitor) { |
|
226 | 244 | visitor->visitEnter(this); |
|
227 | 245 | |
|
228 | // Apply visitor to graph children | |
|
229 | auto layout = ui->visualizationZoneFrame->layout(); | |
|
230 | for (auto i = 0; i < layout->count(); ++i) { | |
|
231 | if (auto item = layout->itemAt(i)) { | |
|
232 | // Widgets different from graphs are not visited (no action) | |
|
233 | if (auto visualizationGraphWidget | |
|
234 | = dynamic_cast<VisualizationGraphWidget *>(item->widget())) { | |
|
235 | visualizationGraphWidget->accept(visitor); | |
|
236 | } | |
|
237 | } | |
|
238 | } | |
|
246 | // Apply visitor to graph children: widgets different from graphs are not visited (no | |
|
247 | // action) | |
|
248 | processGraphs( | |
|
249 | *ui->visualizationZoneFrame->layout(), | |
|
250 | [visitor](VisualizationGraphWidget &graphWidget) { graphWidget.accept(visitor); }); | |
|
239 | 251 | |
|
240 | 252 | visitor->visitLeave(this); |
|
241 | 253 | } |
@@ -262,6 +274,15 QString VisualizationZoneWidget::name() const | |||
|
262 | 274 | return ui->zoneNameLabel->text(); |
|
263 | 275 | } |
|
264 | 276 | |
|
277 | void VisualizationZoneWidget::closeEvent(QCloseEvent *event) | |
|
278 | { | |
|
279 | // Closes graphs in the zone | |
|
280 | processGraphs(*ui->visualizationZoneFrame->layout(), | |
|
281 | [](VisualizationGraphWidget &graphWidget) { graphWidget.close(); }); | |
|
282 | ||
|
283 | QWidget::closeEvent(event); | |
|
284 | } | |
|
285 | ||
|
265 | 286 | void VisualizationZoneWidget::onVariableAdded(std::shared_ptr<Variable> variable) |
|
266 | 287 | { |
|
267 | 288 | QMetaObject::invokeMethod(&sqpApp->variableController(), "onAddSynchronized", |
General Comments 0
You need to be logged in to leave comments.
Login now