mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-17 11:24:14 +02:00
Terminal sections: show the AWG equivalent in the section lists
Linux build and tests / Build and test (Qt 6, Debug) (push) Failing after 1m42s
Linux build and tests / Build and test (Qt 6, Debug) (push) Failing after 1m42s
The section combo boxes of the terminal strip editor and of the element editor now show the nearest AWG / kcmil size next to the section in mm2, for example "2.5 mm² (AWG 14)". The correspondence is approximate (the two systems don't have the same steps) and is stored in TerminalCatalog::awgForSection(). The stored value is unchanged (terminal_section, in mm2).
This commit is contained in:
@@ -18,6 +18,8 @@
|
||||
#ifndef TERMINALCATALOG_H
|
||||
#define TERMINALCATALOG_H
|
||||
|
||||
#include <QLocale>
|
||||
#include <QString>
|
||||
#include <QVector>
|
||||
|
||||
/**
|
||||
@@ -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<WidthEntry> &widthEntries()
|
||||
{
|
||||
static const QVector<WidthEntry> entries_ {
|
||||
|
||||
@@ -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_);
|
||||
|
||||
@@ -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²"));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user