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
+2 -2
View File
@@ -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;
TerminalNumberingDialog dialog(this, project);
if (dialog.exec() == QDialog::Accepted) {
// Fetch the generated undo command from the dialog logic
QUndoCommand *macro = dialog.getUndoCommand(project);
+80 -5
View File
@@ -5,18 +5,57 @@
#include "../qetgraphicsitem/element.h"
#include "../undocommand/changeelementinformationcommand.h"
#include <QUndoCommand>
#include <QCheckBox>
#include <QVBoxLayout>
#include <QSet>
#include <algorithm>
/**
* @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<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();
}
/**
* @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
* 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,9 +224,14 @@ 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!
// 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();
DiagramContext newInfo = oldInfo;
+7 -1
View File
@@ -2,9 +2,11 @@
#define TERMINALNUMBERINGDIALOG_H
#include <QDialog>
#include <QMap>
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<QString, QCheckBox*> m_stripCheckboxes;
};
#endif // TERMINALNUMBERINGDIALOG_H
+69 -2
View File
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<width>500</width>
<height>450</height>
</rect>
</property>
<property name="windowTitle">
@@ -24,6 +24,10 @@
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_main">
<item>
<layout class="QVBoxLayout" name="verticalLayout_left">
<item>
<widget class="QGroupBox" name="groupBox_axis">
<property name="title">
@@ -73,9 +77,72 @@
</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>
<spacer name="verticalSpacer">
<property name="orientation">