76 lines
1.9 KiB
C++
76 lines
1.9 KiB
C++
#include "baseModelItem/electricBaseModelPortItem.h"
|
|
#include "graphicsItem/itemPort.h"
|
|
#include "baseProperty.h"
|
|
#include <QPainter>
|
|
#include <QStyleOption>
|
|
#include <QJsonArray>
|
|
|
|
ElectricBaseModelPortItem::ElectricBaseModelPortItem(QGraphicsItem *parent)
|
|
: GraphicsBaseModelItem(parent)
|
|
{
|
|
m_boundingRect = QRectF(-1,-1,2,2);
|
|
m_pen = QPen(Qt::black);
|
|
m_brush = QBrush(Qt::black);
|
|
setHandleVisible(false);
|
|
setFunctionHandleIfShow(false);
|
|
setFunctionHandleEnaable(false);
|
|
}
|
|
|
|
ElectricBaseModelPortItem::ElectricBaseModelPortItem(const ElectricBaseModelPortItem& obj)
|
|
:GraphicsBaseModelItem(obj)
|
|
{
|
|
m_boundingRect = QRectF(-1,-1,2,2);
|
|
m_pen = QPen(Qt::black);
|
|
m_brush = QBrush(Qt::black);
|
|
setHandleVisible(false);
|
|
setFunctionHandleIfShow(false);
|
|
setFunctionHandleEnaable(false);
|
|
}
|
|
|
|
ElectricBaseModelPortItem* ElectricBaseModelPortItem::clone() const
|
|
{
|
|
return new ElectricBaseModelPortItem(*this);
|
|
}
|
|
|
|
ElectricBaseModelPortItem::~ElectricBaseModelPortItem()
|
|
{
|
|
|
|
}
|
|
|
|
QRectF ElectricBaseModelPortItem::boundingRect() const
|
|
{
|
|
return m_boundingRect;
|
|
}
|
|
|
|
void ElectricBaseModelPortItem::updateConnectData()
|
|
{
|
|
QJsonObject obj;
|
|
QJsonArray arr;
|
|
if(_property)
|
|
{
|
|
for(auto ptr:m_mapPort)
|
|
{
|
|
//if(ptr->connected())
|
|
{
|
|
QJsonObject port;
|
|
port["portId"] = ptr->getId();
|
|
auto pLine = ptr->getConnectPtr();
|
|
port["x"] = ptr->pos().x();
|
|
port["y"] = ptr->pos().y();
|
|
port["portType"] = ptr->getType();
|
|
arr.push_back(port);
|
|
}
|
|
}
|
|
|
|
obj["port"] = arr;
|
|
obj["metaModel"] = _property->metaModelName();
|
|
_property->setContext(obj);
|
|
}
|
|
}
|
|
|
|
void ElectricBaseModelPortItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
|
|
{
|
|
painter->setBrush(m_brush);
|
|
painter->drawEllipse(m_boundingRect);
|
|
}
|