mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-08-01 17:14:13 +02:00
Implement slave contact groups — label transfer, terminal assignment and UI fixes
This commit is contained in:
@@ -741,7 +741,9 @@ bool Element::fromXml(QDomElement &e,
|
||||
QStringLiteral("links_uuids"),
|
||||
QStringLiteral("link_uuid"));
|
||||
foreach (QDomElement qdo, uuid_list) {
|
||||
tmp_uuids_link << QUuid(qdo.attribute(QStringLiteral("uuid")));
|
||||
QUuid uuid(qdo.attribute(QStringLiteral("uuid")));
|
||||
int group_index = qdo.attribute(QStringLiteral("group_index"), QStringLiteral("-1")).toInt();
|
||||
tmp_uuids_link << LinkInfo(uuid, group_index);
|
||||
}
|
||||
|
||||
//uuid of this element
|
||||
@@ -932,6 +934,13 @@ QDomElement Element::toXml(
|
||||
QDomElement link_uuid =
|
||||
document.createElement(QStringLiteral("link_uuid"));
|
||||
link_uuid.setAttribute(QStringLiteral("uuid"), elmt->uuid().toString());
|
||||
|
||||
// Save group index if assigned (for slave->master links)
|
||||
int gi = m_group_index_map.value(elmt, -1);
|
||||
if (gi >= 0) {
|
||||
link_uuid.setAttribute(QStringLiteral("group_index"), gi);
|
||||
}
|
||||
|
||||
links_uuids.appendChild(link_uuid);
|
||||
}
|
||||
element.appendChild(links_uuids);
|
||||
@@ -1267,8 +1276,21 @@ void Element::initLink(QETProject *prj)
|
||||
if (tmp_uuids_link.isEmpty()) return;
|
||||
|
||||
ElementProvider ep(prj);
|
||||
foreach (Element *elmt, ep.fromUuids(tmp_uuids_link)) {
|
||||
elmt->linkToElement(this);
|
||||
QList<QUuid> uuids;
|
||||
for (const auto &linkInfo : tmp_uuids_link) {
|
||||
uuids.append(linkInfo.uuid);
|
||||
}
|
||||
QList<Element *> elements = ep.fromUuids(uuids);
|
||||
for (int i = 0; i < tmp_uuids_link.size(); ++i) {
|
||||
for (Element *elmt : elements) {
|
||||
if (elmt->uuid() == tmp_uuids_link[i].uuid) {
|
||||
elmt->linkToElement(this);
|
||||
if (tmp_uuids_link[i].group_index >= 0) {
|
||||
m_group_index_map[elmt] = tmp_uuids_link[i].group_index;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
tmp_uuids_link.clear();
|
||||
}
|
||||
@@ -1304,6 +1326,34 @@ QString Element::linkTypeToString() const
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Element::groupIndexForElement
|
||||
* Returns the group index assigned to the given linked element.
|
||||
* For slave elements, this indicates which contact group of the master
|
||||
* this slave is assigned to.
|
||||
* @param elmt the linked element to query
|
||||
* @return group index, or -1 if not assigned
|
||||
*/
|
||||
int Element::groupIndexForElement(Element *elmt) const
|
||||
{
|
||||
return m_group_index_map.value(elmt, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Element::setGroupIndexForElement
|
||||
* Sets the group index for a linked element.
|
||||
* @param elmt the linked element
|
||||
* @param index the group index to assign
|
||||
*/
|
||||
void Element::setGroupIndexForElement(Element *elmt, int index)
|
||||
{
|
||||
if (index >= 0) {
|
||||
m_group_index_map[elmt] = index;
|
||||
} else {
|
||||
m_group_index_map.remove(elmt);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Element::setElementInformations
|
||||
Set new information for this element.
|
||||
|
||||
@@ -62,6 +62,20 @@ class Element : public QetGraphicsItem
|
||||
Thumbnail = 64,
|
||||
ConductorDefinition = 128};
|
||||
|
||||
/**
|
||||
* @brief The LinkInfo struct
|
||||
* Stores link data for element connections.
|
||||
* For slave elements, group_index indicates which contact group
|
||||
* of the master this slave is assigned to (-1 = no group assigned).
|
||||
*/
|
||||
struct LinkInfo {
|
||||
QUuid uuid;
|
||||
int group_index = -1; ///< Index into master's slaveContactGroups, -1 = not assigned
|
||||
|
||||
LinkInfo() = default;
|
||||
LinkInfo(const QUuid &u, int gi = -1) : uuid(u), group_index(gi) {}
|
||||
};
|
||||
|
||||
Element(const ElementsLocation &location,
|
||||
QGraphicsItem * = nullptr,
|
||||
int *state = nullptr,
|
||||
@@ -181,6 +195,9 @@ class Element : public QetGraphicsItem
|
||||
virtual void initLink(QETProject *);
|
||||
QList<Element *> linkedElements ();
|
||||
|
||||
int groupIndexForElement(Element *elmt) const;
|
||||
void setGroupIndexForElement(Element *elmt, int index);
|
||||
|
||||
/**
|
||||
* @brief linkType
|
||||
* use elementData function instead
|
||||
@@ -228,7 +245,8 @@ class Element : public QetGraphicsItem
|
||||
protected:
|
||||
//ATTRIBUTES related to linked element
|
||||
QList <Element *> connected_elements;
|
||||
QList <QUuid> tmp_uuids_link;
|
||||
QList <LinkInfo> tmp_uuids_link;
|
||||
QHash <Element *, int> m_group_index_map; ///< Maps linked elements to their group index (for slave->master links)
|
||||
QUuid m_uuid;
|
||||
kind m_link_type = Element::Simple;
|
||||
|
||||
|
||||
@@ -274,7 +274,8 @@ void Terminal::paint(
|
||||
}
|
||||
|
||||
// Draw label if show_name is enabled
|
||||
if (d->m_show_name && !d->m_name.isEmpty()) {
|
||||
const QString display_name = name();
|
||||
if (d->m_show_name && !display_name.isEmpty()) {
|
||||
painter->setRenderHint(QPainter::Antialiasing, true);
|
||||
painter->setRenderHint(QPainter::TextAntialiasing, true);
|
||||
painter->setFont(d->m_label_font);
|
||||
@@ -282,7 +283,7 @@ void Terminal::paint(
|
||||
|
||||
QPointF label_pos = d->m_pos + d->m_label_pos;
|
||||
QFontMetrics fm(d->m_label_font);
|
||||
QSizeF text_size = fm.size(Qt::TextSingleLine, d->m_name);
|
||||
QSizeF text_size = fm.size(Qt::TextSingleLine, display_name);
|
||||
|
||||
if (!qFuzzyIsNull(d->m_label_rotation)) {
|
||||
painter->save();
|
||||
@@ -290,7 +291,7 @@ void Terminal::paint(
|
||||
painter->rotate(d->m_label_rotation);
|
||||
QRectF text_rect(-text_size.width()/2.0, -text_size.height()/2.0,
|
||||
text_size.width(), text_size.height());
|
||||
painter->drawText(text_rect, static_cast<int>(d->m_label_halignment | d->m_label_valignment), d->m_name);
|
||||
painter->drawText(text_rect, static_cast<int>(d->m_label_halignment | d->m_label_valignment), display_name);
|
||||
painter->restore();
|
||||
} else {
|
||||
qreal dx = 0, dy = 0;
|
||||
@@ -306,7 +307,7 @@ void Terminal::paint(
|
||||
if (d->m_label_frame) {
|
||||
painter->drawRect(text_rect.adjusted(-1, -1, 1, 1));
|
||||
}
|
||||
painter->drawText(text_rect, static_cast<int>(Qt::AlignLeft | Qt::AlignTop), d->m_name);
|
||||
painter->drawText(text_rect, static_cast<int>(Qt::AlignLeft | Qt::AlignTop), display_name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -378,12 +379,13 @@ QLineF Terminal::HelpLine() const
|
||||
@return Le rectangle (en precision flottante) delimitant la borne et ses alentours.
|
||||
*/
|
||||
QRectF Terminal::boundingRect() const {
|
||||
if (!d->m_show_name || d->m_name.isEmpty()) {
|
||||
const QString display_name = name();
|
||||
if (!d->m_show_name || display_name.isEmpty()) {
|
||||
return m_br;
|
||||
}
|
||||
|
||||
QFontMetrics fm(d->m_label_font);
|
||||
QSizeF text_size = fm.size(Qt::TextSingleLine, d->m_name);
|
||||
QSizeF text_size = fm.size(Qt::TextSingleLine, display_name);
|
||||
QPointF label_pos = d->m_pos + d->m_label_pos;
|
||||
|
||||
qreal dx = 0, dy = 0;
|
||||
@@ -808,6 +810,25 @@ QUuid Terminal::uuid() const
|
||||
|
||||
QString Terminal::name() const
|
||||
{
|
||||
if (d->m_use_master_label && parent_element_) {
|
||||
// Find the master element in the slave's linked elements
|
||||
for (Element *elmt : parent_element_->linkedElements()) {
|
||||
if (elmt->linkType() == Element::Master) {
|
||||
int group_idx = elmt->groupIndexForElement(parent_element_);
|
||||
if (group_idx >= 0) {
|
||||
const auto &groups = elmt->elementData().m_slave_contact_groups;
|
||||
if (group_idx < groups.size()) {
|
||||
int label_idx = d->m_master_label_index;
|
||||
const QStringList &labels = groups.at(group_idx).labels;
|
||||
if (label_idx >= 0 && label_idx < labels.size()) {
|
||||
return labels.at(label_idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return d->m_name;
|
||||
}
|
||||
|
||||
@@ -820,6 +841,28 @@ TerminalData::Type Terminal::terminalType() const
|
||||
return d->m_type;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Terminal::setUseMasterLabel
|
||||
Set whether this terminal uses a label from the master's contact group
|
||||
@param use true to use master label
|
||||
*/
|
||||
void Terminal::setUseMasterLabel(bool use)
|
||||
{
|
||||
d->m_use_master_label = use;
|
||||
update();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Terminal::setMasterLabelIndex
|
||||
Set the index into the master's contact group labels
|
||||
@param index the label index (0-based)
|
||||
*/
|
||||
void Terminal::setMasterLabelIndex(int index)
|
||||
{
|
||||
d->m_master_label_index = index;
|
||||
update();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Conductor::relatedPotentialTerminal
|
||||
Return terminal at the same potential from the same
|
||||
|
||||
@@ -77,6 +77,10 @@ class Terminal : public QGraphicsObject
|
||||
QUuid uuid () const;
|
||||
QString name () const;
|
||||
TerminalData::Type terminalType() const;
|
||||
bool useMasterLabel() const { return d->m_use_master_label; }
|
||||
void setUseMasterLabel(bool use);
|
||||
int masterLabelIndex() const { return d->m_master_label_index; }
|
||||
void setMasterLabelIndex(int index);
|
||||
|
||||
QList<Conductor *> conductors() const;
|
||||
Qet::Orientation orientation() const;
|
||||
|
||||
Reference in New Issue
Block a user