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.
This commit is contained in:
Laurent Trinques
2026-10-18 15:33:30 +02:00
parent 851ddfad16
commit f7196c48e1
5 changed files with 29 additions and 2 deletions
+2
View File
@@ -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;
@@ -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;
+2 -1
View File
@@ -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();
};
@@ -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);
}
/**
@@ -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();