做网站的费用入什么科目建筑人才网怎么样
2026/1/28 11:47:12 网站建设 项目流程
做网站的费用入什么科目,建筑人才网怎么样,wordpress做一个说说页面,中国十大电商平台排名前十名在项目中为了便于对组合后的图元进行管理#xff0c;一般会继承 QGraphicsItemGroup 实现自己的 group 类#xff0c;这样可以方便的借用 QGraphicsItemGroup 对内部图元进行管理#xff0c;但同时也受到了 QGraphicsItemGroup 实现的约束。例如#xff1a;QGraphicsItemGr…在项目中为了便于对组合后的图元进行管理一般会继承 QGraphicsItemGroup 实现自己的 group 类这样可以方便的借用 QGraphicsItemGroup 对内部图元进行管理但同时也受到了 QGraphicsItemGroup 实现的约束。例如QGraphicsItemGroup 对象的默认原点坐标为{00}对鼠标键盘的消息默认由 QGraphicsItemGroup 处理内部图元控件不会处理等。这里主要讨论使用 addToGroup() 或 removeFromGroup() 时 group 的 bound 会发生变化此时需要调整 group 的坐标及尺寸。因为我们可能一次向 group 添加/移除一个控件也可能添加、移除多个group 的坐标及尺寸最好在添加/移除后进行调整。但是为了提高代码的内聚性我们更希望在 group 内部图元发生变化后由 group 自动调整位置及大小。继承 QGraphicsItemGroup 后重载 itemChange() 方法当内部图元发生变化时可以通过 change QGraphicsItem::ItemChildAddedChange 监听添加图元的信号、change QGraphicsItem::ItemChildRemovedChange 监听移除图元的信号。如果在 itemChange() 方法中处理 group 的坐标及尺寸就会发生不可思议的问题明明位置与尺寸都计算正确但是内部图元的位置却发生莫名的偏移。通过监控内部图元的坐标发现计算的坐标完全正确但是显示位置就是不对。如下图图一是组合前的位置图二是组合后的位置组合后显示的选择框就是重新调整后的 group 的位置及大小内部的矩形与圆形已经偏离了原位置。image图一 组合前的位置image图二 组合后的位置发生这个问题的原因是不能在 itemChange() 方法内处理 group 的位置及坐标因为此时addToGroup() 或 removeFromGroup() 的代码还未执行完毕。看一下 addToGroup() 的源码// 文件位置 qt-everywhere-src-6.7.3\qtbase\src\widgets\graphicsview\qgraphicsitem.cppvoid QGraphicsItemGroup::addToGroup(QGraphicsItem *item){Q_D(QGraphicsItemGroup);if (!item) {qWarning(QGraphicsItemGroup::addToGroup: cannot add null item);return;}if (item this) {qWarning(QGraphicsItemGroup::addToGroup: cannot add a group to itself);return;}// COMBINEbool ok;QTransform itemTransform item-itemTransform(this, ok);if (!ok) {qWarning(QGraphicsItemGroup::addToGroup: could not find a valid transformation from item to group coordinates);return;}QTransform newItemTransform(itemTransform);item-setPos(mapFromItem(item, 0, 0));// 设置父项目时会触发 itemChange() 方法item-setParentItem(this);// removing position from translation component of the new transformif (!item-pos().isNull())newItemTransform * QTransform::fromTranslate(-item-x(), -item-y());// removing additional transformations properties applied with itemTransform()QPointF origin item-transformOriginPoint();QMatrix4x4 m;QListQGraphicsTransform* transformList item-transformations();for (int i 0; i transformList.size(); i)transformList.at(i)-applyTo(m);newItemTransform * m.toTransform().inverted();newItemTransform.translate(origin.x(), origin.y());newItemTransform.rotate(-item-rotation());newItemTransform.scale(1/item-scale(), 1/item-scale());newItemTransform.translate(-origin.x(), -origin.y());// ### Expensive, we could maybe use dirtySceneTransform bit for optimizationitem-setTransform(newItemTransform);item-d_func()-setIsMemberOfGroup(true);prepareGeometryChange();d-itemsBoundingRect | itemTransform.mapRect(item-boundingRect() | item-childrenBoundingRect());update();}void QGraphicsItem::setParentItem(QGraphicsItem *newParent){if (newParent this) {qWarning(QGraphicsItem::setParentItem: cannot assign %p as a parent of itself, this);return;}if (newParent d_ptr-parent)return;const QVariant newParentVariant(itemChange(QGraphicsItem::ItemParentChange,QVariant::fromValueQGraphicsItem *(newParent)));newParent qvariant_castQGraphicsItem *(newParentVariant);if (newParent d_ptr-parent)return;const QVariant thisPointerVariant(QVariant::fromValueQGraphicsItem *(this));// setParentItemHelper 内部触发 itemChange() 方法d_ptr-setParentItemHelper(newParent, newParentVariant, thisPointerVariant);}void QGraphicsItemPrivate::setParentItemHelper(QGraphicsItem *newParent, const QVariant *newParentVariant, const QVariant *thisPointerVariant){Q_Q(QGraphicsItem);if (newParent parent)return;...if (parent) {// Remove from current parentparent-d_ptr-removeChild(q);if (thisPointerVariant)parent-itemChange(QGraphicsItem::ItemChildRemovedChange, thisPointerVariant);}...// Deliver post-change notificationif (newParentVariant)q-itemChange(QGraphicsItem::ItemParentHasChanged, *newParentVariant);if (isObject)emit static_castQGraphicsObject *(q)-parentChanged();}通过源码可以发现如果在 itemChange() 内部处理 group 的坐标及尺寸确实会出现很多问题因为此时 addToGroup() 还未执行 transform 变换。要解决此问题就必须等待addToGroup() 执行完成再去计算坐标及尺寸。可以在 itemChange() 发射一个信号采用异步处理该信号将处理过程推迟到下一个事件循环。这样就能够完美解决问题。具体代码可以参考项目 Compelling Data Designer 中 dashboard/BIDesigner/graphicsitemgroup.cpp 的处理过程。该项目用于数据的可视化设计软件采用可扩展架构支持扩展图形插件、数据接口。项目仍在开发中目前已设计完成基本图形、多属性配置、动画等功能。image

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询