##// END OF EJS Templates
Handles desynchronisation when removing variable from a graph (2)...
Alexandre Leroux -
r738:48ebbf123b7f
parent child
Show More
@@ -62,6 +62,7 signals:
62 void variableAdded(std::shared_ptr<Variable> var);
62 void variableAdded(std::shared_ptr<Variable> var);
63
63
64 protected:
64 protected:
65 void closeEvent(QCloseEvent *event) override;
65 void enterEvent(QEvent *event) override;
66 void enterEvent(QEvent *event) override;
66 void leaveEvent(QEvent *event) override;
67 void leaveEvent(QEvent *event) override;
67
68
@@ -41,6 +41,9 public:
41 bool contains(const Variable &variable) const override;
41 bool contains(const Variable &variable) const override;
42 QString name() const override;
42 QString name() const override;
43
43
44 protected:
45 void closeEvent(QCloseEvent *event) override;
46
44 private:
47 private:
45 /// @return the layout of tab in which zones are added
48 /// @return the layout of tab in which zones are added
46 QLayout &tabLayout() const noexcept;
49 QLayout &tabLayout() const noexcept;
@@ -44,6 +44,9 public slots:
44
44
45 void onRangeChanged(std::shared_ptr<Variable> variable, const SqpRange &range) noexcept;
45 void onRangeChanged(std::shared_ptr<Variable> variable, const SqpRange &range) noexcept;
46
46
47 protected:
48 void closeEvent(QCloseEvent *event) override;
49
47 private:
50 private:
48 Ui::VisualizationWidget *ui;
51 Ui::VisualizationWidget *ui;
49 };
52 };
@@ -42,6 +42,9 public:
42 bool contains(const Variable &variable) const override;
42 bool contains(const Variable &variable) const override;
43 QString name() const override;
43 QString name() const override;
44
44
45 protected:
46 void closeEvent(QCloseEvent *event) override;
47
45 private:
48 private:
46 Ui::VisualizationZoneWidget *ui;
49 Ui::VisualizationZoneWidget *ui;
47
50
@@ -220,6 +220,16 QString VisualizationGraphWidget::name() const
220 return impl->m_Name;
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 void VisualizationGraphWidget::enterEvent(QEvent *event)
233 void VisualizationGraphWidget::enterEvent(QEvent *event)
224 {
234 {
225 Q_UNUSED(event);
235 Q_UNUSED(event);
@@ -22,6 +22,24 QString defaultZoneName(const QLayout &layout)
22 return QObject::tr("Zone %1").arg(count + 1);
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 } // namespace
43 } // namespace
26
44
27 struct VisualizationTabWidget::VisualizationTabWidgetPrivate {
45 struct VisualizationTabWidget::VisualizationTabWidgetPrivate {
@@ -67,17 +85,10 void VisualizationTabWidget::accept(IVisualizationWidgetVisitor *visitor)
67 if (visitor) {
85 if (visitor) {
68 visitor->visitEnter(this);
86 visitor->visitEnter(this);
69
87
70 // Apply visitor to zone children
88 // Apply visitor to zone children: widgets different from zones are not visited (no action)
71 auto &layout = tabLayout();
89 processZones(tabLayout(), [visitor](VisualizationZoneWidget &zoneWidget) {
72 for (auto i = 0; i < layout.count(); ++i) {
90 zoneWidget.accept(visitor);
73 if (auto item = layout.itemAt(i)) {
91 });
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 }
81
92
82 visitor->visitLeave(this);
93 visitor->visitLeave(this);
83 }
94 }
@@ -104,6 +115,14 QString VisualizationTabWidget::name() const
104 return impl->m_Name;
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 QLayout &VisualizationTabWidget::tabLayout() const noexcept
126 QLayout &VisualizationTabWidget::tabLayout() const noexcept
108 {
127 {
109 return *ui->scrollAreaWidgetContents->layout();
128 return *ui->scrollAreaWidgetContents->layout();
@@ -157,3 +157,16 void VisualizationWidget::onRangeChanged(std::shared_ptr<Variable> variable,
157 auto rescaleVariableOperation = RescaleAxeOperation{variable, range};
157 auto rescaleVariableOperation = RescaleAxeOperation{variable, range};
158 accept(&rescaleVariableOperation);
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 return QObject::tr("Graph %1").arg(count + 1);
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 } // namespace
55 } // namespace
38
56
39 struct VisualizationZoneWidget::VisualizationZoneWidgetPrivate {
57 struct VisualizationZoneWidget::VisualizationZoneWidgetPrivate {
@@ -225,17 +243,11 void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor)
225 if (visitor) {
243 if (visitor) {
226 visitor->visitEnter(this);
244 visitor->visitEnter(this);
227
245
228 // Apply visitor to graph children
246 // Apply visitor to graph children: widgets different from graphs are not visited (no
229 auto layout = ui->visualizationZoneFrame->layout();
247 // action)
230 for (auto i = 0; i < layout->count(); ++i) {
248 processGraphs(
231 if (auto item = layout->itemAt(i)) {
249 *ui->visualizationZoneFrame->layout(),
232 // Widgets different from graphs are not visited (no action)
250 [visitor](VisualizationGraphWidget &graphWidget) { graphWidget.accept(visitor); });
233 if (auto visualizationGraphWidget
234 = dynamic_cast<VisualizationGraphWidget *>(item->widget())) {
235 visualizationGraphWidget->accept(visitor);
236 }
237 }
238 }
239
251
240 visitor->visitLeave(this);
252 visitor->visitLeave(this);
241 }
253 }
@@ -262,6 +274,15 QString VisualizationZoneWidget::name() const
262 return ui->zoneNameLabel->text();
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 void VisualizationZoneWidget::onVariableAdded(std::shared_ptr<Variable> variable)
286 void VisualizationZoneWidget::onVariableAdded(std::shared_ptr<Variable> variable)
266 {
287 {
267 QMetaObject::invokeMethod(&sqpApp->variableController(), "onAddSynchronized",
288 QMetaObject::invokeMethod(&sqpApp->variableController(), "onAddSynchronized",
General Comments 0
You need to be logged in to leave comments. Login now