From 27bbf5102462b9e9aeb2bbb1340a000f02b363bf Mon Sep 17 00:00:00 2001 From: ispyisail Date: Mon, 21 Sep 2026 21:26:03 +1200 Subject: [PATCH] Let a script style a conductor setConductorProperty()/conductorProperty() now also take the properties that control how a conductor looks, under the names the .qet file uses: style normal, dashed or dashdotted bicolor true/false, with color2 as the second colour dash-size positive integer condsize positive number (line width) numsize positive integer (text size) displaytext true/false Values are validated rather than stored: a boolean other than true/false, a non-positive size, an unparseable colour or a line style the file format cannot express is refused, because ConductorProperties would write the latter back as a solid line and silently lose it. The change is still applied to the whole potential. Verified: all eight set, read back, written to the file in its own form (style as "line-style: dashed;", displaytext as 0) and read back again after a reload. Four invalid values decline. Co-Authored-By: Claude Sonnet 5 --- sources/scripting/qetscriptapi.cpp | 55 ++++++++++++++++++++++++++++-- sources/scripting/qetscriptapi.h | 5 ++- 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/sources/scripting/qetscriptapi.cpp b/sources/scripting/qetscriptapi.cpp index 7b1ce35d0..1e3300b7f 100644 --- a/sources/scripting/qetscriptapi.cpp +++ b/sources/scripting/qetscriptapi.cpp @@ -359,6 +359,17 @@ QString conductorPropertyValue(const ConductorProperties &p, const QString &name if (name == QLatin1String("conductor_section")) return p.m_wire_section; if (name == QLatin1String("color")) return p.color.name(); if (name == QLatin1String("text_color")) return p.text_color.name(); + if (name == QLatin1String("color2")) return p.m_color_2.name(); + if (name == QLatin1String("bicolor")) return p.m_bicolor ? QStringLiteral("true") : QStringLiteral("false"); + if (name == QLatin1String("dash-size")) return QString::number(p.m_dash_size); + if (name == QLatin1String("condsize")) return QString::number(p.cond_size); + if (name == QLatin1String("numsize")) return QString::number(p.text_size); + if (name == QLatin1String("displaytext")) return p.m_show_text ? QStringLiteral("true") : QStringLiteral("false"); + if (name == QLatin1String("style")) { + if (p.style == Qt::DashLine) return QStringLiteral("dashed"); + if (p.style == Qt::DashDotLine) return QStringLiteral("dashdotted"); + return QStringLiteral("normal"); + } return QString(); } @@ -374,11 +385,47 @@ bool setConductorPropertyValue(ConductorProperties &p, const QString &name, cons if (name == QLatin1String("conductor_section")) { p.m_wire_section = value; return true; } // The two real colours are QColor, not free text: an unparseable name // would otherwise be stored as an invalid colour and drawn as black. - if (name == QLatin1String("color") || name == QLatin1String("text_color")) + if (name == QLatin1String("color") || name == QLatin1String("text_color") + || name == QLatin1String("color2")) { const QColor c(value); if (!c.isValid()) return false; - if (name == QLatin1String("color")) p.color = c; else p.text_color = c; + if (name == QLatin1String("color")) p.color = c; + else if (name == QLatin1String("color2")) p.m_color_2 = c; + else p.text_color = c; + return true; + } + if (name == QLatin1String("bicolor") || name == QLatin1String("displaytext")) + { + const QString v = value.toLower(); + if (v != QLatin1String("true") && v != QLatin1String("false")) return false; + (name == QLatin1String("bicolor") ? p.m_bicolor : p.m_show_text) = (v == QLatin1String("true")); + return true; + } + if (name == QLatin1String("dash-size") || name == QLatin1String("numsize")) + { + bool ok = false; + const int n = value.toInt(&ok); + if (!ok || n < 1) return false; + (name == QLatin1String("dash-size") ? p.m_dash_size : p.text_size) = n; + return true; + } + if (name == QLatin1String("condsize")) + { + bool ok = false; + const double d = value.toDouble(&ok); + if (!ok || d <= 0) return false; + p.cond_size = d; + return true; + } + if (name == QLatin1String("style")) + { + // The three the file format can express (ConductorProperties::readStyle); + // any other Qt pen style would be written back as a solid line. + if (value == QLatin1String("normal")) p.style = Qt::SolidLine; + else if (value == QLatin1String("dashed")) p.style = Qt::DashLine; + else if (value == QLatin1String("dashdotted")) p.style = Qt::DashDotLine; + else return false; return true; } return false; @@ -390,7 +437,9 @@ const QStringList &conductorPropertyNames() QStringLiteral("num"), QStringLiteral("formula"), QStringLiteral("function"), QStringLiteral("bus"), QStringLiteral("cable"), QStringLiteral("tension_protocol"), QStringLiteral("conductor_color"), QStringLiteral("conductor_section"), - QStringLiteral("color"), QStringLiteral("text_color")}; + QStringLiteral("color"), QStringLiteral("text_color"), QStringLiteral("color2"), + QStringLiteral("bicolor"), QStringLiteral("style"), QStringLiteral("dash-size"), + QStringLiteral("condsize"), QStringLiteral("numsize"), QStringLiteral("displaytext")}; return names; } diff --git a/sources/scripting/qetscriptapi.h b/sources/scripting/qetscriptapi.h index 69c622606..ba3ad4604 100644 --- a/sources/scripting/qetscriptapi.h +++ b/sources/scripting/qetscriptapi.h @@ -99,7 +99,10 @@ class QetShapeItem; where present, identical across every instance of that element -- so it does not distinguish one placed coil's A1 from another's. - @b Conductor properties and @b cross-references: set a conductor's - number, formula, colour or section, and link a master to a slave or + number, formula, colour or section (and its look: style normal/ + dashed/dashdotted, two-colour mode and second colour, dash size, + line width, text size, whether its number is shown -- all under the + names the .qet file uses for them), and link a master to a slave or one report to another. Both follow the application's own rules rather than writing the field: a conductor property is applied to every conductor of the same electrical potential, which is what the GUI and