From 458c9921c2a6d1a56c2c2b458705681cdcab3e1a Mon Sep 17 00:00:00 2001 From: Kellermorph Date: Thu, 13 Aug 2026 13:51:13 +0200 Subject: [PATCH] Extend terminal numbering dialog with letter numbering and strip selection --- sources/qetdiagrameditor.cpp | 8 +- sources/ui/terminalnumberingdialog.cpp | 87 ++++++++++++- sources/ui/terminalnumberingdialog.h | 8 +- sources/ui/terminalnumberingdialog.ui | 171 +++++++++++++++++-------- 4 files changed, 211 insertions(+), 63 deletions(-) diff --git a/sources/qetdiagrameditor.cpp b/sources/qetdiagrameditor.cpp index 44353b655..1edc21d2e 100644 --- a/sources/qetdiagrameditor.cpp +++ b/sources/qetdiagrameditor.cpp @@ -2799,11 +2799,11 @@ void QETDiagramEditor::generateTerminalBlock() * Opens the dialog for automatic terminal numbering and applies the generated undo command. */ void QETDiagramEditor::slot_terminalNumbering() { - TerminalNumberingDialog dialog(this); - if (dialog.exec() == QDialog::Accepted) { - QETProject *project = currentProject(); - if (!project) return; + QETProject *project = currentProject(); + if (!project) return; + TerminalNumberingDialog dialog(this, project); + if (dialog.exec() == QDialog::Accepted) { // Fetch the generated undo command from the dialog logic QUndoCommand *macro = dialog.getUndoCommand(project); diff --git a/sources/ui/terminalnumberingdialog.cpp b/sources/ui/terminalnumberingdialog.cpp index 689fc5cda..189750a1a 100644 --- a/sources/ui/terminalnumberingdialog.cpp +++ b/sources/ui/terminalnumberingdialog.cpp @@ -5,18 +5,57 @@ #include "../qetgraphicsitem/element.h" #include "../undocommand/changeelementinformationcommand.h" #include +#include +#include +#include #include /** * @brief TerminalNumberingDialog::TerminalNumberingDialog * Constructor * @param parent + * @param project Pointer to the current project (used to populate terminal strips) */ -TerminalNumberingDialog::TerminalNumberingDialog(QWidget *parent) : -QDialog(parent), -ui(new Ui::TerminalNumberingDialog) +TerminalNumberingDialog::TerminalNumberingDialog(QWidget *parent, QETProject *project) : + QDialog(parent), + ui(new Ui::TerminalNumberingDialog), + m_project(project) { ui->setupUi(this); + + // Connect radio button to enable/disable the "also number letters" checkbox + connect(ui->rb_type_alpha, &QRadioButton::toggled, ui->cb_also_alpha, &QCheckBox::setEnabled); + + // Collect all unique terminal strip prefixes from the project + if (m_project) { + QSet prefixes; + foreach (Diagram *diagram, m_project->diagrams()) { + foreach (QGraphicsItem *qgi, diagram->items()) { + if (Element *elmt = qgraphicsitem_cast(qgi)) { + if (elmt->elementData().m_type == ElementData::Terminal) { + QString label = elmt->actualLabel(); + if (label.isEmpty()) continue; + int colonIndex = label.lastIndexOf(':'); + if (colonIndex != -1) { + QString prefix = label.left(colonIndex); + prefixes.insert(prefix); + } + } + } + } + } + + // Sort prefixes alphabetically and create checkboxes + QStringList sortedPrefixes = prefixes.values(); + sortedPrefixes.sort(Qt::CaseInsensitive); + + foreach (const QString &prefix, sortedPrefixes) { + QCheckBox *cb = new QCheckBox(prefix); + cb->setChecked(true); + ui->verticalLayout_strips_content->addWidget(cb); + m_stripCheckboxes.insert(prefix, cb); + } + } } /** @@ -46,11 +85,37 @@ bool TerminalNumberingDialog::isAlphanumeric() const return ui->rb_type_alpha->isChecked(); } +/** + * @brief TerminalNumberingDialog::alsoNumberLetters + * @return true if the "also number letters" checkbox is checked + */ +bool TerminalNumberingDialog::alsoNumberLetters() const +{ + return ui->cb_also_alpha->isChecked(); +} + +/** + * @brief TerminalNumberingDialog::excludedStrips + * @return List of terminal strip prefixes that should be excluded from numbering + */ +QStringList TerminalNumberingDialog::excludedStrips() const +{ + QStringList excluded; + QMapIterator it(m_stripCheckboxes); + while (it.hasNext()) { + it.next(); + if (!it.value()->isChecked()) { + excluded.append(it.key()); + } + } + return excluded; +} + /** * @brief TerminalNumberingDialog::getUndoCommand * Scans the given project for terminals, sorts them according to user preferences * (X/Y axis, alphanumeric rules), and generates an undo command containing all label changes. - * * @param project Pointer to the current QETProject + * @param project Pointer to the current QETProject * @return QUndoCommand* containing the modifications, or nullptr if no changes are needed. */ QUndoCommand* TerminalNumberingDialog::getUndoCommand(QETProject *project) const { @@ -58,6 +123,8 @@ QUndoCommand* TerminalNumberingDialog::getUndoCommand(QETProject *project) const bool axisX = isXAxisPriority(); bool alpha = isAlphanumeric(); + bool alsoAlpha = alsoNumberLetters(); + QStringList excluded = excludedStrips(); // 1. Helper structure to store and sort terminal data struct TermInfo { @@ -97,6 +164,9 @@ QUndoCommand* TerminalNumberingDialog::getUndoCommand(QETProject *project) const suffix = label.mid(colonIndex + 1); } + // Skip excluded terminal strips + if (excluded.contains(prefix)) continue; + // If user chose purely numeric, skip terminals with alphabetical suffixes if (!alpha && !suffix.isEmpty()) { bool isNum; @@ -154,8 +224,13 @@ QUndoCommand* TerminalNumberingDialog::getUndoCommand(QETProject *project) const // If it was a number (e.g., "1") or empty, update it with the new counter newLabel = ti.prefix + ":" + QString::number(newNum); } else { - // If it was alphabetical (e.g., "N", "PE"), keep the original text but consume the count! - newLabel = ti.prefix + ":" + ti.suffix; + // If it was alphabetical (e.g., "N", "PE"), keep the original text + // If "also number letters" is enabled, append the counter + if (alsoAlpha) { + newLabel = ti.prefix + ":" + ti.suffix + QString::number(newNum); + } else { + newLabel = ti.prefix + ":" + ti.suffix; + } } DiagramContext oldInfo = ti.elmt->elementInformations(); diff --git a/sources/ui/terminalnumberingdialog.h b/sources/ui/terminalnumberingdialog.h index c3e756ba5..eae04d7c9 100644 --- a/sources/ui/terminalnumberingdialog.h +++ b/sources/ui/terminalnumberingdialog.h @@ -2,9 +2,11 @@ #define TERMINALNUMBERINGDIALOG_H #include +#include class QETProject; class QUndoCommand; +class QCheckBox; namespace Ui { class TerminalNumberingDialog; @@ -19,17 +21,21 @@ class TerminalNumberingDialog : public QDialog Q_OBJECT public: - explicit TerminalNumberingDialog(QWidget *parent = nullptr); + explicit TerminalNumberingDialog(QWidget *parent, QETProject *project); ~TerminalNumberingDialog(); // Getters for the user's choices bool isXAxisPriority() const; bool isAlphanumeric() const; + bool alsoNumberLetters() const; + QStringList excludedStrips() const; QUndoCommand* getUndoCommand(QETProject *project) const; private: Ui::TerminalNumberingDialog *ui; + QETProject *m_project; + QMap m_stripCheckboxes; }; #endif // TERMINALNUMBERINGDIALOG_H diff --git a/sources/ui/terminalnumberingdialog.ui b/sources/ui/terminalnumberingdialog.ui index 4a6bc97a2..5fb53890e 100644 --- a/sources/ui/terminalnumberingdialog.ui +++ b/sources/ui/terminalnumberingdialog.ui @@ -6,8 +6,8 @@ 0 0 - 400 - 300 + 500 + 450 @@ -25,56 +25,123 @@ - - - Priorité des axes - - - - - - Priorité à l'axe X (horizontal) - - - true - - - - - - - Priorité à l'axe Y (vertical) - - - - - - - - - - Type de numérotation - - - - - - Numérique uniquement (1, 2, 3...) - - - true - - - - - - - Alphanumérique (A, B, C... 1, 2...) - - - - - + + + + + + + Priorité des axes + + + + + + Priorité à l'axe X (horizontal) + + + true + + + + + + + Priorité à l'axe Y (vertical) + + + + + + + + + + Type de numérotation + + + + + + Numérique uniquement (1, 2, 3...) + + + true + + + + + + + Alphanumérique (A, B, C... 1, 2...) + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 20 + 0 + + + + + + + + Numéroter également les lettres + + + false + + + + + + + + + + + + + + Borniers + + + + + + Décochez les borniers dont la numérotation doit être exclue + + + true + + + + + + + true + + + + + + + + + +