Add cable management: drawing, cores, numbering, cross-references and cable list

Cables are drawn line objects (toolbar button next to the auto
break/reconnect button, click-move-click, right click cancels), not
components. The type comes from a CSV catalog following the material
list pattern (designation, cores, core colours, editable through the
entry dialog with "Nouvelle entrée" / "Modifier l'entrée").

Each core is bound to the wire its colour label stands on, and the
cable reference is generated per core and written into the Conductor
entry via Conductor::setCableReference(label, cable uuid, slot). The
conductor entry is where it has to live because the terminal strip
plan (Klemmenplan) consumes it in the next step.

Numbering: "Cables" rule under Programmeinstellungen/Neues
Projekt/Nummerierung auto (mirrored in project properties), literal
"W" fallback without a rule, French gate dialog when no rule exists,
Nummerierung menu with the renumber dialog (preferred axis, per-folio
counter, rule and counter state written back, hand-typed names ask,
whole-project scope).

Also included: label block and under-line texts with per-text font and
alignment plus the material-list cell margins, free-core placement and
right-click removal, claim questions for wires of other cables,
multi-selection drag as one undo step, type change with confirmation,
cross-references for type "Cable" (%f-%l%c, own font, clickable links
in exported PDFs), report propagation of the cable definition,
Listes menu (table of contents, material list, terminal strip manager,
terminal generator plugin, cable list), cable list with freely
selectable columns (installation/localisation of cable, start and end,
Blatt start/end, length, used cores...), CSV export dialog with column
pick and preview in the Projekt menu, script API (addTable kind
"cable_list", exportCableList) and a unit test for the type catalog.
This commit is contained in:
Kellermorph
2026-10-08 15:56:00 +02:00
parent 1ca13ce62d
commit bf9b34398d
108 changed files with 18482 additions and 293 deletions
+17
View File
@@ -147,6 +147,23 @@ add_test(NAME tst_legacyelementtypes COMMAND tst_legacyelementtypes)
target_include_directories(tst_legacyelementtypes PRIVATE ${QET_DIR}/sources)
target_link_libraries(tst_legacyelementtypes PRIVATE Qt::Test)
# The cable type catalogue is plain data (it reads and writes the CSV file
# holding the cable kinds), so it is compiled here on its own, together with
# the material file helpers it shares and the element information wording.
add_executable(
tst_cabletypelist
tst_cabletypelist.cpp
${QET_DIR}/sources/cablelist/cabletypelist.cpp
${QET_DIR}/sources/cablelist/cabletypelist.h
${QET_DIR}/sources/materiallist/materiallist.cpp
${QET_DIR}/sources/materiallist/materiallist.h
${QET_DIR}/sources/qetinformation.cpp
${QET_DIR}/sources/qetinformation.h)
add_test(NAME tst_cabletypelist COMMAND tst_cabletypelist)
target_include_directories(tst_cabletypelist PRIVATE ${QET_DIR}/sources)
# qetinformation.h uses QRegularExpressionValidator, which lives in QtGui.
target_link_libraries(tst_cabletypelist PRIVATE Qt::Test Qt::Gui)
add_executable(
tst_qetpalette
tst_qetpalette.cpp
+186
View File
@@ -0,0 +1,186 @@
/*
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 "cablelist/cabletypelist.h"
#include <QFile>
#include <QTemporaryDir>
#include <QTest>
/**
The cable type catalogue is read back the way it was written, and the
three columns it really uses are the only ones a new file gets:
- a catalogue carrying the material file's whole shape (ten columns,
two header lines) reads as ten columns, its machine header line is
not mistaken for a cable, and the type comes out of it : this is
the catalogue a user already has on disk;
- a file the program creates itself holds the two header lines and
the three columns, no more;
- a file written by hand with the label line alone still gives the
type, so dropping the machine header never costs a column;
- and a line of cables is never taken for the machine header, even
when it happens to be written in key shaped words.
*/
class tst_cabletypelist : public QObject
{
Q_OBJECT
QTemporaryDir m_dir;
QString write(const QString &name, const QString &content)
{
const QString path = m_dir.filePath(name);
QFile file(path);
if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
return {};
}
file.write(content.toUtf8());
file.close();
return path;
}
bool load(const QString &path, CableTypeListData *data)
{
QString error;
const bool ok = CableTypeList::load(path, data, &error);
if (!ok) {
qWarning("%s", qPrintable(error));
}
return ok;
}
private slots:
void tenColumnCatalogueReadsBack()
{
const QString path = write(QStringLiteral("ten.csv"),
QStringLiteral(
"Désignation;Nombre d'âmes;Couleurs des âmes;Section du câble;Couleur du fourreau;Fabricant;Numéro de commande;Fournisseur;Description textuelle;Notes\n"
"designation;cores;core_colors;section;color;manufacturer;manufacturer_reference;supplier;description;notes\n"
"H07V-K 3G1,5;3;wh|bn|bl;1.5;PVC;Nexans;X123;Rexel;courant fort;note\n"
"NYM-J 3G2,5;3;wh|bn|bl;2.5;PVC;;;;;\n"));
QVERIFY(!path.isEmpty());
CableTypeListData data;
QVERIFY2(load(path, &data), "the catalogue could not be read");
//The machine header line is not one of the cables...
QCOMPARE(data.records.size(), 2);
//... and every column it names is read under that name, even the
//ones this program never gave a meaning to.
QCOMPARE(data.columns, QStringList({
QStringLiteral("designation"), QStringLiteral("cores"),
QStringLiteral("core_colors"), QStringLiteral("section"),
QStringLiteral("color"), QStringLiteral("manufacturer"),
QStringLiteral("manufacturer_reference"),
QStringLiteral("supplier"), QStringLiteral("description"),
QStringLiteral("notes")}));
QCOMPARE(CableTypeList::designation(data.records.at(0)),
QStringLiteral("H07V-K 3G1,5"));
QCOMPARE(CableTypeList::coreCount(data.records.at(0)), 3);
QCOMPARE(CableTypeList::coreColors(data.records.at(0)),
QStringList({QStringLiteral("wh"), QStringLiteral("bn"),
QStringLiteral("bl")}));
//A column outside the three the program uses keeps its name and
//its data.
QCOMPARE(data.records.at(0).value(QStringLiteral("section")),
QStringLiteral("1.5"));
QCOMPARE(CableTypeList::designation(data.records.at(1)),
QStringLiteral("NYM-J 3G2,5"));
}
void newFileHasThreeColumns()
{
const QString path = m_dir.filePath(QStringLiteral("new.csv"));
QVERIFY2(CableTypeList::createFile(path), "the file was not created");
CableTypeListData data;
QVERIFY(load(path, &data));
QCOMPARE(data.columns, QStringList({
QStringLiteral("designation"), QStringLiteral("cores"),
QStringLiteral("core_colors")}));
QVERIFY(data.records.isEmpty());
//The label line reads the way the cable form names the type.
QCOMPARE(CableTypeList::translatedHeader(data.columns), QStringList({
QStringLiteral("Désignation"),
QStringLiteral("Nombre d'âmes"),
QStringLiteral("Couleurs des âmes")}));
CableTypeRecord record;
record.setValue(QStringLiteral("designation"),
QStringLiteral("H07V-K 3G1,5"));
record.setValue(QStringLiteral("cores"), QStringLiteral("3"));
record.setValue(QStringLiteral("core_colors"),
QStringLiteral("wh|bn|bl"));
QVERIFY2(CableTypeList::appendRecord(path, record),
"the record was not appended");
CableTypeListData read_back;
QVERIFY(load(path, &read_back));
QCOMPARE(read_back.columns, data.columns);
QCOMPARE(read_back.records.size(), 1);
QCOMPARE(CableTypeList::designation(read_back.records.first()),
QStringLiteral("H07V-K 3G1,5"));
QCOMPARE(CableTypeList::coreCount(read_back.records.first()), 3);
QCOMPARE(CableTypeList::coreColors(read_back.records.first()),
QStringList({QStringLiteral("wh"), QStringLiteral("bn"),
QStringLiteral("bl")}));
}
void labelLineAloneStillGivesTheType()
{
const QString path = write(QStringLiteral("hand.csv"),
QStringLiteral(
"Désignation;Nombre d'âmes;Couleurs des âmes\n"
"H07V-K 3G1,5;3;wh|bn|bl\n"));
QVERIFY(!path.isEmpty());
CableTypeListData data;
QVERIFY2(load(path, &data), "the hand written file could not be read");
QCOMPARE(data.columns, QStringList({
QStringLiteral("designation"), QStringLiteral("cores"),
QStringLiteral("core_colors")}));
QCOMPARE(data.records.size(), 1);
QCOMPARE(CableTypeList::designation(data.records.first()),
QStringLiteral("H07V-K 3G1,5"));
QCOMPARE(CableTypeList::coreCount(data.records.first()), 3);
}
void aCableIsNeverMistakenForTheHeader()
{
//Three cells which all look like column keys, none of which means
//anything here : far more likely to be a cable than a header.
const QString path = write(QStringLiteral("unknown.csv"),
QStringLiteral(
"Désignation;Nombre d'âmes;Couleurs des âmes\n"
"ymj;;wh\n"
"H07V-K 3G1,5;3;wh|bn|bl\n"));
QVERIFY(!path.isEmpty());
CableTypeListData data;
QVERIFY2(load(path, &data), "the file could not be read");
QCOMPARE(data.records.size(), 2);
QCOMPARE(CableTypeList::designation(data.records.first()),
QStringLiteral("ymj"));
QCOMPARE(CableTypeList::designation(data.records.last()),
QStringLiteral("H07V-K 3G1,5"));
}
};
QTEST_APPLESS_MAIN(tst_cabletypelist)
#include "tst_cabletypelist.moc"