diff --git a/sources/qet.cpp b/sources/qet.cpp index 2260d5d3a..8f9b79908 100644 --- a/sources/qet.cpp +++ b/sources/qet.cpp @@ -255,6 +255,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; }