Keep the texts of turned symbols horizontal, per project (#1335)

A project can now keep the texts drawn in its symbols, and the names of
their terminals, horizontal when a symbol is turned: Project properties >
General, "Garder horizontaux les textes des symboles pivotés". The box of
each text turns with the symbol; the text does not, and reads as it does
in the symbol itself.

It is a project setting, saved as <symbol_texts upright="true"/> and
only when on. A new project starts with it on; a project saved without
it (every existing one) reads with it off, so it looks and saves exactly
as before, and looks the same on every computer. The MCP server's new
projects start with it on too.

It builds on the mirror of #1354, which already redraws the texts of a
mirrored symbol readable: what the symbol does to its texts is now its
mirrors and, with the setting on, its turn (Element::symbolTextsTransform()).
ElementPictureFactory caches one drawing per such transform, terminal
names undo it the same way, and the DXF export places the texts alike.

The fields of a symbol (label, comment...) already keep their angle with
"Garder la rotation visuelle" and are left as they are.

Known limit: two texts stacked in a symbol end up side by side when it is
turned, and can overlap when kept horizontal; the setting can be turned
off for such a project.

Test: tst_uprightsymboltexts turns the symbols of a folio and checks the
angle of each motor's "M" in the DXF, with the setting off and on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ispyisail
2026-10-07 12:43:04 +13:00
parent a3b1468b0f
commit 592cbdbf0b
14 changed files with 428 additions and 93 deletions
+70
View File
@@ -74,6 +74,11 @@ m_project_properties_handler{this}
m_elements_collection = new XmlElementCollection(this);
init();
//A new project keeps the texts of its turned symbols horizontal; a
//project saved without the setting is read with it off, so it looks
//as it always did (readSymbolTextsXml())
m_upright_symbol_texts = true;
QSettings settings;
//Read auto break conductor default from global settings
@@ -1380,6 +1385,37 @@ void QETProject::setWireHops(WireHops::Mode mode)
}
}
/**
@brief QETProject::uprightSymbolTexts
@return true if the texts drawn in a symbol stay horizontal, and read
normally, when the symbol is turned or mirrored on a folio, instead of
turning with it. A mirrored symbol always keeps its texts readable.
*/
bool QETProject::uprightSymbolTexts() const {
return m_upright_symbol_texts;
}
/**
@brief QETProject::setUprightSymbolTexts
Set whether the texts drawn in a turned symbol stay horizontal, and
redraw every symbol of the project.
@param upright
*/
void QETProject::setUprightSymbolTexts(bool upright)
{
if (upright == m_upright_symbol_texts) {
return;
}
m_upright_symbol_texts = upright;
for (Diagram *diagram : diagrams()) {
for (QGraphicsItem *item : diagram->items()) {
if (Element *element = qgraphicsitem_cast<Element *>(item)) {
element->updateSymbolPictures();
}
}
}
}
/**
@brief QETProject::wiringRules
@return how many wires a terminal of this project may take
@@ -1521,6 +1557,7 @@ QDomDocument QETProject::toXml()
// local, non-transmitted usage tracking (time spent on this project)
writeUsageXml(project_root);
writeWireHopsXml(project_root);
writeSymbolTextsXml(project_root);
writeWiringRulesXml(project_root);
// Properties for news diagrams
@@ -2032,6 +2069,7 @@ void QETProject::readProjectXml(QDomDocument &xml_project)
//Load the local, non-transmitted usage tracking
readUsageXml(xml_project);
readWireHopsXml(xml_project);
readSymbolTextsXml(xml_project);
readWiringRulesXml(xml_project);
//Load the default properties for the new diagrams
@@ -2229,6 +2267,21 @@ void QETProject::readWireHopsXml(QDomDocument &xml_project)
: WireHops::fromString(crossings.attribute(QStringLiteral("hop")));
}
/**
@brief QETProject::readSymbolTextsXml
Read the <symbol_texts> element of the project, if any. A project
without it was saved before the setting existed, or with it off, and
keeps the texts of its turned symbols turned.
@param xml_project : the xml description of the project
*/
void QETProject::readSymbolTextsXml(QDomDocument &xml_project)
{
const QDomElement texts = xml_project.documentElement()
.firstChildElement(QStringLiteral("symbol_texts"));
m_upright_symbol_texts = !texts.isNull()
&& texts.attribute(QStringLiteral("upright")) == QLatin1String("true");
}
/**
@brief QETProject::readWiringRulesXml
Read the <wiring_rules> element of the project, if any.
@@ -2420,6 +2473,23 @@ void QETProject::writeWireHopsXml(QDomElement &xml_element)
xml_element.appendChild(crossings);
}
/**
@brief QETProject::writeSymbolTextsXml
Export whether the texts of turned symbols stay horizontal, as a
<symbol_texts> child of \a xml_element. Written only when on, so a
project with it off saves exactly as before.
*/
void QETProject::writeSymbolTextsXml(QDomElement &xml_element)
{
if (!m_upright_symbol_texts) {
return;
}
QDomElement texts = xml_element.ownerDocument()
.createElement(QStringLiteral("symbol_texts"));
texts.setAttribute(QStringLiteral("upright"), QStringLiteral("true"));
xml_element.appendChild(texts);
}
/**
@brief QETProject::writeWiringRulesXml
Export the project's wiring rules as a <wiring_rules> child of