155 lines
4.2 KiB
C++
155 lines
4.2 KiB
C++
#include "graphicsItem/electricSvgItemRect.h"
|
|
#include "graphicsItem/itemPort.h"
|
|
|
|
#include <QPainter>
|
|
#include <QStyleOption>
|
|
#include <QGraphicsScene>
|
|
#include <QGraphicsView>
|
|
|
|
ElectricSvgItemRect::ElectricSvgItemRect(const QRect &rect, QGraphicsItem *parent)
|
|
: ElectricSvgItem(rect,parent)
|
|
,_pDlg(nullptr)
|
|
{
|
|
loadSvg(":/images/element/svg_rect.svg");
|
|
setHandleIfShow(H_textCaption,false);
|
|
setHandleIfShow(H_textCurrent,false);
|
|
setHandleIfShow(h_textVoltage,false);
|
|
setHandleVisible(false);
|
|
setFunctionHandleIfShow(false);
|
|
setFunctionHandleEnaable(false);
|
|
|
|
//入线口
|
|
ItemPort* pHandle1 = new ItemPort(this);
|
|
pHandle1->setType(T_lineIn);
|
|
pHandle1->setTag(H_connect);
|
|
pHandle1->setPortPos(P_top);
|
|
pHandle1->setParent(this);
|
|
m_vecHanle.insert(H_connect,pHandle1);
|
|
//出线口
|
|
ItemPort* pHandle2 = new ItemPort(this);
|
|
pHandle2->setType(T_lineOut);
|
|
pHandle2->setTag(H_connect+1);
|
|
pHandle2->setPortPos(P_down);
|
|
pHandle2->setParent(this);
|
|
m_vecHanle.insert(H_connect+1,pHandle2);
|
|
|
|
m_dRatioX = 0.5;
|
|
|
|
m_mapPort.insert(QString::number(_portId++),pHandle1);
|
|
m_mapPort.insert(QString::number(_portId++),pHandle2);
|
|
|
|
qRegisterMetaType<PropertyInfo>("PropertyInfo"); //注册自定义数据类型
|
|
}
|
|
|
|
ElectricSvgItemRect::~ElectricSvgItemRect()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
void ElectricSvgItemRect::updateHandles()
|
|
{
|
|
ElectricSvgItem::updateHandles();
|
|
if( m_vecHanle.contains(H_connect))
|
|
{
|
|
const QRectF& boundingRect = this->boundingRect();
|
|
|
|
if(m_vecHanle.contains(H_connect))
|
|
{
|
|
m_vecHanle[H_connect]->move(boundingRect.right() - boundingRect.width() * m_dRatioX, boundingRect.top());
|
|
}
|
|
|
|
if(m_vecHanle.contains(H_connect + 1))
|
|
{
|
|
m_vecHanle[H_connect + 1]->move(boundingRect.right() - boundingRect.width() * m_dRatioX, boundingRect.bottom());
|
|
}
|
|
}
|
|
}
|
|
|
|
void ElectricSvgItemRect::onPropertyChanged(PropertyInfo inf)
|
|
{
|
|
auto p = getProperty();
|
|
if(p)
|
|
{
|
|
p->setResistance(inf.resistance);
|
|
p->setAnchor_v(inf.anchor_v);
|
|
p->setUv_alarm(inf.uv_alarm);
|
|
p->setOv_alarm(inf.ov_alarm);
|
|
p->setAnchor_i(inf.anchor_i);
|
|
p->setUi_alarm(inf.ui_alarm);
|
|
p->setOi_alarm(inf.oi_alarm);
|
|
p->setDataChanged(true);
|
|
}
|
|
}
|
|
|
|
void ElectricSvgItemRect::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
|
|
{
|
|
ElectricSvgItem::paint(painter,option,widget);
|
|
}
|
|
|
|
void ElectricSvgItemRect::showPropertyDlg(QWidget* p)
|
|
{
|
|
auto pro = getProperty();
|
|
if(pro)
|
|
{
|
|
PropertyInfo data;
|
|
data.resistance = pro->getResistance();
|
|
data.anchor_v = pro->getAnchor_v();
|
|
data.uv_alarm = pro->getUv_alarm();
|
|
data.ov_alarm = pro->getOv_alarm();
|
|
data.anchor_i = pro->getAnchor_i();
|
|
data.ui_alarm = pro->getUi_alarm();
|
|
data.oi_alarm = pro->getOi_alarm();
|
|
if(_pDlg)
|
|
{
|
|
_pDlg->show();
|
|
_pDlg->synchroniseData(data);
|
|
}
|
|
else
|
|
{
|
|
_pDlg = new ItemPropertyDlg(p);
|
|
connect(_pDlg,&ItemPropertyDlg::PropertyChange,this,&ElectricSvgItemRect::onPropertyChanged);
|
|
_pDlg->show();
|
|
_pDlg->synchroniseData(data);
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
//todo:没有关联数据,提示
|
|
qDebug()<<"no associate data";
|
|
}
|
|
}
|
|
|
|
void ElectricSvgItemRect::updateByProperty()
|
|
{
|
|
auto p = dynamic_cast<ElectricSvgItemRect_Property*>(_property);
|
|
if(p)
|
|
{
|
|
setLabelTag(p->tag());
|
|
setLabelVoltage(QString::number(p->getVolt()));
|
|
setLabelCurrent(QString::number(p->getElec()));
|
|
scene()->update();
|
|
}
|
|
}
|
|
/****************************************************************/
|
|
|
|
ElectricSvgItemRect_Property::ElectricSvgItemRect_Property(QObject* parent)
|
|
:BaseProperty(parent)
|
|
{
|
|
electricity = 0;
|
|
voltage = 0;
|
|
resistance = 2; //电阻
|
|
anchor_v = false; //是否锚定电压
|
|
uv_alarm = 90; //电压下限
|
|
ov_alarm = 110; //电压上限
|
|
anchor_i = false; //是否锚定电流
|
|
ui_alarm = 45; //电流下限
|
|
oi_alarm = 55; //电流上限
|
|
}
|
|
|
|
ElectricSvgItemRect_Property::~ElectricSvgItemRect_Property()
|
|
{
|
|
|
|
}
|