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.
This commit is contained in:
Kellermorph
2026-10-23 13:02:17 +02:00
parent 208b5e1570
commit f6be424cad
2 changed files with 39 additions and 0 deletions
@@ -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);
+33
View File
@@ -19,7 +19,9 @@
#include "qetapptest.h"
#include "TerminalStrip/realterminal.h"
#include "TerminalStrip/terminalstrip.h"
#include "dataBase/ui/elementquerywidget.h"
#include "diagram.h"
#include <QListWidget>
#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<QListWidget *>(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)