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 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 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 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 From 0d0f02be045f05838d0c219321809b46db16b50d Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 10 Dec 2009 07:39:21 +1000 Subject: Avoid creating a new dynamic metaobject for each delegate. --- .../graphicsitems/qmlgraphicsvisualitemmodel.cpp | 47 ++++-- src/declarative/util/qmlopenmetaobject.cpp | 181 +++++++++++++++------ src/declarative/util/qmlopenmetaobject_p.h | 18 +- 3 files changed, 174 insertions(+), 72 deletions(-) diff --git a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp index a6c40c5..7530c43 100644 --- a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp @@ -341,6 +341,9 @@ public: QmlGraphicsVisualDataModelParts *m_parts; friend class QmlGraphicsVisualItemParts; + QmlOpenMetaObjectType *m_delegateDataType; + friend class QmlGraphicsVisualDataModelData; + QmlGraphicsVisualDataModelData *data(QObject *item); QVariant m_modelVariant; @@ -362,10 +365,11 @@ public: class QmlGraphicsVisualDataModelDataMetaObject : public QmlOpenMetaObject { public: - QmlGraphicsVisualDataModelDataMetaObject(QObject *parent) - : QmlOpenMetaObject(parent) {} + QmlGraphicsVisualDataModelDataMetaObject(QObject *parent, QmlOpenMetaObjectType *type) + : QmlOpenMetaObject(parent, type) {} - virtual QVariant propertyCreated(int, QMetaPropertyBuilder &); + virtual void propertyCreated(int, QMetaPropertyBuilder &); + virtual QVariant initialValue(int); virtual int createProperty(const char *, const char *); private: @@ -442,20 +446,22 @@ int QmlGraphicsVisualDataModelDataMetaObject::createProperty(const char *name, c return -1; } -QVariant -QmlGraphicsVisualDataModelDataMetaObject::propertyCreated(int, QMetaPropertyBuilder &prop) +void QmlGraphicsVisualDataModelDataMetaObject::propertyCreated(int, QMetaPropertyBuilder &prop) { prop.setWritable(false); +} +QVariant QmlGraphicsVisualDataModelDataMetaObject::initialValue(int propId) +{ QmlGraphicsVisualDataModelData *data = static_cast(object()); Q_ASSERT(data->m_model); QmlGraphicsVisualDataModelPrivate *model = QmlGraphicsVisualDataModelPrivate::get(data->m_model); - QString name = QString::fromUtf8(prop.name()); + QString strName = QString::fromUtf8(name(propId)); if ((!model->m_listModelInterface || !model->m_abstractItemModel) && model->m_listAccessor) { - if (name == QLatin1String("modelData")) { + if (strName == QLatin1String("modelData")) { if (model->m_listAccessor->type() == QmlListAccessor::Instance) { QObject *object = model->m_listAccessor->at(0).value(); return object->metaObject()->property(1).read(object); // the first property after objectName @@ -464,11 +470,11 @@ QmlGraphicsVisualDataModelDataMetaObject::propertyCreated(int, QMetaPropertyBuil } else { // return any property of a single object instance. QObject *object = model->m_listAccessor->at(data->m_index).value(); - return object->property(prop.name()); + return object->property(name(propId)); } } else if (model->m_listModelInterface) { model->ensureRoles(); - QHash::const_iterator it = model->m_roleNames.find(name); + QHash::const_iterator it = model->m_roleNames.find(strName); if (it != model->m_roleNames.end()) { roles.append(*it); QHash values = model->m_listModelInterface->data(data->m_index, QList() << *it); @@ -476,7 +482,7 @@ QmlGraphicsVisualDataModelDataMetaObject::propertyCreated(int, QMetaPropertyBuil return QVariant(); else return values.value(*it); - } else if (model->m_roles.count() == 1 && name == QLatin1String("modelData")) { + } else if (model->m_roles.count() == 1 && strName == QLatin1String("modelData")) { //for compatability with other lists, assign modelData if there is only a single role QHash values = model->m_listModelInterface->data(data->m_index, QList() << model->m_roles.first()); if (values.isEmpty()) @@ -486,7 +492,7 @@ QmlGraphicsVisualDataModelDataMetaObject::propertyCreated(int, QMetaPropertyBuil } } else if (model->m_abstractItemModel) { model->ensureRoles(); - QHash::const_iterator it = model->m_roleNames.find(name); + QHash::const_iterator it = model->m_roleNames.find(strName); if (it != model->m_roleNames.end()) { roles.append(*it); QModelIndex index = model->m_abstractItemModel->index(data->m_index, 0); @@ -500,7 +506,7 @@ QmlGraphicsVisualDataModelDataMetaObject::propertyCreated(int, QMetaPropertyBuil QmlGraphicsVisualDataModelData::QmlGraphicsVisualDataModelData(int index, QmlGraphicsVisualDataModel *model) : m_index(index), m_model(model), - m_meta(new QmlGraphicsVisualDataModelDataMetaObject(this)) +m_meta(new QmlGraphicsVisualDataModelDataMetaObject(this, QmlGraphicsVisualDataModelPrivate::get(model)->m_delegateDataType)) { } @@ -526,7 +532,8 @@ public: QmlGraphicsVisualDataModelPartsMetaObject(QObject *parent) : QmlOpenMetaObject(parent) {} - virtual QVariant propertyCreated(int, QMetaPropertyBuilder &); + virtual void propertyCreated(int, QMetaPropertyBuilder &); + virtual QVariant initialValue(int); }; class QmlGraphicsVisualDataModelParts : public QObject @@ -540,14 +547,16 @@ private: QmlGraphicsVisualDataModel *model; }; -QVariant -QmlGraphicsVisualDataModelPartsMetaObject::propertyCreated(int, QMetaPropertyBuilder &prop) +void QmlGraphicsVisualDataModelPartsMetaObject::propertyCreated(int, QMetaPropertyBuilder &prop) { prop.setWritable(false); +} +QVariant QmlGraphicsVisualDataModelPartsMetaObject::initialValue(int id) +{ QmlGraphicsVisualDataModel *m = new QmlGraphicsVisualDataModel; m->setParent(object()); - m->setPart(QString::fromUtf8(prop.name())); + m->setPart(QString::fromUtf8(property(id).name())); m->setModel(QVariant::fromValue(static_cast(object())->model)); QVariant var = QVariant::fromValue((QObject *)m); @@ -562,7 +571,7 @@ QmlGraphicsVisualDataModelParts::QmlGraphicsVisualDataModelParts(QmlGraphicsVisu QmlGraphicsVisualDataModelPrivate::QmlGraphicsVisualDataModelPrivate(QmlContext *ctxt) : m_listModelInterface(0), m_abstractItemModel(0), m_visualItemModel(0), m_delegate(0) -, m_context(ctxt), m_parts(0), m_listAccessor(0) +, m_context(ctxt), m_parts(0), m_delegateDataType(0), m_listAccessor(0) { } @@ -639,6 +648,8 @@ void QmlGraphicsVisualDataModel::setModel(const QVariant &model) d->m_roles.clear(); d->m_roleNames.clear(); + delete d->m_delegateDataType; + d->m_delegateDataType = new QmlOpenMetaObjectType(d->m_context->engine()); QObject *object = qvariant_cast(model); if (object && (d->m_listModelInterface = qobject_cast(object))) { @@ -761,7 +772,7 @@ QmlGraphicsVisualDataModel::ReleaseFlags QmlGraphicsVisualDataModel::release(Qml if (inPackage) emit destroyingPackage(qobject_cast(obj)); stat |= Destroyed; - delete obj; + obj->deleteLater(); } else if (!inPackage) { stat |= Referenced; } diff --git a/src/declarative/util/qmlopenmetaobject.cpp b/src/declarative/util/qmlopenmetaobject.cpp index 04cd8a5..30457f9 100644 --- a/src/declarative/util/qmlopenmetaobject.cpp +++ b/src/declarative/util/qmlopenmetaobject.cpp @@ -40,70 +40,141 @@ ****************************************************************************/ #include "qmlopenmetaobject_p.h" - +#include "qmlpropertycache_p.h" +#include "qmldeclarativedata_p.h" #include #include QT_BEGIN_NAMESPACE -class QmlOpenMetaObjectPrivate + +class QmlOpenMetaObjectTypePrivate { public: - QmlOpenMetaObjectPrivate() : parent(0), mem(0) {} + QmlOpenMetaObjectTypePrivate() : mem(0), engine(0) {} + + void init(QObject *obj); - bool autoCreate; - QAbstractDynamicMetaObject *parent; int propertyOffset; int signalOffset; - QList data; QHash names; QMetaObjectBuilder mob; QMetaObject *mem; + QmlEngine *engine; +}; + +QmlOpenMetaObjectType::QmlOpenMetaObjectType(QmlEngine *engine) + : d(new QmlOpenMetaObjectTypePrivate) +{ + d->engine = engine; +} + +QmlOpenMetaObjectType::~QmlOpenMetaObjectType() +{ + qFree(d->mem); +} + +void QmlOpenMetaObjectTypePrivate::init(QObject *obj) +{ + if (!mem) { + mob.setSuperClass(obj->metaObject()); + mob.setClassName(obj->metaObject()->className()); + mob.setFlags(QMetaObjectBuilder::DynamicMetaObject); + + QObjectPrivate *op = QObjectPrivate::get(obj); + if (op->metaObject) + mob.setSuperClass(op->metaObject); + mem = mob.toMetaObject(); + + propertyOffset = mem->propertyOffset(); + signalOffset = mem->methodOffset(); + } +} + +class QmlOpenMetaObjectPrivate +{ +public: + QmlOpenMetaObjectPrivate(QmlOpenMetaObject *_q) : q(_q), parent(0), type(0), ownType(false) {} + + inline QVariant &getData(int idx) { + while (data.count() <= idx) + data << QPair(QVariant(), false); + QPair &prop = data[idx]; + if (!prop.second) { + prop.first = q->initialValue(idx); + prop.second = true; + } + return prop.first; + } + + inline void writeData(int idx, const QVariant &value) { + while (data.count() <= idx) + data << QPair(QVariant(), false); + QPair &prop = data[idx]; + prop.first = value; + prop.second = true; + } + + bool autoCreate; + QmlOpenMetaObject *q; + QAbstractDynamicMetaObject *parent; + QList > data; QObject *object; + QmlOpenMetaObjectType *type; + bool ownType; }; QmlOpenMetaObject::QmlOpenMetaObject(QObject *obj, bool automatic) -: d(new QmlOpenMetaObjectPrivate) +: d(new QmlOpenMetaObjectPrivate(this)) { d->autoCreate = automatic; d->object = obj; - d->mob.setSuperClass(obj->metaObject()); - d->mob.setClassName(obj->metaObject()->className()); - d->mob.setFlags(QMetaObjectBuilder::DynamicMetaObject); + d->type = new QmlOpenMetaObjectType(0); + d->ownType = true; + d->type->d->init(obj); QObjectPrivate *op = QObjectPrivate::get(obj); - if (op->metaObject) - d->mob.setSuperClass(op->metaObject); + *static_cast(this) = *d->type->d->mem; + op->metaObject = this; +} + +QmlOpenMetaObject::QmlOpenMetaObject(QObject *obj, QmlOpenMetaObjectType *type, bool automatic) +: d(new QmlOpenMetaObjectPrivate(this)) +{ + d->autoCreate = automatic; + d->object = obj; - d->mem = d->mob.toMetaObject(); - *static_cast(this) = *d->mem; + d->type = type; + d->type->d->init(obj); + + QObjectPrivate *op = QObjectPrivate::get(obj); + *static_cast(this) = *d->type->d->mem; op->metaObject = this; - d->propertyOffset = propertyOffset(); - d->signalOffset = methodOffset(); } QmlOpenMetaObject::~QmlOpenMetaObject() { if (d->parent) delete d->parent; - qFree(d->mem); + if (d->ownType) + delete d->type; delete d; } int QmlOpenMetaObject::metaCall(QMetaObject::Call c, int id, void **a) { if (( c == QMetaObject::ReadProperty || c == QMetaObject::WriteProperty) - && id >= d->propertyOffset) { - int propId = id - d->propertyOffset; + && id >= d->type->d->propertyOffset) { + int propId = id - d->type->d->propertyOffset; if (c == QMetaObject::ReadProperty) { propertyRead(propId); - *reinterpret_cast(a[0]) = d->data[propId]; + *reinterpret_cast(a[0]) = d->getData(propId); } else if (c == QMetaObject::WriteProperty) { - if (d->data[propId] != *reinterpret_cast(a[0])) { + if (d->data[propId].first != *reinterpret_cast(a[0])) { propertyWrite(propId); - d->data[propId] = *reinterpret_cast(a[0]); - activate(d->object, d->signalOffset + propId, 0); + d->writeData(propId, *reinterpret_cast(a[0])); + activate(d->object, d->type->d->signalOffset + propId, 0); } } return -1; @@ -117,50 +188,49 @@ int QmlOpenMetaObject::metaCall(QMetaObject::Call c, int id, void **a) QVariant QmlOpenMetaObject::value(int id) const { - Q_ASSERT(id >= 0 && id < d->data.count()); - return d->data.at(id); + return d->getData(id); } void QmlOpenMetaObject::setValue(int id, const QVariant &value) { - Q_ASSERT(id >= 0 && id < d->data.count()); - d->data[id] = value; - activate(d->object, id + d->signalOffset, 0); + d->writeData(id, value); + activate(d->object, id + d->type->d->signalOffset, 0); } QVariant QmlOpenMetaObject::value(const QByteArray &name) const { - QHash::ConstIterator iter = d->names.find(name); - if (iter == d->names.end()) + QHash::ConstIterator iter = d->type->d->names.find(name); + if (iter == d->type->d->names.end()) return QVariant(); - return d->data.at(*iter); + return d->getData(*iter); } QVariant &QmlOpenMetaObject::operator[](const QByteArray &name) { - QHash::ConstIterator iter = d->names.find(name); - Q_ASSERT(iter != d->names.end()); + QHash::ConstIterator iter = d->type->d->names.find(name); + Q_ASSERT(iter != d->type->d->names.end()); - return d->data[*iter]; + return d->getData(*iter); } void QmlOpenMetaObject::setValue(const QByteArray &name, const QVariant &val) { - QHash::ConstIterator iter = d->names.find(name); + QHash::ConstIterator iter = d->type->d->names.find(name); int id = -1; - if (iter == d->names.end()) { - id = doCreateProperty(name.constData()) - d->propertyOffset; + if (iter == d->type->d->names.end()) { + id = doCreateProperty(name.constData()) - d->type->d->propertyOffset; } else { id = *iter; } - if (d->data[id] == val) + QVariant &dataVal = d->getData(id); + if (dataVal == val) return; - d->data[id] = val; - activate(d->object, id + d->signalOffset, 0); + dataVal = val; + activate(d->object, id + d->type->d->signalOffset, 0); } int QmlOpenMetaObject::createProperty(const char *name, const char *) @@ -173,17 +243,18 @@ int QmlOpenMetaObject::createProperty(const char *name, const char *) int QmlOpenMetaObject::doCreateProperty(const char *name) { - int id = d->mob.propertyCount(); - d->mob.addSignal("__" + QByteArray::number(id) + "()"); - QMetaPropertyBuilder build = d->mob.addProperty(name, "QVariant", id); + qDebug() << "doCreateProperty()" << name; + int id = d->type->d->mob.propertyCount(); + d->type->d->mob.addSignal("__" + QByteArray::number(id) + "()"); + QMetaPropertyBuilder build = d->type->d->mob.addProperty(name, "QVariant", id); build.setDynamic(true); - d->data << propertyCreated(id, build); - qFree(d->mem); - d->mem = d->mob.toMetaObject(); - *static_cast(this) = *d->mem; - d->names.insert(name, id); + propertyCreated(id, build); + qFree(d->type->d->mem); + d->type->d->mem = d->type->d->mob.toMetaObject(); + *static_cast(this) = *d->type->d->mem; + d->type->d->names.insert(name, id); - return d->propertyOffset + id; + return d->type->d->propertyOffset + id; } void QmlOpenMetaObject::propertyRead(int) @@ -194,21 +265,25 @@ void QmlOpenMetaObject::propertyWrite(int) { } -QVariant QmlOpenMetaObject::propertyCreated(int, QMetaPropertyBuilder &) +void QmlOpenMetaObject::propertyCreated(int id, QMetaPropertyBuilder &) +{ +} + +QVariant QmlOpenMetaObject::initialValue(int) { return QVariant(); } int QmlOpenMetaObject::count() const { - return d->data.count(); + return d->type->d->names.count(); } QByteArray QmlOpenMetaObject::name(int idx) const { - Q_ASSERT(idx >= 0 && idx < d->data.count()); + Q_ASSERT(idx >= 0 && idx < d->type->d->names.count()); - return d->mob.property(idx).name(); + return d->type->d->mob.property(idx).name(); } QObject *QmlOpenMetaObject::object() const diff --git a/src/declarative/util/qmlopenmetaobject_p.h b/src/declarative/util/qmlopenmetaobject_p.h index 6045678..b33f99b 100644 --- a/src/declarative/util/qmlopenmetaobject_p.h +++ b/src/declarative/util/qmlopenmetaobject_p.h @@ -53,12 +53,27 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) +class QmlEngine; +class QmlOpenMetaObjectTypePrivate; +class QmlOpenMetaObjectType +{ +public: + QmlOpenMetaObjectType(QmlEngine *engine); + ~QmlOpenMetaObjectType(); + +private: + QmlOpenMetaObjectTypePrivate *d; + friend class QmlOpenMetaObject; + friend class QmlOpenMetaObjectPrivate; +}; + class QmlOpenMetaObjectPrivate; class QMetaPropertyBuilder; class Q_DECLARATIVE_EXPORT QmlOpenMetaObject : public QAbstractDynamicMetaObject { public: QmlOpenMetaObject(QObject *, bool = true); + QmlOpenMetaObject(QObject *, QmlOpenMetaObjectType *, bool = true); ~QmlOpenMetaObject(); QVariant value(const QByteArray &) const; @@ -71,13 +86,14 @@ public: QByteArray name(int) const; QObject *object() const; + virtual QVariant initialValue(int); protected: virtual int metaCall(QMetaObject::Call _c, int _id, void **_a); virtual int createProperty(const char *, const char *); virtual void propertyRead(int); virtual void propertyWrite(int); - virtual QVariant propertyCreated(int, QMetaPropertyBuilder &); + virtual void propertyCreated(int, QMetaPropertyBuilder &); private: int doCreateProperty(const char *); -- cgit v0.12 From 77d0d5706c157e31b842d9eab90565e05ae21ca8 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 10 Dec 2009 07:58:41 +1000 Subject: Remove debug --- src/declarative/util/qmlopenmetaobject.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/declarative/util/qmlopenmetaobject.cpp b/src/declarative/util/qmlopenmetaobject.cpp index 30457f9..473d9d9 100644 --- a/src/declarative/util/qmlopenmetaobject.cpp +++ b/src/declarative/util/qmlopenmetaobject.cpp @@ -243,7 +243,6 @@ int QmlOpenMetaObject::createProperty(const char *name, const char *) int QmlOpenMetaObject::doCreateProperty(const char *name) { - qDebug() << "doCreateProperty()" << name; int id = d->type->d->mob.propertyCount(); d->type->d->mob.addSignal("__" + QByteArray::number(id) + "()"); QMetaPropertyBuilder build = d->type->d->mob.addProperty(name, "QVariant", id); -- cgit v0.12 From 62a9598e0e3989b54211e540d83e4dcf1df9609c Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 10 Dec 2009 08:10:17 +1000 Subject: Fix view positioning when moving first visible item. --- src/declarative/graphicsitems/qmlgraphicslistview.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/declarative/graphicsitems/qmlgraphicslistview.cpp b/src/declarative/graphicsitems/qmlgraphicslistview.cpp index a4fa07a..a49794c 100644 --- a/src/declarative/graphicsitems/qmlgraphicslistview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicslistview.cpp @@ -2172,7 +2172,6 @@ void QmlGraphicsListView::trackedPositionChanged() } else { if (trackedPos < viewPos && d->currentItem->position() < viewPos) { d->setPosition(d->currentItem->position() < trackedPos ? trackedPos : d->currentItem->position()); - d->fixupPosition(); } else if (d->trackedItem->endPosition() > viewPos + d->size() && d->currentItem->endPosition() > viewPos + d->size()) { qreal pos; @@ -2186,7 +2185,6 @@ void QmlGraphicsListView::trackedPositionChanged() pos = d->currentItem->position(); } d->setPosition(pos); - d->fixupPosition(); } } } @@ -2493,7 +2491,7 @@ void QmlGraphicsListView::itemsMoved(int from, int to, int count) FxListItem *movedItem = moved.take(item->index); if (!movedItem) movedItem = d->createItem(item->index); - if (item->index < firstVisible->index) + if (item->index <= firstVisible->index) moveBy -= movedItem->size(); it = d->visibleItems.insert(it, movedItem); ++it; -- cgit v0.12 From 6ad82eebb3ba5205340f1bd5f8321306d14597f8 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 10 Dec 2009 09:15:34 +1000 Subject: Document Flickable properties. Task-number: QTBUG-6650 --- .../graphicsitems/qmlgraphicsflickable.cpp | 49 +++++++++++++++------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/src/declarative/graphicsitems/qmlgraphicsflickable.cpp b/src/declarative/graphicsitems/qmlgraphicsflickable.cpp index 89c7657..eebc231 100644 --- a/src/declarative/graphicsitems/qmlgraphicsflickable.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsflickable.cpp @@ -371,25 +371,34 @@ QML_DEFINE_TYPE(Qt,4,6,Flickable,QmlGraphicsFlickable) */ /*! - \internal - \class QmlGraphicsFlickable - \brief The QmlGraphicsFlickable class provides a view that can be "flicked". + \qmlsignal Flickable::onMovementStarted() - \ingroup group_widgets + This handler is called when the view begins moving due to user + interaction. +*/ - QmlGraphicsFlickable allows its children to be dragged and flicked. +/*! + \qmlsignal Flickable::onMovementEnded() -\code -Flickable { - width: 320; height: 480; viewportWidth: image.width; viewportHeight: image.height - Image { id: image; source: "bigimage.png" } -} -\endcode + This handler is called when the view stops moving due to user + interaction. If a flick was generated, this handler will + be triggered once the flick stops. If a flick was not + generated, the handler will be triggered when the + user stops dragging - i.e. a mouse or touch release. +*/ - Note that QmlGraphicsFlickable does not automatically clip its contents. If - it is not full-screen it is likely that QmlGraphicsItem::clip should be set - to true. +/*! + \qmlsignal Flickable::onFlickStarted() + + This handler is called when the view is flicked. A flick + starts from the point that the mouse or touch is released, + while still in motion. +*/ +/*! + \qmlsignal Flickable::onFlickEnded() + + This handler is called when the view stops moving due to a flick. */ /*! @@ -1195,6 +1204,12 @@ void QmlGraphicsFlickable::setFlickDeceleration(qreal deceleration) d->deceleration = deceleration; } +/*! + \qmlproperty bool Flickable::flicking + + This property holds whether the view is currently moving due to + the user flicking the view. +*/ bool QmlGraphicsFlickable::isFlicking() const { Q_D(const QmlGraphicsFlickable); @@ -1242,6 +1257,12 @@ void QmlGraphicsFlickable::setReportedVelocitySmoothing(qreal reportedVelocitySm emit reportedVelocitySmoothingChanged(reportedVelocitySmoothing); } +/*! + \qmlproperty bool Flickable::moving + + This property holds whether the view is currently moving due to + the user either dragging or flicking the view. +*/ bool QmlGraphicsFlickable::isMoving() const { Q_D(const QmlGraphicsFlickable); -- cgit v0.12 From 97bae0afbcd754f55b2aa8e37c704437eeec8a22 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 10 Dec 2009 09:30:04 +1000 Subject: Fix doc Qt.MiddleButton -> Qt.MidButton Task-number: QTBUG-6617 --- src/declarative/graphicsitems/qmlgraphicsmouseregion.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/graphicsitems/qmlgraphicsmouseregion.cpp b/src/declarative/graphicsitems/qmlgraphicsmouseregion.cpp index 159fc29..f788077 100644 --- a/src/declarative/graphicsitems/qmlgraphicsmouseregion.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsmouseregion.cpp @@ -574,7 +574,7 @@ void QmlGraphicsMouseRegion::setHovered(bool h) \list \o Qt.LeftButton \o Qt.RightButton - \o Qt.MiddleButton + \o Qt.MidButton \endlist To accept more than one button the flags can be combined with the -- cgit v0.12 From 4c5a4f4d520d05de6eceb58887c4b065fe103275 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 10 Dec 2009 10:24:07 +1000 Subject: Fix models using Package. --- src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp index 7530c43..c6f790c 100644 --- a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp @@ -556,7 +556,7 @@ QVariant QmlGraphicsVisualDataModelPartsMetaObject::initialValue(int id) { QmlGraphicsVisualDataModel *m = new QmlGraphicsVisualDataModel; m->setParent(object()); - m->setPart(QString::fromUtf8(property(id).name())); + m->setPart(QString::fromUtf8(name(id))); m->setModel(QVariant::fromValue(static_cast(object())->model)); QVariant var = QVariant::fromValue((QObject *)m); @@ -649,7 +649,7 @@ void QmlGraphicsVisualDataModel::setModel(const QVariant &model) d->m_roles.clear(); d->m_roleNames.clear(); delete d->m_delegateDataType; - d->m_delegateDataType = new QmlOpenMetaObjectType(d->m_context->engine()); + d->m_delegateDataType = new QmlOpenMetaObjectType(d->m_context?d->m_context->engine():qmlEngine(this)); QObject *object = qvariant_cast(model); if (object && (d->m_listModelInterface = qobject_cast(object))) { -- cgit v0.12