Stop a folio report's text jumping when the report is not linked

A report's texts that show a wire's properties (function, section...)
are only filled once the wires are read, and those are read after the
symbols: the fill comes from the 100 ms timer of
DynamicElementTextItem::conductorWasAdded(), by which time the project
state is Ok again and the alignment is live.

For a report whose partner is linked, that fill had already happened
inside the loading state (Element::initLink() -> linkedElementChanged()
-> reportChanged()), so the alignment was blocked and the text stayed
where the file put it. buildFolios() relies on that and says so. An
unlinked report, and one whose partner sits on a folio not built yet,
got nothing during loading: the first fill was the timer's one. It took
the rect of the still empty text for anchor and shifted the item by the
whole width of the text, on every open. Only the right, centred or
bottom aligned texts showed it -- the others have a null offset.

Fill those texts inside the loading state instead. Element::
updateConductorTexts(), already run when a wire is connected to a
terminal, now covers a report as well as a wire label, and
Diagram::refreshContents() runs it for every symbol while the project
is still parsing, right after initLink() has resolved the links. The
timer's fill that comes 100 ms later then finds the text already set,
and DynamicElementTextItem::setPlainText() returns on it unchanged, so
the alignment is never handed an empty rect to anchor. A wire that
appears, or a property that changes, while the project is open is
aligned as it was.

A report's "label" text is left to updateReportText(): it is the linked
folio's, not the symbol's own information.
This commit is contained in:
Kellermorph
2026-10-15 10:28:22 +02:00
parent 6af9c097d8
commit 68914ee31b
2 changed files with 43 additions and 12 deletions
+21
View File
@@ -2389,6 +2389,8 @@ void Diagram::folioSequentialsFromXml(const QDomElement &root,
- linking the elements waiting to be linked
- Refresh the connection of the dynamic element text item
(use for text with source of text label)
- Fill the texts of a report (or a wire label) that show the
properties of the wire they are on.
*/
void Diagram::refreshContents()
{
@@ -2398,6 +2400,25 @@ void Diagram::refreshContents()
elmt->initLink(project());
for (auto &deti : elmt->dynamicTextItems())
deti->refreshLabelConnection();
/*
* A report's texts showing a wire's properties are filled when
* the wires are added, which is after the symbols are read
* (Diagram::buildContents()), and once more 100 ms later by
* DynamicElementTextItem::conductorWasAdded(). Both run after
* the project left the parsing state, so the alignment is live
* and the fill would take the rect of the still empty text for
* anchor -- a right aligned one then shifts by the whole width
* of its text, on every open.
*
* A linked report gets that fill here already, through
* initLink() -> linkedElementChanged() -> reportChanged(), while
* the project is still parsing; buildFolios() relies on it. An
* unlinked one, and one whose partner is on a folio not built
* yet, got nothing: fill them here too, in that same state. The
* later fill then finds the text already set and changes
* nothing.
*/
elmt->updateConductorTexts();
}
for (auto &conductor : dc_.conductors()) {
+22 -12
View File
@@ -2502,22 +2502,32 @@ bool Element::definitionGeometryMatches(const QDomElement &definition) const
/**
* @brief Element::updateConductorTexts
*Slot that is triggered when a cable is *
*connected to or disconnected from a terminal on this component.
*/
/**
* @brief Element::updateConductorTexts
* Refresh the texts of this symbol that show the properties of the wire
* it is on: a wire label's own, and a folio report's (its function,
* section...). Slot triggered when a wire is connected to or
* disconnected from a terminal of this symbol.
*/
void Element::updateConductorTexts()
{
if (m_link_type != Element::ConductorDefinition) {
return;
if (m_link_type == Element::ConductorDefinition)
{
for (DynamicElementTextItem *deti : m_dynamic_text_list) {
if (deti) {
deti->setPotentialConductor();
deti->updateLabel();
}
}
}
for (DynamicElementTextItem *deti : m_dynamic_text_list) {
if (deti) {
deti->setPotentialConductor();
deti->updateLabel();
else if (m_link_type & Element::AllReport)
{
//setPotentialConductor() ends on conductorPropertiesChanged(),
//which fills those texts. No updateLabel() here: a report's
//"label" text is not its own information but the linked
//folio's, refreshed by updateReportText().
for (DynamicElementTextItem *deti : m_dynamic_text_list) {
if (deti) {
deti->setPotentialConductor();
}
}
}
}