Show the NO/NC/SW contact breakdown in a master's General tab

Requested in #819: after drawing a schematic you need to know how many
NO, NC and changeover contacts a coil ended up using, so you can pick an
auxiliary block that satisfies it. Until now the General tab reported
only a single total, and counting the contacts by type meant counting
rows on the cross reference by hand.

Three changes to that block:

 - the used count now counts contacts rather than linked elements. The
   label already said "contacts" while the value was
   linkedElements().count(), so a slave standing for several contacts
   was under-reported. It reads MasterElement::contactUsage(), the
   same count isFull() uses.

 - a breakdown line is added below it, printed only when the master
   actually has contacts to break down.

 - a declared limit of -1 means "no limit set" rather than a real
   limit, so it is printed as such instead of showing "-1", which
   reads as a bad value.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
ispyisail
2026-09-09 10:36:25 +12:00
parent c33f250910
commit c39c7414cf
+29 -3
View File
@@ -23,6 +23,7 @@
#include "../qetgraphicsitem/dynamicelementtextitem.h"
#include "../qetgraphicsitem/element.h"
#include "../qetgraphicsitem/elementtextitemgroup.h"
#include "../qetgraphicsitem/masterelement.h"
#include "../qeticons.h"
#include "dynamicelementtextitemeditor.h"
#include "elementinfowidget.h"
@@ -380,9 +381,34 @@ QWidget *ElementPropertiesWidget::generalWidget()
description_string += QString(tr("Rotation : %1°\n")).arg(m_element.data()->rotation());
description_string += QString(tr("Dimensions : %1*%2\n")).arg(m_element -> size().width()).arg(m_element -> size().height());
description_string += QString(tr("Bornes : %1\n")).arg(m_element -> terminals().count());
if (m_element->linkType() == Element::Master){
description_string += QString(tr("Nombre maximum de contacts esclaves définis : %1\n")).arg(m_element -> elementData().m_max_slaves);
description_string += QString(tr("Nombre de contacts esclaves utilisés : %1\n")).arg(m_element ->linkedElements().count());
if (m_element->linkType() == Element::Master)
{
//The declared limit is optional: -1 means the element sets no
//limit at all, which is worth saying rather than printing "-1".
const int max_slaves = m_element->elementData().m_max_slaves;
description_string += max_slaves == -1
? QString(tr("Nombre maximum de contacts esclaves définis : non défini\n"))
: QString(tr("Nombre maximum de contacts esclaves définis : %1\n")).arg(max_slaves);
//Counted in contacts rather than in linked elements, so that a
//slave standing for several contacts is reported as the number
//of contacts it actually uses.
const ContactUsage usage =
static_cast<MasterElement *>(m_element.data())->contactUsage();
description_string += QString(tr("Nombre de contacts esclaves utilisés : %1\n")).arg(usage.total());
//The breakdown is what tells you which auxiliary block would
//satisfy this coil, so it is only worth printing once there is
//something to break down.
if (usage.total() > 0)
{
description_string += QString(tr(" NO : %1, NC : %2, inverseurs : %3, autres : %4\n"))
.arg(usage.no)
.arg(usage.nc)
.arg(usage.sw)
.arg(usage.other);
}
}
description_string += QString(tr("Emplacement : %1\n")).arg(m_element.data()->location().toString());