aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/quick/designer/qquickdesignersupport.cpp20
-rw-r--r--src/quick/items/qquickanchors.cpp415
-rw-r--r--src/quick/items/qquickanchors_p.h1
-rw-r--r--src/quick/items/qquickanchors_p_p.h137
-rw-r--r--src/quick/items/qquickitem.cpp14
-rw-r--r--tests/auto/quick/qquickanchors/tst_qquickanchors.cpp33
-rw-r--r--tests/auto/quick/qquickstates/tst_qquickstates.cpp4
-rw-r--r--tests/benchmarks/qml/creation/tst_creation.cpp15
8 files changed, 366 insertions, 273 deletions
diff --git a/src/quick/designer/qquickdesignersupport.cpp b/src/quick/designer/qquickdesignersupport.cpp
index 5bb36c5192..78ed89a107 100644
--- a/src/quick/designer/qquickdesignersupport.cpp
+++ b/src/quick/designer/qquickdesignersupport.cpp
@@ -187,17 +187,17 @@ QTransform QQuickDesignerSupport::parentTransform(QQuickItem *referencedItem)
return parentTransform;
}
-QString propertyNameForAnchorLine(const QQuickAnchorLine::AnchorLine &anchorLine)
+QString propertyNameForAnchorLine(const QQuickAnchors::Anchor &anchorLine)
{
switch (anchorLine) {
- case QQuickAnchorLine::Left: return QLatin1String("left");
- case QQuickAnchorLine::Right: return QLatin1String("right");
- case QQuickAnchorLine::Top: return QLatin1String("top");
- case QQuickAnchorLine::Bottom: return QLatin1String("bottom");
- case QQuickAnchorLine::HCenter: return QLatin1String("horizontalCenter");
- case QQuickAnchorLine::VCenter: return QLatin1String("verticalCenter");
- case QQuickAnchorLine::Baseline: return QLatin1String("baseline");
- case QQuickAnchorLine::Invalid:
+ case QQuickAnchors::LeftAnchor: return QLatin1String("left");
+ case QQuickAnchors::RightAnchor: return QLatin1String("right");
+ case QQuickAnchors::TopAnchor: return QLatin1String("top");
+ case QQuickAnchors::BottomAnchor: return QLatin1String("bottom");
+ case QQuickAnchors::HCenterAnchor: return QLatin1String("horizontalCenter");
+ case QQuickAnchors::VCenterAnchor: return QLatin1String("verticalCenter");
+ case QQuickAnchors::BaselineAnchor: return QLatin1String("baseline");
+ case QQuickAnchors::InvalidAnchor: // fallthrough:
default: return QString();
}
}
@@ -343,7 +343,7 @@ QPair<QString, QObject*> QQuickDesignerSupport::anchorLineTarget(QQuickItem *ite
return QPair<QString, QObject*>();
QQuickAnchorLine anchorLine = metaProperty.read().value<QQuickAnchorLine>();
- if (anchorLine.anchorLine != QQuickAnchorLine::Invalid) {
+ if (anchorLine.anchorLine != QQuickAnchors::InvalidAnchor) {
targetObject = anchorLine.item;
targetName = propertyNameForAnchorLine(anchorLine.anchorLine);
}
diff --git a/src/quick/items/qquickanchors.cpp b/src/quick/items/qquickanchors.cpp
index df33a0cc5c..4cbd41106e 100644
--- a/src/quick/items/qquickanchors.cpp
+++ b/src/quick/items/qquickanchors.cpp
@@ -45,32 +45,32 @@
QT_BEGIN_NAMESPACE
-static Q_ALWAYS_INLINE QQuickItem *readParentItem(QQuickItem *item)
+static Q_ALWAYS_INLINE QQuickItem *readParentItem(const QQuickItem *item)
{
return QQuickItemPrivate::get(item)->parentItem;
}
-static Q_ALWAYS_INLINE qreal readX(QQuickItem *item)
+static Q_ALWAYS_INLINE qreal readX(const QQuickItem *item)
{
return QQuickItemPrivate::get(item)->x;
}
-static Q_ALWAYS_INLINE qreal readY(QQuickItem *item)
+static Q_ALWAYS_INLINE qreal readY(const QQuickItem *item)
{
return QQuickItemPrivate::get(item)->y;
}
-static Q_ALWAYS_INLINE qreal readWidth(QQuickItem *item)
+static Q_ALWAYS_INLINE qreal readWidth(const QQuickItem *item)
{
return QQuickItemPrivate::get(item)->width;
}
-static Q_ALWAYS_INLINE qreal readHeight(QQuickItem *item)
+static Q_ALWAYS_INLINE qreal readHeight(const QQuickItem *item)
{
return QQuickItemPrivate::get(item)->height;
}
-static Q_ALWAYS_INLINE qreal readBaselineOffset(QQuickItem *item)
+static Q_ALWAYS_INLINE qreal readBaselineOffset(const QQuickItem *item)
{
return QQuickItemPrivate::get(item)->baselineOffset;
}
@@ -78,7 +78,7 @@ static Q_ALWAYS_INLINE qreal readBaselineOffset(QQuickItem *item)
//TODO: should we cache relationships, so we don't have to check each time (parent-child or sibling)?
//TODO: support non-parent, non-sibling (need to find lowest common ancestor)
-static inline qreal hcenter(QQuickItem *item)
+static inline qreal hcenter(const QQuickItem *item)
{
qreal width = readWidth(item);
if (QQuickAnchors *anchors = QQuickItemPrivate::get(item)->_anchors) {
@@ -92,7 +92,7 @@ static inline qreal hcenter(QQuickItem *item)
return width / 2;
}
-static inline qreal vcenter(QQuickItem *item)
+static inline qreal vcenter(const QQuickItem *item)
{
qreal height = readHeight(item);
if (QQuickAnchors *anchors = QQuickItemPrivate::get(item)->_anchors) {
@@ -106,31 +106,30 @@ static inline qreal vcenter(QQuickItem *item)
return height / 2;
}
-//### const item?
//local position
-static qreal position(QQuickItem *item, QQuickAnchorLine::AnchorLine anchorLine)
+static inline qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
{
qreal ret = 0.0;
switch (anchorLine) {
- case QQuickAnchorLine::Left:
+ case QQuickAnchors::LeftAnchor:
ret = readX(item);
break;
- case QQuickAnchorLine::Right:
+ case QQuickAnchors::RightAnchor:
ret = readX(item) + readWidth(item);
break;
- case QQuickAnchorLine::Top:
+ case QQuickAnchors::TopAnchor:
ret = readY(item);
break;
- case QQuickAnchorLine::Bottom:
+ case QQuickAnchors::BottomAnchor:
ret = readY(item) + readHeight(item);
break;
- case QQuickAnchorLine::HCenter:
+ case QQuickAnchors::HCenterAnchor:
ret = readX(item) + hcenter(item);
break;
- case QQuickAnchorLine::VCenter:
+ case QQuickAnchors::VCenterAnchor:
ret = readY(item) + vcenter(item);
break;
- case QQuickAnchorLine::Baseline:
+ case QQuickAnchors::BaselineAnchor:
ret = readY(item) + readBaselineOffset(item);
break;
default:
@@ -141,29 +140,29 @@ static qreal position(QQuickItem *item, QQuickAnchorLine::AnchorLine anchorLine)
}
//position when origin is 0,0
-static inline qreal adjustedPosition(QQuickItem *item, QQuickAnchorLine::AnchorLine anchorLine)
+static inline qreal adjustedPosition(QQuickItem *item, QQuickAnchors::Anchor anchorLine)
{
qreal ret = 0.0;
switch (anchorLine) {
- case QQuickAnchorLine::Left:
+ case QQuickAnchors::LeftAnchor:
ret = 0.0;
break;
- case QQuickAnchorLine::Right:
+ case QQuickAnchors::RightAnchor:
ret = readWidth(item);
break;
- case QQuickAnchorLine::Top:
+ case QQuickAnchors::TopAnchor:
ret = 0.0;
break;
- case QQuickAnchorLine::Bottom:
+ case QQuickAnchors::BottomAnchor:
ret = readHeight(item);
break;
- case QQuickAnchorLine::HCenter:
+ case QQuickAnchors::HCenterAnchor:
ret = hcenter(item);
break;
- case QQuickAnchorLine::VCenter:
+ case QQuickAnchors::VCenterAnchor:
ret = vcenter(item);
break;
- case QQuickAnchorLine::Baseline:
+ case QQuickAnchors::BaselineAnchor:
ret = readBaselineOffset(item);
break;
default:
@@ -184,13 +183,13 @@ QQuickAnchors::~QQuickAnchors()
d->inDestructor = true;
d->remDepend(d->fill);
d->remDepend(d->centerIn);
- d->remDepend(d->left.item);
- d->remDepend(d->right.item);
- d->remDepend(d->top.item);
- d->remDepend(d->bottom.item);
- d->remDepend(d->vCenter.item);
- d->remDepend(d->hCenter.item);
- d->remDepend(d->baseline.item);
+ d->remDepend(d->leftAnchorItem);
+ d->remDepend(d->rightAnchorItem);
+ d->remDepend(d->topAnchorItem);
+ d->remDepend(d->bottomAnchorItem);
+ d->remDepend(d->vCenterAnchorItem);
+ d->remDepend(d->hCenterAnchorItem);
+ d->remDepend(d->baselineAnchorItem);
}
void QQuickAnchorsPrivate::fillChanged()
@@ -256,32 +255,32 @@ void QQuickAnchorsPrivate::clearItem(QQuickItem *item)
fill = 0;
if (centerIn == item)
centerIn = 0;
- if (left.item == item) {
- left.item = 0;
+ if (leftAnchorItem == item) {
+ leftAnchorItem = 0;
usedAnchors &= ~QQuickAnchors::LeftAnchor;
}
- if (right.item == item) {
- right.item = 0;
+ if (rightAnchorItem == item) {
+ rightAnchorItem = 0;
usedAnchors &= ~QQuickAnchors::RightAnchor;
}
- if (top.item == item) {
- top.item = 0;
+ if (topAnchorItem == item) {
+ topAnchorItem = 0;
usedAnchors &= ~QQuickAnchors::TopAnchor;
}
- if (bottom.item == item) {
- bottom.item = 0;
+ if (bottomAnchorItem == item) {
+ bottomAnchorItem = 0;
usedAnchors &= ~QQuickAnchors::BottomAnchor;
}
- if (vCenter.item == item) {
- vCenter.item = 0;
+ if (vCenterAnchorItem == item) {
+ vCenterAnchorItem = 0;
usedAnchors &= ~QQuickAnchors::VCenterAnchor;
}
- if (hCenter.item == item) {
- hCenter.item = 0;
+ if (hCenterAnchorItem == item) {
+ hCenterAnchorItem = 0;
usedAnchors &= ~QQuickAnchors::HCenterAnchor;
}
- if (baseline.item == item) {
- baseline.item = 0;
+ if (baselineAnchorItem == item) {
+ baselineAnchorItem = 0;
usedAnchors &= ~QQuickAnchors::BaselineAnchor;
}
}
@@ -309,19 +308,19 @@ int QQuickAnchorsPrivate::calculateDependency(QQuickItem *controlItem)
return dependency; //exit early
}
- if ((usedAnchors & QQuickAnchors::LeftAnchor && left.item == controlItem) ||
- (usedAnchors & QQuickAnchors::RightAnchor && right.item == controlItem) ||
- (usedAnchors & QQuickAnchors::HCenterAnchor && hCenter.item == controlItem)) {
+ if ((usedAnchors & QQuickAnchors::LeftAnchor && leftAnchorItem == controlItem) ||
+ (usedAnchors & QQuickAnchors::RightAnchor && rightAnchorItem == controlItem) ||
+ (usedAnchors & QQuickAnchors::HCenterAnchor && hCenterAnchorItem == controlItem)) {
if (controlItem == readParentItem(item))
dependency |= QQuickItemPrivate::WidthChange;
else //sibling
dependency |= QFlags<QQuickItemPrivate::GeometryChangeType>(QQuickItemPrivate::XChange | QQuickItemPrivate::WidthChange);
}
- if ((usedAnchors & QQuickAnchors::TopAnchor && top.item == controlItem) ||
- (usedAnchors & QQuickAnchors::BottomAnchor && bottom.item == controlItem) ||
- (usedAnchors & QQuickAnchors::VCenterAnchor && vCenter.item == controlItem) ||
- (usedAnchors & QQuickAnchors::BaselineAnchor && baseline.item == controlItem)) {
+ if ((usedAnchors & QQuickAnchors::TopAnchor && topAnchorItem == controlItem) ||
+ (usedAnchors & QQuickAnchors::BottomAnchor && bottomAnchorItem == controlItem) ||
+ (usedAnchors & QQuickAnchors::VCenterAnchor && vCenterAnchorItem == controlItem) ||
+ (usedAnchors & QQuickAnchors::BaselineAnchor && baselineAnchorItem == controlItem)) {
if (controlItem == readParentItem(item))
dependency |= QQuickItemPrivate::HeightChange;
else //sibling
@@ -453,13 +452,13 @@ void QQuickAnchorsPrivate::updateOnComplete()
QQuickItem *dependencies[9];
dependencies[0] = fill;
dependencies[1] = centerIn;
- dependencies[2] = left.item;
- dependencies[3] = right.item;
- dependencies[4] = hCenter.item;
- dependencies[5] = top.item;
- dependencies[6] = bottom.item;
- dependencies[7] = vCenter.item;
- dependencies[8] = baseline.item;
+ dependencies[2] = leftAnchorItem;
+ dependencies[3] = rightAnchorItem;
+ dependencies[4] = hCenterAnchorItem;
+ dependencies[5] = topAnchorItem;
+ dependencies[6] = bottomAnchorItem;
+ dependencies[7] = vCenterAnchorItem;
+ dependencies[8] = baselineAnchorItem;
std::sort(dependencies, dependencies + 9);
@@ -486,9 +485,9 @@ void QQuickAnchorsPrivate::update()
} else if (centerIn) {
centerInChanged();
} else {
- if (usedAnchors & QQuickAnchorLine::Horizontal_Mask)
+ if (usedAnchors & QQuickAnchors::Horizontal_Mask)
updateHorizontalAnchors();
- if (usedAnchors & QQuickAnchorLine::Vertical_Mask)
+ if (usedAnchors & QQuickAnchors::Vertical_Mask)
updateVerticalAnchors();
}
}
@@ -503,9 +502,11 @@ void QQuickAnchorsPrivate::itemGeometryChanged(QQuickItem *, const QRectF &newG,
} else if (centerIn) {
centerInChanged();
} else {
- if ((usedAnchors & QQuickAnchorLine::Horizontal_Mask) && (newG.x() != oldG.x() || newG.width() != oldG.width()))
+ if ((usedAnchors & QQuickAnchors::Horizontal_Mask)
+ && (newG.x() != oldG.x() || newG.width() != oldG.width()))
updateHorizontalAnchors();
- if ((usedAnchors & QQuickAnchorLine::Vertical_Mask) && (newG.y() != oldG.y() || newG.height() != oldG.height()))
+ if ((usedAnchors & QQuickAnchors::Vertical_Mask)
+ && (newG.y() != oldG.y() || newG.height() != oldG.height()))
updateVerticalAnchors();
}
}
@@ -582,29 +583,31 @@ void QQuickAnchors::resetCenterIn()
setCenterIn(0);
}
-bool QQuickAnchorsPrivate::calcStretch(const QQuickAnchorLine &edge1,
- const QQuickAnchorLine &edge2,
- qreal offset1,
- qreal offset2,
- QQuickAnchorLine::AnchorLine line,
- qreal &stretch)
+bool QQuickAnchorsPrivate::calcStretch(QQuickItem *edge1Item,
+ QQuickAnchors::Anchor edge1Line,
+ QQuickItem *edge2Item,
+ QQuickAnchors::Anchor edge2Line,
+ qreal offset1,
+ qreal offset2,
+ QQuickAnchors::Anchor line,
+ qreal &stretch)
{
- bool edge1IsParent = (edge1.item == readParentItem(item));
- bool edge2IsParent = (edge2.item == readParentItem(item));
- bool edge1IsSibling = (readParentItem(edge1.item) == readParentItem(item));
- bool edge2IsSibling = (readParentItem(edge2.item) == readParentItem(item));
+ bool edge1IsParent = (edge1Item == readParentItem(item));
+ bool edge2IsParent = (edge2Item == readParentItem(item));
+ bool edge1IsSibling = (readParentItem(edge1Item) == readParentItem(item));
+ bool edge2IsSibling = (readParentItem(edge2Item) == readParentItem(item));
bool invalid = false;
if ((edge2IsParent && edge1IsParent) || (edge2IsSibling && edge1IsSibling)) {
- stretch = (position(edge2.item, edge2.anchorLine) + offset2)
- - (position(edge1.item, edge1.anchorLine) + offset1);
+ stretch = (position(edge2Item, edge2Line) + offset2)
+ - (position(edge1Item, edge1Line) + offset1);
} else if (edge2IsParent && edge1IsSibling) {
- stretch = (position(edge2.item, edge2.anchorLine) + offset2)
+ stretch = (position(edge2Item, edge2Line) + offset2)
- (position(readParentItem(item), line)
- + position(edge1.item, edge1.anchorLine) + offset1);
+ + position(edge1Item, edge1Line) + offset1);
} else if (edge2IsSibling && edge1IsParent) {
- stretch = (position(readParentItem(item), line) + position(edge2.item, edge2.anchorLine) + offset2)
- - (position(edge1.item, edge1.anchorLine) + offset1);
+ stretch = (position(readParentItem(item), line) + position(edge2Item, edge2Line) + offset2)
+ - (position(edge1Item, edge1Line) + offset1);
} else
invalid = true;
@@ -623,53 +626,59 @@ void QQuickAnchorsPrivate::updateVerticalAnchors()
bool invalid = true;
qreal height = 0.0;
if (usedAnchors & QQuickAnchors::BottomAnchor) {
- invalid = calcStretch(top, bottom, topMargin, -bottomMargin, QQuickAnchorLine::Top, height);
+ invalid = calcStretch(topAnchorItem, topAnchorLine,
+ bottomAnchorItem, bottomAnchorLine,
+ topMargin, -bottomMargin, QQuickAnchors::TopAnchor, height);
} else if (usedAnchors & QQuickAnchors::VCenterAnchor) {
- invalid = calcStretch(top, vCenter, topMargin, vCenterOffset, QQuickAnchorLine::Top, height);
+ invalid = calcStretch(topAnchorItem, topAnchorLine,
+ vCenterAnchorItem, vCenterAnchorLine,
+ topMargin, vCenterOffset, QQuickAnchors::TopAnchor, height);
height *= 2;
}
if (!invalid)
setItemHeight(height);
//Handle top
- if (top.item == readParentItem(item)) {
- setItemY(adjustedPosition(top.item, top.anchorLine) + topMargin);
- } else if (readParentItem(top.item) == readParentItem(item)) {
- setItemY(position(top.item, top.anchorLine) + topMargin);
+ if (topAnchorItem == readParentItem(item)) {
+ setItemY(adjustedPosition(topAnchorItem, topAnchorLine) + topMargin);
+ } else if (readParentItem(topAnchorItem) == readParentItem(item)) {
+ setItemY(position(topAnchorItem, topAnchorLine) + topMargin);
}
} else if (usedAnchors & QQuickAnchors::BottomAnchor) {
//Handle stretching (top + bottom case is handled above)
if (usedAnchors & QQuickAnchors::VCenterAnchor) {
qreal height = 0.0;
- bool invalid = calcStretch(vCenter, bottom, vCenterOffset, -bottomMargin,
- QQuickAnchorLine::Top, height);
+ bool invalid = calcStretch(vCenterAnchorItem, vCenterAnchorLine,
+ bottomAnchorItem, bottomAnchorLine,
+ vCenterOffset, -bottomMargin, QQuickAnchors::TopAnchor,
+ height);
if (!invalid)
setItemHeight(height*2);
}
//Handle bottom
- if (bottom.item == readParentItem(item)) {
- setItemY(adjustedPosition(bottom.item, bottom.anchorLine) - readHeight(item) - bottomMargin);
- } else if (readParentItem(bottom.item) == readParentItem(item)) {
- setItemY(position(bottom.item, bottom.anchorLine) - readHeight(item) - bottomMargin);
+ if (bottomAnchorItem == readParentItem(item)) {
+ setItemY(adjustedPosition(bottomAnchorItem, bottomAnchorLine) - readHeight(item) - bottomMargin);
+ } else if (readParentItem(bottomAnchorItem) == readParentItem(item)) {
+ setItemY(position(bottomAnchorItem, bottomAnchorLine) - readHeight(item) - bottomMargin);
}
} else if (usedAnchors & QQuickAnchors::VCenterAnchor) {
//(stetching handled above)
//Handle vCenter
- if (vCenter.item == readParentItem(item)) {
- setItemY(adjustedPosition(vCenter.item, vCenter.anchorLine)
+ if (vCenterAnchorItem == readParentItem(item)) {
+ setItemY(adjustedPosition(vCenterAnchorItem, vCenterAnchorLine)
- vcenter(item) + vCenterOffset);
- } else if (readParentItem(vCenter.item) == readParentItem(item)) {
- setItemY(position(vCenter.item, vCenter.anchorLine) - vcenter(item) + vCenterOffset);
+ } else if (readParentItem(vCenterAnchorItem) == readParentItem(item)) {
+ setItemY(position(vCenterAnchorItem, vCenterAnchorLine) - vcenter(item) + vCenterOffset);
}
} else if (usedAnchors & QQuickAnchors::BaselineAnchor) {
//Handle baseline
- if (baseline.item == readParentItem(item)) {
- setItemY(adjustedPosition(baseline.item, baseline.anchorLine)
+ if (baselineAnchorItem == readParentItem(item)) {
+ setItemY(adjustedPosition(baselineAnchorItem, baselineAnchorLine)
- readBaselineOffset(item) + baselineOffset);
- } else if (readParentItem(baseline.item) == readParentItem(item)) {
- setItemY(position(baseline.item, baseline.anchorLine)
+ } else if (readParentItem(baselineAnchorItem) == readParentItem(item)) {
+ setItemY(position(baselineAnchorItem, baselineAnchorLine)
- readBaselineOffset(item) + baselineOffset);
}
}
@@ -680,12 +689,12 @@ void QQuickAnchorsPrivate::updateVerticalAnchors()
}
}
-inline QQuickAnchorLine::AnchorLine reverseAnchorLine(QQuickAnchorLine::AnchorLine anchorLine)
+static inline QQuickAnchors::Anchor reverseAnchorLine(QQuickAnchors::Anchor anchorLine)
{
- if (anchorLine == QQuickAnchorLine::Left) {
- return QQuickAnchorLine::Right;
- } else if (anchorLine == QQuickAnchorLine::Right) {
- return QQuickAnchorLine::Left;
+ if (anchorLine == QQuickAnchors::LeftAnchor) {
+ return QQuickAnchors::RightAnchor;
+ } else if (anchorLine == QQuickAnchors::RightAnchor) {
+ return QQuickAnchors::LeftAnchor;
} else {
return anchorLine;
}
@@ -700,26 +709,30 @@ void QQuickAnchorsPrivate::updateHorizontalAnchors()
if (updatingHorizontalAnchor < 3) {
++updatingHorizontalAnchor;
qreal effectiveRightMargin, effectiveLeftMargin, effectiveHorizontalCenterOffset;
- QQuickAnchorLine effectiveLeft, effectiveRight, effectiveHorizontalCenter;
+ QQuickItem *effectiveLeftItem, *effectiveRightItem, *effectiveHorizontalCenterItem;
+ QQuickAnchors::Anchor effectiveLeftLine, effectiveRightLine, effectiveHorizontalCenterLine;
QQuickAnchors::Anchor effectiveLeftAnchor, effectiveRightAnchor;
if (q->mirrored()) {
effectiveLeftAnchor = QQuickAnchors::RightAnchor;
effectiveRightAnchor = QQuickAnchors::LeftAnchor;
- effectiveLeft.item = right.item;
- effectiveLeft.anchorLine = reverseAnchorLine(right.anchorLine);
- effectiveRight.item = left.item;
- effectiveRight.anchorLine = reverseAnchorLine(left.anchorLine);
- effectiveHorizontalCenter.item = hCenter.item;
- effectiveHorizontalCenter.anchorLine = reverseAnchorLine(hCenter.anchorLine);
+ effectiveLeftItem = rightAnchorItem;
+ effectiveLeftLine = reverseAnchorLine(rightAnchorLine);
+ effectiveRightItem = leftAnchorItem;
+ effectiveRightLine = reverseAnchorLine(leftAnchorLine);
+ effectiveHorizontalCenterItem = hCenterAnchorItem;
+ effectiveHorizontalCenterLine = reverseAnchorLine(hCenterAnchorLine);
effectiveLeftMargin = rightMargin;
effectiveRightMargin = leftMargin;
effectiveHorizontalCenterOffset = -hCenterOffset;
} else {
effectiveLeftAnchor = QQuickAnchors::LeftAnchor;
effectiveRightAnchor = QQuickAnchors::RightAnchor;
- effectiveLeft = left;
- effectiveRight = right;
- effectiveHorizontalCenter = hCenter;
+ effectiveLeftItem = leftAnchorItem;
+ effectiveLeftLine = leftAnchorLine;
+ effectiveRightItem = rightAnchorItem;
+ effectiveRightLine = rightAnchorLine;
+ effectiveHorizontalCenterItem = hCenterAnchorItem;
+ effectiveHorizontalCenterLine = hCenterAnchorLine;
effectiveLeftMargin = leftMargin;
effectiveRightMargin = rightMargin;
effectiveHorizontalCenterOffset = hCenterOffset;
@@ -730,44 +743,53 @@ void QQuickAnchorsPrivate::updateHorizontalAnchors()
bool invalid = true;
qreal width = 0.0;
if (usedAnchors & effectiveRightAnchor) {
- invalid = calcStretch(effectiveLeft, effectiveRight, effectiveLeftMargin, -effectiveRightMargin, QQuickAnchorLine::Left, width);
+ invalid = calcStretch(effectiveLeftItem, effectiveLeftLine,
+ effectiveRightItem, effectiveRightLine,
+ effectiveLeftMargin, -effectiveRightMargin,
+ QQuickAnchors::LeftAnchor, width);
} else if (usedAnchors & QQuickAnchors::HCenterAnchor) {
- invalid = calcStretch(effectiveLeft, effectiveHorizontalCenter, effectiveLeftMargin, effectiveHorizontalCenterOffset, QQuickAnchorLine::Left, width);
+ invalid = calcStretch(effectiveLeftItem, effectiveLeftLine,
+ effectiveHorizontalCenterItem, effectiveHorizontalCenterLine,
+ effectiveLeftMargin, effectiveHorizontalCenterOffset,
+ QQuickAnchors::LeftAnchor, width);
width *= 2;
}
if (!invalid)
setItemWidth(width);
//Handle left
- if (effectiveLeft.item == readParentItem(item)) {
- setItemX(adjustedPosition(effectiveLeft.item, effectiveLeft.anchorLine) + effectiveLeftMargin);
- } else if (readParentItem(effectiveLeft.item) == readParentItem(item)) {
- setItemX(position(effectiveLeft.item, effectiveLeft.anchorLine) + effectiveLeftMargin);
+ if (effectiveLeftItem == readParentItem(item)) {
+ setItemX(adjustedPosition(effectiveLeftItem, effectiveLeftLine) + effectiveLeftMargin);
+ } else if (readParentItem(effectiveLeftItem) == readParentItem(item)) {
+ setItemX(position(effectiveLeftItem, effectiveLeftLine) + effectiveLeftMargin);
}
} else if (usedAnchors & effectiveRightAnchor) {
//Handle stretching (left + right case is handled in updateLeftAnchor)
if (usedAnchors & QQuickAnchors::HCenterAnchor) {
qreal width = 0.0;
- bool invalid = calcStretch(effectiveHorizontalCenter, effectiveRight, effectiveHorizontalCenterOffset, -effectiveRightMargin,
- QQuickAnchorLine::Left, width);
+ bool invalid = calcStretch(effectiveHorizontalCenterItem,
+ effectiveHorizontalCenterLine,
+ effectiveRightItem, effectiveRightLine,
+ effectiveHorizontalCenterOffset, -effectiveRightMargin,
+ QQuickAnchors::LeftAnchor, width);
if (!invalid)
setItemWidth(width*2);
}
//Handle right
- if (effectiveRight.item == readParentItem(item)) {
- setItemX(adjustedPosition(effectiveRight.item, effectiveRight.anchorLine)
+ if (effectiveRightItem == readParentItem(item)) {
+ setItemX(adjustedPosition(effectiveRightItem, effectiveRightLine)
- readWidth(item) - effectiveRightMargin);
- } else if (readParentItem(effectiveRight.item) == readParentItem(item)) {
- setItemX(position(effectiveRight.item, effectiveRight.anchorLine)
+ } else if (readParentItem(effectiveRightItem) == readParentItem(item)) {
+ setItemX(position(effectiveRightItem, effectiveRightLine)
- readWidth(item) - effectiveRightMargin);
}
} else if (usedAnchors & QQuickAnchors::HCenterAnchor) {
//Handle hCenter
- if (effectiveHorizontalCenter.item == readParentItem(item)) {
- setItemX(adjustedPosition(effectiveHorizontalCenter.item, effectiveHorizontalCenter.anchorLine) - hcenter(item) + effectiveHorizontalCenterOffset);
- } else if (readParentItem(effectiveHorizontalCenter.item) == readParentItem(item)) {
- setItemX(position(effectiveHorizontalCenter.item, effectiveHorizontalCenter.anchorLine) - hcenter(item) + effectiveHorizontalCenterOffset);
+ if (effectiveHorizontalCenterItem == readParentItem(item)) {
+ setItemX(adjustedPosition(effectiveHorizontalCenterItem, effectiveHorizontalCenterLine) - hcenter(item) + effectiveHorizontalCenterOffset);
+ } else if (readParentItem(effectiveHorizontalCenterItem) == readParentItem(item)) {
+ setItemX(position(effectiveHorizontalCenterItem, effectiveHorizontalCenterLine) - hcenter(item) + effectiveHorizontalCenterOffset);
}
}
--updatingHorizontalAnchor;
@@ -780,13 +802,14 @@ void QQuickAnchorsPrivate::updateHorizontalAnchors()
QQuickAnchorLine QQuickAnchors::top() const
{
Q_D(const QQuickAnchors);
- return d->top;
+ return QQuickAnchorLine(d->topAnchorItem, d->topAnchorLine);
}
void QQuickAnchors::setTop(const QQuickAnchorLine &edge)
{
Q_D(QQuickAnchors);
- if (!d->checkVAnchorValid(edge) || d->top == edge)
+ if (!d->checkVAnchorValid(edge) ||
+ (d->topAnchorItem == edge.item && d->topAnchorLine == edge.anchorLine))
return;
d->usedAnchors |= TopAnchor;
@@ -796,10 +819,11 @@ void QQuickAnchors::setTop(const QQuickAnchorLine &edge)
return;
}
- QQuickItem *oldTop = d->top.item;
- d->top = edge;
+ QQuickItem *oldTop = d->topAnchorItem;
+ d->topAnchorItem = edge.item;
+ d->topAnchorLine = edge.anchorLine;
d->remDepend(oldTop);
- d->addDepend(d->top.item);
+ d->addDepend(d->topAnchorItem);
emit topChanged();
d->updateVerticalAnchors();
}
@@ -808,8 +832,9 @@ void QQuickAnchors::resetTop()
{
Q_D(QQuickAnchors);
d->usedAnchors &= ~TopAnchor;
- d->remDepend(d->top.item);
- d->top = QQuickAnchorLine();
+ d->remDepend(d->topAnchorItem);
+ d->topAnchorItem = Q_NULLPTR;
+ d->topAnchorLine = QQuickAnchors::InvalidAnchor;
emit topChanged();
d->updateVerticalAnchors();
}
@@ -817,13 +842,14 @@ void QQuickAnchors::resetTop()
QQuickAnchorLine QQuickAnchors::bottom() const
{
Q_D(const QQuickAnchors);
- return d->bottom;
+ return QQuickAnchorLine(d->bottomAnchorItem, d->bottomAnchorLine);
}
void QQuickAnchors::setBottom(const QQuickAnchorLine &edge)
{
Q_D(QQuickAnchors);
- if (!d->checkVAnchorValid(edge) || d->bottom == edge)
+ if (!d->checkVAnchorValid(edge) ||
+ (d->bottomAnchorItem == edge.item && d->bottomAnchorLine == edge.anchorLine))
return;
d->usedAnchors |= BottomAnchor;
@@ -833,10 +859,11 @@ void QQuickAnchors::setBottom(const QQuickAnchorLine &edge)
return;
}
- QQuickItem *oldBottom = d->bottom.item;
- d->bottom = edge;
+ QQuickItem *oldBottom = d->bottomAnchorItem;
+ d->bottomAnchorItem = edge.item;
+ d->bottomAnchorLine = edge.anchorLine;
d->remDepend(oldBottom);
- d->addDepend(d->bottom.item);
+ d->addDepend(d->bottomAnchorItem);
emit bottomChanged();
d->updateVerticalAnchors();
}
@@ -845,8 +872,9 @@ void QQuickAnchors::resetBottom()
{
Q_D(QQuickAnchors);
d->usedAnchors &= ~BottomAnchor;
- d->remDepend(d->bottom.item);
- d->bottom = QQuickAnchorLine();
+ d->remDepend(d->bottomAnchorItem);
+ d->bottomAnchorItem = Q_NULLPTR;
+ d->bottomAnchorLine = QQuickAnchors::InvalidAnchor;
emit bottomChanged();
d->updateVerticalAnchors();
}
@@ -854,13 +882,14 @@ void QQuickAnchors::resetBottom()
QQuickAnchorLine QQuickAnchors::verticalCenter() const
{
Q_D(const QQuickAnchors);
- return d->vCenter;
+ return QQuickAnchorLine(d->vCenterAnchorItem, d->vCenterAnchorLine);
}
void QQuickAnchors::setVerticalCenter(const QQuickAnchorLine &edge)
{
Q_D(QQuickAnchors);
- if (!d->checkVAnchorValid(edge) || d->vCenter == edge)
+ if (!d->checkVAnchorValid(edge) ||
+ (d->vCenterAnchorItem == edge.item && d->vCenterAnchorLine == edge.anchorLine))
return;
d->usedAnchors |= VCenterAnchor;
@@ -870,10 +899,11 @@ void QQuickAnchors::setVerticalCenter(const QQuickAnchorLine &edge)
return;
}
- QQuickItem *oldVCenter = d->vCenter.item;
- d->vCenter = edge;
+ QQuickItem *oldVCenter = d->vCenterAnchorItem;
+ d->vCenterAnchorItem = edge.item;
+ d->vCenterAnchorLine = edge.anchorLine;
d->remDepend(oldVCenter);
- d->addDepend(d->vCenter.item);
+ d->addDepend(d->vCenterAnchorItem);
emit verticalCenterChanged();
d->updateVerticalAnchors();
}
@@ -882,8 +912,9 @@ void QQuickAnchors::resetVerticalCenter()
{
Q_D(QQuickAnchors);
d->usedAnchors &= ~VCenterAnchor;
- d->remDepend(d->vCenter.item);
- d->vCenter = QQuickAnchorLine();
+ d->remDepend(d->vCenterAnchorItem);
+ d->vCenterAnchorItem = Q_NULLPTR;
+ d->vCenterAnchorLine = QQuickAnchors::InvalidAnchor;
emit verticalCenterChanged();
d->updateVerticalAnchors();
}
@@ -891,13 +922,14 @@ void QQuickAnchors::resetVerticalCenter()
QQuickAnchorLine QQuickAnchors::baseline() const
{
Q_D(const QQuickAnchors);
- return d->baseline;
+ return QQuickAnchorLine(d->baselineAnchorItem, d->baselineAnchorLine);
}
void QQuickAnchors::setBaseline(const QQuickAnchorLine &edge)
{
Q_D(QQuickAnchors);
- if (!d->checkVAnchorValid(edge) || d->baseline == edge)
+ if (!d->checkVAnchorValid(edge) ||
+ (d->baselineAnchorItem == edge.item && d->baselineAnchorLine == edge.anchorLine))
return;
d->usedAnchors |= BaselineAnchor;
@@ -907,10 +939,11 @@ void QQuickAnchors::setBaseline(const QQuickAnchorLine &edge)
return;
}
- QQuickItem *oldBaseline = d->baseline.item;
- d->baseline = edge;
+ QQuickItem *oldBaseline = d->baselineAnchorItem;
+ d->baselineAnchorItem = edge.item;
+ d->baselineAnchorLine = edge.anchorLine;
d->remDepend(oldBaseline);
- d->addDepend(d->baseline.item);
+ d->addDepend(d->baselineAnchorItem);
emit baselineChanged();
d->updateVerticalAnchors();
}
@@ -919,8 +952,9 @@ void QQuickAnchors::resetBaseline()
{
Q_D(QQuickAnchors);
d->usedAnchors &= ~BaselineAnchor;
- d->remDepend(d->baseline.item);
- d->baseline = QQuickAnchorLine();
+ d->remDepend(d->baselineAnchorItem);
+ d->baselineAnchorItem = Q_NULLPTR;
+ d->baselineAnchorLine = QQuickAnchors::InvalidAnchor;
emit baselineChanged();
d->updateVerticalAnchors();
}
@@ -928,13 +962,14 @@ void QQuickAnchors::resetBaseline()
QQuickAnchorLine QQuickAnchors::left() const
{
Q_D(const QQuickAnchors);
- return d->left;
+ return QQuickAnchorLine(d->leftAnchorItem, d->leftAnchorLine);
}
void QQuickAnchors::setLeft(const QQuickAnchorLine &edge)
{
Q_D(QQuickAnchors);
- if (!d->checkHAnchorValid(edge) || d->left == edge)
+ if (!d->checkHAnchorValid(edge) ||
+ (d->leftAnchorItem == edge.item && d->leftAnchorLine == edge.anchorLine))
return;
d->usedAnchors |= LeftAnchor;
@@ -944,10 +979,11 @@ void QQuickAnchors::setLeft(const QQuickAnchorLine &edge)
return;
}
- QQuickItem *oldLeft = d->left.item;
- d->left = edge;
+ QQuickItem *oldLeft = d->leftAnchorItem;
+ d->leftAnchorItem = edge.item;
+ d->leftAnchorLine = edge.anchorLine;
d->remDepend(oldLeft);
- d->addDepend(d->left.item);
+ d->addDepend(d->leftAnchorItem);
emit leftChanged();
d->updateHorizontalAnchors();
}
@@ -956,8 +992,9 @@ void QQuickAnchors::resetLeft()
{
Q_D(QQuickAnchors);
d->usedAnchors &= ~LeftAnchor;
- d->remDepend(d->left.item);
- d->left = QQuickAnchorLine();
+ d->remDepend(d->leftAnchorItem);
+ d->leftAnchorItem = Q_NULLPTR;
+ d->leftAnchorLine = QQuickAnchors::InvalidAnchor;
emit leftChanged();
d->updateHorizontalAnchors();
}
@@ -965,13 +1002,14 @@ void QQuickAnchors::resetLeft()
QQuickAnchorLine QQuickAnchors::right() const
{
Q_D(const QQuickAnchors);
- return d->right;
+ return QQuickAnchorLine(d->rightAnchorItem, d->rightAnchorLine);
}
void QQuickAnchors::setRight(const QQuickAnchorLine &edge)
{
Q_D(QQuickAnchors);
- if (!d->checkHAnchorValid(edge) || d->right == edge)
+ if (!d->checkHAnchorValid(edge) ||
+ (d->rightAnchorItem == edge.item && d->rightAnchorLine == edge.anchorLine))
return;
d->usedAnchors |= RightAnchor;
@@ -981,10 +1019,11 @@ void QQuickAnchors::setRight(const QQuickAnchorLine &edge)
return;
}
- QQuickItem *oldRight = d->right.item;
- d->right = edge;
+ QQuickItem *oldRight = d->rightAnchorItem;
+ d->rightAnchorItem = edge.item;
+ d->rightAnchorLine = edge.anchorLine;
d->remDepend(oldRight);
- d->addDepend(d->right.item);
+ d->addDepend(d->rightAnchorItem);
emit rightChanged();
d->updateHorizontalAnchors();
}
@@ -993,8 +1032,9 @@ void QQuickAnchors::resetRight()
{
Q_D(QQuickAnchors);
d->usedAnchors &= ~RightAnchor;
- d->remDepend(d->right.item);
- d->right = QQuickAnchorLine();
+ d->remDepend(d->rightAnchorItem);
+ d->rightAnchorItem = Q_NULLPTR;
+ d->rightAnchorLine = QQuickAnchors::InvalidAnchor;
emit rightChanged();
d->updateHorizontalAnchors();
}
@@ -1002,13 +1042,14 @@ void QQuickAnchors::resetRight()
QQuickAnchorLine QQuickAnchors::horizontalCenter() const
{
Q_D(const QQuickAnchors);
- return d->hCenter;
+ return QQuickAnchorLine(d->hCenterAnchorItem, d->hCenterAnchorLine);
}
void QQuickAnchors::setHorizontalCenter(const QQuickAnchorLine &edge)
{
Q_D(QQuickAnchors);
- if (!d->checkHAnchorValid(edge) || d->hCenter == edge)
+ if (!d->checkHAnchorValid(edge) ||
+ (d->hCenterAnchorItem == edge.item && d->hCenterAnchorLine == edge.anchorLine))
return;
d->usedAnchors |= HCenterAnchor;
@@ -1018,10 +1059,11 @@ void QQuickAnchors::setHorizontalCenter(const QQuickAnchorLine &edge)
return;
}
- QQuickItem *oldHCenter = d->hCenter.item;
- d->hCenter = edge;
+ QQuickItem *oldHCenter = d->hCenterAnchorItem;
+ d->hCenterAnchorItem = edge.item;
+ d->hCenterAnchorLine = edge.anchorLine;
d->remDepend(oldHCenter);
- d->addDepend(d->hCenter.item);
+ d->addDepend(d->hCenterAnchorItem);
emit horizontalCenterChanged();
d->updateHorizontalAnchors();
}
@@ -1030,8 +1072,9 @@ void QQuickAnchors::resetHorizontalCenter()
{
Q_D(QQuickAnchors);
d->usedAnchors &= ~HCenterAnchor;
- d->remDepend(d->hCenter.item);
- d->hCenter = QQuickAnchorLine();
+ d->remDepend(d->hCenterAnchorItem);
+ d->hCenterAnchorItem = Q_NULLPTR;
+ d->hCenterAnchorLine = QQuickAnchors::InvalidAnchor;
emit horizontalCenterChanged();
d->updateHorizontalAnchors();
}
@@ -1279,7 +1322,7 @@ void QQuickAnchors::setBaselineOffset(qreal offset)
QQuickAnchors::Anchors QQuickAnchors::usedAnchors() const
{
Q_D(const QQuickAnchors);
- return d->usedAnchors;
+ return static_cast<QQuickAnchors::Anchors>(d->usedAnchors);
}
bool QQuickAnchorsPrivate::checkHValid() const
@@ -1299,10 +1342,11 @@ bool QQuickAnchorsPrivate::checkHAnchorValid(QQuickAnchorLine anchor) const
if (!anchor.item) {
qmlInfo(item) << QQuickAnchors::tr("Cannot anchor to a null item.");
return false;
- } else if (anchor.anchorLine & QQuickAnchorLine::Vertical_Mask) {
+ } else if (anchor.anchorLine & QQuickAnchors::Vertical_Mask) {
qmlInfo(item) << QQuickAnchors::tr("Cannot anchor a horizontal edge to a vertical edge.");
return false;
- } else if (anchor.item != readParentItem(item) && readParentItem(anchor.item) != readParentItem(item)){
+ } else if (anchor.item != readParentItem(item)
+ && readParentItem(anchor.item) != readParentItem(item)) {
qmlInfo(item) << QQuickAnchors::tr("Cannot anchor to an item that isn't a parent or sibling.");
return false;
} else if (anchor.item == item) {
@@ -1336,10 +1380,11 @@ bool QQuickAnchorsPrivate::checkVAnchorValid(QQuickAnchorLine anchor) const
if (!anchor.item) {
qmlInfo(item) << QQuickAnchors::tr("Cannot anchor to a null item.");
return false;
- } else if (anchor.anchorLine & QQuickAnchorLine::Horizontal_Mask) {
+ } else if (anchor.anchorLine & QQuickAnchors::Horizontal_Mask) {
qmlInfo(item) << QQuickAnchors::tr("Cannot anchor a vertical edge to a horizontal edge.");
return false;
- } else if (anchor.item != readParentItem(item) && readParentItem(anchor.item) != readParentItem(item)){
+ } else if (anchor.item != readParentItem(item)
+ && readParentItem(anchor.item) != readParentItem(item)) {
qmlInfo(item) << QQuickAnchors::tr("Cannot anchor to an item that isn't a parent or sibling.");
return false;
} else if (anchor.item == item){
diff --git a/src/quick/items/qquickanchors_p.h b/src/quick/items/qquickanchors_p.h
index 0e02d80ae8..d3c8ed82be 100644
--- a/src/quick/items/qquickanchors_p.h
+++ b/src/quick/items/qquickanchors_p.h
@@ -90,6 +90,7 @@ public:
virtual ~QQuickAnchors();
enum Anchor {
+ InvalidAnchor = 0x0,
LeftAnchor = 0x01,
RightAnchor = 0x02,
TopAnchor = 0x04,
diff --git a/src/quick/items/qquickanchors_p_p.h b/src/quick/items/qquickanchors_p_p.h
index 205d9a40da..da659946c0 100644
--- a/src/quick/items/qquickanchors_p_p.h
+++ b/src/quick/items/qquickanchors_p_p.h
@@ -60,24 +60,15 @@ QT_BEGIN_NAMESPACE
class QQuickAnchorLine
{
public:
- enum AnchorLine {
- Invalid = 0x0,
- Left = 0x01,
- Right = 0x02,
- Top = 0x04,
- Bottom = 0x08,
- HCenter = 0x10,
- VCenter = 0x20,
- Baseline = 0x40,
- Horizontal_Mask = Left | Right | HCenter,
- Vertical_Mask = Top | Bottom | VCenter | Baseline
- };
-
- QQuickAnchorLine() : item(0), anchorLine(Invalid) {}
- QQuickAnchorLine(QQuickItem *i, AnchorLine l) : item(i), anchorLine(l) {}
+ QQuickAnchorLine() : item(0), anchorLine(QQuickAnchors::InvalidAnchor) {}
+ QQuickAnchorLine(QQuickItem *i, QQuickAnchors::Anchor l) : item(i), anchorLine(l) {}
+ QQuickAnchorLine(QQuickItem *i, uint l)
+ : item(i)
+ , anchorLine(static_cast<QQuickAnchors::Anchor>(l))
+ { Q_ASSERT(l < ((QQuickAnchors::BaselineAnchor << 1) - 1)); }
QQuickItem *item;
- AnchorLine anchorLine;
+ QQuickAnchors::Anchor anchorLine;
};
inline bool operator==(const QQuickAnchorLine& a, const QQuickAnchorLine& b)
@@ -90,13 +81,44 @@ class QQuickAnchorsPrivate : public QObjectPrivate, public QQuickItemChangeListe
Q_DECLARE_PUBLIC(QQuickAnchors)
public:
QQuickAnchorsPrivate(QQuickItem *i)
- : componentComplete(true), updatingMe(false), inDestructor(false), centerAligned(true),
- leftMarginExplicit(false), rightMarginExplicit(false), topMarginExplicit(false),
- bottomMarginExplicit(false), updatingHorizontalAnchor(0),
- updatingVerticalAnchor(0), updatingFill(0), updatingCenterIn(0), item(i), usedAnchors(0), fill(0),
- centerIn(0), leftMargin(0), rightMargin(0), topMargin(0), bottomMargin(0),
- margins(0), vCenterOffset(0), hCenterOffset(0), baselineOffset(0)
-
+ : leftMargin(0)
+ , rightMargin(0)
+ , topMargin(0)
+ , bottomMargin(0)
+ , margins(0)
+ , vCenterOffset(0)
+ , hCenterOffset(0)
+ , baselineOffset(0)
+ , item(i)
+ , fill(Q_NULLPTR)
+ , centerIn(Q_NULLPTR)
+ , leftAnchorItem(Q_NULLPTR)
+ , rightAnchorItem(Q_NULLPTR)
+ , topAnchorItem(Q_NULLPTR)
+ , bottomAnchorItem(Q_NULLPTR)
+ , vCenterAnchorItem(Q_NULLPTR)
+ , hCenterAnchorItem(Q_NULLPTR)
+ , baselineAnchorItem(Q_NULLPTR)
+ , leftAnchorLine(QQuickAnchors::InvalidAnchor)
+ , leftMarginExplicit(false)
+ , rightAnchorLine(QQuickAnchors::InvalidAnchor)
+ , rightMarginExplicit(false)
+ , topAnchorLine(QQuickAnchors::InvalidAnchor)
+ , topMarginExplicit(false)
+ , bottomAnchorLine(QQuickAnchors::InvalidAnchor)
+ , bottomMarginExplicit(false)
+ , vCenterAnchorLine(QQuickAnchors::InvalidAnchor)
+ , updatingMe(false)
+ , hCenterAnchorLine(QQuickAnchors::InvalidAnchor)
+ , inDestructor(false)
+ , baselineAnchorLine(QQuickAnchors::InvalidAnchor)
+ , centerAligned(true)
+ , updatingFill(0)
+ , updatingCenterIn(0)
+ , updatingHorizontalAnchor(0)
+ , updatingVerticalAnchor(0)
+ , componentComplete(true)
+ , usedAnchors(QQuickAnchors::InvalidAnchor)
{
}
@@ -107,19 +129,6 @@ public:
void remDepend(QQuickItem *);
bool isItemComplete() const;
- bool componentComplete:1;
- bool updatingMe:1;
- bool inDestructor:1;
- bool centerAligned:1;
- bool leftMarginExplicit : 1;
- bool rightMarginExplicit : 1;
- bool topMarginExplicit : 1;
- bool bottomMarginExplicit : 1;
- uint updatingHorizontalAnchor:2;
- uint updatingVerticalAnchor:2;
- uint updatingFill:2;
- uint updatingCenterIn:2;
-
void setItemHeight(qreal);
void setItemWidth(qreal);
void setItemX(qreal);
@@ -139,7 +148,9 @@ public:
bool checkVValid() const;
bool checkHAnchorValid(QQuickAnchorLine anchor) const;
bool checkVAnchorValid(QQuickAnchorLine anchor) const;
- bool calcStretch(const QQuickAnchorLine &edge1, const QQuickAnchorLine &edge2, qreal offset1, qreal offset2, QQuickAnchorLine::AnchorLine line, qreal &stretch);
+ bool calcStretch(QQuickItem *edge1Item, QQuickAnchors::Anchor edge1Line,
+ QQuickItem *edge2Item, QQuickAnchors::Anchor edge2Line,
+ qreal offset1, qreal offset2, QQuickAnchors::Anchor line, qreal &stretch);
bool isMirrored() const;
void updateHorizontalAnchors();
@@ -147,20 +158,6 @@ public:
void fillChanged();
void centerInChanged();
- QQuickItem *item;
- QQuickAnchors::Anchors usedAnchors;
-
- QQuickItem *fill;
- QQuickItem *centerIn;
-
- QQuickAnchorLine left;
- QQuickAnchorLine right;
- QQuickAnchorLine top;
- QQuickAnchorLine bottom;
- QQuickAnchorLine vCenter;
- QQuickAnchorLine hCenter;
- QQuickAnchorLine baseline;
-
qreal leftMargin;
qreal rightMargin;
qreal topMargin;
@@ -170,6 +167,44 @@ public:
qreal hCenterOffset;
qreal baselineOffset;
+ QQuickItem *item;
+
+ QQuickItem *fill;
+ QQuickItem *centerIn;
+
+ QQuickItem *leftAnchorItem;
+ QQuickItem *rightAnchorItem;
+ QQuickItem *topAnchorItem;
+ QQuickItem *bottomAnchorItem;
+ QQuickItem *vCenterAnchorItem;
+ QQuickItem *hCenterAnchorItem;
+ QQuickItem *baselineAnchorItem;
+
+ // The bit fields below are carefully laid out in chunks of 1 byte, so the compiler doesn't
+ // need to generate 2 loads (and combining shifts/ors) to create a single field.
+
+ QQuickAnchors::Anchor leftAnchorLine : 7;
+ uint leftMarginExplicit : 1;
+ QQuickAnchors::Anchor rightAnchorLine : 7;
+ uint rightMarginExplicit : 1;
+ QQuickAnchors::Anchor topAnchorLine : 7;
+ uint topMarginExplicit : 1;
+ QQuickAnchors::Anchor bottomAnchorLine : 7;
+ uint bottomMarginExplicit : 1;
+
+ QQuickAnchors::Anchor vCenterAnchorLine : 7;
+ uint updatingMe : 1;
+ QQuickAnchors::Anchor hCenterAnchorLine : 7;
+ uint inDestructor : 1;
+ QQuickAnchors::Anchor baselineAnchorLine : 7;
+ uint centerAligned : 1;
+ uint updatingFill : 2;
+ uint updatingCenterIn : 2;
+ uint updatingHorizontalAnchor : 2;
+ uint updatingVerticalAnchor : 2;
+
+ uint componentComplete : 1;
+ uint usedAnchors : 7; // QQuickAnchors::Anchors
static inline QQuickAnchorsPrivate *get(QQuickAnchors *o) {
return static_cast<QQuickAnchorsPrivate *>(QObjectPrivate::get(o));
diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp
index 0edbcd8780..95b4e09aa5 100644
--- a/src/quick/items/qquickitem.cpp
+++ b/src/quick/items/qquickitem.cpp
@@ -4188,43 +4188,43 @@ QVariant QQuickItem::inputMethodQuery(Qt::InputMethodQuery query) const
QQuickAnchorLine QQuickItemPrivate::left() const
{
Q_Q(const QQuickItem);
- return QQuickAnchorLine(const_cast<QQuickItem *>(q), QQuickAnchorLine::Left);
+ return QQuickAnchorLine(const_cast<QQuickItem *>(q), QQuickAnchors::LeftAnchor);
}
QQuickAnchorLine QQuickItemPrivate::right() const
{
Q_Q(const QQuickItem);
- return QQuickAnchorLine(const_cast<QQuickItem *>(q), QQuickAnchorLine::Right);
+ return QQuickAnchorLine(const_cast<QQuickItem *>(q), QQuickAnchors::RightAnchor);
}
QQuickAnchorLine QQuickItemPrivate::horizontalCenter() const
{
Q_Q(const QQuickItem);
- return QQuickAnchorLine(const_cast<QQuickItem *>(q), QQuickAnchorLine::HCenter);
+ return QQuickAnchorLine(const_cast<QQuickItem *>(q), QQuickAnchors::HCenterAnchor);
}
QQuickAnchorLine QQuickItemPrivate::top() const
{
Q_Q(const QQuickItem);
- return QQuickAnchorLine(const_cast<QQuickItem *>(q), QQuickAnchorLine::Top);
+ return QQuickAnchorLine(const_cast<QQuickItem *>(q), QQuickAnchors::TopAnchor);
}
QQuickAnchorLine QQuickItemPrivate::bottom() const
{
Q_Q(const QQuickItem);
- return QQuickAnchorLine(const_cast<QQuickItem *>(q), QQuickAnchorLine::Bottom);
+ return QQuickAnchorLine(const_cast<QQuickItem *>(q), QQuickAnchors::BottomAnchor);
}
QQuickAnchorLine QQuickItemPrivate::verticalCenter() const
{
Q_Q(const QQuickItem);
- return QQuickAnchorLine(const_cast<QQuickItem *>(q), QQuickAnchorLine::VCenter);
+ return QQuickAnchorLine(const_cast<QQuickItem *>(q), QQuickAnchors::VCenterAnchor);
}
QQuickAnchorLine QQuickItemPrivate::baseline() const
{
Q_Q(const QQuickItem);
- return QQuickAnchorLine(const_cast<QQuickItem *>(q), QQuickAnchorLine::Baseline);
+ return QQuickAnchorLine(const_cast<QQuickItem *>(q), QQuickAnchors::BaselineAnchor);
}
/*!
diff --git a/tests/auto/quick/qquickanchors/tst_qquickanchors.cpp b/tests/auto/quick/qquickanchors/tst_qquickanchors.cpp
index ab111a6cd3..77fa1292c4 100644
--- a/tests/auto/quick/qquickanchors/tst_qquickanchors.cpp
+++ b/tests/auto/quick/qquickanchors/tst_qquickanchors.cpp
@@ -39,7 +39,6 @@
#include "../shared/visualtestutil.h"
Q_DECLARE_METATYPE(QQuickAnchors::Anchor)
-Q_DECLARE_METATYPE(QQuickAnchorLine::AnchorLine)
using namespace QQuickVisualTestUtil;
@@ -351,14 +350,13 @@ void tst_qquickanchors::illegalSets_data()
void tst_qquickanchors::reset()
{
QFETCH(QString, side);
- QFETCH(QQuickAnchorLine::AnchorLine, anchorLine);
- QFETCH(QQuickAnchors::Anchor, usedAnchor);
+ QFETCH(QQuickAnchors::Anchor, anchor);
QQuickItem *baseItem = new QQuickItem;
- QQuickAnchorLine anchor;
- anchor.item = baseItem;
- anchor.anchorLine = anchorLine;
+ QQuickAnchorLine anchorLine;
+ anchorLine.item = baseItem;
+ anchorLine.anchorLine = anchor;
QQuickItem *item = new QQuickItem;
QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item);
@@ -366,11 +364,11 @@ void tst_qquickanchors::reset()
const QMetaObject *meta = itemPrivate->anchors()->metaObject();
QMetaProperty p = meta->property(meta->indexOfProperty(side.toUtf8().constData()));
- QVERIFY(p.write(itemPrivate->anchors(), qVariantFromValue(anchor)));
- QCOMPARE(itemPrivate->anchors()->usedAnchors().testFlag(usedAnchor), true);
+ QVERIFY(p.write(itemPrivate->anchors(), qVariantFromValue(anchorLine)));
+ QCOMPARE(itemPrivate->anchors()->usedAnchors().testFlag(anchor), true);
QVERIFY(p.reset(itemPrivate->anchors()));
- QCOMPARE(itemPrivate->anchors()->usedAnchors().testFlag(usedAnchor), false);
+ QCOMPARE(itemPrivate->anchors()->usedAnchors().testFlag(anchor), false);
delete item;
delete baseItem;
@@ -379,17 +377,16 @@ void tst_qquickanchors::reset()
void tst_qquickanchors::reset_data()
{
QTest::addColumn<QString>("side");
- QTest::addColumn<QQuickAnchorLine::AnchorLine>("anchorLine");
- QTest::addColumn<QQuickAnchors::Anchor>("usedAnchor");
+ QTest::addColumn<QQuickAnchors::Anchor>("anchor");
- QTest::newRow("left") << "left" << QQuickAnchorLine::Left << QQuickAnchors::LeftAnchor;
- QTest::newRow("top") << "top" << QQuickAnchorLine::Top << QQuickAnchors::TopAnchor;
- QTest::newRow("right") << "right" << QQuickAnchorLine::Right << QQuickAnchors::RightAnchor;
- QTest::newRow("bottom") << "bottom" << QQuickAnchorLine::Bottom << QQuickAnchors::BottomAnchor;
+ QTest::newRow("left") << "left" << QQuickAnchors::LeftAnchor;
+ QTest::newRow("top") << "top" << QQuickAnchors::TopAnchor;
+ QTest::newRow("right") << "right" << QQuickAnchors::RightAnchor;
+ QTest::newRow("bottom") << "bottom" << QQuickAnchors::BottomAnchor;
- QTest::newRow("hcenter") << "horizontalCenter" << QQuickAnchorLine::HCenter << QQuickAnchors::HCenterAnchor;
- QTest::newRow("vcenter") << "verticalCenter" << QQuickAnchorLine::VCenter << QQuickAnchors::VCenterAnchor;
- QTest::newRow("baseline") << "baseline" << QQuickAnchorLine::Baseline << QQuickAnchors::BaselineAnchor;
+ QTest::newRow("hcenter") << "horizontalCenter" << QQuickAnchors::HCenterAnchor;
+ QTest::newRow("vcenter") << "verticalCenter" << QQuickAnchors::VCenterAnchor;
+ QTest::newRow("baseline") << "baseline" << QQuickAnchors::BaselineAnchor;
}
void tst_qquickanchors::resetConvenience()
diff --git a/tests/auto/quick/qquickstates/tst_qquickstates.cpp b/tests/auto/quick/qquickstates/tst_qquickstates.cpp
index 562d53bceb..9b152b0676 100644
--- a/tests/auto/quick/qquickstates/tst_qquickstates.cpp
+++ b/tests/auto/quick/qquickstates/tst_qquickstates.cpp
@@ -698,7 +698,7 @@ void tst_qquickstates::anchorChanges()
rectPrivate->setState("right");
QCOMPARE(innerRect->x(), qreal(150));
QCOMPARE(aChanges->object(), qobject_cast<QQuickItem*>(innerRect));
- QCOMPARE(QQuickItemPrivate::get(aChanges->object())->anchors()->left().anchorLine, QQuickAnchorLine::Invalid); //### was reset (how do we distinguish from not set at all)
+ QCOMPARE(QQuickItemPrivate::get(aChanges->object())->anchors()->left().anchorLine, QQuickAnchors::InvalidAnchor); //### was reset (how do we distinguish from not set at all)
QCOMPARE(QQuickItemPrivate::get(aChanges->object())->anchors()->right().item, rectPrivate->right().item);
QCOMPARE(QQuickItemPrivate::get(aChanges->object())->anchors()->right().anchorLine, rectPrivate->right().anchorLine);
@@ -891,7 +891,7 @@ void tst_qquickstates::anchorChangesRTL()
rectPrivate->setState("right");
QCOMPARE(innerRect->x(), offsetRTL(rect, innerRect) - qreal(150));
QCOMPARE(aChanges->object(), qobject_cast<QQuickItem*>(innerRect));
- QCOMPARE(QQuickItemPrivate::get(aChanges->object())->anchors()->left().anchorLine, QQuickAnchorLine::Invalid); //### was reset (how do we distinguish from not set at all)
+ QCOMPARE(QQuickItemPrivate::get(aChanges->object())->anchors()->left().anchorLine, QQuickAnchors::InvalidAnchor); //### was reset (how do we distinguish from not set at all)
QCOMPARE(QQuickItemPrivate::get(aChanges->object())->anchors()->right().item, rectPrivate->right().item);
QCOMPARE(QQuickItemPrivate::get(aChanges->object())->anchors()->right().anchorLine, rectPrivate->right().anchorLine);
diff --git a/tests/benchmarks/qml/creation/tst_creation.cpp b/tests/benchmarks/qml/creation/tst_creation.cpp
index e126cdae7e..7b00eabc28 100644
--- a/tests/benchmarks/qml/creation/tst_creation.cpp
+++ b/tests/benchmarks/qml/creation/tst_creation.cpp
@@ -68,6 +68,7 @@ private slots:
void itemtests_qml_data();
void itemtests_qml();
+ void anchors_creation();
void anchors_heightChange();
private:
@@ -375,6 +376,20 @@ void tst_creation::itemtests_qml()
QBENCHMARK { delete component.create(); }
}
+void tst_creation::anchors_creation()
+{
+ QQmlComponent component(&engine);
+ component.setData("import QtQuick 2.0\nItem { Item { anchors.bottom: parent.bottom } }", QUrl());
+
+ QObject *obj = component.create();
+ delete obj;
+
+ QBENCHMARK {
+ QObject *obj = component.create();
+ delete obj;
+ }
+}
+
void tst_creation::anchors_heightChange()
{
QQmlComponent component(&engine);