66 lines
1.7 KiB
C++
66 lines
1.7 KiB
C++
|
|
#include "graphicsItem/functionModelItem/electricFunctionModelPortItem.h"
|
||
|
|
#include "graphicsItem/itemPort.h"
|
||
|
|
#include "baseProperty.h"
|
||
|
|
#include <QPainter>
|
||
|
|
#include <QStyleOption>
|
||
|
|
#include <QJsonArray>
|
||
|
|
|
||
|
|
ElectricFunctionModelPortItem::ElectricFunctionModelPortItem(QGraphicsItem *parent)
|
||
|
|
: GraphicsFunctionModelItem(parent)
|
||
|
|
{
|
||
|
|
initial();
|
||
|
|
}
|
||
|
|
|
||
|
|
ElectricFunctionModelPortItem::~ElectricFunctionModelPortItem()
|
||
|
|
{
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
QRectF ElectricFunctionModelPortItem::boundingRect() const
|
||
|
|
{
|
||
|
|
return m_boundingRect;
|
||
|
|
}
|
||
|
|
|
||
|
|
void ElectricFunctionModelPortItem::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();
|
||
|
|
obj["extraInfo"] = _property->getVoltageLevel();
|
||
|
|
_property->setContext(obj);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
void ElectricFunctionModelPortItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
|
||
|
|
{
|
||
|
|
painter->setBrush(m_brush);
|
||
|
|
painter->drawEllipse(m_boundingRect);
|
||
|
|
}
|
||
|
|
|
||
|
|
void ElectricFunctionModelPortItem::initial()
|
||
|
|
{
|
||
|
|
m_boundingRect = QRectF(-1,-1,2,2);
|
||
|
|
m_pen = QPen(Qt::black);
|
||
|
|
m_brush = QBrush(Qt::black);
|
||
|
|
setHandleVisible(false);
|
||
|
|
setFunctionHandleIfShow(false);
|
||
|
|
setFunctionHandleEnaable(false);
|
||
|
|
}
|