QmlDesigner: Add try catch blocks for anchoring

There have been casual unreproducible crashes.
This kind of code should be replaced by using lambdas in master.

Change-Id: I5b44a4c7b013f70a012c22ff9610e5579b165ab4
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Thomas Hartmann
2019-05-27 17:36:54 +02:00
parent 2001e96f01
commit aff3e204c1

View File

@@ -24,7 +24,9 @@
****************************************************************************/ ****************************************************************************/
#include "qmlanchorbindingproxy.h" #include "qmlanchorbindingproxy.h"
#include "abstractview.h"
#include <exception.h>
#include <abstractview.h>
#include <qmlanchors.h> #include <qmlanchors.h>
#include <nodeabstractproperty.h> #include <nodeabstractproperty.h>
#include <variantproperty.h> #include <variantproperty.h>
@@ -359,14 +361,20 @@ void QmlAnchorBindingProxy::setTopTarget(const QString &target)
if (!newTarget.isValid()) if (!newTarget.isValid())
return; return;
RewriterTransaction transaction = beginRewriterTransaction( try {
QByteArrayLiteral("QmlAnchorBindingProxy::setTopTarget")); RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::setTopTarget"));
m_topTarget = newTarget; m_topTarget = newTarget;
setDefaultRelativeTopTarget(); setDefaultRelativeTopTarget();
anchorTop(); anchorTop();
transaction.commit();
} catch (const Exception &e) {
e.showException();
}
emit topTargetChanged(); emit topTargetChanged();
} }
@@ -385,12 +393,18 @@ void QmlAnchorBindingProxy::setBottomTarget(const QString &target)
if (!newTarget.isValid()) if (!newTarget.isValid())
return; return;
RewriterTransaction transaction = beginRewriterTransaction( try {
QByteArrayLiteral("QmlAnchorBindingProxy::setBottomTarget")); RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::setBottomTarget"));
m_bottomTarget = newTarget; m_bottomTarget = newTarget;
setDefaultRelativeBottomTarget(); setDefaultRelativeBottomTarget();
anchorBottom(); anchorBottom();
transaction.commit();
} catch (const Exception &e) {
e.showException();
}
emit bottomTargetChanged(); emit bottomTargetChanged();
} }
@@ -408,12 +422,18 @@ void QmlAnchorBindingProxy::setLeftTarget(const QString &target)
if (!newTarget.isValid()) if (!newTarget.isValid())
return; return;
RewriterTransaction transaction = beginRewriterTransaction( try {
QByteArrayLiteral("QmlAnchorBindingProxy::setLeftTarget")); RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::setLeftTarget"));
m_leftTarget = newTarget; m_leftTarget = newTarget;
setDefaultRelativeLeftTarget(); setDefaultRelativeLeftTarget();
anchorLeft(); anchorLeft();
transaction.commit();
} catch (const Exception &e) {
e.showException();
}
emit leftTargetChanged(); emit leftTargetChanged();
} }
@@ -431,12 +451,18 @@ void QmlAnchorBindingProxy::setRightTarget(const QString &target)
if (!newTarget.isValid()) if (!newTarget.isValid())
return; return;
RewriterTransaction transaction = beginRewriterTransaction( try {
QByteArrayLiteral("QmlAnchorBindingProxy::setRightTarget")); RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::setRightTarget"));
m_rightTarget = newTarget; m_rightTarget = newTarget;
setDefaultRelativeRightTarget(); setDefaultRelativeRightTarget();
anchorRight(); anchorRight();
transaction.commit();
} catch (const Exception &e) {
e.showException();
}
emit rightTargetChanged(); emit rightTargetChanged();
} }
@@ -454,11 +480,17 @@ void QmlAnchorBindingProxy::setVerticalTarget(const QString &target)
if (!newTarget.isValid()) if (!newTarget.isValid())
return; return;
RewriterTransaction transaction = beginRewriterTransaction( try {
QByteArrayLiteral("QmlAnchorBindingProxy::setVerticalTarget")); RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::setVerticalTarget"));
m_verticalTarget = newTarget; m_verticalTarget = newTarget;
anchorVertical(); anchorVertical();
transaction.commit();
} catch (const Exception &e) {
e.showException();
}
emit verticalTargetChanged(); emit verticalTargetChanged();
} }
@@ -476,11 +508,17 @@ void QmlAnchorBindingProxy::setHorizontalTarget(const QString &target)
if (!newTarget.isValid()) if (!newTarget.isValid())
return; return;
RewriterTransaction transaction = beginRewriterTransaction( try {
QByteArrayLiteral("QmlAnchorBindingProxy::setHorizontalTarget")); RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::setHorizontalTarget"));
m_horizontalTarget = newTarget; m_horizontalTarget = newTarget;
anchorHorizontal(); anchorHorizontal();\
transaction.commit();
} catch (const Exception &e) {
e.showException();
}
emit horizontalTargetChanged(); emit horizontalTargetChanged();
} }
@@ -493,12 +531,18 @@ void QmlAnchorBindingProxy::setRelativeAnchorTargetTop(QmlAnchorBindingProxy::Re
if (target == m_relativeTopTarget) if (target == m_relativeTopTarget)
return; return;
RewriterTransaction transaction = beginRewriterTransaction( try {
QByteArrayLiteral("QmlAnchorBindingProxy::setRelativeAnchorTargetTop")); RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::setRelativeAnchorTargetTop"));
m_relativeTopTarget = target; m_relativeTopTarget = target;
anchorTop(); anchorTop();
transaction.commit();
} catch (const Exception &e) {
e.showException();
}
emit relativeAnchorTargetTopChanged(); emit relativeAnchorTargetTopChanged();
} }
@@ -511,12 +555,19 @@ void QmlAnchorBindingProxy::setRelativeAnchorTargetBottom(QmlAnchorBindingProxy:
if (target == m_relativeBottomTarget) if (target == m_relativeBottomTarget)
return; return;
RewriterTransaction transaction = beginRewriterTransaction( try {
QByteArrayLiteral("QmlAnchorBindingProxy::setRelativeAnchorTargetBottom")); RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::setRelativeAnchorTargetBottom"));
m_relativeBottomTarget = target; m_relativeBottomTarget = target;
anchorBottom();
anchorBottom();
transaction.commit();
} catch (const Exception &e) {
e.showException();
}
emit relativeAnchorTargetBottomChanged(); emit relativeAnchorTargetBottomChanged();
} }
@@ -529,12 +580,18 @@ void QmlAnchorBindingProxy::setRelativeAnchorTargetLeft(QmlAnchorBindingProxy::R
if (target == m_relativeLeftTarget) if (target == m_relativeLeftTarget)
return; return;
RewriterTransaction transaction = beginRewriterTransaction( try {
QByteArrayLiteral("QmlAnchorBindingProxy::setRelativeAnchorTargetLeft")); RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::setRelativeAnchorTargetLeft"));
m_relativeLeftTarget = target; m_relativeLeftTarget = target;
anchorLeft(); anchorLeft();
transaction.commit();
} catch (const Exception &e) {
e.showException();
}
emit relativeAnchorTargetLeftChanged(); emit relativeAnchorTargetLeftChanged();
} }
@@ -547,12 +604,18 @@ void QmlAnchorBindingProxy::setRelativeAnchorTargetRight(QmlAnchorBindingProxy::
if (target == m_relativeRightTarget) if (target == m_relativeRightTarget)
return; return;
RewriterTransaction transaction = beginRewriterTransaction( try {
QByteArrayLiteral("QmlAnchorBindingProxy::setRelativeAnchorTargetRight")); RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::setRelativeAnchorTargetRight"));
m_relativeRightTarget = target; m_relativeRightTarget = target;
anchorRight(); anchorRight();
transaction.commit();
} catch (const Exception &e) {
e.showException();
}
emit relativeAnchorTargetRightChanged(); emit relativeAnchorTargetRightChanged();
@@ -566,12 +629,18 @@ void QmlAnchorBindingProxy::setRelativeAnchorTargetVertical(QmlAnchorBindingProx
if (target == m_relativeVerticalTarget) if (target == m_relativeVerticalTarget)
return; return;
RewriterTransaction transaction = beginRewriterTransaction( try {
QByteArrayLiteral("QmlAnchorBindingProxy::setRelativeAnchorTargetVertical")); RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::setRelativeAnchorTargetVertical"));
m_relativeVerticalTarget = target; m_relativeVerticalTarget = target;
anchorVertical(); anchorVertical();
transaction.commit();
} catch (const Exception &e) {
e.showException();
}
emit relativeAnchorTargetVerticalChanged(); emit relativeAnchorTargetVerticalChanged();
} }
@@ -584,12 +653,18 @@ void QmlAnchorBindingProxy::setRelativeAnchorTargetHorizontal(QmlAnchorBindingPr
if (target == m_relativeHorizontalTarget) if (target == m_relativeHorizontalTarget)
return; return;
RewriterTransaction transaction = beginRewriterTransaction( try {
QByteArrayLiteral("QmlAnchorBindingProxy::setRelativeAnchorTargetHorizontal")); RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::setRelativeAnchorTargetHorizontal"));
m_relativeHorizontalTarget = target; m_relativeHorizontalTarget = target;
anchorHorizontal(); anchorHorizontal();
transaction.commit();
} catch (const Exception &e) {
e.showException();
}
emit relativeAnchorTargetHorizontalChanged(); emit relativeAnchorTargetHorizontalChanged();
} }
@@ -635,8 +710,10 @@ int QmlAnchorBindingProxy::indexOfPossibleTargetItem(const QString &targetName)
} }
void QmlAnchorBindingProxy::resetLayout() { void QmlAnchorBindingProxy::resetLayout() {
RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::resetLayout")); try {
RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::resetLayout"));
m_qmlItemNode.anchors().removeAnchors(); m_qmlItemNode.anchors().removeAnchors();
m_qmlItemNode.anchors().removeMargins(); m_qmlItemNode.anchors().removeMargins();
@@ -646,6 +723,11 @@ void QmlAnchorBindingProxy::resetLayout() {
restoreProperty(modelNode(), "width"); restoreProperty(modelNode(), "width");
restoreProperty(modelNode(), "height"); restoreProperty(modelNode(), "height");
transaction.commit();
} catch (const Exception &e) {
e.showException();
}
emit topAnchorChanged(); emit topAnchorChanged();
emit bottomAnchorChanged(); emit bottomAnchorChanged();
emit leftAnchorChanged(); emit leftAnchorChanged();
@@ -661,16 +743,22 @@ void QmlAnchorBindingProxy::setBottomAnchor(bool anchor)
if (bottomAnchored() == anchor) if (bottomAnchored() == anchor)
return; return;
RewriterTransaction transaction = beginRewriterTransaction( try {
QByteArrayLiteral("QmlAnchorBindingProxy::setBottomAnchor")); RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::setBottomAnchor"));
if (!anchor) { if (!anchor) {
removeBottomAnchor(); removeBottomAnchor();
} else { } else {
setDefaultRelativeBottomTarget(); setDefaultRelativeBottomTarget();
anchorBottom(); anchorBottom();
if (topAnchored()) if (topAnchored())
backupPropertyAndRemove(modelNode(), "height"); backupPropertyAndRemove(modelNode(), "height");
}
transaction.commit();
} catch (const Exception &e) {
e.showException();
} }
emit relativeAnchorTargetBottomChanged(); emit relativeAnchorTargetBottomChanged();
@@ -688,18 +776,24 @@ void QmlAnchorBindingProxy::setLeftAnchor(bool anchor)
if (leftAnchored() == anchor) if (leftAnchored() == anchor)
return; return;
RewriterTransaction transaction = beginRewriterTransaction( try {
QByteArrayLiteral("QmlAnchorBindingProxy::setLeftAnchor")); RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::setLeftAnchor"));
if (!anchor) { if (!anchor) {
removeLeftAnchor(); removeLeftAnchor();
} else { } else {
setDefaultRelativeLeftTarget(); setDefaultRelativeLeftTarget();
anchorLeft(); anchorLeft();
backupPropertyAndRemove(modelNode(), "x"); backupPropertyAndRemove(modelNode(), "x");
if (rightAnchored()) if (rightAnchored())
backupPropertyAndRemove(modelNode(), "width"); backupPropertyAndRemove(modelNode(), "width");
}
transaction.commit();
} catch (const Exception &e) {
e.showException();
} }
emit relativeAnchorTargetLeftChanged(); emit relativeAnchorTargetLeftChanged();
@@ -716,17 +810,23 @@ void QmlAnchorBindingProxy::setRightAnchor(bool anchor)
if (rightAnchored() == anchor) if (rightAnchored() == anchor)
return; return;
RewriterTransaction transaction = beginRewriterTransaction( try {
QByteArrayLiteral("QmlAnchorBindingProxy::setRightAnchor")); RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::setRightAnchor"));
if (!anchor) { if (!anchor) {
removeRightAnchor(); removeRightAnchor();
} else { } else {
setDefaultRelativeRightTarget(); setDefaultRelativeRightTarget();
anchorRight(); anchorRight();
if (leftAnchored()) if (leftAnchored())
backupPropertyAndRemove(modelNode(), "width"); backupPropertyAndRemove(modelNode(), "width");
}
transaction.commit();
} catch (const Exception &e) {
e.showException();
} }
emit relativeAnchorTargetRightChanged(); emit relativeAnchorTargetRightChanged();
@@ -926,18 +1026,23 @@ void QmlAnchorBindingProxy::setTopAnchor(bool anchor)
if (topAnchored() == anchor) if (topAnchored() == anchor)
return; return;
RewriterTransaction transaction = beginRewriterTransaction( try {
QByteArrayLiteral("QmlAnchorBindingProxy::setTopAnchor")); RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::setTopAnchor"));
if (!anchor) { if (!anchor) {
removeTopAnchor(); removeTopAnchor();
} else { } else {
setDefaultRelativeTopTarget(); setDefaultRelativeTopTarget();
anchorTop(); anchorTop();
backupPropertyAndRemove(modelNode(), "y"); backupPropertyAndRemove(modelNode(), "y");
if (bottomAnchored()) if (bottomAnchored())
backupPropertyAndRemove(modelNode(), "height"); backupPropertyAndRemove(modelNode(), "height");
}
transaction.commit();
} catch (const Exception &e) {
e.showException();
} }
emit relativeAnchorTargetTopChanged(); emit relativeAnchorTargetTopChanged();
@@ -947,47 +1052,70 @@ void QmlAnchorBindingProxy::setTopAnchor(bool anchor)
} }
void QmlAnchorBindingProxy::removeTopAnchor() { void QmlAnchorBindingProxy::removeTopAnchor() {
RewriterTransaction transaction = beginRewriterTransaction( try {
QByteArrayLiteral("QmlAnchorBindingProxy::removeTopAnchor")); RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::removeTopAnchor"));
m_qmlItemNode.anchors().removeAnchor(AnchorLineTop); m_qmlItemNode.anchors().removeAnchor(AnchorLineTop);
m_qmlItemNode.anchors().removeMargin(AnchorLineTop); m_qmlItemNode.anchors().removeMargin(AnchorLineTop);
restoreProperty(modelNode(), "y"); restoreProperty(modelNode(), "y");
restoreProperty(modelNode(), "height"); restoreProperty(modelNode(), "height");
transaction.commit();
} catch (const Exception &e) {
e.showException();
}
} }
void QmlAnchorBindingProxy::removeBottomAnchor() { void QmlAnchorBindingProxy::removeBottomAnchor() {
RewriterTransaction transaction = beginRewriterTransaction( try {
QByteArrayLiteral("QmlAnchorBindingProxy::removeBottomAnchor")); RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::removeBottomAnchor"));
m_qmlItemNode.anchors().removeAnchor(AnchorLineBottom); m_qmlItemNode.anchors().removeAnchor(AnchorLineBottom);
m_qmlItemNode.anchors().removeMargin(AnchorLineBottom); m_qmlItemNode.anchors().removeMargin(AnchorLineBottom);
restoreProperty(modelNode(), "height"); restoreProperty(modelNode(), "height");
transaction.commit();
} catch (const Exception &e) {
e.showException();
}
} }
void QmlAnchorBindingProxy::removeLeftAnchor() { void QmlAnchorBindingProxy::removeLeftAnchor() {
RewriterTransaction transaction = beginRewriterTransaction( try {
QByteArrayLiteral("QmlAnchorBindingProxy::removeLeftAnchor")); RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::removeLeftAnchor"));
m_qmlItemNode.anchors().removeAnchor(AnchorLineLeft); m_qmlItemNode.anchors().removeAnchor(AnchorLineLeft);
m_qmlItemNode.anchors().removeMargin(AnchorLineLeft); m_qmlItemNode.anchors().removeMargin(AnchorLineLeft);
restoreProperty(modelNode(), "x"); restoreProperty(modelNode(), "x");
restoreProperty(modelNode(), "width"); restoreProperty(modelNode(), "width");
transaction.commit();
} catch (const Exception &e) {
e.showException();
}
} }
void QmlAnchorBindingProxy::removeRightAnchor() { void QmlAnchorBindingProxy::removeRightAnchor() {
RewriterTransaction transaction = beginRewriterTransaction( try {
QByteArrayLiteral("QmlAnchorBindingProxy::removeRightAnchor")); RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::removeRightAnchor"));
m_qmlItemNode.anchors().removeAnchor(AnchorLineRight); m_qmlItemNode.anchors().removeAnchor(AnchorLineRight);
m_qmlItemNode.anchors().removeMargin(AnchorLineRight); m_qmlItemNode.anchors().removeMargin(AnchorLineRight);
restoreProperty(modelNode(), "width"); restoreProperty(modelNode(), "width");
transaction.commit();
} catch (const Exception &e) {
e.showException();
}
} }
void QmlAnchorBindingProxy::setVerticalCentered(bool centered) void QmlAnchorBindingProxy::setVerticalCentered(bool centered)
@@ -1000,18 +1128,23 @@ void QmlAnchorBindingProxy::setVerticalCentered(bool centered)
m_locked = true; m_locked = true;
RewriterTransaction transaction = beginRewriterTransaction( try {
QByteArrayLiteral("QmlAnchorBindingProxy::setVerticalCentered")); RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::setVerticalCentered"));
if (!centered) { if (!centered) {
m_qmlItemNode.anchors().removeAnchor(AnchorLineVerticalCenter); m_qmlItemNode.anchors().removeAnchor(AnchorLineVerticalCenter);
m_qmlItemNode.anchors().removeMargin(AnchorLineVerticalCenter); m_qmlItemNode.anchors().removeMargin(AnchorLineVerticalCenter);
} else { } else {
m_relativeVerticalTarget = Center; m_relativeVerticalTarget = Center;
anchorVertical(); anchorVertical();
}
transaction.commit();
} catch (const Exception &e) {
e.showException();
} }
m_locked = false; m_locked = false;
emit relativeAnchorTargetVerticalChanged(); emit relativeAnchorTargetVerticalChanged();
@@ -1028,18 +1161,23 @@ void QmlAnchorBindingProxy::setHorizontalCentered(bool centered)
m_locked = true; m_locked = true;
RewriterTransaction transaction = beginRewriterTransaction( try {
QByteArrayLiteral("QmlAnchorBindingProxy::setHorizontalCentered")); RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::setHorizontalCentered"));
if (!centered) { if (!centered) {
m_qmlItemNode.anchors().removeAnchor(AnchorLineHorizontalCenter); m_qmlItemNode.anchors().removeAnchor(AnchorLineHorizontalCenter);
m_qmlItemNode.anchors().removeMargin(AnchorLineHorizontalCenter); m_qmlItemNode.anchors().removeMargin(AnchorLineHorizontalCenter);
} else { } else {
m_relativeHorizontalTarget = Center; m_relativeHorizontalTarget = Center;
anchorHorizontal(); anchorHorizontal();
}
transaction.commit();
} catch (const Exception &e) {
e.showException();
} }
m_locked = false; m_locked = false;
emit relativeAnchorTargetHorizontalChanged(); emit relativeAnchorTargetHorizontalChanged();
@@ -1119,24 +1257,30 @@ bool QmlAnchorBindingProxy::horizontalCentered()
void QmlAnchorBindingProxy::fill() void QmlAnchorBindingProxy::fill()
{ {
RewriterTransaction transaction = beginRewriterTransaction( try {
QByteArrayLiteral("QmlAnchorBindingProxy::fill")); RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::fill"));
backupPropertyAndRemove(modelNode(), "x"); backupPropertyAndRemove(modelNode(), "x");
backupPropertyAndRemove(modelNode(), "y"); backupPropertyAndRemove(modelNode(), "y");
backupPropertyAndRemove(modelNode(), "width"); backupPropertyAndRemove(modelNode(), "width");
backupPropertyAndRemove(modelNode(), "height"); backupPropertyAndRemove(modelNode(), "height");
m_qmlItemNode.anchors().fill(); m_qmlItemNode.anchors().fill();
setHorizontalCentered(false); setHorizontalCentered(false);
setVerticalCentered(false); setVerticalCentered(false);
m_qmlItemNode.anchors().removeMargin(AnchorLineRight); m_qmlItemNode.anchors().removeMargin(AnchorLineRight);
m_qmlItemNode.anchors().removeMargin(AnchorLineLeft); m_qmlItemNode.anchors().removeMargin(AnchorLineLeft);
m_qmlItemNode.anchors().removeMargin(AnchorLineTop); m_qmlItemNode.anchors().removeMargin(AnchorLineTop);
m_qmlItemNode.anchors().removeMargin(AnchorLineBottom); m_qmlItemNode.anchors().removeMargin(AnchorLineBottom);
transaction.commit();
} catch (const Exception &e) {
e.showException();
}
emit topAnchorChanged(); emit topAnchorChanged();
emit bottomAnchorChanged(); emit bottomAnchorChanged();