From f7196c48e163afc816184dc77a4d2e2c26544e9c Mon Sep 17 00:00:00 2001 From: Laurent Trinques Date: Sun, 18 Oct 2026 15:33:30 +0200 Subject: [PATCH] Terminal strip editor: remember the manufacturer filter of each strip The manufacturer chosen to filter the terminals of the Width column is stored in the data of the terminal strip (information "manufacturer" of terminal_strip_data, written only when set), and selected again when the strip is shown in the editor. Each strip keeps its own manufacturer. Older versions ignore this information. TerminalStripEditor::apply() now starts from the current data of the strip instead of a new TerminalStripData: the uuid of the strip was replaced by a new one at each apply, and the new information would have been lost. --- sources/TerminalStrip/terminalstrip.h | 2 ++ sources/TerminalStrip/terminalstripdata.cpp | 5 +++++ sources/TerminalStrip/terminalstripdata.h | 3 ++- .../TerminalStrip/ui/terminalstripeditor.cpp | 20 ++++++++++++++++++- .../TerminalStrip/ui/terminalstripeditor.h | 1 + 5 files changed, 29 insertions(+), 2 deletions(-) diff --git a/sources/TerminalStrip/terminalstrip.h b/sources/TerminalStrip/terminalstrip.h index a188f7ae6..9aa2201f5 100644 --- a/sources/TerminalStrip/terminalstrip.h +++ b/sources/TerminalStrip/terminalstrip.h @@ -72,6 +72,8 @@ class TerminalStrip : public QObject QString comment() const {return m_data.m_comment;} void setDescription(const QString &description); QString description() const {return m_data.m_description;} + ///Manufacturer of the terminals proposed by the editor, empty = all + QString manufacturer() const {return m_data.m_manufacturer;} QUuid uuid() const {return m_data.m_uuid;} QETProject *project() const; diff --git a/sources/TerminalStrip/terminalstripdata.cpp b/sources/TerminalStrip/terminalstripdata.cpp index 04318f0a1..15a9eb3d9 100644 --- a/sources/TerminalStrip/terminalstripdata.cpp +++ b/sources/TerminalStrip/terminalstripdata.cpp @@ -52,6 +52,9 @@ QDomElement TerminalStripData::toXml(QDomDocument &xml_document) const if (!m_description.isEmpty()) { info_elmt.appendChild(infoToXml(xml_document, QStringLiteral("description"), m_description)); } + if (!m_manufacturer.isEmpty()) { + info_elmt.appendChild(infoToXml(xml_document, QStringLiteral("manufacturer"), m_manufacturer)); + } return root_elmt; } @@ -79,6 +82,7 @@ bool TerminalStripData::fromXml(const QDomElement &xml_element) else if (name == QLatin1String("name")) {m_name = value;} else if (name == QLatin1String("comment")) {m_comment = value;} else if (name == QLatin1String("description")) {m_description = value;} + else if (name == QLatin1String("manufacturer")) {m_manufacturer = value;} } return true; @@ -91,6 +95,7 @@ TerminalStripData &TerminalStripData::operator=(const TerminalStripData &other) m_name = other.m_name; m_comment = other.m_comment; m_description = other.m_description; + m_manufacturer = other.m_manufacturer; m_uuid = other.m_uuid; return *this; diff --git a/sources/TerminalStrip/terminalstripdata.h b/sources/TerminalStrip/terminalstripdata.h index 3e03299d9..191cccadc 100644 --- a/sources/TerminalStrip/terminalstripdata.h +++ b/sources/TerminalStrip/terminalstripdata.h @@ -48,7 +48,8 @@ class TerminalStripData : public PropertiesInterface m_location = QStringLiteral("+"), m_name, m_comment, - m_description; + m_description, + m_manufacturer; //Manufacturer of the terminals proposed in the editor, empty = all QUuid m_uuid = QUuid::createUuid(); }; diff --git a/sources/TerminalStrip/ui/terminalstripeditor.cpp b/sources/TerminalStrip/ui/terminalstripeditor.cpp index 9bcb23e65..509d106bb 100644 --- a/sources/TerminalStrip/ui/terminalstripeditor.cpp +++ b/sources/TerminalStrip/ui/terminalstripeditor.cpp @@ -130,6 +130,7 @@ void TerminalStripEditor::setCurrentStrip(TerminalStrip *strip_) ui->m_name_le ->setText(strip_->name()); ui->m_comment_le ->setText(strip_->comment()); ui->m_description_te ->setPlainText(strip_->description()); + setManufacturerFilter(strip_->manufacturer()); ui->m_move_to_cb->addItem(tr("Independent terminals"), QUuid()); const auto project_{strip_->project()}; @@ -202,12 +203,14 @@ void TerminalStripEditor::apply() { m_project->undoStack()->beginMacro(tr("Modify terminal strip properties")); - TerminalStripData data; + //Start from the current data : keep the uuid of the strip + TerminalStripData data = m_current_strip->data(); data.m_installation = ui->m_installation_le->text(); data.m_location = ui->m_location_le->text(); data.m_name = ui->m_name_le->text(); data.m_comment = ui->m_comment_le->text(); data.m_description = ui->m_description_te->toPlainText(); + data.m_manufacturer = ui->m_manufacturer_cb->currentData().toString(); m_project->undoStack()->push(new ChangeTerminalStripData(m_current_strip, data, nullptr)); @@ -269,6 +272,21 @@ void TerminalStripEditor::clear() m_model->deleteLater(); m_model = nullptr; } + setManufacturerFilter(QString()); +} + +/** + * @brief TerminalStripEditor::setManufacturerFilter + * Select @a manufacturer in the manufacturer combo box : only the terminals + * of this manufacturer are proposed in the Width column. + * Each terminal strip stores its own manufacturer (TerminalStripData), + * an empty or unknown manufacturer proposes all the manufacturers. + * @param manufacturer + */ +void TerminalStripEditor::setManufacturerFilter(const QString &manufacturer) +{ + const auto index_ = ui->m_manufacturer_cb->findData(manufacturer); + ui->m_manufacturer_cb->setCurrentIndex(index_ > 0 ? index_ : 0); } /** diff --git a/sources/TerminalStrip/ui/terminalstripeditor.h b/sources/TerminalStrip/ui/terminalstripeditor.h index ea9e46d35..ceef6ac0e 100644 --- a/sources/TerminalStrip/ui/terminalstripeditor.h +++ b/sources/TerminalStrip/ui/terminalstripeditor.h @@ -54,6 +54,7 @@ class TerminalStripEditor : public QWidget void pasteFromClipboard(); void clearSelectedTexts(); void clear(); + void setManufacturerFilter(const QString &manufacturer); void spanMultiLevelTerminals(); void selectionChanged(); QSize setUpBridgeCellWidth();