Improve terminal_strip
Linux build and tests / Build and test (Qt 6, Debug) (push) Failing after 1m45s

This commit is contained in:
Laurent Trinques
2026-10-15 16:26:45 +02:00
parent e883d2c3bf
commit 8d59d25796
2 changed files with 86 additions and 21 deletions
@@ -468,6 +468,52 @@ TerminalColors terminalColors(const QSharedPointer<AbstractRealTerminalInterface
}
}
/**
* @brief drawTerminalBody Draw a terminal housing with simple connection details.
* The details are deliberately schematic and scale with the terminal width.
*/
void drawTerminalBody(QPainter *painter, const QRectF &rect)
{
if (rect.width() <= 0 || rect.height() <= 0) {
return;
}
const qreal bevel = qMin(qreal(2.0), rect.width() * 0.12);
QPolygonF housing;
housing << QPointF(rect.left() + bevel, rect.top())
<< QPointF(rect.right() - bevel, rect.top())
<< QPointF(rect.right(), rect.top() + bevel)
<< QPointF(rect.right(), rect.bottom() - bevel)
<< QPointF(rect.right() - bevel, rect.bottom())
<< QPointF(rect.left() + bevel, rect.bottom())
<< QPointF(rect.left(), rect.bottom() - bevel)
<< QPointF(rect.left(), rect.top() + bevel);
painter->drawPolygon(housing);
// Fine inner edge to give the housing some depth.
if (rect.width() >= 5.0 && rect.height() >= 12.0) {
const qreal margin = qMin(qreal(2.0), rect.width() * 0.12);
painter->drawLine(QPointF(rect.left() + margin, rect.top() + 3.0),
QPointF(rect.right() - margin, rect.top() + 3.0));
// Schematic screw head and slot.
const qreal radius = qMin(qreal(1.8), rect.width() * 0.12);
const qreal screw_y = rect.top() + rect.height() * 0.18;
painter->drawEllipse(QPointF(rect.center().x(), screw_y), radius, radius);
painter->drawLine(QPointF(rect.center().x() - radius * 0.65, screw_y),
QPointF(rect.center().x() + radius * 0.65, screw_y));
// Wire entry / clamp mark near the lower part of the terminal.
const qreal opening_width = qMin(qreal(5.0), rect.width() * 0.28);
const qreal opening_height = qMin(qreal(2.0), rect.height() * 0.025);
if (opening_width >= 1.0 && opening_height >= 1.0) {
painter->drawRect(QRectF(rect.center().x() - opening_width / 2,
rect.top() + rect.height() * 0.78,
opening_width, opening_height));
}
}
}
/**
* @brief drawStripes
* Draw diagonal stripes of @a color inside @a rect.
@@ -631,7 +677,7 @@ void TerminalStripDrawer::paint(QPainter *painter)
if (fill_color_.isValid()) {
painter->setBrush(QBrush(fill_color_));
}
painter->drawRect(terminal_rect);
drawTerminalBody(painter, terminal_rect);
if (colors_.stripe.isValid())
{
drawStripes(painter, terminal_rect, colors_.stripe);
+39 -20
View File
@@ -917,24 +917,26 @@ namespace {
* any other width can be typed in the cell.
* For ABB Entrelec the value is the spacing (pitch) given by the catalog.
*/
struct WidthEntry { double mm; const char *label; };
struct WidthEntry { double mm; const char *label; double section; };
const WidthEntry WIDTH_ENTRIES[] {
{5.1, "Weidmüller WDU 2.5"},
{5.2, "WAGO 2002 (TOPJOB S)"},
{6.0, "ABB Entrelec M 4/6"},
{6.1, "Weidmüller WDU 4"},
{6.2, "Phoenix Contact UT 4"},
{8.0, "ABB Entrelec M 6/8, M 4/8"},
{8.2, "Phoenix Contact UT 6"},
{10.0, "ABB Entrelec M 10/10"},
{10.2, "Phoenix Contact UT 10"},
{11.9, "Weidmüller WDU 16/ZA"},
{12.2, "Phoenix Contact UT 16"},
{16.0, "Phoenix Contact UT 35, Weidmüller WDU 35N"},
{26.0, "ABB Entrelec M 35/26.FF"},
{31.0, "ABB Entrelec M 70/31.AF"},
{35.0, "ABB Entrelec M 120/35.F"},
{42.0, "ABB Entrelec M 300/42.FF"}
{5.1, "Weidmüller WDU 2.5", 2.5},
{5.2, "WAGO 2002 (TOPJOB S)", 2.5},
{6.0, "ABB Entrelec M 4/6", 4.0},
{6.1, "Weidmüller WDU 4", 4.0},
{6.2, "Phoenix Contact UT 4", 4.0},
{8.0, "ABB Entrelec M 6/8", 6.0},
{8.0, "ABB Entrelec M 4/8", 4.0},
{8.2, "Phoenix Contact UT 6", 6.0},
{10.0, "ABB Entrelec M 10/10", 10.0},
{10.2, "Phoenix Contact UT 10", 10.0},
{11.9, "Weidmüller WDU 16/ZA", 16.0},
{12.2, "Phoenix Contact UT 16", 16.0},
{16.0, "Phoenix Contact UT 35", 35.0},
{16.0, "Weidmüller WDU 35N", 35.0},
{26.0, "ABB Entrelec M 35/26.FF", 35.0},
{31.0, "ABB Entrelec M 70/31.AF", 70.0},
{35.0, "ABB Entrelec M 120/35.F", 120.0},
{42.0, "ABB Entrelec M 300/42.FF", 300.0}
};
QString widthItemText(double mm, const QString &label = QString())
@@ -980,7 +982,7 @@ QWidget *TerminalStripModelDelegate::createEditor(QWidget *parent, const QStyleO
qcb->setObjectName(QStringLiteral("terminal_section"));
qcb->addItem(tr("None (default)"), 0.0);
//Usual sections, in mm2
static const QVector<double> sections_ {0.5, 0.75, 1, 1.5, 2.5, 4, 6, 10, 16, 25, 35, 50, 70, 95, 120, 150, 185, 240};
static const QVector<double> sections_ {0.5, 0.75, 1, 1.5, 2.5, 4, 6, 10, 16, 25, 35, 50, 70, 95, 120, 150, 185, 240, 300};
for (const auto section_ : sections_) {
qcb->addItem(tr("%1 mm²").arg(QLocale().toString(section_, 'g', 6)), section_);
}
@@ -991,8 +993,25 @@ QWidget *TerminalStripModelDelegate::createEditor(QWidget *parent, const QStyleO
auto qcb = new QComboBox(parent);
qcb->setObjectName(QStringLiteral("terminal_width"));
qcb->addItem(tr("None (default)"), 0.0);
for (const auto &entry : WIDTH_ENTRIES) {
qcb->addItem(widthItemText(entry.mm, QString::fromUtf8(entry.label)), entry.mm);
// Show manufacturer products compatible with the section selected in this row.
const auto section_index = index.sibling(index.row(), SECTION_CELL);
bool section_ok = false;
const auto section = parsePositiveNumber(section_index.data(Qt::EditRole).toString(), &section_ok);
bool has_compatible_entry = false;
if (section_ok && section > 0.0) {
for (const auto &entry : WIDTH_ENTRIES) {
if (qFuzzyCompare(1 + entry.section, 1 + section)) {
qcb->addItem(widthItemText(entry.mm, QString::fromUtf8(entry.label)), entry.mm);
has_compatible_entry = true;
}
}
}
// If the section has no catalog match (or is unspecified), keep all widths available.
if (!has_compatible_entry) {
for (const auto &entry : WIDTH_ENTRIES) {
qcb->addItem(widthItemText(entry.mm, QString::fromUtf8(entry.label)), entry.mm);
}
}
return qcb;