This commit is contained in:
Kellermorph
2026-08-14 09:43:39 +02:00
parent 458c9921c2
commit 5acf201067
2 changed files with 23 additions and 11 deletions
+22 -9
View File
@@ -18,8 +18,7 @@
*/ */
TerminalNumberingDialog::TerminalNumberingDialog(QWidget *parent, QETProject *project) : TerminalNumberingDialog::TerminalNumberingDialog(QWidget *parent, QETProject *project) :
QDialog(parent), QDialog(parent),
ui(new Ui::TerminalNumberingDialog), ui(new Ui::TerminalNumberingDialog)
m_project(project)
{ {
ui->setupUi(this); ui->setupUi(this);
@@ -27,19 +26,30 @@ TerminalNumberingDialog::TerminalNumberingDialog(QWidget *parent, QETProject *pr
connect(ui->rb_type_alpha, &QRadioButton::toggled, ui->cb_also_alpha, &QCheckBox::setEnabled); connect(ui->rb_type_alpha, &QRadioButton::toggled, ui->cb_also_alpha, &QCheckBox::setEnabled);
// Collect all unique terminal strip prefixes from the project // Collect all unique terminal strip prefixes from the project
if (m_project) { if (project) {
QSet<QString> prefixes; QSet<QString> prefixes;
foreach (Diagram *diagram, m_project->diagrams()) { foreach (Diagram *diagram, project->diagrams()) {
foreach (QGraphicsItem *qgi, diagram->items()) { foreach (QGraphicsItem *qgi, diagram->items()) {
if (Element *elmt = qgraphicsitem_cast<Element *>(qgi)) { if (Element *elmt = qgraphicsitem_cast<Element *>(qgi)) {
if (elmt->elementData().m_type == ElementData::Terminal) { if (elmt->elementData().m_type == ElementData::Terminal) {
// Ignore locked terminals
DiagramContext info = elmt->elementInformations();
if (info.value(QStringLiteral("auto_num_locked")).toString() == QLatin1String("true")) {
continue;
}
QString label = elmt->actualLabel(); QString label = elmt->actualLabel();
if (label.isEmpty()) continue; if (label.isEmpty()) continue;
// Handle labels with and without colon
int colonIndex = label.lastIndexOf(':'); int colonIndex = label.lastIndexOf(':');
QString prefix;
if (colonIndex != -1) { if (colonIndex != -1) {
QString prefix = label.left(colonIndex); prefix = label.left(colonIndex);
prefixes.insert(prefix); } else {
prefix = label;
} }
prefixes.insert(prefix);
} }
} }
} }
@@ -224,9 +234,12 @@ QUndoCommand* TerminalNumberingDialog::getUndoCommand(QETProject *project) const
// If it was a number (e.g., "1") or empty, update it with the new counter // If it was a number (e.g., "1") or empty, update it with the new counter
newLabel = ti.prefix + ":" + QString::number(newNum); newLabel = ti.prefix + ":" + QString::number(newNum);
} else { } else {
// If it was alphabetical (e.g., "N", "PE"), keep the original text // Only append to purely alphabetic suffixes (N, PE), so re-running is a
// If "also number letters" is enabled, append the counter // no-op and already-numbered suffixes (L1, L2, L3) keep their meaning.
if (alsoAlpha) { const bool allLetters = !ti.suffix.isEmpty()
&& std::all_of(ti.suffix.cbegin(), ti.suffix.cend(),
[](QChar c){ return c.isLetter(); });
if (alsoAlpha && allLetters) {
newLabel = ti.prefix + ":" + ti.suffix + QString::number(newNum); newLabel = ti.prefix + ":" + ti.suffix + QString::number(newNum);
} else { } else {
newLabel = ti.prefix + ":" + ti.suffix; newLabel = ti.prefix + ":" + ti.suffix;
+1 -2
View File
@@ -21,7 +21,7 @@ class TerminalNumberingDialog : public QDialog
Q_OBJECT Q_OBJECT
public: public:
explicit TerminalNumberingDialog(QWidget *parent, QETProject *project); explicit TerminalNumberingDialog(QWidget *parent = nullptr, QETProject *project = nullptr);
~TerminalNumberingDialog(); ~TerminalNumberingDialog();
// Getters for the user's choices // Getters for the user's choices
@@ -34,7 +34,6 @@ public:
private: private:
Ui::TerminalNumberingDialog *ui; Ui::TerminalNumberingDialog *ui;
QETProject *m_project;
QMap<QString, QCheckBox*> m_stripCheckboxes; QMap<QString, QCheckBox*> m_stripCheckboxes;
}; };