diff options
author | Thomas Hartmann <Thomas.Hartmann@nokia.com> | 2010-05-25 17:47:04 +0200 |
---|---|---|
committer | Thomas Hartmann <Thomas.Hartmann@nokia.com> | 2010-05-25 17:51:18 +0200 |
commit | 441403bf60f3a81033a245516a74be2db686d001 (patch) | |
tree | 71fafc63b7725a16a37f5e2bf00c0a03c53b9788 | |
parent | d79f288c070b35d2e255676fecd36d8709e2a88a (diff) | |
download | qt-creator-441403bf60f3a81033a245516a74be2db686d001.tar.gz |
QmlDesigner.model: QmlAnchors get simplification
Now anchors.verticalCenter & anchors.horizontalCenter
get simplified to anchors.centerIn. We also simplify the fill case.
Task-number: Bauhaus-109
Reviewed-by: Marco Bubke
-rw-r--r-- | src/plugins/qmldesigner/designercore/include/qmlanchors.h | 1 | ||||
-rw-r--r-- | src/plugins/qmldesigner/designercore/model/qmlanchors.cpp | 50 |
2 files changed, 50 insertions, 1 deletions
diff --git a/src/plugins/qmldesigner/designercore/include/qmlanchors.h b/src/plugins/qmldesigner/designercore/include/qmlanchors.h index 409a51bc88..ccfd772178 100644 --- a/src/plugins/qmldesigner/designercore/include/qmlanchors.h +++ b/src/plugins/qmldesigner/designercore/include/qmlanchors.h @@ -103,6 +103,7 @@ public: protected: QmlItemNode qmlItemNode() const; + void beautify(); private: QmlItemNode m_qmlItemNode; diff --git a/src/plugins/qmldesigner/designercore/model/qmlanchors.cpp b/src/plugins/qmldesigner/designercore/model/qmlanchors.cpp index 6a71c3e356..1df6106b95 100644 --- a/src/plugins/qmldesigner/designercore/model/qmlanchors.cpp +++ b/src/plugins/qmldesigner/designercore/model/qmlanchors.cpp @@ -130,6 +130,52 @@ bool QmlAnchors::isValid() const return m_qmlItemNode.isValid(); } +void QmlAnchors::beautify() +{ + + if ((instanceHasAnchor(AnchorLine::Left) && + instanceHasAnchor(AnchorLine::Right) && + instanceHasAnchor(AnchorLine::Top) && + instanceHasAnchor(AnchorLine::Bottom)) && + + (instanceAnchor(AnchorLine::Left).type() == AnchorLine::Left && + instanceAnchor(AnchorLine::Right).type() == AnchorLine::Right && + instanceAnchor(AnchorLine::Top).type() == AnchorLine::Top && + instanceAnchor(AnchorLine::Bottom).type() == AnchorLine::Bottom) && + + (instanceAnchor(AnchorLine::Left).qmlItemNode() == + instanceAnchor(AnchorLine::Right).qmlItemNode() && + instanceAnchor(AnchorLine::Top).qmlItemNode() == + instanceAnchor(AnchorLine::Bottom).qmlItemNode()) && + (instanceAnchor(AnchorLine::Left).qmlItemNode() == + instanceAnchor(AnchorLine::Bottom).qmlItemNode())) { + + if (instanceHasAnchor(AnchorLine::Fill)) + return; //avoid recursion + + QmlItemNode targetNode(instanceAnchor(AnchorLine::Left).qmlItemNode()); + removeAnchors(); + setAnchor(AnchorLine::Fill, targetNode, AnchorLine::Fill); + } + + if ((instanceHasAnchor(AnchorLine::VerticalCenter) && + instanceHasAnchor(AnchorLine::HorizontalCenter)) && + + (instanceAnchor(AnchorLine::VerticalCenter).type() == AnchorLine::VerticalCenter && + instanceAnchor(AnchorLine::HorizontalCenter).type() == AnchorLine::HorizontalCenter) && + + (instanceAnchor(AnchorLine::VerticalCenter).qmlItemNode() == + instanceAnchor(AnchorLine::HorizontalCenter).qmlItemNode())) { + + if (instanceHasAnchor(AnchorLine::Center)) + return; //avoid recursion + + QmlItemNode targetNode(instanceAnchor(AnchorLine::VerticalCenter).qmlItemNode()); + removeAnchors(); + setAnchor(AnchorLine::Center, targetNode, AnchorLine::Center); + } +} + void QmlAnchors::setAnchor(AnchorLine::Type sourceAnchorLine, const QmlItemNode &targetQmlItemNode, AnchorLine::Type targetAnchorLine) @@ -145,9 +191,11 @@ void QmlAnchors::setAnchor(AnchorLine::Type sourceAnchorLine, QString targetExpression = targetQmlItemNode.modelNode().validId(); if (targetQmlItemNode.modelNode() == qmlItemNode().modelNode().parentProperty().parentModelNode()) targetExpression = "parent"; - targetExpression = targetExpression + QLatin1Char('.') + lineTypeToString(targetAnchorLine); + if (sourceAnchorLine != AnchorLine::Center && sourceAnchorLine != AnchorLine::Fill) + targetExpression = targetExpression + QLatin1Char('.') + lineTypeToString(targetAnchorLine); qmlItemNode().modelNode().bindingProperty(propertyName).setExpression(targetExpression); } + beautify(); } bool detectHorizontalCycle(const ModelNode &node, QList<ModelNode> knownNodeList) |