From 99dac17327433bc6cab9cc3c82c745b4329a7ddf Mon Sep 17 00:00:00 2001 From: ispyisail Date: Tue, 11 Aug 2026 10:27:52 +1200 Subject: [PATCH] Fix bugtracker #296: cross-reference text overlaps element label by default XRefProperties::fromSettings() read the "xrefpos" QSettings key with no default value. On a fresh install/project, the key doesn't exist yet, so settings.value(...).toString() returns an empty string. QMetaEnum::keyToValue("") returns -1 (invalid), which was then cast directly into m_xref_pos as Qt::AlignmentFlag(-1) -- garbage, despite the class's own default constructor documenting the intended default as Qt::AlignBottom. This explains the reported symptom: dynamically generated cross-reference text for master/slave-linked elements (e.g. magneto-thermal breaker, thermal relay NC) rendered at an undefined position and overlapped the element's own label, making the reference unreadable. The reporter's manual workaround -- explicitly setting alignment to "Bottom" in Project Properties > New Folio/Cross Referencing -- side-steps the bug precisely by writing a valid "AlignBottom" value into QSettings, which fromSettings() then reads back correctly on subsequent loads. Fix: supply "AlignBottom" as the fallback default for the QSettings read, matching the constructor's documented default and the reporter's functioning workaround. Verified: clean rebuild, only the intended object file recompiled and linked successfully. Confirmed via a small standalone QMetaEnum test that keyToValue("") returns -1/invalid while keyToValue("AlignBottom") returns 64 (== Qt::AlignBottom), reproducing the exact mechanism before the fix and confirming the corrected default resolves to the intended value. Not verified: a live before/after visual comparison of the rendered cross-reference text position on an actual magneto-thermal/thermal-relay diagram (would require constructing a multi-folio project with linked master/slave elements and comparing label geometry, which was out of scope for the time available). Confidence rests on the QMetaEnum mechanism being unambiguous and the fix being a one-line default-value correction with no other code path affected. --- sources/properties/xrefproperties.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/properties/xrefproperties.cpp b/sources/properties/xrefproperties.cpp index be0213c2b..bbb4e8b57 100644 --- a/sources/properties/xrefproperties.cpp +++ b/sources/properties/xrefproperties.cpp @@ -90,7 +90,7 @@ void XRefProperties::fromSettings(const QSettings &settings, m_slave_label = settings.value(prefix % "slave_label", "(%f-%l%c)").toString(); QMetaEnum var = QMetaEnum::fromType(); - m_xref_pos = Qt::AlignmentFlag(var.keyToValue((settings.value(prefix % "xrefpos").toString()).toStdString().data())); + m_xref_pos = Qt::AlignmentFlag(var.keyToValue((settings.value(prefix % "xrefpos", "AlignBottom").toString()).toStdString().data())); for (QString key : m_prefix_keys) { m_prefix.insert(key, settings.value(prefix + key % "prefix").toString());