From 7ec586ca736d070fb904252a043b4b85bc761cc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Wed, 19 Jul 2023 10:47:17 +0200 Subject: [PATCH] Temporary workaround the selection item emitting way too many signals --- .../Plugins/Display/Heat_method_plugin.cpp | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Plugins/Display/Heat_method_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Display/Heat_method_plugin.cpp index 7ba691b6cf14..fc6d564379b2 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Display/Heat_method_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Display/Heat_method_plugin.cpp @@ -605,18 +605,25 @@ private Q_SLOTS: sm_item->setRenderingMode(GouraudPlusEdges); sm_item->redraw(); - scene->addItem(heat_item); - scene->setSelectedItem(scene->item_id(sm_item)); + auto heat_item_id = scene->addItem(heat_item); + scene->setSelectedItem(heat_item_id); // any change of sm_item destroys everything - connect(sm_item, &Scene_surface_mesh_item::itemChanged, - this, [this, sm_item, heat_item]() - { - sm_item->resetColors(); - removePluginProperties(sm_item); - scene->erase(scene->item_id(heat_item)); - onItemIndicesSelected(scene->selectionIndices()); - }); + + // @todo do not emit itemChanged when the colors are reset + // @todo with qt6, single connection can be performed with `static_cast(Qt::SingleShotConnection)` + // see https://www.kdab.com/single-shot-connections/ + auto connection = std::make_shared(); + *connection = connect(sm_item, &Scene_surface_mesh_item::itemChanged, + this, [this, sm_item, heat_item, connection]() + { + QObject::disconnect(*connection); + + sm_item->resetColors(); + removePluginProperties(sm_item); + scene->erase(scene->item_id(heat_item)); + onItemIndicesSelected(scene->selectionIndices()); + }); connect(sm_item, &Scene_surface_mesh_item::aboutToBeDestroyed, this, [this, heat_item]() @@ -765,7 +772,8 @@ private Q_SLOTS: Scene_polyhedron_selection_item* source_vertices = new Scene_polyhedron_selection_item(sm_item, mw); source_vertices->setName(tr("%1 (source vertices)").arg(sm_item->name())); - scene->addItem(source_vertices); + auto source_vertices_id = scene->addItem(source_vertices); + scene->setSelectedItem(source_vertices_id); link_mesh_and_selection(sm_item, source_vertices);