From 7f49550deec6cd501987a9a7a2c278d69dbb3967 Mon Sep 17 00:00:00 2001 From: tetektoza Date: Sat, 19 Apr 2025 15:10:13 +0200 Subject: [PATCH] Sketcher: Auto-scroll to selected geometry elements (#20866) * Sketcher: Auto-scroll to selected geometry elements Currently if user selects a geometry element on sketch, listview is not scrolling to it. So, this patch moves the previously added logic to constraints into a separate helper function call and calls it for Geometry Elements as well, resulting in scrolling in both lists - constraints and elements. * Sketcher: Add QListWidget to enable QListWidget symbols for CI --- src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp | 5 +---- src/Mod/Sketcher/Gui/TaskSketcherElements.cpp | 1 + src/Mod/Sketcher/Gui/Utils.h | 9 +++++++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp b/src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp index 49ac068091..ac63cf052d 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp +++ b/src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp @@ -1373,10 +1373,7 @@ void TaskSketcherConstraints::onSelectionChanged(const Gui::SelectionChanges& ms auto tmpBlock = ui->listWidgetConstraints->blockSignals(true); item->setSelected(select); ui->listWidgetConstraints->blockSignals(tmpBlock); - if (select && ui->listWidgetConstraints->model()) { // scrollTo only on select, not de-select - QModelIndex index = ui->listWidgetConstraints->model()->index(i, 0); - ui->listWidgetConstraints->scrollTo(index, QAbstractItemView::PositionAtCenter); - } + SketcherGui::scrollTo(ui->listWidgetConstraints, i, select); break; } } diff --git a/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp b/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp index 93771c5440..95be1ebbea 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp +++ b/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp @@ -1435,6 +1435,7 @@ void TaskSketcherElements::onSelectionChanged(const Gui::SelectionChanges& msg) if (item->ElementNbr == ElementId) { item->isLineSelected = select; modified_item = item; + SketcherGui::scrollTo(ui->listWidgetElements, i, select); break; } } diff --git a/src/Mod/Sketcher/Gui/Utils.h b/src/Mod/Sketcher/Gui/Utils.h index e5b38ecaa3..3bbfbe0618 100644 --- a/src/Mod/Sketcher/Gui/Utils.h +++ b/src/Mod/Sketcher/Gui/Utils.h @@ -27,6 +27,7 @@ #include #include #include +#include #include "AutoConstraint.h" #include "ViewProviderSketchGeometryExtension.h" @@ -210,6 +211,14 @@ bool areCollinear(const Base::Vector2d& p1, const Base::Vector2d& p2, const Base int indexOfGeoId(const std::vector& vec, int elem); +inline void scrollTo(QListWidget* list, int i, bool select) +{ + if (select && list->model()) { // scrollTo only on select, not de-select + QModelIndex index = list->model()->index(i, 0); + list->scrollTo(index, QAbstractItemView::PositionAtCenter); + } +} + } // namespace SketcherGui /// converts a 2D vector into a 3D vector in the XY plane