forked from qt-creator/qt-creator
QmlDesigner: Fix bounding boxes in flow editor
The calculation of the bounding boxes did not take the new items into account. The new implementation now shares code with the painting. Change-Id: If257dbf4a36e925d71c109e245b7c87c7a5c4017 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -646,17 +646,71 @@ void FormEditorTransitionItem::setDataModelPositionInBaseState(const QPointF &)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ResolveConnection
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ResolveConnection(const QmlItemNode &node) :
|
||||||
|
from({})
|
||||||
|
,to(node.modelNode().bindingProperty("to").resolveToModelNode())
|
||||||
|
,areaNode(ModelNode())
|
||||||
|
{
|
||||||
|
if (node.modelNode().hasBindingProperty("from"))
|
||||||
|
from = node.modelNode().bindingProperty("from").resolveToModelNode();
|
||||||
|
const QmlFlowItemNode to = node.modelNode().bindingProperty("to").resolveToModelNode();
|
||||||
|
|
||||||
|
if (from.isValid()) {
|
||||||
|
for (const QmlFlowActionAreaNode &area : from.flowActionAreas()) {
|
||||||
|
ModelNode target = area.targetTransition();
|
||||||
|
if (target == node.modelNode()) {
|
||||||
|
areaNode = area;
|
||||||
|
} else {
|
||||||
|
const ModelNode decisionNode = area.decisionNodeForTransition(node.modelNode());
|
||||||
|
if (decisionNode.isValid()) {
|
||||||
|
from = decisionNode;
|
||||||
|
areaNode = ModelNode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (from.modelNode().hasAuxiliaryData("joinConnection"))
|
||||||
|
joinConnection = from.modelNode().auxiliaryData("joinConnection").toBool();
|
||||||
|
} else {
|
||||||
|
if (from == node.rootModelNode()) {
|
||||||
|
isStartLine = true;
|
||||||
|
} else {
|
||||||
|
for (const ModelNode wildcard : QmlFlowViewNode(node.rootModelNode()).wildcards()) {
|
||||||
|
if (wildcard.bindingProperty("target").resolveToModelNode() == node.modelNode()) {
|
||||||
|
from = wildcard;
|
||||||
|
isWildcardLine = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool joinConnection = false;
|
||||||
|
|
||||||
|
bool isStartLine = false;
|
||||||
|
|
||||||
|
bool isWildcardLine = false;
|
||||||
|
|
||||||
|
QmlFlowItemNode from;
|
||||||
|
QmlFlowItemNode to;
|
||||||
|
QmlFlowActionAreaNode areaNode;
|
||||||
|
};
|
||||||
|
|
||||||
void FormEditorTransitionItem::updateGeometry()
|
void FormEditorTransitionItem::updateGeometry()
|
||||||
{
|
{
|
||||||
FormEditorItem::updateGeometry();
|
FormEditorItem::updateGeometry();
|
||||||
|
|
||||||
const ModelNode from = qmlItemNode().modelNode().bindingProperty("from").resolveToModelNode();
|
ResolveConnection resolved(qmlItemNode());
|
||||||
const ModelNode to = qmlItemNode().modelNode().bindingProperty("to").resolveToModelNode();
|
|
||||||
|
|
||||||
QPointF fromP = QmlItemNode(from).flowPosition();
|
QPointF fromP = QmlItemNode(resolved.from).flowPosition();
|
||||||
QRectF sizeTo = QmlItemNode(to).instanceBoundingRect();
|
QRectF sizeTo = resolved.to.instanceBoundingRect();
|
||||||
|
|
||||||
QPointF toP = QmlItemNode(to).flowPosition();
|
QPointF toP = QmlItemNode(resolved.to).flowPosition();
|
||||||
|
|
||||||
|
if (QmlItemNode(resolved.to).isFlowDecision())
|
||||||
|
sizeTo = QRectF(0,0,200,200);
|
||||||
|
|
||||||
qreal x1 = fromP.x();
|
qreal x1 = fromP.x();
|
||||||
qreal x2 = toP.x();
|
qreal x2 = toP.x();
|
||||||
@@ -923,83 +977,44 @@ void FormEditorTransitionItem::paint(QPainter *painter, const QStyleOptionGraphi
|
|||||||
if (!qmlItemNode().modelNode().isValid())
|
if (!qmlItemNode().modelNode().isValid())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!(qmlItemNode().modelNode().hasBindingProperty("from")
|
if (!qmlItemNode().modelNode().hasBindingProperty("to"))
|
||||||
&& qmlItemNode().modelNode().hasBindingProperty("to")))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
painter->save();
|
painter->save();
|
||||||
|
|
||||||
QmlFlowItemNode from = qmlItemNode().modelNode().bindingProperty("from").resolveToModelNode();
|
ResolveConnection resolved(qmlItemNode());
|
||||||
const QmlFlowItemNode to = qmlItemNode().modelNode().bindingProperty("to").resolveToModelNode();
|
|
||||||
|
|
||||||
QmlFlowActionAreaNode areaNode = ModelNode();
|
if (!resolved.from.modelNode().isValid())
|
||||||
|
|
||||||
bool joinConnection = false;
|
|
||||||
|
|
||||||
bool isStartLine = false;
|
|
||||||
|
|
||||||
bool isWildcardLine = false;
|
|
||||||
|
|
||||||
if (from.isValid()) {
|
|
||||||
for (const QmlFlowActionAreaNode &area : from.flowActionAreas()) {
|
|
||||||
ModelNode target = area.targetTransition();
|
|
||||||
if (target == qmlItemNode().modelNode()) {
|
|
||||||
areaNode = area;
|
|
||||||
} else {
|
|
||||||
const ModelNode decisionNode = area.decisionNodeForTransition(qmlItemNode().modelNode());
|
|
||||||
if (decisionNode.isValid()) {
|
|
||||||
from = decisionNode;
|
|
||||||
areaNode = ModelNode();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (from.modelNode().hasAuxiliaryData("joinConnection"))
|
|
||||||
joinConnection = from.modelNode().auxiliaryData("joinConnection").toBool();
|
|
||||||
} else {
|
|
||||||
if (from == qmlItemNode().rootModelNode()) {
|
|
||||||
isStartLine = true;
|
|
||||||
} else {
|
|
||||||
for (const ModelNode wildcard : QmlFlowViewNode(qmlItemNode().rootModelNode()).wildcards()) {
|
|
||||||
if (wildcard.bindingProperty("target").resolveToModelNode() == qmlItemNode().modelNode()) {
|
|
||||||
from = wildcard;
|
|
||||||
isWildcardLine = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!from.modelNode().isValid())
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QRectF fromRect = QmlItemNode(from).instanceBoundingRect();
|
QRectF fromRect = QmlItemNode(resolved.from).instanceBoundingRect();
|
||||||
if (QmlItemNode(from).isFlowDecision())
|
if (QmlItemNode(resolved.from).isFlowDecision())
|
||||||
fromRect = QRectF(0,0,200,200);
|
fromRect = QRectF(0,0,200,200);
|
||||||
|
|
||||||
if (QmlItemNode(from).isFlowWildcard())
|
if (QmlItemNode(resolved.from).isFlowWildcard())
|
||||||
fromRect = QRectF(0,0,200,200);
|
fromRect = QRectF(0,0,200,200);
|
||||||
fromRect.translate(QmlItemNode(from).flowPosition());
|
fromRect.translate(QmlItemNode(resolved.from).flowPosition());
|
||||||
|
|
||||||
if (isStartLine) {
|
if (resolved.isStartLine) {
|
||||||
fromRect = QRectF(0,0,100,100);
|
fromRect = QRectF(0,0,100,100);
|
||||||
fromRect.translate(QmlItemNode(to).flowPosition()- QPoint(200, 0));
|
fromRect.translate(QmlItemNode(resolved.to).flowPosition()- QPoint(200, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!joinConnection && areaNode.isValid()) {
|
if (!resolved.joinConnection && resolved.areaNode.isValid()) {
|
||||||
fromRect = QmlItemNode(areaNode).instanceBoundingRect();
|
fromRect = QmlItemNode(resolved.areaNode).instanceBoundingRect();
|
||||||
fromRect.translate(QmlItemNode(from).flowPosition());
|
fromRect.translate(QmlItemNode(resolved.from).flowPosition());
|
||||||
fromRect.translate(areaNode.instancePosition());
|
fromRect.translate(resolved.areaNode.instancePosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF toRect = QmlItemNode(to).instanceBoundingRect();
|
QRectF toRect = QmlItemNode(resolved.to).instanceBoundingRect();
|
||||||
if (QmlItemNode(to).isFlowDecision())
|
if (QmlItemNode(resolved.to).isFlowDecision())
|
||||||
toRect = QRectF(0,0,200,200);
|
toRect = QRectF(0,0,200,200);
|
||||||
|
|
||||||
toRect.translate(QmlItemNode(to).flowPosition());
|
toRect.translate(QmlItemNode(resolved.to).flowPosition());
|
||||||
|
|
||||||
if (isStartLine) {
|
if (resolved.isStartLine) {
|
||||||
fromRect = QRectF(0,0,50,50);
|
fromRect = QRectF(0,0,50,50);
|
||||||
fromRect.translate(QmlItemNode(to).flowPosition() + QPoint(-120, toRect.height() / 2 - 25));
|
fromRect.translate(QmlItemNode(resolved.to).flowPosition() + QPoint(-120, toRect.height() / 2 - 25));
|
||||||
}
|
}
|
||||||
|
|
||||||
toRect.translate(-pos());
|
toRect.translate(-pos());
|
||||||
@@ -1021,9 +1036,12 @@ void FormEditorTransitionItem::paint(QPainter *painter, const QStyleOptionGraphi
|
|||||||
|
|
||||||
QColor color = "#e71919";
|
QColor color = "#e71919";
|
||||||
|
|
||||||
if (isStartLine)
|
if (resolved.isStartLine)
|
||||||
color = "blue";
|
color = "blue";
|
||||||
|
|
||||||
|
if (resolved.isWildcardLine)
|
||||||
|
color = "green";
|
||||||
|
|
||||||
bool dash = false;
|
bool dash = false;
|
||||||
|
|
||||||
if (qmlItemNode().modelNode().hasAuxiliaryData("color"))
|
if (qmlItemNode().modelNode().hasAuxiliaryData("color"))
|
||||||
@@ -1048,7 +1066,7 @@ void FormEditorTransitionItem::paint(QPainter *painter, const QStyleOptionGraphi
|
|||||||
|
|
||||||
paintConnection(painter, fromRect, toRect, width, adjustedWidth ,color, dash, outOffset, inOffset, breakOffset);
|
paintConnection(painter, fromRect, toRect, width, adjustedWidth ,color, dash, outOffset, inOffset, breakOffset);
|
||||||
|
|
||||||
if (isStartLine) {
|
if (resolved.isStartLine) {
|
||||||
QPen pen;
|
QPen pen;
|
||||||
pen.setCosmetic(true);
|
pen.setCosmetic(true);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user