From 5b0785fcceb6dfdee04f706ab6576271caa5c523 Mon Sep 17 00:00:00 2001 From: ispyisail Date: Wed, 23 Sep 2026 16:47:07 +1200 Subject: [PATCH] Make auto_num_locked/potential_isolating case-insensitive Reviving the still-relevant part of #785, closed 2026-09-10 purely to clear a review backlog, not on merit. Investigated fresh against current master -- one of the original PR's three targets turned out to already be fixed independently: element_nomenclature_view's SQL predicate for exclude_from_bom already does "COALESCE(LOWER(TRIM(ei.exclude_from_bom)), '') NOT IN ('true', '1', 'yes', 'on')" (projectDataBase::createElementNomenclatureView()). auto_num_locked and potential_isolating had no equivalent: five call sites across terminal.cpp, terminalnumberingdialog.cpp and elementinfowidget.cpp compared the raw stored string against the literal "true" with QString::operator==, silently treating "True", "TRUE", a trailing space, or any value written by something other than this app's own checkbox as off -- with no error and no visible difference from the checkbox being genuinely unticked. Added QET::infoFlagIsTrue(), matching the same accepted spellings ("true"/"1"/"yes"/"on", case-insensitive, trimmed) the SQL predicate already uses, and switched all five call sites to it. Verified the exact comparison logic in isolation, outside any QET build: 15 cases including "True", "TRUE", padded whitespace, "1", "yes", "on", and their false counterparts -- all correctly discriminated. Qt 6.10.2, ctest 13/13. Co-Authored-By: Claude Sonnet 5 --- sources/qet.cpp | 17 +++++++++++++++++ sources/qet.h | 16 ++++++++++++++++ sources/qetgraphicsitem/terminal.cpp | 3 ++- sources/ui/elementinfowidget.cpp | 5 +++-- sources/ui/terminalnumberingdialog.cpp | 5 +++-- 5 files changed, 41 insertions(+), 5 deletions(-) diff --git a/sources/qet.cpp b/sources/qet.cpp index 060bce7b2..9263615f0 100644 --- a/sources/qet.cpp +++ b/sources/qet.cpp @@ -248,6 +248,23 @@ bool QET::attributeIsAReal( return(true); } +/** + @brief QET::infoFlagIsTrue + @see the header comment for why this exists rather than a bare + == "true" comparison. + @param value the raw elementInformations string to test + @return true if @p value, trimmed and case-folded, is one of the + truthy spellings this codebase already accepts elsewhere +*/ +bool QET::infoFlagIsTrue(const QString &value) +{ + const QString v = value.trimmed().toLower(); + return v == QLatin1String("true") + || v == QLatin1String("1") + || v == QLatin1String("yes") + || v == QLatin1String("on"); +} + /** @brief QET::ElementsAndConductorsSentence Permet de composer rapidement la proposition "x elements et y conducteurs" diff --git a/sources/qet.h b/sources/qet.h index da544ac13..cb5a8a0a8 100644 --- a/sources/qet.h +++ b/sources/qet.h @@ -161,6 +161,22 @@ namespace QET { bool orthogonalProjection(const QPointF &, const QLineF &, QPointF * = nullptr); bool attributeIsAnInteger(const QDomElement &, const QString& , int * = nullptr); bool attributeIsAReal(const QDomElement &, const QString& , qreal * = nullptr); + /** + Whether an elementInformations flag (auto_num_locked, + potential_isolating, exclude_from_bom, ...) counts as "on". + Case-insensitive and tolerant of surrounding whitespace, and + accepts the same set of truthy spellings ("true", "1", "yes", + "on") that element_nomenclature_view's SQL predicate for + exclude_from_bom already does -- see + projectDataBase::createElementNomenclatureView(). These flags + are only ever written by this app's own checkboxes as literal + "true"/"false" today, but a bare == "true" comparison silently + treats anything else -- "True", "TRUE", a trailing space from + a hand-edited file, a value some other tool wrote -- as off, + with no error and no visible difference from the checkbox + being genuinely unticked (discussion #785). + */ + bool infoFlagIsTrue(const QString &value); QString ElementsAndConductorsSentence(int elements=0, int conductors=0, int indi_texts=0, diff --git a/sources/qetgraphicsitem/terminal.cpp b/sources/qetgraphicsitem/terminal.cpp index f559e326d..a1c9af780 100644 --- a/sources/qetgraphicsitem/terminal.cpp +++ b/sources/qetgraphicsitem/terminal.cpp @@ -16,6 +16,7 @@ along with QElectroTech. If not, see . */ #include "../qetgraphicsitem/terminal.h" +#include "../qet.h" #include "../qetproject.h" #include "../conductorautonumerotation.h" #include "../diagram.h" @@ -986,7 +987,7 @@ QList relatedPotentialTerminal ( else if (terminal -> parentElement() -> linkType() & Element::Terminale) { // English: Check if the user activated the potential isolation checkbox for this terminal - if (terminal->parentElement()->elementInformations().value(QStringLiteral("potential_isolating")).toString() == QLatin1String("true")) { + if (QET::infoFlagIsTrue(terminal->parentElement()->elementInformations().value(QStringLiteral("potential_isolating")).toString())) { // English: Potential is isolated. Return an empty list so it does not propagate to the other side. return QList(); } diff --git a/sources/ui/elementinfowidget.cpp b/sources/ui/elementinfowidget.cpp index 0107c9664..f67f2bd85 100644 --- a/sources/ui/elementinfowidget.cpp +++ b/sources/ui/elementinfowidget.cpp @@ -16,6 +16,7 @@ along with QElectroTech. If not, see . */ #include "elementinfowidget.h" +#include "../qet.h" #include #include #include "../diagram.h" @@ -366,12 +367,12 @@ void ElementInfoWidget::updateUi() // Load the lock status for auto numbering if (m_element->elementData().m_type == ElementData::Terminal) { QString lock_value = element_info.value(QStringLiteral("auto_num_locked")).toString(); - ui->m_auto_num_locked_cb->setChecked(lock_value == QLatin1String("true")); + ui->m_auto_num_locked_cb->setChecked(QET::infoFlagIsTrue(lock_value)); // English: Load the potential isolating status from the element information mapping if (m_potential_isolating_cb) { QString isolating_value = element_info.value(QStringLiteral("potential_isolating")).toString(); - m_potential_isolating_cb->setChecked(isolating_value == QLatin1String("true")); + m_potential_isolating_cb->setChecked(QET::infoFlagIsTrue(isolating_value)); } } // English: Load the BOM exclusion status from the element information mapping diff --git a/sources/ui/terminalnumberingdialog.cpp b/sources/ui/terminalnumberingdialog.cpp index 38c8a655d..85f299214 100644 --- a/sources/ui/terminalnumberingdialog.cpp +++ b/sources/ui/terminalnumberingdialog.cpp @@ -1,5 +1,6 @@ #include "terminalnumberingdialog.h" #include "ui_terminalnumberingdialog.h" +#include "../qet.h" #include "../qetproject.h" #include "../diagram.h" #include "../qetgraphicsitem/element.h" @@ -34,7 +35,7 @@ TerminalNumberingDialog::TerminalNumberingDialog(QWidget *parent, QETProject *pr if (elmt->elementData().m_type == ElementData::Terminal) { // Ignore locked terminals DiagramContext info = elmt->elementInformations(); - if (info.value(QStringLiteral("auto_num_locked")).toString() == QLatin1String("true")) { + if (QET::infoFlagIsTrue(info.value(QStringLiteral("auto_num_locked")).toString())) { continue; } @@ -158,7 +159,7 @@ QUndoCommand* TerminalNumberingDialog::getUndoCommand(QETProject *project) const DiagramContext info = elmt->elementInformations(); // Ignore locked terminals (if the user checked a 'lock' property) - if (info.value(QStringLiteral("auto_num_locked")).toString() == QLatin1String("true")) { + if (QET::infoFlagIsTrue(info.value(QStringLiteral("auto_num_locked")).toString())) { continue; }