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,6 +361,7 @@ void QmlAnchorBindingProxy::setTopTarget(const QString &target)
if (!newTarget.isValid()) if (!newTarget.isValid())
return; return;
try {
RewriterTransaction transaction = beginRewriterTransaction( RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::setTopTarget")); QByteArrayLiteral("QmlAnchorBindingProxy::setTopTarget"));
@@ -368,6 +371,11 @@ void QmlAnchorBindingProxy::setTopTarget(const QString &target)
anchorTop(); anchorTop();
transaction.commit();
} catch (const Exception &e) {
e.showException();
}
emit topTargetChanged(); emit topTargetChanged();
} }
@@ -385,6 +393,7 @@ void QmlAnchorBindingProxy::setBottomTarget(const QString &target)
if (!newTarget.isValid()) if (!newTarget.isValid())
return; return;
try {
RewriterTransaction transaction = beginRewriterTransaction( RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::setBottomTarget")); QByteArrayLiteral("QmlAnchorBindingProxy::setBottomTarget"));
@@ -392,6 +401,11 @@ void QmlAnchorBindingProxy::setBottomTarget(const QString &target)
setDefaultRelativeBottomTarget(); setDefaultRelativeBottomTarget();
anchorBottom(); anchorBottom();
transaction.commit();
} catch (const Exception &e) {
e.showException();
}
emit bottomTargetChanged(); emit bottomTargetChanged();
} }
@@ -408,6 +422,7 @@ void QmlAnchorBindingProxy::setLeftTarget(const QString &target)
if (!newTarget.isValid()) if (!newTarget.isValid())
return; return;
try {
RewriterTransaction transaction = beginRewriterTransaction( RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::setLeftTarget")); QByteArrayLiteral("QmlAnchorBindingProxy::setLeftTarget"));
@@ -415,6 +430,11 @@ void QmlAnchorBindingProxy::setLeftTarget(const QString &target)
setDefaultRelativeLeftTarget(); setDefaultRelativeLeftTarget();
anchorLeft(); anchorLeft();
transaction.commit();
} catch (const Exception &e) {
e.showException();
}
emit leftTargetChanged(); emit leftTargetChanged();
} }
@@ -431,6 +451,7 @@ void QmlAnchorBindingProxy::setRightTarget(const QString &target)
if (!newTarget.isValid()) if (!newTarget.isValid())
return; return;
try {
RewriterTransaction transaction = beginRewriterTransaction( RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::setRightTarget")); QByteArrayLiteral("QmlAnchorBindingProxy::setRightTarget"));
@@ -438,6 +459,11 @@ void QmlAnchorBindingProxy::setRightTarget(const QString &target)
setDefaultRelativeRightTarget(); setDefaultRelativeRightTarget();
anchorRight(); anchorRight();
transaction.commit();
} catch (const Exception &e) {
e.showException();
}
emit rightTargetChanged(); emit rightTargetChanged();
} }
@@ -454,12 +480,18 @@ void QmlAnchorBindingProxy::setVerticalTarget(const QString &target)
if (!newTarget.isValid()) if (!newTarget.isValid())
return; return;
try {
RewriterTransaction transaction = beginRewriterTransaction( RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::setVerticalTarget")); 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;
try {
RewriterTransaction transaction = beginRewriterTransaction( RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::setHorizontalTarget")); QByteArrayLiteral("QmlAnchorBindingProxy::setHorizontalTarget"));
m_horizontalTarget = newTarget; m_horizontalTarget = newTarget;
anchorHorizontal(); anchorHorizontal();\
transaction.commit();
} catch (const Exception &e) {
e.showException();
}
emit horizontalTargetChanged(); emit horizontalTargetChanged();
} }
@@ -493,6 +531,7 @@ void QmlAnchorBindingProxy::setRelativeAnchorTargetTop(QmlAnchorBindingProxy::Re
if (target == m_relativeTopTarget) if (target == m_relativeTopTarget)
return; return;
try {
RewriterTransaction transaction = beginRewriterTransaction( RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::setRelativeAnchorTargetTop")); QByteArrayLiteral("QmlAnchorBindingProxy::setRelativeAnchorTargetTop"));
@@ -500,6 +539,11 @@ void QmlAnchorBindingProxy::setRelativeAnchorTargetTop(QmlAnchorBindingProxy::Re
anchorTop(); anchorTop();
transaction.commit();
} catch (const Exception &e) {
e.showException();
}
emit relativeAnchorTargetTopChanged(); emit relativeAnchorTargetTopChanged();
} }
@@ -511,13 +555,20 @@ void QmlAnchorBindingProxy::setRelativeAnchorTargetBottom(QmlAnchorBindingProxy:
if (target == m_relativeBottomTarget) if (target == m_relativeBottomTarget)
return; return;
try {
RewriterTransaction transaction = beginRewriterTransaction( RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::setRelativeAnchorTargetBottom")); QByteArrayLiteral("QmlAnchorBindingProxy::setRelativeAnchorTargetBottom"));
m_relativeBottomTarget = target; m_relativeBottomTarget = target;
anchorBottom(); anchorBottom();
transaction.commit();
} catch (const Exception &e) {
e.showException();
}
emit relativeAnchorTargetBottomChanged(); emit relativeAnchorTargetBottomChanged();
} }
@@ -529,6 +580,7 @@ void QmlAnchorBindingProxy::setRelativeAnchorTargetLeft(QmlAnchorBindingProxy::R
if (target == m_relativeLeftTarget) if (target == m_relativeLeftTarget)
return; return;
try {
RewriterTransaction transaction = beginRewriterTransaction( RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::setRelativeAnchorTargetLeft")); QByteArrayLiteral("QmlAnchorBindingProxy::setRelativeAnchorTargetLeft"));
@@ -536,6 +588,11 @@ void QmlAnchorBindingProxy::setRelativeAnchorTargetLeft(QmlAnchorBindingProxy::R
anchorLeft(); anchorLeft();
transaction.commit();
} catch (const Exception &e) {
e.showException();
}
emit relativeAnchorTargetLeftChanged(); emit relativeAnchorTargetLeftChanged();
} }
@@ -547,6 +604,7 @@ void QmlAnchorBindingProxy::setRelativeAnchorTargetRight(QmlAnchorBindingProxy::
if (target == m_relativeRightTarget) if (target == m_relativeRightTarget)
return; return;
try {
RewriterTransaction transaction = beginRewriterTransaction( RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::setRelativeAnchorTargetRight")); QByteArrayLiteral("QmlAnchorBindingProxy::setRelativeAnchorTargetRight"));
@@ -554,6 +612,11 @@ void QmlAnchorBindingProxy::setRelativeAnchorTargetRight(QmlAnchorBindingProxy::
anchorRight(); anchorRight();
transaction.commit();
} catch (const Exception &e) {
e.showException();
}
emit relativeAnchorTargetRightChanged(); emit relativeAnchorTargetRightChanged();
} }
@@ -566,6 +629,7 @@ void QmlAnchorBindingProxy::setRelativeAnchorTargetVertical(QmlAnchorBindingProx
if (target == m_relativeVerticalTarget) if (target == m_relativeVerticalTarget)
return; return;
try {
RewriterTransaction transaction = beginRewriterTransaction( RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::setRelativeAnchorTargetVertical")); QByteArrayLiteral("QmlAnchorBindingProxy::setRelativeAnchorTargetVertical"));
@@ -573,6 +637,11 @@ void QmlAnchorBindingProxy::setRelativeAnchorTargetVertical(QmlAnchorBindingProx
anchorVertical(); anchorVertical();
transaction.commit();
} catch (const Exception &e) {
e.showException();
}
emit relativeAnchorTargetVerticalChanged(); emit relativeAnchorTargetVerticalChanged();
} }
@@ -584,6 +653,7 @@ void QmlAnchorBindingProxy::setRelativeAnchorTargetHorizontal(QmlAnchorBindingPr
if (target == m_relativeHorizontalTarget) if (target == m_relativeHorizontalTarget)
return; return;
try {
RewriterTransaction transaction = beginRewriterTransaction( RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::setRelativeAnchorTargetHorizontal")); QByteArrayLiteral("QmlAnchorBindingProxy::setRelativeAnchorTargetHorizontal"));
@@ -591,6 +661,11 @@ void QmlAnchorBindingProxy::setRelativeAnchorTargetHorizontal(QmlAnchorBindingPr
anchorHorizontal(); anchorHorizontal();
transaction.commit();
} catch (const Exception &e) {
e.showException();
}
emit relativeAnchorTargetHorizontalChanged(); emit relativeAnchorTargetHorizontalChanged();
} }
@@ -635,6 +710,8 @@ int QmlAnchorBindingProxy::indexOfPossibleTargetItem(const QString &targetName)
} }
void QmlAnchorBindingProxy::resetLayout() { void QmlAnchorBindingProxy::resetLayout() {
try {
RewriterTransaction transaction = beginRewriterTransaction( RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::resetLayout")); QByteArrayLiteral("QmlAnchorBindingProxy::resetLayout"));
@@ -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,6 +743,7 @@ void QmlAnchorBindingProxy::setBottomAnchor(bool anchor)
if (bottomAnchored() == anchor) if (bottomAnchored() == anchor)
return; return;
try {
RewriterTransaction transaction = beginRewriterTransaction( RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::setBottomAnchor")); QByteArrayLiteral("QmlAnchorBindingProxy::setBottomAnchor"));
@@ -673,6 +756,11 @@ void QmlAnchorBindingProxy::setBottomAnchor(bool anchor)
backupPropertyAndRemove(modelNode(), "height"); backupPropertyAndRemove(modelNode(), "height");
} }
transaction.commit();
} catch (const Exception &e) {
e.showException();
}
emit relativeAnchorTargetBottomChanged(); emit relativeAnchorTargetBottomChanged();
emit bottomAnchorChanged(); emit bottomAnchorChanged();
@@ -688,6 +776,7 @@ void QmlAnchorBindingProxy::setLeftAnchor(bool anchor)
if (leftAnchored() == anchor) if (leftAnchored() == anchor)
return; return;
try {
RewriterTransaction transaction = beginRewriterTransaction( RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::setLeftAnchor")); QByteArrayLiteral("QmlAnchorBindingProxy::setLeftAnchor"));
@@ -702,6 +791,11 @@ void QmlAnchorBindingProxy::setLeftAnchor(bool anchor)
backupPropertyAndRemove(modelNode(), "width"); backupPropertyAndRemove(modelNode(), "width");
} }
transaction.commit();
} catch (const Exception &e) {
e.showException();
}
emit relativeAnchorTargetLeftChanged(); emit relativeAnchorTargetLeftChanged();
emit leftAnchorChanged(); emit leftAnchorChanged();
if (hasAnchors() != anchor) if (hasAnchors() != anchor)
@@ -716,6 +810,7 @@ void QmlAnchorBindingProxy::setRightAnchor(bool anchor)
if (rightAnchored() == anchor) if (rightAnchored() == anchor)
return; return;
try {
RewriterTransaction transaction = beginRewriterTransaction( RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::setRightAnchor")); QByteArrayLiteral("QmlAnchorBindingProxy::setRightAnchor"));
@@ -729,6 +824,11 @@ void QmlAnchorBindingProxy::setRightAnchor(bool anchor)
backupPropertyAndRemove(modelNode(), "width"); backupPropertyAndRemove(modelNode(), "width");
} }
transaction.commit();
} catch (const Exception &e) {
e.showException();
}
emit relativeAnchorTargetRightChanged(); emit relativeAnchorTargetRightChanged();
emit rightAnchorChanged(); emit rightAnchorChanged();
@@ -926,6 +1026,7 @@ void QmlAnchorBindingProxy::setTopAnchor(bool anchor)
if (topAnchored() == anchor) if (topAnchored() == anchor)
return; return;
try {
RewriterTransaction transaction = beginRewriterTransaction( RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::setTopAnchor")); QByteArrayLiteral("QmlAnchorBindingProxy::setTopAnchor"));
@@ -939,6 +1040,10 @@ void QmlAnchorBindingProxy::setTopAnchor(bool anchor)
if (bottomAnchored()) if (bottomAnchored())
backupPropertyAndRemove(modelNode(), "height"); backupPropertyAndRemove(modelNode(), "height");
} }
transaction.commit();
} catch (const Exception &e) {
e.showException();
}
emit relativeAnchorTargetTopChanged(); emit relativeAnchorTargetTopChanged();
emit topAnchorChanged(); emit topAnchorChanged();
@@ -947,6 +1052,7 @@ void QmlAnchorBindingProxy::setTopAnchor(bool anchor)
} }
void QmlAnchorBindingProxy::removeTopAnchor() { void QmlAnchorBindingProxy::removeTopAnchor() {
try {
RewriterTransaction transaction = beginRewriterTransaction( RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::removeTopAnchor")); QByteArrayLiteral("QmlAnchorBindingProxy::removeTopAnchor"));
@@ -956,9 +1062,14 @@ void QmlAnchorBindingProxy::removeTopAnchor() {
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() {
try {
RewriterTransaction transaction = beginRewriterTransaction( RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::removeBottomAnchor")); QByteArrayLiteral("QmlAnchorBindingProxy::removeBottomAnchor"));
@@ -967,9 +1078,15 @@ void QmlAnchorBindingProxy::removeBottomAnchor() {
restoreProperty(modelNode(), "height"); restoreProperty(modelNode(), "height");
transaction.commit();
} catch (const Exception &e) {
e.showException();
}
} }
void QmlAnchorBindingProxy::removeLeftAnchor() { void QmlAnchorBindingProxy::removeLeftAnchor() {
try {
RewriterTransaction transaction = beginRewriterTransaction( RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::removeLeftAnchor")); QByteArrayLiteral("QmlAnchorBindingProxy::removeLeftAnchor"));
@@ -978,9 +1095,15 @@ void QmlAnchorBindingProxy::removeLeftAnchor() {
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() {
try {
RewriterTransaction transaction = beginRewriterTransaction( RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::removeRightAnchor")); QByteArrayLiteral("QmlAnchorBindingProxy::removeRightAnchor"));
@@ -988,6 +1111,11 @@ void QmlAnchorBindingProxy::removeRightAnchor() {
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,6 +1128,7 @@ void QmlAnchorBindingProxy::setVerticalCentered(bool centered)
m_locked = true; m_locked = true;
try {
RewriterTransaction transaction = beginRewriterTransaction( RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::setVerticalCentered")); QByteArrayLiteral("QmlAnchorBindingProxy::setVerticalCentered"));
@@ -1012,6 +1141,10 @@ void QmlAnchorBindingProxy::setVerticalCentered(bool centered)
anchorVertical(); anchorVertical();
} }
transaction.commit();
} catch (const Exception &e) {
e.showException();
}
m_locked = false; m_locked = false;
emit relativeAnchorTargetVerticalChanged(); emit relativeAnchorTargetVerticalChanged();
@@ -1028,6 +1161,7 @@ void QmlAnchorBindingProxy::setHorizontalCentered(bool centered)
m_locked = true; m_locked = true;
try {
RewriterTransaction transaction = beginRewriterTransaction( RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::setHorizontalCentered")); QByteArrayLiteral("QmlAnchorBindingProxy::setHorizontalCentered"));
@@ -1040,6 +1174,10 @@ void QmlAnchorBindingProxy::setHorizontalCentered(bool centered)
anchorHorizontal(); anchorHorizontal();
} }
transaction.commit();
} catch (const Exception &e) {
e.showException();
}
m_locked = false; m_locked = false;
emit relativeAnchorTargetHorizontalChanged(); emit relativeAnchorTargetHorizontalChanged();
@@ -1119,6 +1257,7 @@ bool QmlAnchorBindingProxy::horizontalCentered()
void QmlAnchorBindingProxy::fill() void QmlAnchorBindingProxy::fill()
{ {
try {
RewriterTransaction transaction = beginRewriterTransaction( RewriterTransaction transaction = beginRewriterTransaction(
QByteArrayLiteral("QmlAnchorBindingProxy::fill")); QByteArrayLiteral("QmlAnchorBindingProxy::fill"));
@@ -1138,6 +1277,11 @@ void QmlAnchorBindingProxy::fill()
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();
emit leftAnchorChanged(); emit leftAnchorChanged();