mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-09-28 21:34:12 +02:00
29d16c3337
Two bugs reported by @arummler on #591 after merge: "It works but to select the text field one has to right click on it...I think there are competing handlers or something." "the drag elements should be on the border of the box. In the moment they appear directly left and right from the text." Both reproduced headlessly (scripts/qet-gui-dialog.sh) against a fresh build of current master and root-caused before touching anything. Selection: DynamicElementTextItem::mousePressEvent() forwards a plain click (no Shift) straight to parentElement()->mousePressEvent(), by design and pre-existing -- it's what lets dragging a symbol by its own label move the whole symbol rather than just the label. That's correct and untouched here. But it means a plain click leaves the *parent* selected, not the text, and #591's handles were wired only to the text's own ItemSelectedHasChanged -- so they were only reachable via Shift+click or a right-click's context menu (which happens to select the item under the cursor for its own context menu, unrelated to the Shift path), neither of which anyone reaches for to resize a text. Confirmed with screenshots at each step, including that Shift+click already reached the existing (if misplaced) handles correctly. Fix: DynamicElementTextItem::refreshResizeHandlesVisibility() shows the handles when either the text itself or its parent element is selected, and Element gets an itemChange() override (it had none) that calls it on each of its own texts when the element's own selection changes. Both sides driven from itemChange(), Qt's own hook for exactly this and the same one already used for the text's own selection. First attempt drove this from paint() instead, since the PR's own updateResizeHandlesPos() already runs there. That crashed reproducibly (SIGABRT) on deselecting a text: paint() runs while QGraphicsScene iterates its item list to draw it, and addResizeHandles()/ removeResizeHandles() mutate that list via QGraphicsScene::addItem()/ removeItem(), which cannot safely happen mid-iteration. Caught it with the same headless repro before it went anywhere near a PR, moved the logic to itemChange(), and re-ran the full sequence -- select, resize, undo, deselect, twice through -- clean. Position: updateResizeHandlesPos() placed the handles on frameRect(), which is a box sized to the text's natural (idealWidth()) content and then re-centred inside boundingRect() -- it does not grow with textWidth(). Once a text has been widened, frameRect() stays tight around the glyphs while boundingRect() -- the box QGraphicsView actually outlines as the selection, and the box a user drags relative to -- grows around it, leaving the handles stranded well inside the visible selection border. Fix: position them on boundingRect() instead, which does track textWidth(); confirmed by widening a text and checking the handle lands exactly on the new edge rather than partway across it. Verified headlessly end to end on the original report's own element ("motor off" on grafcet.qet, folio 1): a single plain left-click (no Shift, no right-click) now shows both handles at the true box border; dragging resizes correctly and the handle tracks the growing edge; Ctrl+Z restores the -1 auto-width sentinel and the handles stay at the reverted position; clicking away removes them; repeated twice with no crash. Qt 6.10.2, ctest 12/12, no new warnings in either changed file. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>