diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2009-11-25 05:51:31 (GMT) |
---|---|---|
committer | Michael Brasser <michael.brasser@nokia.com> | 2009-11-25 05:54:54 (GMT) |
commit | 1c9dcb09b79d77bc7d4958e1393437597892bb0b (patch) | |
tree | 3836e4507b7feed6f07b958331fff7c10993cbe9 | |
parent | 50ef19f6eca9d433deed3f3c7062901a5d2f292c (diff) | |
download | Qt-1c9dcb09b79d77bc7d4958e1393437597892bb0b.zip Qt-1c9dcb09b79d77bc7d4958e1393437597892bb0b.tar.gz Qt-1c9dcb09b79d77bc7d4958e1393437597892bb0b.tar.bz2 |
Add reset function for anchors.fill and anchors.centerIn.
Task-number: QTBUG-5337
-rw-r--r-- | src/declarative/graphicsitems/qmlgraphicsanchors.cpp | 12 | ||||
-rw-r--r-- | src/declarative/graphicsitems/qmlgraphicsanchors_p.h | 6 | ||||
-rw-r--r-- | tests/auto/declarative/anchors/tst_anchors.cpp | 22 |
3 files changed, 38 insertions, 2 deletions
diff --git a/src/declarative/graphicsitems/qmlgraphicsanchors.cpp b/src/declarative/graphicsitems/qmlgraphicsanchors.cpp index f26fbf5..8642476 100644 --- a/src/declarative/graphicsitems/qmlgraphicsanchors.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsanchors.cpp @@ -355,6 +355,7 @@ void QmlGraphicsAnchors::setFill(QmlGraphicsItem *f) if (!f) { d->remDepend(d->fill); d->fill = f; + emit fillChanged(); return; } if (f != d->item->parentItem() && f->parentItem() != d->item->parentItem()){ @@ -368,6 +369,11 @@ void QmlGraphicsAnchors::setFill(QmlGraphicsItem *f) d->fillChanged(); } +void QmlGraphicsAnchors::resetFill() +{ + setFill(0); +} + QmlGraphicsItem *QmlGraphicsAnchors::centerIn() const { Q_D(const QmlGraphicsAnchors); @@ -383,6 +389,7 @@ void QmlGraphicsAnchors::setCenterIn(QmlGraphicsItem* c) if (!c) { d->remDepend(d->centerIn); d->centerIn = c; + emit centerInChanged(); return; } if (c != d->item->parentItem() && c->parentItem() != d->item->parentItem()){ @@ -397,6 +404,11 @@ void QmlGraphicsAnchors::setCenterIn(QmlGraphicsItem* c) d->centerInChanged(); } +void QmlGraphicsAnchors::resetCenterIn() +{ + setCenterIn(0); +} + bool QmlGraphicsAnchorsPrivate::calcStretch(const QmlGraphicsAnchorLine &edge1, const QmlGraphicsAnchorLine &edge2, int offset1, diff --git a/src/declarative/graphicsitems/qmlgraphicsanchors_p.h b/src/declarative/graphicsitems/qmlgraphicsanchors_p.h index e432428..507b4d8 100644 --- a/src/declarative/graphicsitems/qmlgraphicsanchors_p.h +++ b/src/declarative/graphicsitems/qmlgraphicsanchors_p.h @@ -72,8 +72,8 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsAnchors : public QObject Q_PROPERTY(qreal bottomMargin READ bottomMargin WRITE setBottomMargin NOTIFY bottomMarginChanged) Q_PROPERTY(qreal verticalCenterOffset READ verticalCenterOffset WRITE setVerticalCenterOffset NOTIFY verticalCenterOffsetChanged()) Q_PROPERTY(qreal baselineOffset READ baselineOffset WRITE setBaselineOffset NOTIFY baselineOffsetChanged()) - Q_PROPERTY(QmlGraphicsItem *fill READ fill WRITE setFill NOTIFY fillChanged) - Q_PROPERTY(QmlGraphicsItem *centerIn READ centerIn WRITE setCenterIn NOTIFY centerInChanged) + Q_PROPERTY(QmlGraphicsItem *fill READ fill WRITE setFill RESET resetFill NOTIFY fillChanged) + Q_PROPERTY(QmlGraphicsItem *centerIn READ centerIn WRITE setCenterIn RESET resetCenterIn NOTIFY centerInChanged) public: QmlGraphicsAnchors(QObject *parent=0); @@ -143,9 +143,11 @@ public: QmlGraphicsItem *fill() const; void setFill(QmlGraphicsItem *); + void resetFill(); QmlGraphicsItem *centerIn() const; void setCenterIn(QmlGraphicsItem *); + void resetCenterIn(); UsedAnchors usedAnchors() const; diff --git a/tests/auto/declarative/anchors/tst_anchors.cpp b/tests/auto/declarative/anchors/tst_anchors.cpp index 3011fdc..44e812a 100644 --- a/tests/auto/declarative/anchors/tst_anchors.cpp +++ b/tests/auto/declarative/anchors/tst_anchors.cpp @@ -67,6 +67,7 @@ private slots: void illegalSets_data(); void reset(); void reset_data(); + void resetConvenience(); void nullItem(); void nullItem_data(); void crash1(); @@ -312,6 +313,27 @@ void tst_anchors::reset_data() QTest::newRow("baseline") << "baseline" << QmlGraphicsAnchorLine::Baseline << QmlGraphicsAnchors::HasBaselineAnchor; } +void tst_anchors::resetConvenience() +{ + QmlGraphicsItem *baseItem = new QmlGraphicsItem; + QmlGraphicsItem *item = new QmlGraphicsItem; + + //fill + item->anchors()->setFill(baseItem); + QVERIFY(item->anchors()->fill() == baseItem); + item->anchors()->resetFill(); + QVERIFY(item->anchors()->fill() == 0); + + //centerIn + item->anchors()->setCenterIn(baseItem); + QVERIFY(item->anchors()->centerIn() == baseItem); + item->anchors()->resetCenterIn(); + QVERIFY(item->anchors()->centerIn() == 0); + + delete item; + delete baseItem; +} + void tst_anchors::nullItem() { QFETCH(QString, side); |