mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-19 12:34:15 +02:00
Terminal catalog: remember the chosen terminal, not only its width
Several terminals of the catalog have the same width (6.2 mm: Phoenix
Contact UT 4 and ST 4; 5.2 mm: WAGO 2002 and Phoenix Contact ST 2,5...).
Only the width was stored, so on reopening the first entry with that
width was shown instead of the terminal that was chosen.
- New element information terminal_catalog_entry: the label of the
terminal chosen in the catalog (e.g. "Phoenix Contact ST 4").
- Choosing a terminal also fills the manufacturer and manufacturer
reference informations (bill of materials, %{manufacturer_reference}),
only when they are empty or still hold what the previous catalog entry
wrote: a value typed by the user is never overwritten.
- Element editor: the manufacturer and the exact terminal are restored on
reopening. A width typed by hand, or stored before this change, stays a
plain width instead of taking the first terminal with the same width.
- Terminal strip editor: new "Manufacturer" combo filtering the terminals
proposed in the Width column (with the section filter); the column shows
"6,2 - Phoenix Contact ST 4", and copy/paste keeps the terminal.
Existing projects are unchanged: without the new information, only the
width is used, as before.
This commit is contained in:
@@ -20,7 +20,9 @@
|
||||
#include "../qetgraphicsitem/terminalelement.h"
|
||||
#include "physicalterminal.h"
|
||||
#include "terminalcolor.h"
|
||||
#include "terminalcatalog.h"
|
||||
#include "../qetgraphicsitem/conductor.h"
|
||||
#include "../qetinformation.h"
|
||||
|
||||
/**
|
||||
* @brief RealTerminal
|
||||
@@ -264,6 +266,67 @@ qreal RealTerminal::widthMm() const
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief RealTerminal::catalogEntry
|
||||
* @return the label of the terminal chosen in the catalog
|
||||
* (TerminalCatalog::WidthEntry::label), for example "Phoenix Contact ST 4",
|
||||
* or an empty string if the width was typed or not set.
|
||||
* Several terminals of the catalog can have the same width,
|
||||
* the width alone doesn't say which one was chosen.
|
||||
*/
|
||||
QString RealTerminal::catalogEntry() const
|
||||
{
|
||||
if (m_element) {
|
||||
return m_element->elementData().m_informations.value(catalogEntryInfoKey()).toString();
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief RealTerminal::applyCatalogEntry
|
||||
* Store in @a informations the terminal chosen in the catalog,
|
||||
* and write its manufacturer and its reference in the manufacturer and
|
||||
* manufacturer reference informations (used by the bill of materials).
|
||||
* These two informations are only written when they are empty,
|
||||
* or when they still hold what the previous entry of the catalog wrote :
|
||||
* a value typed by the user is never overwritten.
|
||||
* @param informations : the informations of the element
|
||||
* @param entry_label : label of an entry of the catalog,
|
||||
* an empty string (or a label unknown by the catalog) removes the entry.
|
||||
*/
|
||||
void RealTerminal::applyCatalogEntry(DiagramContext &informations, const QString &entry_label)
|
||||
{
|
||||
const auto *old_entry = TerminalCatalog::entryByLabel(
|
||||
informations.value(catalogEntryInfoKey()).toString());
|
||||
const auto *new_entry = TerminalCatalog::entryByLabel(entry_label);
|
||||
|
||||
if (new_entry) {
|
||||
informations.addValue(catalogEntryInfoKey(), QString::fromUtf8(new_entry->label));
|
||||
} else if (informations.contains(catalogEntryInfoKey())) {
|
||||
informations.remove(catalogEntryInfoKey());
|
||||
}
|
||||
|
||||
const auto update_ = [&informations](const QString &key, const QString &old_value, const QString &new_value)
|
||||
{
|
||||
const auto current_ = informations.value(key).toString();
|
||||
if (!current_.isEmpty() && current_ != old_value) {
|
||||
return; //Typed by the user, keep it
|
||||
}
|
||||
if (!new_value.isEmpty()) {
|
||||
informations.addValue(key, new_value);
|
||||
} else if (!current_.isEmpty()) {
|
||||
informations.addValue(key, QString());
|
||||
}
|
||||
};
|
||||
|
||||
update_(QETInformation::ELMT_MANUFACTURER,
|
||||
old_entry ? QString::fromUtf8(old_entry->manufacturer) : QString(),
|
||||
new_entry ? QString::fromUtf8(new_entry->manufacturer) : QString());
|
||||
update_(QETInformation::ELMT_MANUFACTURER_REF,
|
||||
old_entry ? TerminalCatalog::modelName(*old_entry) : QString(),
|
||||
new_entry ? TerminalCatalog::modelName(*new_entry) : QString());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief RealTerminal::hasSeparatorAfter
|
||||
* @return true if a separator plate (partition plate) is mounted
|
||||
|
||||
@@ -71,6 +71,7 @@ class RealTerminal
|
||||
QColor stripeColor() const;
|
||||
qreal section() const;
|
||||
qreal widthMm() const;
|
||||
QString catalogEntry() const;
|
||||
bool hasSeparatorAfter() const;
|
||||
|
||||
//Keys used to store the cable data in the element informations
|
||||
@@ -82,9 +83,13 @@ class RealTerminal
|
||||
static QString sectionInfoKey() { return QStringLiteral("terminal_section"); }
|
||||
//Key used to store the width (mm) of the terminal, drawn in the terminal strip
|
||||
static QString widthInfoKey() { return QStringLiteral("terminal_width"); }
|
||||
//Key used to store the terminal chosen in the catalog (TerminalCatalog::WidthEntry::label)
|
||||
static QString catalogEntryInfoKey() { return QStringLiteral("terminal_catalog_entry"); }
|
||||
//Key used to store if a separator plate is mounted after the terminal
|
||||
static QString separatorInfoKey() { return QStringLiteral("terminal_separator"); }
|
||||
|
||||
static void applyCatalogEntry(DiagramContext &informations, const QString &entry_label);
|
||||
|
||||
QString conductor() const;
|
||||
|
||||
ElementData::TerminalType type() const;
|
||||
|
||||
@@ -136,6 +136,41 @@ namespace TerminalCatalog
|
||||
}
|
||||
return list_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief entryByLabel
|
||||
* @param label : the label of an entry, as stored in the element
|
||||
* informations (RealTerminal::catalogEntryInfoKey())
|
||||
* @return the entry of the catalog with this label, or nullptr
|
||||
*/
|
||||
inline const WidthEntry *entryByLabel(const QString &label)
|
||||
{
|
||||
if (label.isEmpty()) {
|
||||
return nullptr;
|
||||
}
|
||||
for (const auto &entry : widthEntries()) {
|
||||
if (label == QString::fromUtf8(entry.label)) {
|
||||
return &entry;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief modelName
|
||||
* @param entry
|
||||
* @return the label of @a entry without the name of its manufacturer :
|
||||
* "ST 4" for "Phoenix Contact ST 4"
|
||||
*/
|
||||
inline QString modelName(const WidthEntry &entry)
|
||||
{
|
||||
const auto label_ = QString::fromUtf8(entry.label);
|
||||
const auto manufacturer_ = QString::fromUtf8(entry.manufacturer);
|
||||
if (label_.startsWith(manufacturer_ + QLatin1Char(' '))) {
|
||||
return label_.mid(manufacturer_.size() + 1);
|
||||
}
|
||||
return label_;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // TERMINALCATALOG_H
|
||||
|
||||
@@ -43,6 +43,7 @@ struct modelRealTerminalData
|
||||
mrtd.stripe_color_ = real_t->stripeColor();
|
||||
mrtd.section_ = real_t->section();
|
||||
mrtd.width_mm_ = real_t->widthMm();
|
||||
mrtd.catalog_entry_ = real_t->catalogEntry();
|
||||
mrtd.type_ = real_t->type();
|
||||
mrtd.function_ = real_t->function();
|
||||
mrtd.element_ = real_t->element();
|
||||
@@ -66,6 +67,7 @@ struct modelRealTerminalData
|
||||
QColor stripe_color_; //Second color of a two-tone color, invalid if plain
|
||||
qreal section_ = 0; //In mm2, 0 = no section set by the user
|
||||
qreal width_mm_ = 0; //In mm, 0 = no width set by the user
|
||||
QString catalog_entry_; //Terminal chosen in the catalog, empty if the width was typed
|
||||
bool bridged_ = false;
|
||||
|
||||
ElementData::TerminalType type_ = ElementData::TerminalType::TTGeneric;
|
||||
|
||||
@@ -32,6 +32,8 @@
|
||||
#include "../physicalterminal.h"
|
||||
#include "../terminalstripbridge.h"
|
||||
#include "../terminalcolor.h"
|
||||
#include "../terminalcatalog.h"
|
||||
#include "../realterminal.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
@@ -52,7 +54,18 @@ TerminalStripEditor::TerminalStripEditor(QETProject *project, QWidget *parent) :
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->m_table_widget->setItemDelegate(new TerminalStripModelDelegate{this});
|
||||
auto delegate_ = new TerminalStripModelDelegate{this};
|
||||
ui->m_table_widget->setItemDelegate(delegate_);
|
||||
|
||||
//Manufacturer of the terminals proposed in the Width column
|
||||
ui->m_manufacturer_cb->addItem(tr("All manufacturers"), QString());
|
||||
for (const auto &name_ : TerminalCatalog::manufacturers()) {
|
||||
ui->m_manufacturer_cb->addItem(name_, name_);
|
||||
}
|
||||
connect(ui->m_manufacturer_cb, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
||||
this, [this, delegate_]() {
|
||||
delegate_->setManufacturer(ui->m_manufacturer_cb->currentData().toString());
|
||||
});
|
||||
|
||||
//Copy, paste and delete of the cells with the keyboard
|
||||
ui->m_table_widget->installEventFilter(this);
|
||||
@@ -222,6 +235,10 @@ void TerminalStripEditor::apply()
|
||||
set_info(RealTerminal::colorInfoKey(), TerminalColor::toSpec(data_.color_, data_.stripe_color_));
|
||||
set_info(RealTerminal::sectionInfoKey(), data_.section_ > 0 ? QString::number(data_.section_, 'g', 6) : QString());
|
||||
set_info(RealTerminal::widthInfoKey(), data_.width_mm_ > 0 ? QString::number(data_.width_mm_, 'g', 6) : QString());
|
||||
//The terminal chosen in the catalog, its manufacturer and its reference
|
||||
//(only written when the user didn't type them)
|
||||
RealTerminal::applyCatalogEntry(current_data.m_informations,
|
||||
data_.width_mm_ > 0 ? data_.catalog_entry_ : QString());
|
||||
set_info(RealTerminal::separatorInfoKey(), data_.separator_ ? QStringLiteral("true") : QString());
|
||||
|
||||
if (element->elementData() != current_data)
|
||||
|
||||
@@ -199,6 +199,20 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="15" column="0">
|
||||
<widget class="QLabel" name="m_manufacturer_label">
|
||||
<property name="text">
|
||||
<string>Manufacturer :</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="15" column="1" colspan="2">
|
||||
<widget class="QComboBox" name="m_manufacturer_cb">
|
||||
<property name="toolTip">
|
||||
<string>Manufacturer of the terminals proposed in the Width column</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="16" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
|
||||
@@ -211,7 +211,13 @@ QVariant TerminalStripModel::data(const QModelIndex &index, int role) const
|
||||
case FUNCTION_CELL : return ElementData::translatedTerminalFunction(mrtd.function_);
|
||||
case COLOR_CELL : return TerminalColor::displayName(mrtd.color_, mrtd.stripe_color_);
|
||||
case SECTION_CELL : return mrtd.section_ > 0 ? QLocale().toString(mrtd.section_, 'g', 6) : QString();
|
||||
case WIDTH_CELL : return mrtd.width_mm_ > 0 ? QLocale().toString(mrtd.width_mm_, 'g', 6) : QString();
|
||||
case WIDTH_CELL :
|
||||
if (mrtd.width_mm_ <= 0) {
|
||||
return QString();
|
||||
}
|
||||
//"6,2 - Phoenix Contact ST 4" : the width alone doesn't say which terminal it is
|
||||
return mrtd.catalog_entry_.isEmpty() ? QLocale().toString(mrtd.width_mm_, 'g', 6)
|
||||
: QLocale().toString(mrtd.width_mm_, 'g', 6) + QStringLiteral(" - ") + mrtd.catalog_entry_;
|
||||
default : return QVariant();
|
||||
}
|
||||
}
|
||||
@@ -228,6 +234,11 @@ QVariant TerminalStripModel::data(const QModelIndex &index, int role) const
|
||||
|
||||
}
|
||||
}
|
||||
else if (role == CatalogEntryRole &&
|
||||
index.column() == WIDTH_CELL)
|
||||
{
|
||||
return mrtd.catalog_entry_;
|
||||
}
|
||||
else if (role == Qt::CheckStateRole &&
|
||||
index.column() == LED_CELL)
|
||||
{
|
||||
@@ -369,13 +380,41 @@ bool TerminalStripModel::setData(const QModelIndex &index, const QVariant &value
|
||||
}
|
||||
}
|
||||
else if (column_ == WIDTH_CELL &&
|
||||
role == Qt::EditRole)
|
||||
(role == Qt::EditRole || role == CatalogEntryRole))
|
||||
{
|
||||
bool ok_ = false;
|
||||
const auto width_ = parsePositiveNumber(value.toString(), &ok_);
|
||||
if (ok_ && !qFuzzyCompare(1 + mrtd.width_mm_, 1 + width_))
|
||||
qreal width_ = 0;
|
||||
QString entry_;
|
||||
if (role == CatalogEntryRole)
|
||||
{
|
||||
//Chosen in the list : the width and the terminal of the catalog
|
||||
const auto map_ = value.toMap();
|
||||
width_ = map_.value(QStringLiteral("mm")).toDouble(&ok_);
|
||||
ok_ = ok_ && width_ >= 0;
|
||||
entry_ = map_.value(QStringLiteral("entry")).toString();
|
||||
}
|
||||
else
|
||||
{
|
||||
//Typed or pasted : "6.2", or "6,2 - Phoenix Contact ST 4" as copied from this column
|
||||
const auto text_ = value.toString();
|
||||
const auto separator_ = text_.indexOf(QStringLiteral(" - "));
|
||||
width_ = parsePositiveNumber(separator_ < 0 ? text_ : text_.left(separator_), &ok_);
|
||||
if (ok_ && separator_ >= 0) {
|
||||
entry_ = text_.mid(separator_ + 3).trimmed();
|
||||
}
|
||||
}
|
||||
//Only a terminal of the catalog with this width is kept
|
||||
const auto *catalog_entry_ = TerminalCatalog::entryByLabel(entry_);
|
||||
if (!catalog_entry_ || width_ <= 0 ||
|
||||
!qFuzzyCompare(1 + catalog_entry_->mm, 1 + width_)) {
|
||||
entry_.clear();
|
||||
}
|
||||
|
||||
if (ok_ && (!qFuzzyCompare(1 + mrtd.width_mm_, 1 + width_) ||
|
||||
mrtd.catalog_entry_ != entry_))
|
||||
{
|
||||
mrtd.width_mm_ = width_;
|
||||
mrtd.catalog_entry_ = entry_;
|
||||
modified_ = true;
|
||||
modified_cell = WIDTH_CELL;
|
||||
}
|
||||
@@ -937,6 +976,15 @@ TerminalStripModelDelegate::TerminalStripModelDelegate(QObject *parent) :
|
||||
QStyledItemDelegate(parent)
|
||||
{}
|
||||
|
||||
/**
|
||||
* @brief TerminalStripModelDelegate::setManufacturer
|
||||
* @param manufacturer : manufacturer of the terminals proposed
|
||||
* in the Width column, an empty string proposes all the manufacturers.
|
||||
*/
|
||||
void TerminalStripModelDelegate::setManufacturer(const QString &manufacturer) {
|
||||
m_manufacturer = manufacturer;
|
||||
}
|
||||
|
||||
QWidget *TerminalStripModelDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
if (index.column() == TYPE_CELL) {
|
||||
@@ -980,23 +1028,29 @@ QWidget *TerminalStripModelDelegate::createEditor(QWidget *parent, const QStyleO
|
||||
qcb->setObjectName(QStringLiteral("terminal_width"));
|
||||
qcb->addItem(tr("None (default)"), 0.0);
|
||||
|
||||
// Show manufacturer products compatible with the section selected in this row.
|
||||
// Show the terminals of the selected manufacturer (all if none),
|
||||
// compatible with the section selected in this row.
|
||||
const auto manufacturer_ok = [this](const TerminalCatalog::WidthEntry &entry) {
|
||||
return m_manufacturer.isEmpty() || m_manufacturer == QString::fromUtf8(entry.manufacturer);
|
||||
};
|
||||
const auto section_index = index.sibling(index.row(), SECTION_CELL);
|
||||
bool section_ok = false;
|
||||
const auto section = parsePositiveNumber(section_index.data(Qt::EditRole).toString(), §ion_ok);
|
||||
bool has_compatible_entry = false;
|
||||
if (section_ok && section > 0.0) {
|
||||
for (const auto &entry : TerminalCatalog::widthEntries()) {
|
||||
if (qFuzzyCompare(1 + entry.section, 1 + section)) {
|
||||
qcb->addItem(widthItemText(entry.mm, QString::fromUtf8(entry.label)), entry.mm);
|
||||
if (manufacturer_ok(entry) && qFuzzyCompare(1 + entry.section, 1 + section)) {
|
||||
has_compatible_entry = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// If the section has no catalog match (or is unspecified), keep all widths available.
|
||||
if (!has_compatible_entry) {
|
||||
for (const auto &entry : TerminalCatalog::widthEntries()) {
|
||||
// If the section has no catalog match (or is unspecified), keep all widths available.
|
||||
for (const auto &entry : TerminalCatalog::widthEntries()) {
|
||||
if (manufacturer_ok(entry) &&
|
||||
(!has_compatible_entry || qFuzzyCompare(1 + entry.section, 1 + section))) {
|
||||
qcb->addItem(widthItemText(entry.mm, QString::fromUtf8(entry.label)), entry.mm);
|
||||
qcb->setItemData(qcb->count() - 1, QString::fromUtf8(entry.label), TerminalStripModel::CatalogEntryRole);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1077,18 +1131,26 @@ void TerminalStripModelDelegate::setEditorData(QWidget *editor, const QModelInde
|
||||
{
|
||||
bool ok_ = false;
|
||||
const auto width_ = parsePositiveNumber(index.data(Qt::EditRole).toString(), &ok_);
|
||||
auto pos_ = -1;
|
||||
for (auto i = 0 ; i < qcb->count() ; ++i)
|
||||
const auto entry_ = index.data(TerminalStripModel::CatalogEntryRole).toString();
|
||||
//The terminal chosen in the catalog. A width typed or set before
|
||||
//the catalog entry was stored is not tied to a terminal of the
|
||||
//catalog : it must not take the first one with the same width.
|
||||
auto pos_ = entry_.isEmpty() ? -1 : qcb->findData(entry_, TerminalStripModel::CatalogEntryRole);
|
||||
for (auto i = 0 ; pos_ < 0 && entry_.isEmpty() && i < qcb->count() ; ++i)
|
||||
{
|
||||
if (qFuzzyCompare(1 + qcb->itemData(i).toDouble(), 1 + width_)) {
|
||||
if (qcb->itemData(i, TerminalStripModel::CatalogEntryRole).toString().isEmpty() &&
|
||||
qFuzzyCompare(1 + qcb->itemData(i).toDouble(), 1 + width_)) {
|
||||
pos_ = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (pos_ < 0)
|
||||
{
|
||||
//The width is not in the list (typed or pasted), keep it in the list
|
||||
qcb->addItem(widthItemText(width_), width_);
|
||||
//The width or the terminal is not in the list
|
||||
//(typed, pasted, or another manufacturer), keep it in the list
|
||||
qcb->addItem(widthItemText(width_, entry_), width_);
|
||||
if (!entry_.isEmpty()) {
|
||||
qcb->setItemData(qcb->count() - 1, entry_, TerminalStripModel::CatalogEntryRole);
|
||||
}
|
||||
pos_ = qcb->count() - 1;
|
||||
}
|
||||
qcb->setCurrentIndex(pos_);
|
||||
@@ -1124,7 +1186,10 @@ void TerminalStripModelDelegate::setModelData(QWidget *editor, QAbstractItemMode
|
||||
else if (editor->objectName() == QLatin1String("terminal_width"))
|
||||
{
|
||||
if (auto qcb = dynamic_cast<QComboBox *>(editor)) {
|
||||
model->setData(index, qcb->currentData().toDouble(), Qt::EditRole);
|
||||
QVariantMap map_;
|
||||
map_.insert(QStringLiteral("mm"), qcb->currentData().toDouble());
|
||||
map_.insert(QStringLiteral("entry"), qcb->currentData(TerminalStripModel::CatalogEntryRole).toString());
|
||||
model->setData(index, map_, TerminalStripModel::CatalogEntryRole);
|
||||
}
|
||||
}
|
||||
else if (editor->objectName() == QLatin1String("terminal_color"))
|
||||
|
||||
@@ -72,6 +72,10 @@ class TerminalStripModel : public QAbstractTableModel
|
||||
static int levelForColumn(TerminalStripModel::Column column);
|
||||
static TerminalStripModel::Column columnTypeForIndex(const QModelIndex &index);
|
||||
|
||||
///Role of the Width column : the label of the terminal chosen in the catalog.
|
||||
///setData() with this role takes a QVariantMap {"mm": width, "entry": label}
|
||||
static constexpr int CatalogEntryRole = Qt::UserRole + 1;
|
||||
|
||||
Q_OBJECT
|
||||
public:
|
||||
TerminalStripModel(TerminalStrip *terminal_strip, QObject *parent = nullptr);
|
||||
@@ -137,6 +141,12 @@ class TerminalStripModelDelegate : public QStyledItemDelegate
|
||||
const QModelIndex &index) const override;
|
||||
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||
|
||||
void setManufacturer(const QString &manufacturer);
|
||||
|
||||
private:
|
||||
///Manufacturer of the terminals proposed in the Width column, empty = all
|
||||
QString m_manufacturer;
|
||||
};
|
||||
|
||||
#endif // TERMINALSTRIPMODEL_H
|
||||
|
||||
@@ -160,6 +160,42 @@ QString colorSpec(const QComboBox *cb)
|
||||
return cb->property("origSpec").toString();
|
||||
}
|
||||
|
||||
/// Role of the width combo items holding the label of the catalog entry
|
||||
const int CatalogEntryRole = Qt::UserRole + 1;
|
||||
|
||||
/// Label of the catalog entry selected in the width combo,
|
||||
/// empty if the width was typed or "None" is selected.
|
||||
QString catalogEntry(const QComboBox *cb)
|
||||
{
|
||||
const auto index = cb->findText(cb->currentText());
|
||||
return index > 0 ? cb->itemData(index, CatalogEntryRole).toString() : QString();
|
||||
}
|
||||
|
||||
/// Select the item of the catalog entry @a label in the width combo.
|
||||
/// @return false if the combo has no such item
|
||||
bool selectCatalogEntry(QComboBox *cb, const QString &label)
|
||||
{
|
||||
if (label.isEmpty())
|
||||
return false;
|
||||
const auto index = cb->findData(label, CatalogEntryRole);
|
||||
if (index < 0)
|
||||
return false;
|
||||
cb->setCurrentIndex(index);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Set a width not tied to a terminal of the catalog (typed, or stored before
|
||||
/// the catalog entry was) : written as text, so that it doesn't take the first
|
||||
/// terminal of the catalog with the same width.
|
||||
void setPlainWidth(QComboBox *cb, double width, const QString &suffix)
|
||||
{
|
||||
if (width <= 0) {
|
||||
cb->setCurrentIndex(0);
|
||||
return;
|
||||
}
|
||||
cb->setCurrentText(QLocale().toString(width, 'g', 6) + suffix);
|
||||
}
|
||||
|
||||
/// Set the text of an editable combo : select the item with this value or write the value.
|
||||
void setComboValue(QComboBox *cb, double value, const QString &suffix)
|
||||
{
|
||||
@@ -287,7 +323,8 @@ void ElementPropertiesEditorWidget::upDateInterface()
|
||||
//Section (mm2) and width (mm), stored with the dot as decimal separator
|
||||
populateTerminalSizeCombos(
|
||||
info.value(RealTerminal::sectionInfoKey()).toString().toDouble(),
|
||||
info.value(RealTerminal::widthInfoKey()).toString().toDouble());
|
||||
info.value(RealTerminal::widthInfoKey()).toString().toDouble(),
|
||||
info.value(RealTerminal::catalogEntryInfoKey()).toString());
|
||||
populateTerminalColorCombo(info.value(RealTerminal::colorInfoKey()).toString());
|
||||
}
|
||||
|
||||
@@ -477,9 +514,12 @@ void ElementPropertiesEditorWidget::populateTree()
|
||||
@brief ElementPropertiesEditorWidget::populateTerminalSizeCombos
|
||||
Fill the section and width combo boxes of the terminal group box
|
||||
and select @a section (mm2) and @a width (mm), 0 means "none".
|
||||
If the width was chosen in the catalog, @a catalog_entry is the label
|
||||
of the entry : its manufacturer and the entry itself are selected,
|
||||
not only the first terminal of the catalog with the same width.
|
||||
The combo boxes are editable : a value not in the list can be typed.
|
||||
*/
|
||||
void ElementPropertiesEditorWidget::populateTerminalSizeCombos(double section, double width)
|
||||
void ElementPropertiesEditorWidget::populateTerminalSizeCombos(double section, double width, const QString &catalog_entry)
|
||||
{
|
||||
QSignalBlocker blocker(ui->m_terminal_section_cb);
|
||||
ui->m_terminal_section_cb->clear();
|
||||
@@ -506,6 +546,10 @@ void ElementPropertiesEditorWidget::populateTerminalSizeCombos(double section, d
|
||||
for (const auto &name_ : TerminalCatalog::manufacturers()) {
|
||||
man_cb->addItem(name_, name_);
|
||||
}
|
||||
//Select the manufacturer of the terminal chosen in the catalog
|
||||
const auto *entry_ = TerminalCatalog::entryByLabel(catalog_entry);
|
||||
const auto entry_index_ = entry_ ? man_cb->findData(QString::fromUtf8(entry_->manufacturer)) : -1;
|
||||
man_cb->setCurrentIndex(entry_index_ > 0 ? entry_index_ : 0);
|
||||
}
|
||||
connect(ui->m_terminal_section_cb, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
||||
this, [this]() { refreshTerminalWidthCombo(); });
|
||||
@@ -513,7 +557,9 @@ void ElementPropertiesEditorWidget::populateTerminalSizeCombos(double section, d
|
||||
this, [this]() { refreshTerminalWidthCombo(); });
|
||||
|
||||
refreshTerminalWidthCombo();
|
||||
setComboValue(ui->m_terminal_width_cb, width, tr(" mm"));
|
||||
if (!selectCatalogEntry(ui->m_terminal_width_cb, catalog_entry)) {
|
||||
setPlainWidth(ui->m_terminal_width_cb, width, tr(" mm"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -562,6 +608,7 @@ void ElementPropertiesEditorWidget::populateTerminalColorCombo(const QString &sp
|
||||
void ElementPropertiesEditorWidget::refreshTerminalWidthCombo()
|
||||
{
|
||||
const auto current_width = comboValue(ui->m_terminal_width_cb);
|
||||
const auto current_entry = catalogEntry(ui->m_terminal_width_cb);
|
||||
const auto section = comboValue(ui->m_terminal_section_cb);
|
||||
|
||||
auto item_text = [](const TerminalCatalog::WidthEntry &entry) {
|
||||
@@ -593,9 +640,13 @@ void ElementPropertiesEditorWidget::refreshTerminalWidthCombo()
|
||||
if (manufacturer_ok(entry)
|
||||
&& (!has_compatible_entry || qFuzzyCompare(1 + entry.section, 1 + section))) {
|
||||
ui->m_terminal_width_cb->addItem(item_text(entry), entry.mm);
|
||||
ui->m_terminal_width_cb->setItemData(ui->m_terminal_width_cb->count() - 1,
|
||||
QString::fromUtf8(entry.label), CatalogEntryRole);
|
||||
}
|
||||
}
|
||||
setComboValue(ui->m_terminal_width_cb, current_width, tr(" mm"));
|
||||
if (!selectCatalogEntry(ui->m_terminal_width_cb, current_entry)) {
|
||||
setPlainWidth(ui->m_terminal_width_cb, current_width, tr(" mm"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -675,6 +726,11 @@ void ElementPropertiesEditorWidget::on_m_buttonBox_accepted()
|
||||
else
|
||||
m_data.m_informations.remove(RealTerminal::widthInfoKey());
|
||||
|
||||
//The terminal chosen in the catalog, its manufacturer and its reference
|
||||
//(written only if the user didn't type them, after the tree is read)
|
||||
RealTerminal::applyCatalogEntry(m_data.m_informations,
|
||||
width_ > 0 ? catalogEntry(ui->m_terminal_width_cb) : QString());
|
||||
|
||||
const auto color_ = colorSpec(ui->m_terminal_color_cb);
|
||||
if (!color_.isEmpty())
|
||||
m_data.m_informations.addValue(RealTerminal::colorInfoKey(), color_);
|
||||
|
||||
@@ -81,7 +81,7 @@ class ElementPropertiesEditorWidget : public QDialog
|
||||
void createPlcConfigWidgets();
|
||||
void populatePlcTable();
|
||||
void readPlcTable();
|
||||
void populateTerminalSizeCombos(double section, double width);
|
||||
void populateTerminalSizeCombos(double section, double width, const QString &catalog_entry);
|
||||
void refreshTerminalWidthCombo();
|
||||
void populateTerminalColorCombo(const QString &spec);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user