mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
TerminalStripItem : Draw terminal bridge
This commit is contained in:
@@ -20,6 +20,7 @@
|
|||||||
#include "../physicalterminal.h"
|
#include "../physicalterminal.h"
|
||||||
#include "../realterminal.h"
|
#include "../realterminal.h"
|
||||||
#include "../terminalstrip.h"
|
#include "../terminalstrip.h"
|
||||||
|
#include "../terminalstripbridge.h"
|
||||||
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
@@ -79,10 +80,13 @@ void TerminalStripDrawer::paint(QPainter *painter)
|
|||||||
//Move painter pos to next drawing
|
//Move painter pos to next drawing
|
||||||
painter->translate(m_pattern.m_header_rect.width(),0);
|
painter->translate(m_pattern.m_header_rect.width(),0);
|
||||||
|
|
||||||
|
int x_offset{m_pattern.m_header_rect.width()};
|
||||||
|
|
||||||
//Draw spacer
|
//Draw spacer
|
||||||
painter->drawRect(m_pattern.m_spacer_rect);
|
painter->drawRect(m_pattern.m_spacer_rect);
|
||||||
//Move painter pos to next drawing
|
//Move painter pos to next drawing
|
||||||
painter->translate(m_pattern.m_spacer_rect.width(),0);
|
painter->translate(m_pattern.m_spacer_rect.width(),0);
|
||||||
|
x_offset += m_pattern.m_spacer_rect.width();
|
||||||
|
|
||||||
|
|
||||||
//Draw terminals
|
//Draw terminals
|
||||||
@@ -91,6 +95,8 @@ void TerminalStripDrawer::paint(QPainter *painter)
|
|||||||
const auto terminals_text_option{m_pattern.terminalsTextOption()};
|
const auto terminals_text_option{m_pattern.terminalsTextOption()};
|
||||||
QRect terminal_rect;
|
QRect terminal_rect;
|
||||||
|
|
||||||
|
QHash<QUuid, QVector<QPointF>> bridges_anchor_points;
|
||||||
|
|
||||||
//Loop over physical terminals
|
//Loop over physical terminals
|
||||||
for (const auto &physical_t : m_strip->physicalTerminal())
|
for (const auto &physical_t : m_strip->physicalTerminal())
|
||||||
{
|
{
|
||||||
@@ -108,6 +114,7 @@ void TerminalStripDrawer::paint(QPainter *painter)
|
|||||||
}
|
}
|
||||||
|
|
||||||
terminal_rect = m_pattern.m_terminal_rect[index_];
|
terminal_rect = m_pattern.m_terminal_rect[index_];
|
||||||
|
//Draw terminal rect
|
||||||
painter->drawRect(terminal_rect);
|
painter->drawRect(terminal_rect);
|
||||||
|
|
||||||
//Draw text
|
//Draw text
|
||||||
@@ -130,12 +137,44 @@ void TerminalStripDrawer::paint(QPainter *painter)
|
|||||||
terminals_text_option[index_]);
|
terminals_text_option[index_]);
|
||||||
painter->restore();
|
painter->restore();
|
||||||
|
|
||||||
|
//Add bridge anchor
|
||||||
|
if (shared_real_terminal->isBridged())
|
||||||
|
{
|
||||||
|
painter->save();
|
||||||
|
if (const auto bridge_ = shared_real_terminal->bridge())
|
||||||
|
{
|
||||||
|
const auto anchor_center{m_pattern.m_bridge_point_d/2};
|
||||||
|
painter->setBrush(Qt::SolidPattern);
|
||||||
|
painter->drawEllipse(QPointF{terminal_rect.width()/2, m_pattern.m_bridge_point_y_offset[index_]},
|
||||||
|
anchor_center,
|
||||||
|
anchor_center);
|
||||||
|
|
||||||
|
auto anchor_points{bridges_anchor_points.value(bridge_->uuid())};
|
||||||
|
anchor_points.append(QPointF{x_offset + terminal_rect.width()/2,
|
||||||
|
m_pattern.m_bridge_point_y_offset[index_]});
|
||||||
|
bridges_anchor_points.insert(bridge_->uuid(), anchor_points);
|
||||||
|
}
|
||||||
|
painter->restore();
|
||||||
|
}
|
||||||
|
|
||||||
//Move painter pos to next drawing
|
//Move painter pos to next drawing
|
||||||
painter->translate(terminal_rect.width(),0);
|
painter->translate(terminal_rect.width(),0);
|
||||||
|
x_offset += terminal_rect.width();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
painter->restore();
|
painter->restore();
|
||||||
|
|
||||||
|
//Draw the bridges
|
||||||
|
for (const auto &points_ : qAsConst(bridges_anchor_points))
|
||||||
|
{
|
||||||
|
painter->save();
|
||||||
|
auto pen_{painter->pen()};
|
||||||
|
pen_.setWidth(2);
|
||||||
|
painter->setPen(pen_);
|
||||||
|
painter->drawPolyline(QPolygonF{points_});
|
||||||
|
painter->restore();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -120,6 +120,14 @@ void TerminalStripBridge::fromXml(const QDomElement &dom_element)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TerminalStripBridge::uuid
|
||||||
|
* @return The uuid of this terminal
|
||||||
|
*/
|
||||||
|
QUuid TerminalStripBridge::uuid() const noexcept {
|
||||||
|
return m_uuid;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief TerminalStripBridge::addTerminals
|
* @brief TerminalStripBridge::addTerminals
|
||||||
* @param real_terminals
|
* @param real_terminals
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ class TerminalStripBridge
|
|||||||
static QString xmlTagName() {return QStringLiteral("terminal_strip_bridge");}
|
static QString xmlTagName() {return QStringLiteral("terminal_strip_bridge");}
|
||||||
QDomElement toXml(QDomDocument &parent_document) const;
|
QDomElement toXml(QDomDocument &parent_document) const;
|
||||||
void fromXml(const QDomElement &dom_element);
|
void fromXml(const QDomElement &dom_element);
|
||||||
|
QUuid uuid() const noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool addTerminals(const QVector<QSharedPointer<RealTerminal>> &real_terminals);
|
bool addTerminals(const QVector<QSharedPointer<RealTerminal>> &real_terminals);
|
||||||
|
|||||||
Reference in New Issue
Block a user