2026-03-23 11:06:17 +08:00
|
|
|
|
#include "graphicsItem/functionModelItem/graphicsFunctionModelItem.h"
|
2026-04-03 17:56:32 +08:00
|
|
|
|
#include "baseProperty.h"
|
|
|
|
|
|
#include "graphicsDataModel/fixedPortsModel.h"
|
2026-04-08 14:17:47 +08:00
|
|
|
|
#include "baseItemPropertyProxy.h"
|
2026-03-23 11:06:17 +08:00
|
|
|
|
|
|
|
|
|
|
GraphicsFunctionModelItem::GraphicsFunctionModelItem(QGraphicsItem *parent)
|
|
|
|
|
|
: GraphicsProjectModelItem(parent)
|
2026-04-08 14:17:47 +08:00
|
|
|
|
,_pPropertyProxy(nullptr)
|
2026-03-23 11:06:17 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GraphicsFunctionModelItem::~GraphicsFunctionModelItem()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-03 17:56:32 +08:00
|
|
|
|
QMap<QString,bool> GraphicsFunctionModelItem::getMap()
|
|
|
|
|
|
{
|
|
|
|
|
|
QMap<QString,bool> mapBool;
|
|
|
|
|
|
QUuid id = getProperty()->uuid();
|
|
|
|
|
|
auto mapPtr = _pHandle->getProVisibleRef().value(id);
|
|
|
|
|
|
for (const QString& key : mapPtr.keys()) {
|
|
|
|
|
|
bool* valuePtr = mapPtr.value(key);
|
|
|
|
|
|
if (valuePtr) {
|
|
|
|
|
|
mapBool[key] = *valuePtr;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return mapBool;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GraphicsFunctionModelItem::setMap(QMap<QString,bool> boolMap)
|
|
|
|
|
|
{
|
|
|
|
|
|
QUuid id = getProperty()->uuid();
|
|
|
|
|
|
auto boolPtrMap = _pHandle->getProVisibleRef().value(id);
|
|
|
|
|
|
|
|
|
|
|
|
for (auto it = boolMap.begin(); it != boolMap.end(); ++it) {
|
|
|
|
|
|
if (boolPtrMap.contains(it.key())) {
|
|
|
|
|
|
bool* ptr = boolPtrMap.value(it.key());
|
|
|
|
|
|
if (ptr) { // 安全检查
|
|
|
|
|
|
*ptr = it.value(); // 修改指针指向的值
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-23 11:06:17 +08:00
|
|
|
|
void GraphicsFunctionModelItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
|
|
|
|
|
|
{
|
|
|
|
|
|
Q_UNUSED(option)
|
|
|
|
|
|
Q_UNUSED(widget)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/********************************功能模item组*************************************/
|
|
|
|
|
|
|
|
|
|
|
|
GraphicsFunctionModelGroup::GraphicsFunctionModelGroup(QGraphicsItem *parent)
|
|
|
|
|
|
:GraphicsFunctionModelItem(parent)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GraphicsFunctionModelGroup::~GraphicsFunctionModelGroup()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GraphicsFunctionModelGroup::addItem(GraphicsFunctionModelItem* item)
|
|
|
|
|
|
{
|
|
|
|
|
|
item->setParentItem(this); // 关键:设置父项
|
|
|
|
|
|
m_childItems.append(item);
|
|
|
|
|
|
updateLayout();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QRectF GraphicsFunctionModelGroup::updateBoundRect()
|
|
|
|
|
|
{
|
|
|
|
|
|
QRectF rect;
|
|
|
|
|
|
if(m_childItems.size()){
|
|
|
|
|
|
for (auto* child : m_childItems) {
|
|
|
|
|
|
rect |= child->boundingRect().translated(child->pos());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
m_boundingRect = rect;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_boundingRect;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
updateHandles();
|
|
|
|
|
|
return rect;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GraphicsFunctionModelGroup::updateLayout()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_childItems.isEmpty()) return;
|
|
|
|
|
|
|
|
|
|
|
|
// 计算所有子项的总尺寸
|
|
|
|
|
|
qreal totalSize = 0;
|
|
|
|
|
|
QList<qreal> childSizes;
|
|
|
|
|
|
|
|
|
|
|
|
for (GraphicsBaseItem *child : m_childItems) {
|
|
|
|
|
|
QRectF childRect = child->boundingRect();
|
|
|
|
|
|
qreal size = (m_direction == 0) ? childRect.width() : childRect.height();
|
|
|
|
|
|
childSizes.append(size);
|
|
|
|
|
|
totalSize += size;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 计算总间距
|
|
|
|
|
|
qreal totalSpacing = m_spacing * (m_childItems.size() - 1);
|
|
|
|
|
|
|
|
|
|
|
|
// 计算起始位置(相对于父项中心)
|
|
|
|
|
|
qreal startPos = -(totalSize + totalSpacing) / 2;
|
|
|
|
|
|
|
|
|
|
|
|
// 定位每个子项
|
|
|
|
|
|
qreal currentPos = startPos;
|
|
|
|
|
|
for (int i = 0; i < m_childItems.size(); ++i) {
|
|
|
|
|
|
GraphicsBaseItem *child = m_childItems[i];
|
|
|
|
|
|
QRectF childRect = child->boundingRect();
|
|
|
|
|
|
|
|
|
|
|
|
if (m_direction == 0) {
|
|
|
|
|
|
// 水平布局:x坐标变化,y坐标保持中心对齐
|
|
|
|
|
|
child->setPos(currentPos, -childRect.height() / 2);
|
|
|
|
|
|
currentPos += childSizes[i] + m_spacing;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// 垂直布局:y坐标变化,x坐标保持中心对齐
|
|
|
|
|
|
child->setPos(-childRect.width() / 2, currentPos);
|
|
|
|
|
|
currentPos += childSizes[i] + m_spacing;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
updateBoundRect();
|
|
|
|
|
|
}
|