From f6be424cad1de0a9ebbb9ffd507ef0188ae1aa64 Mon Sep 17 00:00:00 2001 From: Kellermorph Date: Fri, 23 Oct 2026 13:02:17 +0200 Subject: [PATCH] Keep the terminal number out of the export columns Manual testing found that the CSV export of the project offered the terminal number as a column, and failed when it was chosen. The export takes its columns from the element info keys, but the query behind the nomenclature has no terminal_number column, so the query breaks. The widget which offers the columns skips the keys it cannot query (formula and exclude_from_bom) and skips the terminal number with them, with a comment saying why. The key itself stays an element info key: the element editor keeps offering %{terminal_number} as a text variable, and the label keeps splitting into label and number the way it was drawn. --- sources/dataBase/ui/elementquerywidget.cpp | 6 ++++ tests/qttest/tst_terminallabeldisplay.cpp | 33 ++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/sources/dataBase/ui/elementquerywidget.cpp b/sources/dataBase/ui/elementquerywidget.cpp index cdd6afc83..0258050d8 100644 --- a/sources/dataBase/ui/elementquerywidget.cpp +++ b/sources/dataBase/ui/elementquerywidget.cpp @@ -548,6 +548,12 @@ void ElementQueryWidget::setUpItems() { if (key == "formula" || key == "exclude_from_bom") continue; + // Terminal number is read-only and not a column of the nomenclature + // query, so offering it as an export/query column would break the + // export (query fails with "no such column"). It stays available as a + // text variable (%{terminal_number}) in the element editor. + if (key == QETInformation::ELMT_TERMINAL_NUMBER) + continue; auto item = new QListWidgetItem(QETInformation::translatedInfoKey(key), ui->m_var_list); item->setData(Qt::UserRole, key); diff --git a/tests/qttest/tst_terminallabeldisplay.cpp b/tests/qttest/tst_terminallabeldisplay.cpp index c21105ffb..797e959be 100644 --- a/tests/qttest/tst_terminallabeldisplay.cpp +++ b/tests/qttest/tst_terminallabeldisplay.cpp @@ -19,7 +19,9 @@ #include "qetapptest.h" #include "TerminalStrip/realterminal.h" #include "TerminalStrip/terminalstrip.h" +#include "dataBase/ui/elementquerywidget.h" #include "diagram.h" +#include #include "properties/elementdata.h" #include "qetgraphicsitem/dynamicelementtextitem.h" #include "qetgraphicsitem/element.h" @@ -407,6 +409,37 @@ private slots: QVERIFY(label->isVisible()); QCOMPARE(label->toPlainText(), QStringLiteral("X1:1")); } + + //The nomenclature/CSV export builds its columns from the element info + //keys, but its query has no terminal_number column: offering the key + //there made the export fail. The key itself stays an info key, so the + //Bauteileditor keeps offering %{terminal_number} as a text variable + void csvExportDoesNotOfferTerminalNumber() + { + ElementQueryWidget widget; + QListWidget *offer = widget.findChild(QStringLiteral("m_var_list")); + QVERIFY2(offer, "the widget which lists the exportable columns"); + + QStringList offered; + for (int row = 0; row < offer->count(); ++row) + offered.append(offer->item(row)->text()); + + const QString terminal_number = QETInformation::translatedInfoKey( + QETInformation::ELMT_TERMINAL_NUMBER); + QVERIFY2(!offered.contains(terminal_number), + qPrintable(QStringLiteral("The export must not offer \"%1\"") + .arg(terminal_number))); + + //The other columns are still offered... + QVERIFY(offered.contains( + QETInformation::translatedInfoKey(QETInformation::ELMT_LABEL))); + + //...and the variable is still a text variable + QVERIFY(QETInformation::elementInfoKeys().contains( + QETInformation::ELMT_TERMINAL_NUMBER)); + QCOMPARE(QETInformation::elementInfoToVar(QETInformation::ELMT_TERMINAL_NUMBER), + QStringLiteral("%{terminal_number}")); + } }; QET_APP_TEST_MAIN(tst_terminallabeldisplay)