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 <noreply@anthropic.com>
This commit is contained in:
ispyisail
2026-09-23 16:47:07 +12:00
parent 6d8459d647
commit 5b0785fcce
5 changed files with 41 additions and 5 deletions
+17
View File
@@ -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"
+16
View File
@@ -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,
+2 -1
View File
@@ -16,6 +16,7 @@
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#include "../qetgraphicsitem/terminal.h"
#include "../qet.h"
#include "../qetproject.h"
#include "../conductorautonumerotation.h"
#include "../diagram.h"
@@ -986,7 +987,7 @@ QList<Terminal *> 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<Terminal *>();
}
+3 -2
View File
@@ -16,6 +16,7 @@
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#include "elementinfowidget.h"
#include "../qet.h"
#include <QCheckBox>
#include <QPushButton>
#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
+3 -2
View File
@@ -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;
}