From b5722c3f2a06bda96a8d3c458647f092f2fed4e5 Mon Sep 17 00:00:00 2001 From: ispyisail Date: Fri, 11 Sep 2026 12:43:07 +1200 Subject: [PATCH] Sort the wiring list by wire number as a number, not as text Follows @scorpio810's review note on merging #630: ORDER BY diagram_position, wire_number sorts wire numbers as text, so "10" comes before "9". Confirmed against the corpus: perceuse.qet put 111 before 12, and affuteuse_250h.qet put 45 before 5. industrial.qet happened to look correct only because its wire numbers are all the same width. Wire numbers are free text and are not always numeric -- perceuse.qet also carries an unresolved "%sequ_1" -- so the ordering has to cope with both. Numeric values come first, ordered by value; anything else follows, ordered as text. The trailing wire_number keeps ties stable. Fixed in both places the query appears: the CLI exporter and the wiring list dialog. They had the same ORDER BY, so fixing only one would have made the dialog and --export-wiring disagree about the order of the same data. Verified on perceuse, affuteuse_250h, industrial and tremie_vibrante: zero out-of-order numeric pairs afterwards, row counts unchanged, and "%sequ_1" now sorts after the numbers rather than among them. Folio 3 of perceuse.qet reads 0 1 2 3 4 4 5 5 6 6 7 7 12 12 where it previously interleaved 111 before 12. Co-Authored-By: Claude Opus 5 --- sources/cli_export.cpp | 9 ++++++++- sources/ui/wiringlistdialog.cpp | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/sources/cli_export.cpp b/sources/cli_export.cpp index 034005d03..314d61606 100644 --- a/sources/cli_export.cpp +++ b/sources/cli_export.cpp @@ -564,7 +564,14 @@ int exportWiring(QETProject &project, const QString &output) QSqlQuery query = project.dataBase()->newQuery( "SELECT " % columns.join(", ") % - " FROM wiring_list_view ORDER BY diagram_position, wire_number"); + " FROM wiring_list_view" + //Wire numbers are text, so a plain sort puts "10" before "9". + //Numeric ones first, ordered by value; anything non-numeric after, + //ordered as text. The trailing wire_number keeps ties stable. + " ORDER BY diagram_position," + " CASE WHEN wire_number GLOB '[0-9]*' THEN 0 ELSE 1 END," + " CAST(wire_number AS INTEGER)," + " wire_number"); if (!query.exec()) { err << "Wiring list query failed: " << query.lastError().text() << "\n"; return 1; diff --git a/sources/ui/wiringlistdialog.cpp b/sources/ui/wiringlistdialog.cpp index cf80a6025..a28f2425e 100644 --- a/sources/ui/wiringlistdialog.cpp +++ b/sources/ui/wiringlistdialog.cpp @@ -52,7 +52,14 @@ WiringListDialog::WiringListDialog(QETProject *project, QWidget *parent) : "SELECT wire_number, from_element_label, from_terminal," " to_element_label, to_terminal, diagram_position" " FROM wiring_list_view" - " ORDER BY diagram_position, wire_number"), + //Wire numbers are text, so a plain sort puts "10" before "9". + //Numeric ones first, ordered by value; anything non-numeric + //after, ordered as text. The trailing wire_number keeps ties + //stable. + " ORDER BY diagram_position," + " CASE WHEN wire_number GLOB '[0-9]*' THEN 0 ELSE 1 END," + " CAST(wire_number AS INTEGER)," + " wire_number"), m_project->dataBase()->database()); model->setHeaderData(0, Qt::Horizontal, tr("Fil", "column title"));