diff --git a/sources/TerminalStrip/terminalcatalog.h b/sources/TerminalStrip/terminalcatalog.h index 5c48939b7..80a5398ac 100644 --- a/sources/TerminalStrip/terminalcatalog.h +++ b/sources/TerminalStrip/terminalcatalog.h @@ -18,6 +18,8 @@ #ifndef TERMINALCATALOG_H #define TERMINALCATALOG_H +#include +#include #include /** @@ -41,6 +43,51 @@ namespace TerminalCatalog return sections_; } + /** + * @brief awgForSection + * @param mm2 : a section in mm2 + * @return the nearest AWG / kcmil size, as text ("14", "1/0", "250 kcmil"), + * or an empty string if the section has no usual equivalent. + * The correspondence is approximate (the usual table of the manufacturers), + * the two systems don't have the same steps. + */ + inline QString awgForSection(double mm2) + { + struct Awg { double mm2; const char *awg; }; + static const Awg table_[] { + {0.5, "20"}, {0.75, "18"}, {1, "17"}, + {1.5, "16"}, {2.5, "14"}, {4, "12"}, + {6, "10"}, {10, "8"}, {16, "6"}, + {25, "4"}, {35, "2"}, {50, "1/0"}, + {70, "2/0"}, {95, "3/0"}, {120, "250 kcmil"}, + {150, "300 kcmil"}, {185, "350 kcmil"}, {240, "500 kcmil"}, + {300, "600 kcmil"} + }; + for (const auto &entry : table_) { + if (qAbs(entry.mm2 - mm2) < 0.0001) { + return QString::fromLatin1(entry.awg); + } + } + return QString(); + } + + /** + * @brief sectionText + * @param mm2 : a section in mm2 + * @param unit_text : the text of the section with its unit, for example "2,5 mm²" + * @return @a unit_text followed by the AWG size if there is one : "2,5 mm² (AWG 14)" + */ + inline QString sectionText(double mm2, const QString &unit_text) + { + const auto awg_ = awgForSection(mm2); + if (awg_.isEmpty()) { + return unit_text; + } + return awg_.contains(QLatin1String("kcmil")) + ? unit_text + QStringLiteral(" (%1)").arg(awg_) + : unit_text + QStringLiteral(" (AWG %1)").arg(awg_); + } + inline const QVector &widthEntries() { static const QVector entries_ { diff --git a/sources/TerminalStrip/ui/terminalstripmodel.cpp b/sources/TerminalStrip/ui/terminalstripmodel.cpp index 0cf0f3d04..029647257 100644 --- a/sources/TerminalStrip/ui/terminalstripmodel.cpp +++ b/sources/TerminalStrip/ui/terminalstripmodel.cpp @@ -956,7 +956,7 @@ QWidget *TerminalStripModelDelegate::createEditor(QWidget *parent, const QStyleO qcb->addItem(tr("None (default)"), 0.0); //Usual sections, in mm2 for (const auto section_ : TerminalCatalog::sections()) { - qcb->addItem(tr("%1 mm²").arg(QLocale().toString(section_, 'g', 6)), section_); + qcb->addItem(TerminalCatalog::sectionText(section_, tr("%1 mm²").arg(QLocale().toString(section_, 'g', 6))), section_); } return qcb; @@ -1048,7 +1048,7 @@ void TerminalStripModelDelegate::setEditorData(QWidget *editor, const QModelInde if (pos_ < 0) { //The section is not in the list (typed or pasted), keep it in the list - qcb->addItem(tr("%1 mm²").arg(QLocale().toString(section_, 'g', 6)), section_); + qcb->addItem(TerminalCatalog::sectionText(section_, tr("%1 mm²").arg(QLocale().toString(section_, 'g', 6))), section_); pos_ = qcb->count() - 1; } qcb->setCurrentIndex(pos_); diff --git a/sources/editor/ui/elementpropertieseditorwidget.cpp b/sources/editor/ui/elementpropertieseditorwidget.cpp index d06823b9b..1dc7de82d 100644 --- a/sources/editor/ui/elementpropertieseditorwidget.cpp +++ b/sources/editor/ui/elementpropertieseditorwidget.cpp @@ -440,7 +440,9 @@ void ElementPropertiesEditorWidget::populateTerminalSizeCombos(double section, d ui->m_terminal_section_cb->clear(); ui->m_terminal_section_cb->addItem(tr("None (default)"), 0.0); for (const auto section_ : TerminalCatalog::sections()) { - ui->m_terminal_section_cb->addItem(tr("%1 mm²").arg(QLocale().toString(section_, 'g', 6)), section_); + ui->m_terminal_section_cb->addItem( + TerminalCatalog::sectionText(section_, tr("%1 mm²").arg(QLocale().toString(section_, 'g', 6))), + section_); } setComboValue(ui->m_terminal_section_cb, section, tr(" mm²"));