Merge pull request #1382 from bhangart/fix/folio-freeze-flags-reload

Read a folio's freeze flags back as the words they are saved as
This commit is contained in:
ispyisail
2026-10-08 13:45:48 +13:00
committed by GitHub
4 changed files with 157 additions and 2 deletions
+6 -2
View File
@@ -1614,10 +1614,14 @@ bool Diagram::fromXml(QDomElement &document,
m_conductors_autonum_name = root.attribute(QStringLiteral("conductorAutonum"));
// Load Freeze New Element
m_freeze_new_elements = root.attribute(QStringLiteral("freezeNewElement")).toInt();
// Written as "true"/"false" by toXml(), so compare the text:
// toInt() of either word is 0.
m_freeze_new_elements = root.attribute(QStringLiteral("freezeNewElement"))
== QLatin1String("true");
// Load Freeze New Conductor
m_freeze_new_conductors_ = root.attribute(QStringLiteral("freezeNewConductor")).toInt();
m_freeze_new_conductors_ = root.attribute(QStringLiteral("freezeNewConductor"))
== QLatin1String("true");
//Load Element Folio Sequential
folioSequentialsFromXml(root,
+12
View File
@@ -908,6 +908,18 @@ target_compile_definitions(tst_resaveunchanged PRIVATE
"QET_TEST_BINARY_PATH=\"$<TARGET_FILE:qelectrotech>\""
"QET_EXAMPLES_DIR=\"${QET_DIR}/examples\"")
# A folio's "freeze new elements/conductors" flags, saved as the words
# "true"/"false", are read back as words: the real binary's --resave on
# fixtures/folio_freeze_flags.qet, one folio per combination.
add_executable(
tst_foliofreezeflags
tst_foliofreezeflags.cpp)
add_test(NAME tst_foliofreezeflags COMMAND tst_foliofreezeflags)
add_dependencies(tst_foliofreezeflags qelectrotech)
target_link_libraries(tst_foliofreezeflags PRIVATE Qt::Test Qt::Xml)
target_compile_definitions(tst_foliofreezeflags PRIVATE
"QET_TEST_BINARY_PATH=\"$<TARGET_FILE:qelectrotech>\"")
# Replacing a symbol's definition in a project keeps its terminal uuids, so
# the wires saved against them still load: TerminalUuids::keep() on its own,
# then the real binary's --info on an example whose symbols were replaced.
@@ -0,0 +1,36 @@
<project title="Folio freeze flags" uuid="{7c1d2e3f-4a5b-4c6d-8e7f-9a0b1c2d3e00}" version="0.200.1">
<properties>
<property name="savedfilename" show="1">folio_freeze_flags</property>
</properties>
<usage enabled="true" time_spent="0"/>
<newdiagrams>
<border cols="17" colsize="60" displaycols="true" displayrows="true" rows="8" rowsize="80"/>
<inset author="" auto_page_num="" date="null" displayAt="bottom" filename="" folio="" indexrev="" locmach="" plant="" title="" version=""/>
<conductors bicolor="false" bus="" cable="" color2="#000000" condsize="1" conductor_color="" conductor_section="" dash-size="1" displaytext="1" formula="" function="" horizontal-alignment="AlignBottom" horizrotatetext="0" num="_" numsize="7" onetextperfolio="0" tension_protocol="" text_color="#000000" type="multi" vertical-alignment="AlignRight" vertirotatetext="270"/>
<report label="%f-%l%c"/>
<xrefs/>
<conductors_autonums auto_break_conductors="false" current_autonum="" freeze_new_conductors="false"/>
<folio_autonums/>
<element_autonums current_autonum="" freeze_new_elements="false"/>
<guides/>
</newdiagrams>
<diagram author="" auto_page_num="" cols="17" colsize="60" date="null" displayAt="bottom" displaycols="true" displayrows="true" filename="" folio="" freezeNewConductor="true" freezeNewElement="true" height="660" indexrev="" locmach="" order="1" plant="" rows="8" rowsize="80" title="both frozen" uuid="{7c1d2e3f-4a5b-4c6d-8e7f-9a0b1c2d3e01}" version="0.200.1-dev">
<defaultconductor bicolor="false" bus="" cable="" color2="#000000" condsize="1" conductor_color="" conductor_section="" dash-size="1" displaytext="1" formula="" function="" horizontal-alignment="AlignBottom" horizrotatetext="0" num="_" numsize="7" onetextperfolio="0" tension_protocol="" text_color="#000000" type="multi" vertical-alignment="AlignRight" vertirotatetext="270"/>
</diagram>
<diagram author="" auto_page_num="" cols="17" colsize="60" date="null" displayAt="bottom" displaycols="true" displayrows="true" filename="" folio="" freezeNewConductor="false" freezeNewElement="true" height="660" indexrev="" locmach="" order="2" plant="" rows="8" rowsize="80" title="elements frozen" uuid="{7c1d2e3f-4a5b-4c6d-8e7f-9a0b1c2d3e02}" version="0.200.1-dev">
<defaultconductor bicolor="false" bus="" cable="" color2="#000000" condsize="1" conductor_color="" conductor_section="" dash-size="1" displaytext="1" formula="" function="" horizontal-alignment="AlignBottom" horizrotatetext="0" num="_" numsize="7" onetextperfolio="0" tension_protocol="" text_color="#000000" type="multi" vertical-alignment="AlignRight" vertirotatetext="270"/>
</diagram>
<diagram author="" auto_page_num="" cols="17" colsize="60" date="null" displayAt="bottom" displaycols="true" displayrows="true" filename="" folio="" freezeNewConductor="false" freezeNewElement="false" height="660" indexrev="" locmach="" order="3" plant="" rows="8" rowsize="80" title="not frozen" uuid="{7c1d2e3f-4a5b-4c6d-8e7f-9a0b1c2d3e03}" version="0.200.1-dev">
<defaultconductor bicolor="false" bus="" cable="" color2="#000000" condsize="1" conductor_color="" conductor_section="" dash-size="1" displaytext="1" formula="" function="" horizontal-alignment="AlignBottom" horizrotatetext="0" num="_" numsize="7" onetextperfolio="0" tension_protocol="" text_color="#000000" type="multi" vertical-alignment="AlignRight" vertirotatetext="270"/>
</diagram>
<diagram author="" auto_page_num="" cols="17" colsize="60" date="null" displayAt="bottom" displaycols="true" displayrows="true" filename="" folio="" height="660" indexrev="" locmach="" order="4" plant="" rows="8" rowsize="80" title="no attributes" uuid="{7c1d2e3f-4a5b-4c6d-8e7f-9a0b1c2d3e04}" version="0.200.1-dev">
<defaultconductor bicolor="false" bus="" cable="" color2="#000000" condsize="1" conductor_color="" conductor_section="" dash-size="1" displaytext="1" formula="" function="" horizontal-alignment="AlignBottom" horizrotatetext="0" num="_" numsize="7" onetextperfolio="0" tension_protocol="" text_color="#000000" type="multi" vertical-alignment="AlignRight" vertirotatetext="270"/>
</diagram>
<collection>
<category name="import">
<names>
<name lang="en">Imported elements</name>
</names>
</category>
</collection>
</project>
+103
View File
@@ -0,0 +1,103 @@
/*
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 <http://www.gnu.org/licenses/>.
*/
#include <QtTest>
#include <QDomDocument>
#include <QProcess>
#include <QTemporaryDir>
/**
A folio's "freeze new elements" and "freeze new conductors" flags are
saved as freezeNewElement="true" and freezeNewConductor="true" on its
<diagram>. Loading must read the words back: the flags used to be read
with toInt(), which is 0 for "true" as well as for "false", so both were
off again after every reload. Runs the real binary's --resave on a
project with one folio per combination and reads the saved attributes.
*/
class tst_foliofreezeflags : public QObject
{
Q_OBJECT
QTemporaryDir m_dir;
static bool runQet(const QStringList &arguments)
{
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert(QStringLiteral("QT_QPA_PLATFORM"), QStringLiteral("offscreen"));
QProcess proc;
proc.setProcessEnvironment(env);
proc.start(QStringLiteral(QET_TEST_BINARY_PATH), arguments);
return proc.waitForFinished(60000)
&& proc.exitStatus() == QProcess::NormalExit
&& proc.exitCode() == 0;
}
/// The <diagram> elements of a saved project, in file order.
static QList<QDomElement> diagrams(const QString &path)
{
QFile file(path);
QDomDocument doc;
if (!file.open(QIODevice::ReadOnly) || !doc.setContent(&file)) return {};
QList<QDomElement> list;
for (QDomElement e = doc.documentElement().firstChildElement(QStringLiteral("diagram"));
!e.isNull();
e = e.nextSiblingElement(QStringLiteral("diagram")))
list << e;
return list;
}
private slots:
void initTestCase()
{
QVERIFY2(QFile::exists(QStringLiteral(QET_TEST_BINARY_PATH)), "qelectrotech binary not found");
QVERIFY(m_dir.isValid());
}
// Folio 1 has both flags, folio 2 only the element one, folio 3 none,
// and folio 4 is an older file without the attributes at all.
void flagsSurviveASave_data()
{
QTest::addColumn<int>("folio");
QTest::addColumn<QString>("element");
QTest::addColumn<QString>("conductor");
QTest::newRow("both frozen") << 0 << "true" << "true";
QTest::newRow("elements frozen") << 1 << "true" << "false";
QTest::newRow("not frozen") << 2 << "false" << "false";
QTest::newRow("no attributes") << 3 << "false" << "false";
}
void flagsSurviveASave()
{
QFETCH(int, folio);
QFETCH(QString, element);
QFETCH(QString, conductor);
const QString fixture = QFINDTESTDATA("fixtures/folio_freeze_flags.qet");
QVERIFY2(!fixture.isEmpty(), "fixture project not found");
const QString out = m_dir.filePath(QStringLiteral("resaved%1.qet").arg(folio));
QVERIFY2(runQet({QStringLiteral("--resave"), fixture, out}), "--resave failed");
const QList<QDomElement> list = diagrams(out);
QCOMPARE(list.size(), 4);
const QDomElement e = list.at(folio);
QCOMPARE(e.attribute(QStringLiteral("freezeNewElement")), element);
QCOMPARE(e.attribute(QStringLiteral("freezeNewConductor")), conductor);
}
};
QTEST_MAIN(tst_foliofreezeflags)
#include "tst_foliofreezeflags.moc"