From 77a41269a5717598fe155ddd4139924e0897e007 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Mon, 7 Dec 2009 08:30:46 +0100 Subject: Rewrite Positioners Cleans up code, reduces memory footprint and increases performance. Largely by removing large chunks of functionality that we don't actually use. Also now that we are clearer on what the new positioner transitions are (how the item moves it's position when it is positioned by a positioner) a remove transition makes no sense and is discarded, and the auto tests have been updated as add transitions are slightly different. --- .../graphicsitems/qmlgraphicspositioners.cpp | 364 +++++---------------- .../graphicsitems/qmlgraphicspositioners_p.h | 23 +- .../graphicsitems/qmlgraphicspositioners_p_p.h | 29 +- .../qmlgraphicspositioners/data/grid-animated.qml | 17 +- .../data/horizontal-animated.qml | 12 +- .../data/vertical-animated.qml | 10 +- .../tst_qmlgraphicspositioners.cpp | 63 +--- 7 files changed, 133 insertions(+), 385 deletions(-) diff --git a/src/declarative/graphicsitems/qmlgraphicspositioners.cpp b/src/declarative/graphicsitems/qmlgraphicspositioners.cpp index db0cc7c..101fae2 100644 --- a/src/declarative/graphicsitems/qmlgraphicspositioners.cpp +++ b/src/declarative/graphicsitems/qmlgraphicspositioners.cpp @@ -66,8 +66,10 @@ void QmlGraphicsBasePositionerPrivate::watchChanges(QmlGraphicsItem *other) QmlGraphicsItemPrivate *otherPrivate = static_cast(QGraphicsItemPrivate::get(other)); - otherPrivate->connectToHeightChanged(q, prePosIdx); - otherPrivate->connectToWidthChanged(q, prePosIdx); + if(type == QmlGraphicsBasePositioner::Vertical || type == QmlGraphicsBasePositioner::Both) + otherPrivate->connectToHeightChanged(q, prePosIdx); + if(type == QmlGraphicsBasePositioner::Horizontal || type == QmlGraphicsBasePositioner::Both) + otherPrivate->connectToWidthChanged(q, prePosIdx); otherPrivate->registerSiblingOrderNotification(this); watched << other; @@ -77,11 +79,14 @@ void QmlGraphicsBasePositionerPrivate::unwatchChanges(QmlGraphicsItem* other) { Q_Q(QmlGraphicsBasePositioner); QmlGraphicsItemPrivate *otherPrivate = static_cast(QGraphicsItemPrivate::get(other)); - bool stillAlive = false; //Use the return from disconnect to see if it was deleted or just reparented + bool stillAlive = false; //Use the returns from disconnect to see if it was deleted or just reparented stillAlive |= QMetaObject::disconnect(other, visibleIdx, q, prePosIdx); stillAlive |= QMetaObject::disconnect(other, opacityIdx, q, prePosIdx); - stillAlive |= otherPrivate->disconnectFromHeightChanged(q, prePosIdx); - stillAlive |= otherPrivate->disconnectFromWidthChanged(q, prePosIdx); + //Is disconnect expensive enough to be worth this check? + if(type == QmlGraphicsBasePositioner::Vertical || type == QmlGraphicsBasePositioner::Both) + stillAlive |= otherPrivate->disconnectFromHeightChanged(q, prePosIdx); + if(type == QmlGraphicsBasePositioner::Horizontal || type == QmlGraphicsBasePositioner::Both) + stillAlive |= otherPrivate->disconnectFromWidthChanged(q, prePosIdx); if(stillAlive) otherPrivate->unregisterSiblingOrderNotification(this); @@ -96,24 +101,24 @@ void QmlGraphicsBasePositionerPrivate::unwatchChanges(QmlGraphicsItem* other) To create a QmlGraphics Positioner, simply subclass QmlGraphicsBasePositioner and implement doLayout(), which is automatically called when the layout might need - updating. + updating. In doLayout() use the setX and setY functions from QmlBasePositioner, and the + base class will apply the positions along with the appropriate transitions. The items to + position are provided in order as the protected member positionedItems. - It is strongly recommended that in your implementation of doLayout() - that you use the move, remove and add transitions when those conditions - arise. You can use the applyAdd, applyMove and applyRemove functions - to do this easily. + You also need to set a PositionerType, to declare whether you are positioning the x, y or both + for the child items. Depending on the chosen type, only x or y changes will be applied. - Note also that the subclass is responsible for adding the + Note that the subclass is responsible for adding the spacing in between items. */ -QmlGraphicsBasePositioner::QmlGraphicsBasePositioner(AutoUpdateType at, QmlGraphicsItem *parent) +QmlGraphicsBasePositioner::QmlGraphicsBasePositioner(PositionerType at, QmlGraphicsItem *parent) : QmlGraphicsItem(*(new QmlGraphicsBasePositionerPrivate), parent) { Q_D(QmlGraphicsBasePositioner); d->init(at); } -QmlGraphicsBasePositioner::QmlGraphicsBasePositioner(QmlGraphicsBasePositionerPrivate &dd, AutoUpdateType at, QmlGraphicsItem *parent) +QmlGraphicsBasePositioner::QmlGraphicsBasePositioner(QmlGraphicsBasePositionerPrivate &dd, PositionerType at, QmlGraphicsItem *parent) : QmlGraphicsItem(dd, parent) { Q_D(QmlGraphicsBasePositioner); @@ -123,15 +128,15 @@ QmlGraphicsBasePositioner::QmlGraphicsBasePositioner(QmlGraphicsBasePositionerPr int QmlGraphicsBasePositioner::spacing() const { Q_D(const QmlGraphicsBasePositioner); - return d->_spacing; + return d->spacing; } void QmlGraphicsBasePositioner::setSpacing(int s) { Q_D(QmlGraphicsBasePositioner); - if (s==d->_spacing) + if (s==d->spacing) return; - d->_spacing = s; + d->spacing = s; prePositioning(); emit spacingChanged(); } @@ -160,18 +165,6 @@ void QmlGraphicsBasePositioner::setAdd(QmlTransition *add) d->addTransition = add; } -QmlTransition *QmlGraphicsBasePositioner::remove() const -{ - Q_D(const QmlGraphicsBasePositioner); - return d->removeTransition; -} - -void QmlGraphicsBasePositioner::setRemove(QmlTransition *remove) -{ - Q_D(QmlGraphicsBasePositioner); - d->removeTransition = remove; -} - void QmlGraphicsBasePositioner::componentComplete() { QmlGraphicsItem::componentComplete(); @@ -192,114 +185,49 @@ QVariant QmlGraphicsBasePositioner::itemChange(GraphicsItemChange change, return QmlGraphicsItem::itemChange(change, value); } -bool QmlGraphicsBasePositioner::event(QEvent *e) -{ - Q_D(QmlGraphicsBasePositioner); - if (e->type() == QEvent::User) { - d->_ep = false; - d->_stableItems += d->_newItems; - d->_leavingItems.clear(); - d->_newItems.clear(); - return true; - } - return QmlGraphicsItem::event(e); -} - -/*! - Items that have just been added to the positioner. This includes invisible items - that have turned visible. -*/ -QSet* QmlGraphicsBasePositioner::newItems() -{ - Q_D(QmlGraphicsBasePositioner); - return &d->_newItems; -} - -/*! - Items that are visible in the positioner, not including ones that have just been added. -*/ -QSet* QmlGraphicsBasePositioner::items() -{ - Q_D(QmlGraphicsBasePositioner); - return &d->_stableItems; -} - -/*! - Items that have just left the positioner. This includes visible items - that have turned invisible. -*/ -QSet* QmlGraphicsBasePositioner::leavingItems() -{ - Q_D(QmlGraphicsBasePositioner); - return &d->_leavingItems; -} - void QmlGraphicsBasePositioner::prePositioning() { Q_D(QmlGraphicsBasePositioner); - if (!isComponentComplete() || d->_movingItem) + if (!isComponentComplete()) return; d->queuedPositioning = false; - if (!d->_ep) { - d->_ep = true; - QCoreApplication::postEvent(this, new QEvent(QEvent::User)); - } //Need to order children by creation order modified by stacking order - //###can we avoid using the QGraphicsItemPrivate? QList children = childItems(); qSort(children.begin(), children.end(), d->insertionOrder); positionedItems.clear(); + d->newItems.clear(); - if (d->_items.isEmpty()) { - for (int ii = 0; ii < children.count(); ++ii) { - QmlGraphicsItem *child = qobject_cast(children.at(ii)); - if (!child) - continue; + for (int ii = 0; ii < children.count(); ++ii) { + QmlGraphicsItem *child = qobject_cast(children.at(ii)); + if (!child) + continue; + if(!d->watched.contains(child)) d->watchChanges(child); - d->_items += child; - if (child->opacity() != 0.0) - d->_newItems += child; - positionedItems << child; - } - } else { - QSet allItems; - allItems.reserve(children.count()); - for (int ii = 0; ii < children.count(); ++ii) { - QmlGraphicsItem *child = qobject_cast(children.at(ii)); - if (!child) - continue; - if (!d->_items.contains(child)){ - d->watchChanges(child); - d->_items += child; - } - if (child->opacity() == 0.0){ - if (d->_stableItems.contains(child)){ - d->_leavingItems += child; - d->_stableItems -= child; - } - }else if (!d->_stableItems.contains(child)){ - d->_newItems+=child; - } - allItems += child; - positionedItems << child; + if(child->opacity() <= 0.0 || !child->isVisible()) + continue; + if (!d->items.contains(child)){ + d->items += child; + d->newItems += child; } - if (d->_items.count() != allItems.count()) { - QSet deletedItems = d->_items - allItems; - foreach(QmlGraphicsItem *child, deletedItems){ - d->unwatchChanges(child); - d->_items -= child; - } + positionedItems << child; + } + if(d->items.count() > positionedItems.count()){ + //Assumed that (aside from init) every add/remove triggers this check + //thus the above check will be triggered every time an item is removed + QSet deletedItems = d->items - positionedItems.toSet(); + foreach(QmlGraphicsItem *child, deletedItems){ + d->unwatchChanges(child); + d->items -= child; } } - d->_animated.clear(); doPositioning(); - finishApplyTransitions(); + if(d->addTransition || d->moveTransition) + finishApplyTransitions(); //Set implicit size to the size of its children - //###To keep this valid, do we need to update on pos change as well? qreal h = 0.0f; qreal w = 0.0f; - foreach(QmlGraphicsItem *child, d->_items){ + foreach(QmlGraphicsItem *child, d->items){ if(!child->isVisible() || child->opacity() <= 0) continue; h = qMax(h, child->y() + child->height()); @@ -309,69 +237,45 @@ void QmlGraphicsBasePositioner::prePositioning() setImplicitWidth(w); } -void QmlGraphicsBasePositioner::applyTransition(const QList >& changes, QmlGraphicsItem* target, QmlStateOperation::ActionList &actions) +void QmlGraphicsBasePositioner::positionX(int x, QmlGraphicsItem* target) { Q_D(QmlGraphicsBasePositioner); - if (!target) - return; - - for (int ii=0; iitype == Horizontal || d->type == Both){ + if(!d->addTransition && !d->moveTransition){ + target->setX(x); + }else{ + if(d->newItems.contains(target)) + d->addActions << Action(target, QLatin1String("x"), QVariant(x)); + else + d->moveActions << Action(target, QLatin1String("x"), QVariant(x)); + } } +} - d->_animated << target; +void QmlGraphicsBasePositioner::positionY(int y, QmlGraphicsItem* target) +{ + Q_D(QmlGraphicsBasePositioner); + if(d->type == Vertical || d->type == Both){ + if(!d->addTransition && !d->moveTransition){ + target->setY(y); + }else{ + if(d->newItems.contains(target)) + d->addActions << Action(target, QLatin1String("y"), QVariant(y)); + else + d->moveActions << Action(target, QLatin1String("y"), QVariant(y)); + } + } } void QmlGraphicsBasePositioner::finishApplyTransitions() { Q_D(QmlGraphicsBasePositioner); // Note that if a transition is not set the transition manager will - // apply the changes directly, in the case someone uses applyAdd/Move/Remove - // without testing add()/move()/remove(). + // apply the changes directly, in the case add/move aren't set d->addTransitionManager.transition(d->addActions, d->addTransition); d->moveTransitionManager.transition(d->moveActions, d->moveTransition); - d->removeTransitionManager.transition(d->removeActions, d->removeTransition); d->addActions.clear(); d->moveActions.clear(); - d->removeActions.clear(); -} -void QmlGraphicsBasePositioner::setMovingItem(QmlGraphicsItem *i) -{ - Q_D(QmlGraphicsBasePositioner); - d->_movingItem = i; -} - -/*! - Applies the positioner's add transition to the \a target item.\a changes is a list of property,value - pairs which will be changed on the target using the add transition. -*/ -void QmlGraphicsBasePositioner::applyAdd(const QList >& changes, QmlGraphicsItem* target) -{ - Q_D(QmlGraphicsBasePositioner); - applyTransition(changes,target, d->addActions); -} - -/*! - Applies the positioner's move transition to the \a target.\a changes is a list of property,value pairs - which will be changed on the target using the move transition. -*/ -void QmlGraphicsBasePositioner::applyMove(const QList >& changes, QmlGraphicsItem* target) -{ - Q_D(QmlGraphicsBasePositioner); - applyTransition(changes,target, d->moveActions); -} - -/*! - Applies the positioner's remove transition to the \a target item.\a changes is a list of - property,value pairs which will be changed on the target using the remove transition. -*/ -void QmlGraphicsBasePositioner::applyRemove(const QList >& changes, QmlGraphicsItem* target) -{ - Q_D(QmlGraphicsBasePositioner); - applyTransition(changes,target, d->removeActions); } QML_DEFINE_TYPE(Qt,4,6,Column,QmlGraphicsColumn) @@ -425,14 +329,6 @@ Column { */ /*! - \qmlproperty Transition Column::remove - This property holds the transition to apply when removing an item from the positioner. The transition is only applied to the removed items. - Positioner transitions will only affect the position (x,y) of items. - - Removed can mean that either the object has been deleted or reparented, and thus is now longer a child of the positioner, or that the object has had its opacity set to zero, and thus is no longer visible. - -*/ -/*! \qmlproperty Transition Column::add This property holds the transition to be applied when adding an item to the positioner. The transition will only be applied to the added item(s). Positioner transitions will only affect the position (x,y) of items. @@ -499,36 +395,14 @@ void QmlGraphicsColumn::doPositioning() { int voffset = 0; - foreach(QmlGraphicsItem* item, *leavingItems()){ - if (remove()){ - QList > changes; - applyRemove(changes, item); - } - } - - QList children = positionedItems; - for (int ii = 0; ii < children.count(); ++ii) { - QmlGraphicsItem *child = children.at(ii); + for (int ii = 0; ii < positionedItems.count(); ++ii) { + QmlGraphicsItem *child = positionedItems.at(ii); if (!child || isInvisible(child)) continue; - bool needMove = (child->y() != voffset || child->x()); - - if (needMove && move() && items()->contains(child)) { - QList > changes; - changes << qMakePair(QString(QLatin1String("y")),QVariant(voffset)); - changes << qMakePair(QString(QLatin1String("x")),QVariant(0)); - applyMove(changes,child); - } else if (add() && !items()->contains(child)) { - QList > changes; - changes << qMakePair(QString(QLatin1String("y")),QVariant(voffset)); - changes << qMakePair(QString(QLatin1String("x")),QVariant(0)); - applyAdd(changes,child); - } else if (needMove) { - setMovingItem(child); - child->setY(voffset); - setMovingItem(0); - } + if(child->y() != voffset) + positionY(voffset, child); + voffset += child->height(); voffset += spacing(); } @@ -567,18 +441,6 @@ Row { */ /*! - \qmlproperty Transition Row::remove - This property holds the transition to apply when removing an item from the positioner. - The transition will only be applied to the removed item(s). - Positioner transitions will only affect the position (x,y) of items. - - Removed can mean that either the object has been deleted or reparented, and thus is now longer a child of the positioner, or that the object has had its opacity set to zero, and thus is no longer visible. - - Note that if the item counts as removed because its opacity is zero it will not be visible during the transition unless you set the opacity in the transition, like in the below example. - - -*/ -/*! \qmlproperty Transition Row::add This property holds the transition to apply when adding an item to the positioner. The transition will only be applied to the added item(s). @@ -638,35 +500,14 @@ void QmlGraphicsRow::doPositioning() { int hoffset = 0; - foreach(QmlGraphicsItem* item, *leavingItems()){ - if (remove()){ - QList > changes; - applyRemove(changes, item); - } - } - QList children = positionedItems; - for (int ii = 0; ii < children.count(); ++ii) { - QmlGraphicsItem *child = children.at(ii); + for (int ii = 0; ii < positionedItems.count(); ++ii) { + QmlGraphicsItem *child = positionedItems.at(ii); if (!child || isInvisible(child)) continue; - bool needMove = (child->x() != hoffset || child->y()); - - if (needMove && move() && items()->contains(child)) { - QList > changes; - changes << qMakePair(QString(QLatin1String("x")),QVariant(hoffset)); - changes << qMakePair(QString(QLatin1String("y")),QVariant(0)); - applyMove(changes,child); - } else if (add() && !items()->contains(child)) { - QList > changes; - changes << qMakePair(QString(QLatin1String("x")),QVariant(hoffset)); - changes << qMakePair(QString(QLatin1String("y")),QVariant(0)); - applyAdd(changes,child); - } else if (needMove) { - setMovingItem(child); - child->setX(hoffset); - setMovingItem(0); - } + if(child->x() != hoffset) + positionX(hoffset, child); + hoffset += child->width(); hoffset += spacing(); } @@ -720,19 +561,6 @@ Grid { positioner may exhibit strange behaviour. */ /*! - \qmlproperty Transition Grid::remove - This property holds the transition to apply when removing an item from the positioner. - The transition is only applied to the removed item(s). - Positioner transitions will only affect the position (x,y) of items. - - Removed can mean that either the object has been deleted or - reparented, and thus is now longer a child of the positioner, or that - the object has had its opacity set to zero, and thus is no longer - visible. - - -*/ -/*! \qmlproperty Transition Grid::add This property holds the transition to apply when adding an item to the positioner. The transition is only applied to the added item(s). @@ -815,7 +643,7 @@ QmlGraphicsGrid::QmlGraphicsGrid(QmlGraphicsItem *parent) : void QmlGraphicsGrid::doPositioning() { int c=_columns,r=_rows;//Actual number of rows/columns - int numVisible = items()->size() + newItems()->size(); + int numVisible = positionedItems.count(); if (_columns==-1 && _rows==-1){ c = 4; r = (numVisible+3)/4; @@ -828,7 +656,6 @@ void QmlGraphicsGrid::doPositioning() QList maxColWidth; QList maxRowHeight; int childIndex =0; - QList children = positionedItems; for (int i=0; iwidth() > maxColWidth[j]) @@ -852,29 +679,12 @@ void QmlGraphicsGrid::doPositioning() int yoffset=0; int curRow =0; int curCol =0; - foreach(QmlGraphicsItem* item, *leavingItems()){ - if (remove()){ - QList > changes; - applyRemove(changes, item); - } - } - foreach(QmlGraphicsItem* child, children){ + foreach(QmlGraphicsItem* child, positionedItems){ if (!child || isInvisible(child)) continue; - bool needMove = (child->x()!=xoffset)||(child->y()!=yoffset); - QList > changes; - changes << qMakePair(QString(QLatin1String("x")),QVariant(xoffset)); - changes << qMakePair(QString(QLatin1String("y")),QVariant(yoffset)); - if (newItems()->contains(child) && add()) { - applyAdd(changes,child); - } else if (needMove) { - if (move()){ - applyMove(changes,child); - }else{ - setMovingItem(child); - child->setPos(QPointF(xoffset, yoffset)); - setMovingItem(0); - } + if((child->x()!=xoffset)||(child->y()!=yoffset)){ + positionX(xoffset, child); + positionY(yoffset, child); } xoffset+=maxColWidth[curCol]+spacing(); curCol++; diff --git a/src/declarative/graphicsitems/qmlgraphicspositioners_p.h b/src/declarative/graphicsitems/qmlgraphicspositioners_p.h index 03e0f41..bc8315e 100644 --- a/src/declarative/graphicsitems/qmlgraphicspositioners_p.h +++ b/src/declarative/graphicsitems/qmlgraphicspositioners_p.h @@ -63,10 +63,9 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsBasePositioner : public QmlGraphicsItem Q_PROPERTY(int spacing READ spacing WRITE setSpacing NOTIFY spacingChanged) Q_PROPERTY(QmlTransition *move READ move WRITE setMove) Q_PROPERTY(QmlTransition *add READ add WRITE setAdd) - Q_PROPERTY(QmlTransition *remove READ remove WRITE setRemove) public: - enum AutoUpdateType { None = 0x0, Horizontal = 0x1, Vertical = 0x2, Both = 0x3 }; - QmlGraphicsBasePositioner(AutoUpdateType, QmlGraphicsItem *parent); + enum PositionerType { None = 0x0, Horizontal = 0x1, Vertical = 0x2, Both = 0x3 }; + QmlGraphicsBasePositioner(PositionerType, QmlGraphicsItem *parent); int spacing() const; void setSpacing(int); @@ -77,23 +76,13 @@ public: QmlTransition *add() const; void setAdd(QmlTransition *); - QmlTransition *remove() const; - void setRemove(QmlTransition *); - protected: + QmlGraphicsBasePositioner(QmlGraphicsBasePositionerPrivate &dd, PositionerType at, QmlGraphicsItem *parent); virtual void componentComplete(); virtual QVariant itemChange(GraphicsItemChange, const QVariant &); - virtual bool event(QEvent *); - QSet* newItems(); - QSet* leavingItems(); - QSet* items(); - void applyAdd(const QList >& changes, QmlGraphicsItem* target); - void applyMove(const QList >& changes, QmlGraphicsItem* target); - void applyRemove(const QList >& changes, QmlGraphicsItem* target); void finishApplyTransitions(); Q_SIGNALS: - void layoutItemChanged(); void spacingChanged(); protected Q_SLOTS: @@ -103,13 +92,11 @@ private Q_SLOTS: void prePositioning(); protected: - QmlGraphicsBasePositioner(QmlGraphicsBasePositionerPrivate &dd, AutoUpdateType at, QmlGraphicsItem *parent); - void setMovingItem(QmlGraphicsItem *); QList positionedItems; + void positionX(int,QmlGraphicsItem* target); + void positionY(int,QmlGraphicsItem* target); private: - void applyTransition(const QList >& changes, QmlGraphicsItem* target, - QmlStateOperation::ActionList &actions); Q_DISABLE_COPY(QmlGraphicsBasePositioner) Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsBasePositioner) }; diff --git a/src/declarative/graphicsitems/qmlgraphicspositioners_p_p.h b/src/declarative/graphicsitems/qmlgraphicspositioners_p_p.h index b079f6a..db795ec 100644 --- a/src/declarative/graphicsitems/qmlgraphicspositioners_p_p.h +++ b/src/declarative/graphicsitems/qmlgraphicspositioners_p_p.h @@ -72,9 +72,8 @@ class QmlGraphicsBasePositionerPrivate : public QmlGraphicsItemPrivate public: QmlGraphicsBasePositionerPrivate() - : _ep(false), _componentComplete(false), _spacing(0), - aut(QmlGraphicsBasePositioner::None), moveTransition(0), addTransition(0), - removeTransition(0), _movingItem(0), queuedPositioning(false) + : spacing(0), type(QmlGraphicsBasePositioner::None), moveTransition(0), addTransition(0), + queuedPositioning(false) { } @@ -85,9 +84,9 @@ public: unwatchChanges(other);//Need to deregister from a list in QmlGI Private } - void init(QmlGraphicsBasePositioner::AutoUpdateType at) + void init(QmlGraphicsBasePositioner::PositionerType at) { - aut = at; + type = at; if (prePosIdx == -1) { prePosIdx = QmlGraphicsBasePositioner::staticMetaObject.indexOfSlot("prePositioning()"); visibleIdx = QmlGraphicsItem::staticMetaObject.indexOfSignal("visibleChanged()"); @@ -95,29 +94,20 @@ public: } } - bool _ep; - bool _componentComplete; - int _spacing; - QmlGraphicsBasePositioner::AutoUpdateType aut; + int spacing; + QmlGraphicsBasePositioner::PositionerType type; QmlTransition *moveTransition; QmlTransition *addTransition; - QmlTransition *removeTransition; - QSet _items; - QSet _leavingItems; - QSet _stableItems; - QSet _newItems; - QSet _animated; + QSet items; + QSet newItems; QmlStateOperation::ActionList addActions; QmlStateOperation::ActionList moveActions; - QmlStateOperation::ActionList removeActions; QmlTransitionManager addTransitionManager; QmlTransitionManager moveTransitionManager; - QmlTransitionManager removeTransitionManager; - QmlGraphicsItem *_movingItem; void watchChanges(QmlGraphicsItem *other); void unwatchChanges(QmlGraphicsItem* other); - QList > watched; + QList > watched;//Can't have QSet and QGuard at the same time? bool queuedPositioning; static int prePosIdx; @@ -130,6 +120,7 @@ public: Q_UNUSED(other); if(!queuedPositioning){ //Delay is due to many children often being reordered at once + //And we only want to reposition them all once QTimer::singleShot(0,q,SLOT(prePositioning())); queuedPositioning = true; } diff --git a/tests/auto/declarative/qmlgraphicspositioners/data/grid-animated.qml b/tests/auto/declarative/qmlgraphicspositioners/data/grid-animated.qml index 6b128ce..022019c 100644 --- a/tests/auto/declarative/qmlgraphicspositioners/data/grid-animated.qml +++ b/tests/auto/declarative/qmlgraphicspositioners/data/grid-animated.qml @@ -7,12 +7,7 @@ Item { columns: 3 add: Transition { NumberAnimation { - matchProperties: "x,y"; from: -100 - } - } - remove: Transition { - NumberAnimation { - matchProperties: "x,y"; to: -100 + matchProperties: "x,y"; } } move: Transition { @@ -23,11 +18,15 @@ Item { Rectangle { objectName: "one" color: "red" + x: -100 + y: -100 width: 50 height: 50 } Rectangle { objectName: "two" + x: -100 + y: -100 opacity: 0 color: "green" width: 50 @@ -36,18 +35,24 @@ Item { Rectangle { objectName: "three" color: "blue" + x: -100 + y: -100 width: 50 height: 50 } Rectangle { objectName: "four" color: "cyan" + x: -100 + y: -100 width: 50 height: 50 } Rectangle { objectName: "five" color: "magenta" + x: -100 + y: -100 width: 50 height: 50 } diff --git a/tests/auto/declarative/qmlgraphicspositioners/data/horizontal-animated.qml b/tests/auto/declarative/qmlgraphicspositioners/data/horizontal-animated.qml index c29d6df..eba165c 100644 --- a/tests/auto/declarative/qmlgraphicspositioners/data/horizontal-animated.qml +++ b/tests/auto/declarative/qmlgraphicspositioners/data/horizontal-animated.qml @@ -6,12 +6,7 @@ Item { Row { add: Transition { NumberAnimation { - matchProperties: "x"; from: -100 - } - } - remove: Transition { - NumberAnimation { - matchProperties: "x"; to: -100 + matchProperties: "x"; } } move: Transition { @@ -22,19 +17,22 @@ Item { Rectangle { objectName: "one" color: "red" + x: -100; width: 50 height: 50 } Rectangle { objectName: "two" color: "blue" + x: -100; opacity: 0 width: 50 height: 50 } Rectangle { objectName: "three" - color: "red" + x: -100; + color: "green" width: 50 height: 50 } diff --git a/tests/auto/declarative/qmlgraphicspositioners/data/vertical-animated.qml b/tests/auto/declarative/qmlgraphicspositioners/data/vertical-animated.qml index fcbc5f7..8e3abbd 100644 --- a/tests/auto/declarative/qmlgraphicspositioners/data/vertical-animated.qml +++ b/tests/auto/declarative/qmlgraphicspositioners/data/vertical-animated.qml @@ -6,12 +6,7 @@ Item { Column { add: Transition { NumberAnimation { - matchProperties: "y"; from: -100 - } - } - remove: Transition { - NumberAnimation { - matchProperties: "y"; to: -100 + matchProperties: "y"; } } move: Transition { @@ -22,12 +17,14 @@ Item { Rectangle { objectName: "one" color: "red" + y: -100 width: 50 height: 50 } Rectangle { objectName: "two" color: "blue" + y: -100 opacity: 0 width: 50 height: 50 @@ -35,6 +32,7 @@ Item { Rectangle { objectName: "three" color: "red" + y: -100 width: 50 height: 50 } diff --git a/tests/auto/declarative/qmlgraphicspositioners/tst_qmlgraphicspositioners.cpp b/tests/auto/declarative/qmlgraphicspositioners/tst_qmlgraphicspositioners.cpp index aca3579..0e2109b 100644 --- a/tests/auto/declarative/qmlgraphicspositioners/tst_qmlgraphicspositioners.cpp +++ b/tests/auto/declarative/qmlgraphicspositioners/tst_qmlgraphicspositioners.cpp @@ -126,14 +126,14 @@ void tst_QmlGraphicsPositioners::test_horizontal_animated() qApp->processEvents(); QTest::qWait(0);//Let the animation start - //Note that one and three animate in + //Note that they animate in QmlGraphicsRectangle *one = canvas->root()->findChild("one"); QVERIFY(one != 0); QCOMPARE(one->x(), -100.0); QmlGraphicsRectangle *two = canvas->root()->findChild("two"); QVERIFY(two != 0); - QCOMPARE(two->x(), 0.0); + QCOMPARE(two->x(), -100.0); QmlGraphicsRectangle *three = canvas->root()->findChild("three"); QVERIFY(three != 0); @@ -144,7 +144,7 @@ void tst_QmlGraphicsPositioners::test_horizontal_animated() QCOMPARE(one->x(), 0.0); QCOMPARE(one->y(), 0.0); QCOMPARE(two->opacity(), 0.0); - QCOMPARE(two->x(), 0.0); + QCOMPARE(two->x(), -100.0);//Not 'in' yet QCOMPARE(two->y(), 0.0); QCOMPARE(three->x(), 50.0); QCOMPARE(three->y(), 0.0); @@ -158,15 +158,6 @@ void tst_QmlGraphicsPositioners::test_horizontal_animated() QTest::qWait(300);//Let the animation complete QCOMPARE(two->x(), 50.0); QCOMPARE(three->x(), 100.0); - - //Remove 'two' - two->setOpacity(0.0); - QCOMPARE(two->opacity(), 0.0); - QCOMPARE(two->x(), 50.0); - QCOMPARE(three->x(), 100.0); - QTest::qWait(300);//Let the animation complete - QCOMPARE(two->x(), 50.0); - QCOMPARE(three->x(), 50.0); } void tst_QmlGraphicsPositioners::test_vertical() @@ -225,14 +216,14 @@ void tst_QmlGraphicsPositioners::test_vertical_animated() qApp->processEvents(); QTest::qWait(0);//Let the animation start - //Note that one and three animate in + //Note that they animate in QmlGraphicsRectangle *one = canvas->root()->findChild("one"); QVERIFY(one != 0); QCOMPARE(one->y(), -100.0); QmlGraphicsRectangle *two = canvas->root()->findChild("two"); QVERIFY(two != 0); - QCOMPARE(two->y(), 0.0); + QCOMPARE(two->y(), -100.0); QmlGraphicsRectangle *three = canvas->root()->findChild("three"); QVERIFY(three != 0); @@ -243,7 +234,7 @@ void tst_QmlGraphicsPositioners::test_vertical_animated() QCOMPARE(one->y(), 0.0); QCOMPARE(one->x(), 0.0); QCOMPARE(two->opacity(), 0.0); - QCOMPARE(two->y(), 0.0); + QCOMPARE(two->y(), -100.0);//Not 'in' yet QCOMPARE(two->x(), 0.0); QCOMPARE(three->y(), 50.0); QCOMPARE(three->x(), 0.0); @@ -258,14 +249,6 @@ void tst_QmlGraphicsPositioners::test_vertical_animated() QCOMPARE(two->y(), 50.0); QCOMPARE(three->y(), 100.0); - //Remove 'two' - two->setOpacity(0.0); - QCOMPARE(two->opacity(), 0.0); - QCOMPARE(two->y(), 50.0); - QCOMPARE(three->y(), 100.0); - QTest::qWait(300);//Let the animation complete - QCOMPARE(two->y(), 50.0); - QCOMPARE(three->y(), 50.0); } void tst_QmlGraphicsPositioners::test_grid() @@ -335,7 +318,7 @@ void tst_QmlGraphicsPositioners::test_grid_animated() qApp->processEvents(); QTest::qWait(0);//Let the animation start - //Note that all but two animate in + //Note that all animate in QmlGraphicsRectangle *one = canvas->root()->findChild("one"); QVERIFY(one != 0); QCOMPARE(one->x(), -100.0); @@ -343,8 +326,8 @@ void tst_QmlGraphicsPositioners::test_grid_animated() QmlGraphicsRectangle *two = canvas->root()->findChild("two"); QVERIFY(two != 0); - QCOMPARE(two->x(), 0.0); - QCOMPARE(two->y(), 0.0); + QCOMPARE(two->x(), -100.0); + QCOMPARE(two->y(), -100.0); QmlGraphicsRectangle *three = canvas->root()->findChild("three"); QVERIFY(three != 0); @@ -366,8 +349,8 @@ void tst_QmlGraphicsPositioners::test_grid_animated() QCOMPARE(one->y(), 0.0); QCOMPARE(one->x(), 0.0); QCOMPARE(two->opacity(), 0.0); - QCOMPARE(two->y(), 0.0); - QCOMPARE(two->x(), 0.0); + QCOMPARE(two->y(), -100.0); + QCOMPARE(two->x(), -100.0); QCOMPARE(three->y(), 0.0); QCOMPARE(three->x(), 50.0); QCOMPARE(four->y(), 0.0); @@ -401,30 +384,6 @@ void tst_QmlGraphicsPositioners::test_grid_animated() QCOMPARE(five->x(), 50.0); QCOMPARE(five->y(), 50.0); - //Remove 'two' - two->setOpacity(0.0); - QCOMPARE(two->opacity(), 0.0); - QCOMPARE(two->x(), 50.0); - QCOMPARE(two->y(), 0.0); - QCOMPARE(one->x(), 0.0); - QCOMPARE(one->y(), 0.0); - QCOMPARE(three->x(), 100.0); - QCOMPARE(three->y(), 0.0); - QCOMPARE(four->x(), 0.0); - QCOMPARE(four->y(), 50.0); - QCOMPARE(five->x(), 50.0); - QCOMPARE(five->y(), 50.0); - QTest::qWait(300);//Let the animation complete - QCOMPARE(two->x(), 50.0); - QCOMPARE(two->y(), 0.0); - QCOMPARE(one->x(), 0.0); - QCOMPARE(one->y(), 0.0); - QCOMPARE(three->x(), 50.0); - QCOMPARE(three->y(), 0.0); - QCOMPARE(four->x(), 100.0); - QCOMPARE(four->y(), 0.0); - QCOMPARE(five->x(), 0.0); - QCOMPARE(five->y(), 50.0); } void tst_QmlGraphicsPositioners::test_repeater() -- cgit v0.12 From 0150b8ffd4e12ca0f3c5197ce225d81b0f9d1537 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 9 Dec 2009 13:03:32 +1000 Subject: Item creation benchmarks. --- .../declarative/creation/tst_creation.cpp | 83 ++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/tests/benchmarks/declarative/creation/tst_creation.cpp b/tests/benchmarks/declarative/creation/tst_creation.cpp index 99411d4..a73de41 100644 --- a/tests/benchmarks/declarative/creation/tst_creation.cpp +++ b/tests/benchmarks/declarative/creation/tst_creation.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include class tst_creation : public QObject @@ -65,6 +66,12 @@ private slots: void qgraphicsitem(); void qgraphicsitem_tree(); + void itemtree_notree_cpp(); + void itemtree_objtree_cpp(); + void itemtree_cpp(); + void itemtree_data_cpp(); + void itemtree_qml(); + private: QmlEngine engine; }; @@ -241,6 +248,82 @@ void tst_creation::qgraphicsitem_tree() } } +struct QmlGraphics_DerivedObject : public QObject +{ + void setParent_noEvent(QObject *parent) { + bool sce = d_ptr->sendChildEvents; + d_ptr->sendChildEvents = false; + setParent(parent); + d_ptr->sendChildEvents = sce; + } +}; + +inline void QmlGraphics_setParent_noEvent(QObject *object, QObject *parent) +{ + static_cast(object)->setParent_noEvent(parent); +} + +void tst_creation::itemtree_notree_cpp() +{ + QBENCHMARK { + QmlGraphicsItem *item = new QmlGraphicsItem; + for (int i = 0; i < 30; ++i) { + QmlGraphicsItem *child = new QmlGraphicsItem; + } + delete item; + } +} + +void tst_creation::itemtree_objtree_cpp() +{ + QBENCHMARK { + QmlGraphicsItem *item = new QmlGraphicsItem; + for (int i = 0; i < 30; ++i) { + QmlGraphicsItem *child = new QmlGraphicsItem; + QmlGraphics_setParent_noEvent(child,item); + } + delete item; + } +} + +void tst_creation::itemtree_cpp() +{ + QBENCHMARK { + QmlGraphicsItem *item = new QmlGraphicsItem; + for (int i = 0; i < 30; ++i) { + QmlGraphicsItem *child = new QmlGraphicsItem; + QmlGraphics_setParent_noEvent(child,item); + child->setParentItem(item); + } + delete item; + } +} + +void tst_creation::itemtree_data_cpp() +{ + QBENCHMARK { + QmlGraphicsItem *item = new QmlGraphicsItem; + for (int i = 0; i < 30; ++i) { + QmlGraphicsItem *child = new QmlGraphicsItem; + QmlGraphics_setParent_noEvent(child,item); + item->data()->append(child); + } + delete item; + } +} + +void tst_creation::itemtree_qml() +{ + QmlComponent component(&engine, TEST_FILE("item.qml")); + QObject *obj = component.create(); + delete obj; + + QBENCHMARK { + QObject *obj = component.create(); + delete obj; + } +} + QTEST_MAIN(tst_creation) -- cgit v0.12 From e569fac3b23885aec1295cb1845a96ca6fca26e2 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Wed, 9 Dec 2009 13:09:39 +1000 Subject: Inline QML still needs a URL so that subtypes are relative to that URL. Fixes tst_qmlecmascript::dynamicCreation --- src/declarative/qml/qmlengine.cpp | 2 ++ tests/auto/declarative/qmlqt/tst_qmlqt.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 63d5b70..ad68c8f 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -680,6 +680,8 @@ QScriptValue QmlEnginePrivate::createQmlObject(QScriptContext *ctxt, QScriptEngi QUrl url; if(ctxt->argumentCount() > 2) url = QUrl(ctxt->argument(2).toString()); + else + url = QUrl("inline"); if (url.isValid() && url.isRelative()) url = context->resolvedUrl(url); diff --git a/tests/auto/declarative/qmlqt/tst_qmlqt.cpp b/tests/auto/declarative/qmlqt/tst_qmlqt.cpp index 21c5478..f184af0 100644 --- a/tests/auto/declarative/qmlqt/tst_qmlqt.cpp +++ b/tests/auto/declarative/qmlqt/tst_qmlqt.cpp @@ -327,7 +327,7 @@ void tst_qmlqt::createQmlObject() QString warning2 = " " + TEST_FILE("main.qml").toString() + ":4:1: Duplicate property name"; QString warning3 = "QmlEngine::createQmlObject(): Component is not ready"; QString warning4 = "QmlEngine::createQmlObject():"; - QString warning5 = " :3: Cannot assign object type QObject with no default method"; + QString warning5 = " " + TEST_FILE("inline").toString() + ":3: Cannot assign object type QObject with no default method"; QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1)); QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2)); -- cgit v0.12 From 8c7e8e7306ad23986b55deaba3ed2c284053b6dd Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 9 Dec 2009 13:31:23 +1000 Subject: Let anchors.centerIn honor horizontalCenterOffset and verticalCenterOffset. --- src/declarative/graphicsitems/qmlgraphicsanchors.cpp | 8 ++++---- tests/auto/declarative/anchors/data/centerin.qml | 12 ++++++++++++ tests/auto/declarative/anchors/tst_anchors.cpp | 16 ++++++++++++++++ 3 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 tests/auto/declarative/anchors/data/centerin.qml diff --git a/src/declarative/graphicsitems/qmlgraphicsanchors.cpp b/src/declarative/graphicsitems/qmlgraphicsanchors.cpp index c838d7d..153149e4 100644 --- a/src/declarative/graphicsitems/qmlgraphicsanchors.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsanchors.cpp @@ -183,14 +183,14 @@ void QmlGraphicsAnchorsPrivate::centerInChanged() ++updatingCenterIn; if (centerIn == item->parentItem()) { - QPointF p((item->parentItem()->width() - item->width()) / 2., - (item->parentItem()->height() - item->height()) / 2.); + QPointF p((item->parentItem()->width() - item->width()) / 2. + hCenterOffset, + (item->parentItem()->height() - item->height()) / 2. + vCenterOffset); setItemPos(p); } else if (centerIn->parentItem() == item->parentItem()) { - QPointF p(centerIn->x() + (centerIn->width() - item->width()) / 2., - centerIn->y() + (centerIn->height() - item->height()) / 2.); + QPointF p(centerIn->x() + (centerIn->width() - item->width()) / 2. + hCenterOffset, + centerIn->y() + (centerIn->height() - item->height()) / 2. + vCenterOffset); setItemPos(p); } diff --git a/tests/auto/declarative/anchors/data/centerin.qml b/tests/auto/declarative/anchors/data/centerin.qml new file mode 100644 index 0000000..09b97f6 --- /dev/null +++ b/tests/auto/declarative/anchors/data/centerin.qml @@ -0,0 +1,12 @@ +import Qt 4.6 + +Rectangle { + width: 200; height: 200 + Rectangle { + objectName: "centered" + width: 50; height: 50; color: "blue" + anchors.centerIn: parent; + anchors.verticalCenterOffset: 30 + anchors.horizontalCenterOffset: 10 + } +} diff --git a/tests/auto/declarative/anchors/tst_anchors.cpp b/tests/auto/declarative/anchors/tst_anchors.cpp index 7378d95..bbe5ef1 100644 --- a/tests/auto/declarative/anchors/tst_anchors.cpp +++ b/tests/auto/declarative/anchors/tst_anchors.cpp @@ -71,6 +71,7 @@ private slots: void nullItem(); void nullItem_data(); void crash1(); + void centerIn(); }; /* @@ -378,6 +379,21 @@ void tst_anchors::crash1() delete view; } +void tst_anchors::centerIn() +{ + QmlView *view = new QmlView; + + view->setUrl(QUrl("file://" SRCDIR "/data/centerin.qml")); + + view->execute(); + qApp->processEvents(); + + QCOMPARE(findItem(view->root(), QLatin1String("centered"))->x(), 85.0); + QCOMPARE(findItem(view->root(), QLatin1String("centered"))->y(), 105.0); + + delete view; +} + QTEST_MAIN(tst_anchors) #include "tst_anchors.moc" -- cgit v0.12 From 2b1aea7db5c6b8e5c31740add1dfb8dd1c9acb87 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 9 Dec 2009 13:33:36 +1000 Subject: Fix leak. --- src/declarative/qml/qmlxmlhttprequest.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/declarative/qml/qmlxmlhttprequest.cpp b/src/declarative/qml/qmlxmlhttprequest.cpp index 5f0fe9ce..9629d7b 100644 --- a/src/declarative/qml/qmlxmlhttprequest.cpp +++ b/src/declarative/qml/qmlxmlhttprequest.cpp @@ -1006,6 +1006,7 @@ QmlXMLHttpRequest::QmlXMLHttpRequest() QmlXMLHttpRequest::~QmlXMLHttpRequest() { destroyNetwork(); + delete m_nam; } QScriptValue QmlXMLHttpRequest::callback() const -- cgit v0.12 From 366abae3466f4a8d91f88caafb87f10f3031c355 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 9 Dec 2009 13:43:38 +1000 Subject: Add missing file. --- .../benchmarks/declarative/creation/data/item.qml | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/benchmarks/declarative/creation/data/item.qml diff --git a/tests/benchmarks/declarative/creation/data/item.qml b/tests/benchmarks/declarative/creation/data/item.qml new file mode 100644 index 0000000..74d2f27 --- /dev/null +++ b/tests/benchmarks/declarative/creation/data/item.qml @@ -0,0 +1,34 @@ +import Qt 4.6 + +Item { + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} +} -- cgit v0.12 From 0a1a4915307b023ce0eb7c34ba8960a1260f7798 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Wed, 9 Dec 2009 14:09:17 +1000 Subject: Remove ASSERT-failing tests QmlListModel is not directly accessible from QML and so it requires that the caller has checked the index validity. --- tests/auto/declarative/qmllistaccessor/tst_qmllistaccessor.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/auto/declarative/qmllistaccessor/tst_qmllistaccessor.cpp b/tests/auto/declarative/qmllistaccessor/tst_qmllistaccessor.cpp index 14de1df..ddf9a07 100644 --- a/tests/auto/declarative/qmllistaccessor/tst_qmllistaccessor.cpp +++ b/tests/auto/declarative/qmllistaccessor/tst_qmllistaccessor.cpp @@ -69,8 +69,6 @@ void tst_QmlListAccessor::invalid() QCOMPARE(accessor.type(), QmlListAccessor::Invalid); QCOMPARE(accessor.count(), 0); - QCOMPARE(accessor.at(0), QVariant()); - QCOMPARE(accessor.at(4), QVariant()); QVERIFY(!accessor.append(QVariant(10))); QVERIFY(!accessor.insert(0, QVariant(10))); QVERIFY(!accessor.removeAt(0)); @@ -83,8 +81,6 @@ void tst_QmlListAccessor::invalid() QCOMPARE(accessor.type(), QmlListAccessor::Invalid); QCOMPARE(accessor.count(), 0); - QCOMPARE(accessor.at(0), QVariant()); - QCOMPARE(accessor.at(4), QVariant()); QVERIFY(!accessor.append(QVariant(10))); QVERIFY(!accessor.insert(0, QVariant(10))); QVERIFY(!accessor.removeAt(0)); -- cgit v0.12 From 611bd1247ff8254c567dc2c50573e84093dd8c5a Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Wed, 9 Dec 2009 14:25:05 +1000 Subject: print error message --- tests/auto/declarative/valuetypes/tst_valuetypes.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/auto/declarative/valuetypes/tst_valuetypes.cpp b/tests/auto/declarative/valuetypes/tst_valuetypes.cpp index d42bfc5..1a5d7b6 100644 --- a/tests/auto/declarative/valuetypes/tst_valuetypes.cpp +++ b/tests/auto/declarative/valuetypes/tst_valuetypes.cpp @@ -474,11 +474,23 @@ void tst_valuetypes::valueSources() delete object; } +static void checkNoErrors(QmlComponent& component) +{ + QList errors = component.errors(); + if (errors.isEmpty()) + return; + for (int ii = 0; ii < errors.count(); ++ii) { + const QmlError &error = errors.at(ii); + qWarning("%d:%d:%s",error.line(),error.column(),error.description().toUtf8().constData()); + } +} + // Test that property value interceptors can be applied to value types void tst_valuetypes::valueInterceptors() { QmlComponent component(&engine, TEST_FILE("valueInterceptors.qml")); MyTypeObject *object = qobject_cast(component.create()); + checkNoErrors(component); QVERIFY(object != 0); QCOMPARE(object->rect().x(), 26); -- cgit v0.12 From 4bad9d6661f6b63c6ce9b9a29e9f5cf7aa032e37 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 9 Dec 2009 14:58:11 +1000 Subject: Another creation benchmark. --- .../benchmarks/declarative/creation/tst_creation.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/benchmarks/declarative/creation/tst_creation.cpp b/tests/benchmarks/declarative/creation/tst_creation.cpp index a73de41..61033e2 100644 --- a/tests/benchmarks/declarative/creation/tst_creation.cpp +++ b/tests/benchmarks/declarative/creation/tst_creation.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -71,6 +72,7 @@ private slots: void itemtree_cpp(); void itemtree_data_cpp(); void itemtree_qml(); + void itemtree_scene_cpp(); private: QmlEngine engine; @@ -324,6 +326,24 @@ void tst_creation::itemtree_qml() } } +void tst_creation::itemtree_scene_cpp() +{ + QGraphicsScene scene; + QmlGraphicsItem *root = new QmlGraphicsItem; + scene.addItem(root); + QBENCHMARK { + QmlGraphicsItem *item = new QmlGraphicsItem; + for (int i = 0; i < 30; ++i) { + QmlGraphicsItem *child = new QmlGraphicsItem; + QmlGraphics_setParent_noEvent(child,item); + child->setParentItem(item); + } + item->setParentItem(root); + delete item; + } + delete root; +} + QTEST_MAIN(tst_creation) -- cgit v0.12 From 1fa993a90b98f5b92488c1449a4bcbbdf45929eb Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Wed, 9 Dec 2009 09:10:54 +0100 Subject: Update positioners example --- examples/declarative/layouts/positioners.qml | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/examples/declarative/layouts/positioners.qml b/examples/declarative/layouts/positioners.qml index e912632..2583cc5 100644 --- a/examples/declarative/layouts/positioners.qml +++ b/examples/declarative/layouts/positioners.qml @@ -16,12 +16,7 @@ Rectangle { } add: Transition { NumberAnimation { - matchProperties: "y"; from: 500; duration:500; easing: "easeOutQuad" - } - } - remove: Transition { - NumberAnimation { - matchProperties:"y"; to: 500; duration:500; easing: "easeInQuad" + matchProperties: "y"; easing: "easeOutQuad" } } Rectangle { color: "red"; width: 100; height: 50; border.color: "black"; radius: 15 } @@ -45,12 +40,7 @@ Rectangle { } add: Transition { NumberAnimation { - matchProperties: "x"; from: 500; duration:500; easing: "easeOutQuad" - } - } - remove: Transition { - NumberAnimation { - matchProperties: "x"; to: 500; duration:500; easing: "easeInQuad" + matchProperties: "x"; easing: "easeOutQuad" } } Rectangle { color: "red"; width: 50; height: 100; border.color: "black"; radius: 15 } @@ -103,12 +93,6 @@ Rectangle { y: 0 columns: 3 - remove: Transition { - NumberAnimation { - matchProperties: "x,y"; easing: "easeOutBounce" - } - } - move: Transition { NumberAnimation { matchProperties: "x,y"; easing: "easeOutBounce" -- cgit v0.12 From c55e7db991f7e4f7f5f443cf3ebebb709eca8d2d Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Wed, 9 Dec 2009 10:07:17 +0100 Subject: Update FlowPositioner to the new BasePositioner implementation --- examples/declarative/layouts/positioners.qml | 5 --- .../graphicsitems/qmlgraphicspositioners.cpp | 43 ++-------------------- 2 files changed, 4 insertions(+), 44 deletions(-) diff --git a/examples/declarative/layouts/positioners.qml b/examples/declarative/layouts/positioners.qml index f84e806..46762f7 100644 --- a/examples/declarative/layouts/positioners.qml +++ b/examples/declarative/layouts/positioners.qml @@ -133,11 +133,6 @@ Rectangle { x: 260 y: 250 width: 150 - remove: Transition { - NumberAnimation { - matchProperties: "x,y"; easing: "easeOutBounce" - } - } move: Transition { NumberAnimation { diff --git a/src/declarative/graphicsitems/qmlgraphicspositioners.cpp b/src/declarative/graphicsitems/qmlgraphicspositioners.cpp index 5e24c86..60abdde 100644 --- a/src/declarative/graphicsitems/qmlgraphicspositioners.cpp +++ b/src/declarative/graphicsitems/qmlgraphicspositioners.cpp @@ -710,18 +710,6 @@ QML_DEFINE_TYPE(Qt,4,6,Flow,QmlGraphicsFlow) */ /*! - \qmlproperty Transition Flow::remove - This property holds the transition to apply when removing an item from the positioner. - The transition will only be applied to the removed item(s). - Positioner transitions will only affect the position (x,y) of items. - - Removed can mean that either the object has been deleted or reparented, and thus is now longer a child of the positioner, or that the object has had its opacity set to zero, and thus is no longer visible. - - Note that if the item counts as removed because its opacity is zero it will not be visible during the transition unless you set the opacity in the transition, like in the below example. - - -*/ -/*! \qmlproperty Transition Flow::add This property holds the transition to apply when adding an item to the positioner. The transition will only be applied to the added item(s). @@ -808,20 +796,12 @@ void QmlGraphicsFlow::setFlow(Flow flow) void QmlGraphicsFlow::doPositioning() { Q_D(QmlGraphicsFlow); - foreach(QmlGraphicsItem* item, *leavingItems()){ - if (remove()){ - QList > changes; - applyRemove(changes, item); - } - } int hoffset = 0; int voffset = 0; int linemax = 0; - QList children = positionedItems; - for (int ii = 0; ii < children.count(); ++ii) { - QmlGraphicsItem *child = children.at(ii); + foreach(QmlGraphicsItem* child, positionedItems){ if (!child || isInvisible(child)) continue; @@ -839,24 +819,9 @@ void QmlGraphicsFlow::doPositioning() } } - bool needMove = (child->x() != hoffset || child->y() != voffset); - - if (newItems()->contains(child) && add()) { - QList > changes; - changes << qMakePair(QString(QLatin1String("x")),QVariant(hoffset)); - changes << qMakePair(QString(QLatin1String("y")),QVariant(voffset)); - applyAdd(changes,child); - } else if (needMove) { - if (move()){ - QList > changes; - changes << qMakePair(QString(QLatin1String("x")),QVariant(hoffset)); - changes << qMakePair(QString(QLatin1String("y")),QVariant(voffset)); - applyMove(changes,child); - } else { - setMovingItem(child); - child->setPos(QPointF(hoffset, voffset)); - setMovingItem(0); - } + if(child->x() != hoffset || child->y() != voffset){ + positionX(hoffset, child); + positionY(voffset, child); } if (d->flow == LeftToRight) { -- cgit v0.12 From 8a0d1d1b273fb2c0de4644d4060d8d5aae27c456 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Wed, 9 Dec 2009 10:24:26 +0100 Subject: Allow anchoring baseline to parent Task-number: QT-2606 --- .../graphicsitems/qmlgraphicsanchors.cpp | 8 +- .../baseline/data-X11/parentanchor.qml | 131 +++++++++++++++++++++ .../qmlgraphicstext/baseline/data/parentanchor.qml | 131 +++++++++++++++++++++ .../qmlgraphicstext/baseline/parentanchor.qml | 14 +++ 4 files changed, 282 insertions(+), 2 deletions(-) create mode 100644 tests/auto/declarative/visual/qmlgraphicstext/baseline/data-X11/parentanchor.qml create mode 100644 tests/auto/declarative/visual/qmlgraphicstext/baseline/data/parentanchor.qml create mode 100644 tests/auto/declarative/visual/qmlgraphicstext/baseline/parentanchor.qml diff --git a/src/declarative/graphicsitems/qmlgraphicsanchors.cpp b/src/declarative/graphicsitems/qmlgraphicsanchors.cpp index 153149e4..b72f010 100644 --- a/src/declarative/graphicsitems/qmlgraphicsanchors.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsanchors.cpp @@ -495,8 +495,12 @@ void QmlGraphicsAnchorsPrivate::updateVerticalAnchors() } } else if (usedAnchors & QmlGraphicsAnchors::HasBaselineAnchor) { //Handle baseline - if (baseline.item->parentItem() == item->parentItem()) { - setItemY(position(baseline.item, baseline.anchorLine) - item->baselineOffset() + baselineOffset); + if (baseline.item == item->parentItem()) { + setItemY(adjustedPosition(baseline.item, baseline.anchorLine) + - item->baselineOffset() + baselineOffset); + } else if (baseline.item->parentItem() == item->parentItem()) { + setItemY(position(baseline.item, baseline.anchorLine) + - item->baselineOffset() + baselineOffset); } } --updatingVerticalAnchor; diff --git a/tests/auto/declarative/visual/qmlgraphicstext/baseline/data-X11/parentanchor.qml b/tests/auto/declarative/visual/qmlgraphicstext/baseline/data-X11/parentanchor.qml new file mode 100644 index 0000000..56d616e --- /dev/null +++ b/tests/auto/declarative/visual/qmlgraphicstext/baseline/data-X11/parentanchor.qml @@ -0,0 +1,131 @@ +import Qt.VisualTest 4.6 + +VisualTest { + Frame { + msec: 0 + } + Frame { + msec: 16 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 32 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 48 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 64 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 80 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 96 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 112 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 128 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 144 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 160 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 176 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 192 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 208 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 224 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 240 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 256 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 272 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 288 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 304 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 320 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 336 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 352 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 368 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 384 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 400 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 416 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 432 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 448 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 464 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 480 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 496 + hash: "3e022a120a2dbe688d53657508de36cf" + } +} diff --git a/tests/auto/declarative/visual/qmlgraphicstext/baseline/data/parentanchor.qml b/tests/auto/declarative/visual/qmlgraphicstext/baseline/data/parentanchor.qml new file mode 100644 index 0000000..56d616e --- /dev/null +++ b/tests/auto/declarative/visual/qmlgraphicstext/baseline/data/parentanchor.qml @@ -0,0 +1,131 @@ +import Qt.VisualTest 4.6 + +VisualTest { + Frame { + msec: 0 + } + Frame { + msec: 16 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 32 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 48 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 64 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 80 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 96 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 112 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 128 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 144 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 160 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 176 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 192 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 208 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 224 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 240 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 256 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 272 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 288 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 304 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 320 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 336 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 352 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 368 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 384 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 400 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 416 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 432 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 448 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 464 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 480 + hash: "3e022a120a2dbe688d53657508de36cf" + } + Frame { + msec: 496 + hash: "3e022a120a2dbe688d53657508de36cf" + } +} diff --git a/tests/auto/declarative/visual/qmlgraphicstext/baseline/parentanchor.qml b/tests/auto/declarative/visual/qmlgraphicstext/baseline/parentanchor.qml new file mode 100644 index 0000000..80f0f03 --- /dev/null +++ b/tests/auto/declarative/visual/qmlgraphicstext/baseline/parentanchor.qml @@ -0,0 +1,14 @@ +import Qt 4.6 + +Rectangle { + id: s; width: 600; height: 100; color: "lightsteelblue" + property string text: "The quick brown fox jumps over the lazy dog." + Text { + text: s.text + anchors.verticalCenter: s.verticalCenter + } + Text { + text: s.text + anchors.baseline: s.verticalCenter + } +} -- cgit v0.12 From 528f822012bab0126c6c51d00632f03f3d3afb9c Mon Sep 17 00:00:00 2001 From: Tapani Mikola Date: Thu, 3 Dec 2009 17:39:27 +0200 Subject: Create xhr url with fromEncoded. --- src/declarative/qml/qmlxmlhttprequest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/qml/qmlxmlhttprequest.cpp b/src/declarative/qml/qmlxmlhttprequest.cpp index 9629d7b..9c39fc8 100644 --- a/src/declarative/qml/qmlxmlhttprequest.cpp +++ b/src/declarative/qml/qmlxmlhttprequest.cpp @@ -1296,7 +1296,7 @@ static QScriptValue qmlxmlhttprequest_open(QScriptContext *context, QScriptEngin // Argument 1 - URL - QUrl url(context->argument(1).toString()); + QUrl url = QUrl::fromEncoded(context->argument(1).toString().toUtf8()); if (url.isRelative()) { url = QmlScriptEngine::get(engine)->resolvedUrl(context,url); -- cgit v0.12