From 7933e89dc04f56fffcf99bd63ae1c634d300ebf1 Mon Sep 17 00:00:00 2001 From: Beat Hangartner Date: Wed, 7 Oct 2026 21:04:22 +0200 Subject: [PATCH] Read the default conductor width from the settings as a decimal ConductorProperties::toSettings() writes the conductor width with QString::number(cond_size), e.g. "1.4", and fromSettings() read it back with toInt(), which is 0 for any value that is not a whole number. A default width of 1.4 set in the configuration became 0 on the next start, so every new conductor was drawn with a pen of width 0. Read it with toDouble(), and fall back to 1 when the stored value is not a positive finite number (a hand-edited or truncated settings file), as the other fallbacks in fromSettings() do. No file-format change: this is the settings file only; the project file's condsize attribute was already read with toDouble(). Tests: tst_conductorsizesetting compiles conductorproperties.cpp alone and round-trips 2, 1.4, 0.4, 61.3 and 61.7 through toSettings() and fromSettings() in a QSettings scope of its own; text, 0, -1, nan, inf and a missing value give 1. Nine of the cases fail on master. Co-Authored-By: Claude Fable 5.1 Signed-off-by: Beat Hangartner --- sources/conductorproperties.cpp | 5 +- tests/qttest/CMakeLists.txt | 13 +++ tests/qttest/tst_conductorsizesetting.cpp | 113 ++++++++++++++++++++++ 3 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 tests/qttest/tst_conductorsizesetting.cpp diff --git a/sources/conductorproperties.cpp b/sources/conductorproperties.cpp index 12a55539c..6cf2f40fd 100644 --- a/sources/conductorproperties.cpp +++ b/sources/conductorproperties.cpp @@ -436,7 +436,10 @@ void ConductorProperties::fromSettings(QSettings &settings, const QString &prefi m_wire_color = settings.value(prefix + "conductor_color", "").toString(); m_wire_section = settings.value(prefix + "conductor_section", "").toString(); text_size = settings.value(prefix + "textsize", "7").toInt(); - cond_size = settings.value(prefix + "size", "1").toInt(); + // Saved with QString::number(cond_size): a decimal such as 1.4, + // which toInt() would read as 0. + cond_size = settings.value(prefix + "size", "1").toDouble(); + if (!qIsFinite(cond_size) || cond_size <= 0) cond_size = 1; m_show_text = settings.value(prefix + "displaytext", true).toBool(); m_one_text_per_folio = settings.value(prefix + "onetextperfolio", false).toBool(); verti_rotate_text = settings.value((prefix + "vertirotatetext"), "270").toDouble(); diff --git a/tests/qttest/CMakeLists.txt b/tests/qttest/CMakeLists.txt index bd8a82c01..42814d580 100644 --- a/tests/qttest/CMakeLists.txt +++ b/tests/qttest/CMakeLists.txt @@ -935,6 +935,19 @@ add_test(NAME tst_conductorapplychanges COMMAND tst_conductorapplychanges) target_include_directories(tst_conductorapplychanges PRIVATE ${QET_DIR}/sources) target_link_libraries(tst_conductorapplychanges PRIVATE Qt::Test Qt::Widgets Qt::Xml pugixml::pugixml) +# ConductorProperties::fromSettings() -- the default conductor width is a +# decimal and comes back as saved (1.4 used to be read as 0). +add_executable( + tst_conductorsizesetting + tst_conductorsizesetting.cpp + ${QET_DIR}/sources/conductorproperties.cpp + ${QET_DIR}/sources/qet.cpp + ${QET_DIR}/sources/qeticons.cpp + ${QET_DIR}/sources/shortcutmanager.cpp) +add_test(NAME tst_conductorsizesetting COMMAND tst_conductorsizesetting) +target_include_directories(tst_conductorsizesetting PRIVATE ${QET_DIR}/sources) +target_link_libraries(tst_conductorsizesetting PRIVATE Qt::Test Qt::Widgets Qt::Xml pugixml::pugixml) + # ConductorMultiEdit -- editing several wires at once in the Selection # properties panel: order, which wires an edit reaches, one undo step for # all of them, and fields shown blank because the wires disagree. diff --git a/tests/qttest/tst_conductorsizesetting.cpp b/tests/qttest/tst_conductorsizesetting.cpp new file mode 100644 index 000000000..7a8afbeac --- /dev/null +++ b/tests/qttest/tst_conductorsizesetting.cpp @@ -0,0 +1,113 @@ +/* + Copyright 2006-2026 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#include "conductorproperties.h" +#include "qetapp.h" + +#include +#include + +// qet.cpp, compiled in for ConductorProperties, refers to this static. +QString QETApp::m_interface_language; + +/** + ConductorProperties::toSettings()/fromSettings() keep the conductor + width (cond_size) as it was saved. The width is a decimal, written with + QString::number(); reading it with toInt() gave 0 for every value that + was not a whole number, so a default width of 1.4 came back as 0 after + a restart. + + This test owns its own QSettings scope (organization + application + name), so it cannot read or write the configuration of whoever runs it. +*/ +class tst_conductorsizesetting : public QObject +{ + Q_OBJECT + +private slots: + void initTestCase() + { + QCoreApplication::setOrganizationName( + QStringLiteral("QElectroTech-tst_conductorsizesetting")); + QCoreApplication::setApplicationName(QStringLiteral("tst_conductorsizesetting")); + QSettings settings; + settings.clear(); + } + + void init() + { + QSettings settings; + settings.clear(); + settings.sync(); + } + + void widthSurvivesARoundTrip_data() + { + QTest::addColumn("width"); + QTest::newRow("whole number") << 2.0; + QTest::newRow("decimal") << 1.4; + QTest::newRow("minimum") << 0.4; + QTest::newRow("rounds down") << 61.3; + QTest::newRow("rounds up") << 61.7; + } + + void widthSurvivesARoundTrip() + { + QFETCH(qreal, width); + QSettings settings; + ConductorProperties saved; + saved.cond_size = width; + saved.toSettings(settings, QStringLiteral("test/")); + + ConductorProperties loaded; + loaded.fromSettings(settings, QStringLiteral("test/")); + QCOMPARE(loaded.cond_size, width); + } + + // A hand-edited or truncated settings file must not give a width of 0. + void unusableValueFallsBackToOne_data() + { + QTest::addColumn("value"); + QTest::newRow("text") << QStringLiteral("wide"); + QTest::newRow("zero") << QStringLiteral("0"); + QTest::newRow("negative") << QStringLiteral("-1"); + QTest::newRow("nan") << QStringLiteral("nan"); + QTest::newRow("inf") << QStringLiteral("inf"); + } + + void unusableValueFallsBackToOne() + { + QFETCH(QString, value); + QSettings settings; + settings.setValue(QStringLiteral("test/size"), value); + + ConductorProperties loaded; + loaded.fromSettings(settings, QStringLiteral("test/")); + QCOMPARE(loaded.cond_size, 1.0); + } + + void missingValueIsOne() + { + QSettings settings; + ConductorProperties loaded; + loaded.fromSettings(settings, QStringLiteral("test/")); + QCOMPARE(loaded.cond_size, 1.0); + } +}; + +QTEST_GUILESS_MAIN(tst_conductorsizesetting) +#include "tst_conductorsizesetting.moc"