From 069cf1e7b59769ba4e77afef73aeb98db9035472 Mon Sep 17 00:00:00 2001 From: Beat Hangartner Date: Tue, 6 Oct 2026 09:50:08 +0200 Subject: [PATCH] Tidy the free text width - setTextWidth() returns without a signal when the width does not change, which is also the case on every load of a text without one. - Say why IndependentTextItem::textWidth()/setTextWidth() hide the non-virtual QGraphicsTextItem functions, and what that means for code holding a base pointer. - The fixture no longer carries a /tmp path from the machine it was made on. Co-Authored-By: Claude Opus 5.5 --- sources/qetgraphicsitem/independenttextitem.cpp | 2 ++ sources/qetgraphicsitem/independenttextitem.h | 5 +++++ tests/qttest/fixtures/free_text_width.qet | 3 +-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/sources/qetgraphicsitem/independenttextitem.cpp b/sources/qetgraphicsitem/independenttextitem.cpp index 208906463..8e5d03ef4 100644 --- a/sources/qetgraphicsitem/independenttextitem.cpp +++ b/sources/qetgraphicsitem/independenttextitem.cpp @@ -130,6 +130,8 @@ void IndependentTextItem::setTextWidth(qreal width) { if (!qIsFinite(width) || width <= 0) width = -1; + if (qFuzzyCompare(width, m_text_width)) + return; qreal document_width = width; //The automatic width of a text with centred or right-aligned diff --git a/sources/qetgraphicsitem/independenttextitem.h b/sources/qetgraphicsitem/independenttextitem.h index 3ff526c5d..571c9eeea 100644 --- a/sources/qetgraphicsitem/independenttextitem.h +++ b/sources/qetgraphicsitem/independenttextitem.h @@ -53,6 +53,11 @@ class IndependentTextItem : public DiagramTextItem void setUuid(const QUuid &uuid) {m_uuid = uuid; emit uuidChanged();} void newUuid() {setUuid(QUuid::createUuid());} //create new uuid for this item + //Hide QGraphicsTextItem::textWidth()/setTextWidth(), which are not + //virtual: called through a QGraphicsTextItem or DiagramTextItem + //pointer they would change the document only, and the width would + //be neither saved nor shown in the properties. Use these, or the + //"textWidth" property. qreal textWidth() const {return m_text_width;} void setTextWidth(qreal width); diff --git a/tests/qttest/fixtures/free_text_width.qet b/tests/qttest/fixtures/free_text_width.qet index f2f9f019b..cd6eb53ee 100644 --- a/tests/qttest/fixtures/free_text_width.qet +++ b/tests/qttest/fixtures/free_text_width.qet @@ -3,8 +3,7 @@ 10/2/26 02-10-2026 2026-10-02 - skeleton - /tmp/qet-mcp-new-k41dmnyo/skeleton.qet + free_text_width 18:39