Extend terminal numbering dialog with letter numbering and strip selection

This commit is contained in:
Kellermorph
2026-08-13 13:51:13 +02:00
parent 10cc162c4e
commit 458c9921c2
4 changed files with 211 additions and 63 deletions
+4 -4
View File
@@ -2799,11 +2799,11 @@ void QETDiagramEditor::generateTerminalBlock()
* Opens the dialog for automatic terminal numbering and applies the generated undo command. * Opens the dialog for automatic terminal numbering and applies the generated undo command.
*/ */
void QETDiagramEditor::slot_terminalNumbering() { void QETDiagramEditor::slot_terminalNumbering() {
TerminalNumberingDialog dialog(this); QETProject *project = currentProject();
if (dialog.exec() == QDialog::Accepted) { 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 // Fetch the generated undo command from the dialog logic
QUndoCommand *macro = dialog.getUndoCommand(project); QUndoCommand *macro = dialog.getUndoCommand(project);
+81 -6
View File
@@ -5,18 +5,57 @@
#include "../qetgraphicsitem/element.h" #include "../qetgraphicsitem/element.h"
#include "../undocommand/changeelementinformationcommand.h" #include "../undocommand/changeelementinformationcommand.h"
#include <QUndoCommand> #include <QUndoCommand>
#include <QCheckBox>
#include <QVBoxLayout>
#include <QSet>
#include <algorithm> #include <algorithm>
/** /**
* @brief TerminalNumberingDialog::TerminalNumberingDialog * @brief TerminalNumberingDialog::TerminalNumberingDialog
* Constructor * Constructor
* @param parent * @param parent
* @param project Pointer to the current project (used to populate terminal strips)
*/ */
TerminalNumberingDialog::TerminalNumberingDialog(QWidget *parent) : 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);
// 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<QString> prefixes;
foreach (Diagram *diagram, m_project->diagrams()) {
foreach (QGraphicsItem *qgi, diagram->items()) {
if (Element *elmt = qgraphicsitem_cast<Element *>(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(); 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<QString, QCheckBox*> it(m_stripCheckboxes);
while (it.hasNext()) {
it.next();
if (!it.value()->isChecked()) {
excluded.append(it.key());
}
}
return excluded;
}
/** /**
* @brief TerminalNumberingDialog::getUndoCommand * @brief TerminalNumberingDialog::getUndoCommand
* Scans the given project for terminals, sorts them according to user preferences * 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. * (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. * @return QUndoCommand* containing the modifications, or nullptr if no changes are needed.
*/ */
QUndoCommand* TerminalNumberingDialog::getUndoCommand(QETProject *project) const { QUndoCommand* TerminalNumberingDialog::getUndoCommand(QETProject *project) const {
@@ -58,6 +123,8 @@ QUndoCommand* TerminalNumberingDialog::getUndoCommand(QETProject *project) const
bool axisX = isXAxisPriority(); bool axisX = isXAxisPriority();
bool alpha = isAlphanumeric(); bool alpha = isAlphanumeric();
bool alsoAlpha = alsoNumberLetters();
QStringList excluded = excludedStrips();
// 1. Helper structure to store and sort terminal data // 1. Helper structure to store and sort terminal data
struct TermInfo { struct TermInfo {
@@ -97,6 +164,9 @@ QUndoCommand* TerminalNumberingDialog::getUndoCommand(QETProject *project) const
suffix = label.mid(colonIndex + 1); 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 user chose purely numeric, skip terminals with alphabetical suffixes
if (!alpha && !suffix.isEmpty()) { if (!alpha && !suffix.isEmpty()) {
bool isNum; 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 // 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 but consume the count! // If it was alphabetical (e.g., "N", "PE"), keep the original text
newLabel = ti.prefix + ":" + ti.suffix; // 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(); DiagramContext oldInfo = ti.elmt->elementInformations();
+7 -1
View File
@@ -2,9 +2,11 @@
#define TERMINALNUMBERINGDIALOG_H #define TERMINALNUMBERINGDIALOG_H
#include <QDialog> #include <QDialog>
#include <QMap>
class QETProject; class QETProject;
class QUndoCommand; class QUndoCommand;
class QCheckBox;
namespace Ui { namespace Ui {
class TerminalNumberingDialog; class TerminalNumberingDialog;
@@ -19,17 +21,21 @@ class TerminalNumberingDialog : public QDialog
Q_OBJECT Q_OBJECT
public: public:
explicit TerminalNumberingDialog(QWidget *parent = nullptr); explicit TerminalNumberingDialog(QWidget *parent, QETProject *project);
~TerminalNumberingDialog(); ~TerminalNumberingDialog();
// Getters for the user's choices // Getters for the user's choices
bool isXAxisPriority() const; bool isXAxisPriority() const;
bool isAlphanumeric() const; bool isAlphanumeric() const;
bool alsoNumberLetters() const;
QStringList excludedStrips() const;
QUndoCommand* getUndoCommand(QETProject *project) const; QUndoCommand* getUndoCommand(QETProject *project) const;
private: private:
Ui::TerminalNumberingDialog *ui; Ui::TerminalNumberingDialog *ui;
QETProject *m_project;
QMap<QString, QCheckBox*> m_stripCheckboxes;
}; };
#endif // TERMINALNUMBERINGDIALOG_H #endif // TERMINALNUMBERINGDIALOG_H
+119 -52
View File
@@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>400</width> <width>500</width>
<height>300</height> <height>450</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@@ -25,56 +25,123 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QGroupBox" name="groupBox_axis"> <layout class="QHBoxLayout" name="horizontalLayout_main">
<property name="title"> <item>
<string>Priorité des axes</string> <layout class="QVBoxLayout" name="verticalLayout_left">
</property> <item>
<layout class="QVBoxLayout" name="verticalLayout_2"> <widget class="QGroupBox" name="groupBox_axis">
<item> <property name="title">
<widget class="QRadioButton" name="rb_priority_x"> <string>Priorité des axes</string>
<property name="text"> </property>
<string>Priorité à l'axe X (horizontal)</string> <layout class="QVBoxLayout" name="verticalLayout_2">
</property> <item>
<property name="checked"> <widget class="QRadioButton" name="rb_priority_x">
<bool>true</bool> <property name="text">
</property> <string>Priorité à l'axe X (horizontal)</string>
</widget> </property>
</item> <property name="checked">
<item> <bool>true</bool>
<widget class="QRadioButton" name="rb_priority_y"> </property>
<property name="text"> </widget>
<string>Priorité à l'axe Y (vertical)</string> </item>
</property> <item>
</widget> <widget class="QRadioButton" name="rb_priority_y">
</item> <property name="text">
</layout> <string>Priorité à l'axe Y (vertical)</string>
</widget> </property>
</item> </widget>
<item> </item>
<widget class="QGroupBox" name="groupBox_type"> </layout>
<property name="title"> </widget>
<string>Type de numérotation</string> </item>
</property> <item>
<layout class="QVBoxLayout" name="verticalLayout_3"> <widget class="QGroupBox" name="groupBox_type">
<item> <property name="title">
<widget class="QRadioButton" name="rb_type_num"> <string>Type de numérotation</string>
<property name="text"> </property>
<string>Numérique uniquement (1, 2, 3...)</string> <layout class="QVBoxLayout" name="verticalLayout_3">
</property> <item>
<property name="checked"> <widget class="QRadioButton" name="rb_type_num">
<bool>true</bool> <property name="text">
</property> <string>Numérique uniquement (1, 2, 3...)</string>
</widget> </property>
</item> <property name="checked">
<item> <bool>true</bool>
<widget class="QRadioButton" name="rb_type_alpha"> </property>
<property name="text"> </widget>
<string>Alphanumérique (A, B, C... 1, 2...)</string> </item>
</property> <item>
</widget> <widget class="QRadioButton" name="rb_type_alpha">
</item> <property name="text">
</layout> <string>Alphanumérique (A, B, C... 1, 2...)</string>
</widget> </property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_also_alpha">
<item>
<spacer name="spacer_also_alpha">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="cb_also_alpha">
<property name="text">
<string>Numéroter également les lettres</string>
</property>
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="groupBox_strips">
<property name="title">
<string>Borniers</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_strips">
<item>
<widget class="QLabel" name="label_strips_description">
<property name="text">
<string>Décochez les borniers dont la numérotation doit être exclue</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QScrollArea" name="scrollArea_strips">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents_strips">
<layout class="QVBoxLayout" name="verticalLayout_strips_content"/>
</widget>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item> </item>
<item> <item>
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">