diff options
author | Thiago Macieira <thiago.macieira@nokia.com> | 2010-02-23 12:02:52 (GMT) |
---|---|---|
committer | Thiago Macieira <thiago.macieira@nokia.com> | 2010-02-23 12:02:52 (GMT) |
commit | de4332a4728e739b37e9c7b04c021e150e096270 (patch) | |
tree | 619aae505826654f3d89492efa53f758214fea6f /src/declarative/util | |
parent | a419d587a666aaf55310b3a18e9f9e1993fef16e (diff) | |
parent | 3db40b0be40c946f547f238ed3f0af813892115e (diff) | |
download | Qt-de4332a4728e739b37e9c7b04c021e150e096270.zip Qt-de4332a4728e739b37e9c7b04c021e150e096270.tar.gz Qt-de4332a4728e739b37e9c7b04c021e150e096270.tar.bz2 |
Merge remote branch 'origin/master'
Conflicts:
doc/src/declarative/advtutorial1.qdoc
doc/src/declarative/tutorial2.qdoc
doc/src/declarative/tutorial3.qdoc
src/declarative/graphicsitems/qmlgraphicsmousearea.cpp
src/multimedia/playback/qmediaplayer.cpp
Diffstat (limited to 'src/declarative/util')
25 files changed, 286 insertions, 417 deletions
diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index 6c9d13f..1be95df 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -177,7 +177,7 @@ QmlAbstractAnimation::QmlAbstractAnimation(QmlAbstractAnimationPrivate &dd, QObj The \c running property can be set to declaratively control whether or not an animation is running. The following example will animate a rectangle - whenever the \l MouseRegion is pressed. + whenever the \l MouseArea is pressed. \code Rectangle { @@ -186,7 +186,7 @@ QmlAbstractAnimation::QmlAbstractAnimation(QmlAbstractAnimationPrivate &dd, QObj running: myMouse.pressed from: 0; to: 100 } - MouseRegion { id: myMouse } + MouseArea { id: myMouse } } \endcode @@ -942,10 +942,10 @@ void QmlPropertyAction::setProperties(const QString &p) emit propertiesChanged(p); } -QList<QObject *> *QmlPropertyAction::targets() +QmlListProperty<QObject> QmlPropertyAction::targets() { Q_D(QmlPropertyAction); - return &d->targets; + return QmlListProperty<QObject>(this, d->targets); } /*! @@ -953,10 +953,10 @@ QList<QObject *> *QmlPropertyAction::targets() This property holds the objects not to be affected by this animation. \sa targets */ -QList<QObject *> *QmlPropertyAction::exclude() +QmlListProperty<QObject> QmlPropertyAction::exclude() { Q_D(QmlPropertyAction); - return &d->exclude; + return QmlListProperty<QObject>(this, d->exclude); } /*! @@ -1585,14 +1585,36 @@ QmlAnimationGroup::QmlAnimationGroup(QObject *parent) { } +void QmlAnimationGroupPrivate::append_animation(QmlListProperty<QmlAbstractAnimation> *list, QmlAbstractAnimation *a) +{ + QmlAnimationGroup *q = qobject_cast<QmlAnimationGroup *>(list->object); + if (q) { + q->d_func()->animations.append(a); + a->setGroup(q); + } +} + +void QmlAnimationGroupPrivate::clear_animation(QmlListProperty<QmlAbstractAnimation> *list) +{ + QmlAnimationGroup *q = qobject_cast<QmlAnimationGroup *>(list->object); + if (q) { + for (int i = 0; i < q->d_func()->animations.count(); ++i) + q->d_func()->animations.at(i)->setGroup(0); + q->d_func()->animations.clear(); + } +} + QmlAnimationGroup::~QmlAnimationGroup() { } -QmlList<QmlAbstractAnimation *> *QmlAnimationGroup::animations() +QmlListProperty<QmlAbstractAnimation> QmlAnimationGroup::animations() { Q_D(QmlAnimationGroup); - return &d->animations; + QmlListProperty<QmlAbstractAnimation> list(this, d->animations); + list.append = &QmlAnimationGroupPrivate::append_animation; + list.clear = &QmlAnimationGroupPrivate::clear_animation; + return list; } /*! @@ -1805,7 +1827,7 @@ void QmlPropertyAnimationPrivate::convertVariant(QVariant &variant, int type) Fade out \c theObject when clicked: \qml - MouseRegion { + MouseArea { anchors.fill: theObject onClicked: PropertyAnimation { target: theObject; property: "opacity"; to: 0 } } @@ -2225,7 +2247,7 @@ void QmlPropertyAnimation::setProperties(const QString &prop) color: Qt.rgba(0,0,1) //need to explicitly specify target and property NumberAnimation { id: theAnim; target: theRect; property: "x" to: 500 } - MouseRegion { + MouseArea { anchors.fill: parent onClicked: theAnim.start() } @@ -2237,10 +2259,10 @@ void QmlPropertyAnimation::setProperties(const QString &prop) \sa exclude */ -QList<QObject *> *QmlPropertyAnimation::targets() +QmlListProperty<QObject> QmlPropertyAnimation::targets() { Q_D(QmlPropertyAnimation); - return &d->targets; + return QmlListProperty<QObject>(this, d->targets); } /*! @@ -2248,10 +2270,10 @@ QList<QObject *> *QmlPropertyAnimation::targets() This property holds the items not to be affected by this animation. \sa targets */ -QList<QObject *> *QmlPropertyAnimation::exclude() +QmlListProperty<QObject> QmlPropertyAnimation::exclude() { Q_D(QmlPropertyAnimation); - return &d->exclude; + return QmlListProperty<QObject>(this, d->exclude); } QAbstractAnimation *QmlPropertyAnimation::qtAnimation() diff --git a/src/declarative/util/qmlanimation_p.h b/src/declarative/util/qmlanimation_p.h index 50eb577..623ad8d 100644 --- a/src/declarative/util/qmlanimation_p.h +++ b/src/declarative/util/qmlanimation_p.h @@ -190,8 +190,8 @@ class QmlPropertyAction : public QmlAbstractAnimation Q_PROPERTY(QObject *target READ target WRITE setTarget NOTIFY targetChanged) Q_PROPERTY(QString property READ property WRITE setProperty NOTIFY targetChanged) Q_PROPERTY(QString properties READ properties WRITE setProperties NOTIFY propertiesChanged) - Q_PROPERTY(QList<QObject *>* targets READ targets) - Q_PROPERTY(QList<QObject *>* exclude READ exclude) + Q_PROPERTY(QmlListProperty<QObject> targets READ targets) + Q_PROPERTY(QmlListProperty<QObject> exclude READ exclude) Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged) public: @@ -207,8 +207,8 @@ public: QString properties() const; void setProperties(const QString &); - QList<QObject *> *targets(); - QList<QObject *> *exclude(); + QmlListProperty<QObject> targets(); + QmlListProperty<QObject> exclude(); QVariant value() const; void setValue(const QVariant &); @@ -265,8 +265,8 @@ class Q_AUTOTEST_EXPORT QmlPropertyAnimation : public QmlAbstractAnimation Q_PROPERTY(QObject *target READ target WRITE setTarget NOTIFY targetChanged) Q_PROPERTY(QString property READ property WRITE setProperty NOTIFY targetChanged) Q_PROPERTY(QString properties READ properties WRITE setProperties NOTIFY propertiesChanged) - Q_PROPERTY(QList<QObject *>* targets READ targets) - Q_PROPERTY(QList<QObject *>* exclude READ exclude) + Q_PROPERTY(QmlListProperty<QObject> targets READ targets) + Q_PROPERTY(QmlListProperty<QObject> exclude READ exclude) public: QmlPropertyAnimation(QObject *parent=0); @@ -293,8 +293,8 @@ public: QString properties() const; void setProperties(const QString &); - QList<QObject *> *targets(); - QList<QObject *> *exclude(); + QmlListProperty<QObject> targets(); + QmlListProperty<QObject> exclude(); protected: QmlPropertyAnimation(QmlPropertyAnimationPrivate &dd, QObject *parent); @@ -404,13 +404,13 @@ class QmlAnimationGroup : public QmlAbstractAnimation Q_DECLARE_PRIVATE(QmlAnimationGroup) Q_CLASSINFO("DefaultProperty", "animations") - Q_PROPERTY(QmlList<QmlAbstractAnimation *> *animations READ animations) + Q_PROPERTY(QmlListProperty<QmlAbstractAnimation> animations READ animations) public: QmlAnimationGroup(QObject *parent); virtual ~QmlAnimationGroup(); - QmlList<QmlAbstractAnimation *>* animations(); + QmlListProperty<QmlAbstractAnimation> animations(); friend class QmlAbstractAnimation; }; diff --git a/src/declarative/util/qmlanimation_p_p.h b/src/declarative/util/qmlanimation_p_p.h index b2ce297..056ce82 100644 --- a/src/declarative/util/qmlanimation_p_p.h +++ b/src/declarative/util/qmlanimation_p_p.h @@ -304,37 +304,13 @@ class QmlAnimationGroupPrivate : public QmlAbstractAnimationPrivate Q_DECLARE_PUBLIC(QmlAnimationGroup) public: QmlAnimationGroupPrivate() - : QmlAbstractAnimationPrivate(), animations(this), ag(0) {} + : QmlAbstractAnimationPrivate(), ag(0) {} - struct AnimationList : public QmlConcreteList<QmlAbstractAnimation *> - { - AnimationList(QmlAnimationGroupPrivate *p) - : anim(p) {} - virtual void append(QmlAbstractAnimation *a) { - QmlConcreteList<QmlAbstractAnimation *>::append(a); - a->setGroup(anim->q_func()); - } - virtual void clear() - { - for (int i = 0; i < count(); ++i) - at(i)->setGroup(0); - QmlConcreteList<QmlAbstractAnimation *>::clear(); - } - virtual void removeAt(int i) - { - at(i)->setGroup(0); - QmlConcreteList<QmlAbstractAnimation *>::removeAt(i); - } - virtual void insert(int i, QmlAbstractAnimation *a) - { - QmlConcreteList<QmlAbstractAnimation *>::insert(i, a); - a->setGroup(anim->q_func()); - } - - QmlAnimationGroupPrivate *anim; - }; - - AnimationList animations; + static void append_animation(QmlListProperty<QmlAbstractAnimation> *list, QmlAbstractAnimation *role); + static void clear_animation(QmlListProperty<QmlAbstractAnimation> *list); + static void removeAt_animation(QmlListProperty<QmlAbstractAnimation> *list, int i); + static void insert_animation(QmlListProperty<QmlAbstractAnimation> *list, int i, QmlAbstractAnimation *role); + QList<QmlAbstractAnimation *> animations; QAnimationGroup *ag; }; diff --git a/src/declarative/util/qmlconnection.cpp b/src/declarative/util/qmlconnection.cpp index c03d618..204377c 100644 --- a/src/declarative/util/qmlconnection.cpp +++ b/src/declarative/util/qmlconnection.cpp @@ -73,7 +73,7 @@ public: "on<Signal>" handler that reacts when a signal is received, like this: \qml - MouseRegion { + MouseArea { onClicked: { foo(x+123,y+456) } } \endqml @@ -95,7 +95,7 @@ public: like this: \qml - MouseRegion { + MouseArea { Connection { signal: "clicked(x,y)" script: { foo(x+123,y+456) } @@ -107,7 +107,7 @@ public: the sender of the signal, and the script is the default attribute: \qml - MouseRegion { + MouseArea { id: mr } ... diff --git a/src/declarative/util/qmleasefollow.cpp b/src/declarative/util/qmleasefollow.cpp index efa6faf..deb474a 100644 --- a/src/declarative/util/qmleasefollow.cpp +++ b/src/declarative/util/qmleasefollow.cpp @@ -300,6 +300,13 @@ Rectangle { } \endcode + The default velocity of EaseFollow is 200 units/second. Note that if the range of the + value being animated is small, then the velocity will need to be adjusted + appropriately. For example, the opacity of an item ranges from 0 - 1.0. + To enable a smooth animation in this range the velocity will need to be + set to a value such as 0.5 units/second. Animating from 0 to 1.0 with a velocity + of 0.5 will take 2000 ms to complete. + \sa SpringFollow */ @@ -415,7 +422,7 @@ void QmlEaseFollow::setSourceValue(qreal s) This property holds the animation duration used when tracking the source. - Setting this to -1 disables the duration value. + Setting this to -1 (the default) disables the duration value. */ qreal QmlEaseFollow::duration() const { @@ -449,6 +456,8 @@ qreal QmlEaseFollow::velocity() const This property holds the average velocity allowed when tracking the source. + The default velocity of EaseFollow is 200 units/second. + Setting this to -1 disables the velocity value. */ void QmlEaseFollow::setVelocity(qreal v) diff --git a/src/declarative/util/qmllistaccessor.cpp b/src/declarative/util/qmllistaccessor.cpp index c1b9247..abdb626 100644 --- a/src/declarative/util/qmllistaccessor.cpp +++ b/src/declarative/util/qmllistaccessor.cpp @@ -84,11 +84,8 @@ void QmlListAccessor::setList(const QVariant &v, QmlEngine *engine) QObject *data = enginePrivate?enginePrivate->toQObject(v):QmlMetaType::toQObject(v); d = QVariant::fromValue(data); m_type = Instance; - } else if ((!enginePrivate && QmlMetaType::isQmlList(d.userType())) || - (enginePrivate && enginePrivate->isQmlList(d.userType()))) { - m_type = QmlList; - } else if (QmlMetaType::isList(d.userType())) { - m_type = QListPtr; + } else if (d.userType() == qMetaTypeId<QmlListReference>()) { + m_type = ListProperty; } else { m_type = Instance; } @@ -101,16 +98,8 @@ int QmlListAccessor::count() const return qvariant_cast<QStringList>(d).count(); case VariantList: return qvariant_cast<QVariantList>(d).count(); - case QmlList: - { - QmlPrivate::ListInterface *li = *(QmlPrivate::ListInterface **)d.constData(); - return li->count(); - } - case QListPtr: - { - QList<void *> *li = *(QList<void *> **)d.constData(); - return li->count(); - } + case ListProperty: + return ((QmlListReference *)d.constData())->count(); case Instance: return 1; case Integer: @@ -129,19 +118,8 @@ QVariant QmlListAccessor::at(int idx) const return QVariant::fromValue(qvariant_cast<QStringList>(d).at(idx)); case VariantList: return qvariant_cast<QVariantList>(d).at(idx); - case QmlList: - { - QmlPrivate::ListInterface *li = *(QmlPrivate::ListInterface **)d.constData(); - void *ptr[1]; - li->at(idx, ptr); - return QVariant::fromValue((QObject*)ptr[0]); - } - case QListPtr: - { - QList<void *> *li = *(QList<void *> **)d.constData(); - void *ptr = li->at(idx); - return QVariant::fromValue((QObject*)ptr); - } + case ListProperty: + return QVariant::fromValue(((QmlListReference *)d.constData())->at(idx)); case Instance: return d; case Integer: @@ -152,106 +130,6 @@ QVariant QmlListAccessor::at(int idx) const } } -bool QmlListAccessor::append(const QVariant &value) -{ - switch(m_type) { - case QmlList: - { - QmlPrivate::ListInterface *li = *(QmlPrivate::ListInterface **)d.constData(); - li->append(const_cast<void *>(value.constData())); //XXX Typesafety - return true; - } - case QListPtr: - { - QList<void *> *li = *(QList<void *> **)d.constData(); - li->append(*reinterpret_cast<void **>(const_cast<void *>(value.constData()))); //XXX Typesafety - return true; - } - case StringList: - case VariantList: - case Invalid: - case Instance: - case Integer: - default: - return false; - } -} - -bool QmlListAccessor::insert(int index, const QVariant &value) -{ - switch(m_type) { - case QmlList: - { - QmlPrivate::ListInterface *li = *(QmlPrivate::ListInterface **)d.constData(); - li->insert(index, const_cast<void *>(value.constData())); //XXX Typesafety - return true; - } - case QListPtr: - { - QList<void *> *li = *(QList<void *>**)d.constData(); - li->insert(index, *reinterpret_cast<void **>(const_cast<void *>(value.constData()))); //XXX Typesafety - return true; - } - case StringList: - case VariantList: - case Invalid: - case Instance: - case Integer: - default: - return false; - } -} - -bool QmlListAccessor::removeAt(int index) -{ - switch(m_type) { - case QmlList: - { - QmlPrivate::ListInterface *li = *(QmlPrivate::ListInterface **)d.constData(); - li->removeAt(index); - return true; - } - case QListPtr: - { - QList<void *> *li = *(QList<void *>**)d.constData(); - li->removeAt(index); - return true; - } - case StringList: - case VariantList: - case Invalid: - case Instance: - case Integer: - default: - return false; - } -} - -bool QmlListAccessor::clear() -{ - switch(m_type) { - case QmlList: - { - QmlPrivate::ListInterface *li = *(QmlPrivate::ListInterface **)d.constData(); - li->clear(); - return true; - } - case QListPtr: - { - QList<void *> *li = *(QList<void *>**)d.constData(); - li->clear(); - return true; - } - case StringList: - case VariantList: - case Invalid: - case Instance: - case Integer: - default: - return false; - } -} - bool QmlListAccessor::isValid() const { return m_type != Invalid; diff --git a/src/declarative/util/qmllistaccessor_p.h b/src/declarative/util/qmllistaccessor_p.h index 8a0b06c..611eebb 100644 --- a/src/declarative/util/qmllistaccessor_p.h +++ b/src/declarative/util/qmllistaccessor_p.h @@ -65,12 +65,7 @@ public: int count() const; QVariant at(int) const; - bool append(const QVariant &); - bool insert(int, const QVariant &); - bool removeAt(int); - bool clear(); - - enum Type { Invalid, StringList, VariantList, QmlList, QListPtr, Instance, Integer }; + enum Type { Invalid, StringList, VariantList, ListProperty, Instance, Integer }; Type type() const { return m_type; } private: diff --git a/src/declarative/util/qmllistmodel.cpp b/src/declarative/util/qmllistmodel.cpp index af41dfd..8fda3ae 100644 --- a/src/declarative/util/qmllistmodel.cpp +++ b/src/declarative/util/qmllistmodel.cpp @@ -188,7 +188,7 @@ static void dump(ModelNode *node, int ind); Text { text: '$'+cost; anchors.right: parent.right } // Double the price when clicked. - MouseRegion { + MouseArea { anchors.fill: parent onClicked: fruitModel.set(index, "cost", cost*2) } diff --git a/src/declarative/util/qmlpackage.cpp b/src/declarative/util/qmlpackage.cpp index 115f2fd..82f776f 100644 --- a/src/declarative/util/qmlpackage.cpp +++ b/src/declarative/util/qmlpackage.cpp @@ -51,28 +51,33 @@ class QmlPackagePrivate : public QObjectPrivate public: QmlPackagePrivate() {} - class DataList; struct DataGuard : public QmlGuard<QObject> { - DataGuard(QObject *obj, DataList *l) : list(l) { (QmlGuard<QObject>&)*this = obj; } - DataList *list; + DataGuard(QObject *obj, QList<DataGuard> *l) : list(l) { (QmlGuard<QObject>&)*this = obj; } + QList<DataGuard> *list; void objectDestroyed(QObject *) { // we assume priv will always be destroyed after objectDestroyed calls list->removeOne(*this); } }; - class DataList : public QList<DataGuard>, public QmlList<QObject*> - { - public: - virtual void append(QObject* v) { QList<DataGuard>::append(DataGuard(v, this)); } - virtual void insert(int i, QObject* v) { QList<DataGuard>::insert(i, DataGuard(v, this)); } - virtual void clear() { QList<DataGuard>::clear(); } - virtual QObject* at(int i) const { return QList<DataGuard>::at(i); } - virtual void removeAt(int i) { QList<DataGuard>::removeAt(i); } - virtual int count() const { return QList<DataGuard>::count(); } - }; - DataList dataList; + QList<DataGuard> dataList; + static void data_append(QmlListProperty<QObject> *prop, QObject *o) { + QList<DataGuard> *list = static_cast<QList<DataGuard> *>(prop->data); + list->append(DataGuard(o, list)); + } + static void data_clear(QmlListProperty<QObject> *prop) { + QList<DataGuard> *list = static_cast<QList<DataGuard> *>(prop->data); + list->clear(); + } + static QObject *data_at(QmlListProperty<QObject> *prop, int index) { + QList<DataGuard> *list = static_cast<QList<DataGuard> *>(prop->data); + return list->at(index); + } + static int data_count(QmlListProperty<QObject> *prop) { + QList<DataGuard> *list = static_cast<QList<DataGuard> *>(prop->data); + return list->count(); + } }; class QmlPackageAttached : public QObject @@ -128,10 +133,13 @@ QmlPackage::~QmlPackage() } } -QmlList<QObject *> *QmlPackage::data() +QmlListProperty<QObject> QmlPackage::data() { Q_D(QmlPackage); - return &d->dataList; + return QmlListProperty<QObject>(this, &d->dataList, QmlPackagePrivate::data_append, + QmlPackagePrivate::data_count, + QmlPackagePrivate::data_at, + QmlPackagePrivate::data_clear); } bool QmlPackage::hasPart(const QString &name) diff --git a/src/declarative/util/qmlpackage_p.h b/src/declarative/util/qmlpackage_p.h index 2538bb9..29b6bbe 100644 --- a/src/declarative/util/qmlpackage_p.h +++ b/src/declarative/util/qmlpackage_p.h @@ -64,13 +64,13 @@ class QmlPackage : public QObject Q_DECLARE_PRIVATE(QmlPackage) Q_CLASSINFO("DefaultProperty", "data") - Q_PROPERTY(QmlList<QObject *> *data READ data SCRIPTABLE false) + Q_PROPERTY(QmlListProperty<QObject> data READ data SCRIPTABLE false) public: QmlPackage(QObject *parent=0); virtual ~QmlPackage(); - QmlList<QObject *> *data(); + QmlListProperty<QObject> data(); QObject *part(const QString & = QString()); bool hasPart(const QString &); diff --git a/src/declarative/util/qmlpixmapcache.cpp b/src/declarative/util/qmlpixmapcache.cpp index 56903ce..2459651 100644 --- a/src/declarative/util/qmlpixmapcache.cpp +++ b/src/declarative/util/qmlpixmapcache.cpp @@ -179,11 +179,19 @@ bool QmlImageRequestHandler::event(QEvent *event) if (reader->cancelled.count()) { for (int i = 0; i < reader->cancelled.count(); ++i) { QmlPixmapReply *job = reader->cancelled.at(i); + // cancel any jobs already started QNetworkReply *reply = replies.key(job, 0); if (reply && reply->isRunning()) { replies.remove(reply); reply->close(); - job->release(true); + } + // remove from pending job list + for (int j = 0; j < reader->jobs.count(); ++j) { + if (reader->jobs.at(j) == job) { + reader->jobs.removeAt(j); + job->release(true); + break; + } } } reader->cancelled.clear(); @@ -195,8 +203,6 @@ bool QmlImageRequestHandler::event(QEvent *event) } QmlPixmapReply *runningJob = reader->jobs.takeLast(); - runningJob->addRef(); - runningJob->setLoading(); QUrl url = runningJob->url(); reader->mutex.unlock(); @@ -292,6 +298,8 @@ QmlPixmapReply *QmlImageReader::getImage(const QUrl &url) { mutex.lock(); QmlPixmapReply *reply = new QmlPixmapReply(this, url); + reply->addRef(); + reply->setLoading(); jobs.append(reply); if (jobs.count() == 1 && handler) QCoreApplication::postEvent(handler, new QEvent(QEvent::User)); @@ -303,21 +311,10 @@ void QmlImageReader::cancel(QmlPixmapReply *reply) { mutex.lock(); if (reply->isLoading()) { - // Already requested. Add to cancel list to be cancelled in reader thread. + // Add to cancel list to be cancelled in reader thread. cancelled.append(reply); if (cancelled.count() == 1 && handler) QCoreApplication::postEvent(handler, new QEvent(QEvent::User)); - } else { - // Not yet processed - just remove from waiting list - QList<QmlPixmapReply*>::iterator it = jobs.begin(); - while (it != jobs.end()) { - QmlPixmapReply *job = *it; - if (job == reply) { - jobs.erase(it); - break; - } - ++it; - } } mutex.unlock(); } @@ -482,8 +479,6 @@ bool QmlPixmapReply::release(bool defer) --d->refCount; if (d->refCount == 0) { qmlActivePixmapReplies()->remove(d->url); - if (d->status == Loading && !d->loading) - d->reader->cancel(this); if (defer) deleteLater(); else diff --git a/src/declarative/util/qmlpropertychanges.cpp b/src/declarative/util/qmlpropertychanges.cpp index b26469e..fba22f9 100644 --- a/src/declarative/util/qmlpropertychanges.cpp +++ b/src/declarative/util/qmlpropertychanges.cpp @@ -84,7 +84,7 @@ QT_BEGIN_NAMESPACE } } - MouseRegion { anchors.fill: parent; onClicked: myText.state = 'myState' } + MouseArea { anchors.fill: parent; onClicked: myText.state = 'myState' } } \endqml @@ -92,7 +92,7 @@ QT_BEGIN_NAMESPACE \qml PropertyChanges { - target: myMouseRegion + target: myMouseArea onClicked: doSomethingDifferent() } \endqml diff --git a/src/declarative/util/qmlstate.cpp b/src/declarative/util/qmlstate.cpp index d550b6f..c743e0b 100644 --- a/src/declarative/util/qmlstate.cpp +++ b/src/declarative/util/qmlstate.cpp @@ -243,16 +243,30 @@ void QmlState::setExtends(const QString &extends) extends another state, then the changes are applied against the state being extended. */ -QmlList<QmlStateOperation *> *QmlState::changes() +QmlListProperty<QmlStateOperation> QmlState::changes() { Q_D(QmlState); - return &d->operations; + return QmlListProperty<QmlStateOperation>(this, &d->operations, QmlStatePrivate::operations_append, + QmlStatePrivate::operations_count, QmlStatePrivate::operations_at, + QmlStatePrivate::operations_clear); +} + +int QmlState::operationCount() const +{ + Q_D(const QmlState); + return d->operations.count(); +} + +QmlStateOperation *QmlState::operationAt(int index) const +{ + Q_D(const QmlState); + return d->operations.at(index); } QmlState &QmlState::operator<<(QmlStateOperation *op) { Q_D(QmlState); - d->operations.append(op); + d->operations.append(QmlStatePrivate::OperationGuard(op, &d->operations)); return *this; } diff --git a/src/declarative/util/qmlstate_p.h b/src/declarative/util/qmlstate_p.h index 785a175..2c92387 100644 --- a/src/declarative/util/qmlstate_p.h +++ b/src/declarative/util/qmlstate_p.h @@ -131,7 +131,7 @@ class Q_DECLARATIVE_EXPORT QmlState : public QObject Q_PROPERTY(QString name READ name WRITE setName) Q_PROPERTY(QmlBinding *when READ when WRITE setWhen) Q_PROPERTY(QString extend READ extends WRITE setExtends) - Q_PROPERTY(QmlList<QmlStateOperation *>* changes READ changes) + Q_PROPERTY(QmlListProperty<QmlStateOperation> changes READ changes) Q_CLASSINFO("DefaultProperty", "changes") Q_CLASSINFO("DeferredPropertyNames", "changes") @@ -151,7 +151,10 @@ public: QString extends() const; void setExtends(const QString &); - QmlList<QmlStateOperation *> *changes(); + QmlListProperty<QmlStateOperation> changes(); + int operationCount() const; + QmlStateOperation *operationAt(int) const; + QmlState &operator<<(QmlStateOperation *); void apply(QmlStateGroup *, QmlTransition *, QmlState *revert); diff --git a/src/declarative/util/qmlstate_p_p.h b/src/declarative/util/qmlstate_p_p.h index c389846..d138e4e 100644 --- a/src/declarative/util/qmlstate_p_p.h +++ b/src/declarative/util/qmlstate_p_p.h @@ -107,28 +107,33 @@ public: QString name; QmlBinding *when; - class OperationList; struct OperationGuard : public QmlGuard<QmlStateOperation> { - OperationGuard(QObject *obj, OperationList *l) : list(l) { (QmlGuard<QObject>&)*this = obj; } - OperationList *list; + OperationGuard(QObject *obj, QList<OperationGuard> *l) : list(l) { (QmlGuard<QObject>&)*this = obj; } + QList<OperationGuard> *list; void objectDestroyed(QmlStateOperation *) { // we assume priv will always be destroyed after objectDestroyed calls list->removeOne(*this); } }; + QList<OperationGuard> operations; - class OperationList : public QList<OperationGuard>, public QmlList<QmlStateOperation*> - { - public: - virtual void append(QmlStateOperation* v) { QList<OperationGuard>::append(OperationGuard(v, this)); } - virtual void insert(int i, QmlStateOperation* v) { QList<OperationGuard>::insert(i, OperationGuard(v, this)); } - virtual void clear() { QList<OperationGuard>::clear(); } - virtual QmlStateOperation* at(int i) const { return QList<OperationGuard>::at(i); } - virtual void removeAt(int i) { QList<OperationGuard>::removeAt(i); } - virtual int count() const { return QList<OperationGuard>::count(); } - }; - OperationList operations; + static void operations_append(QmlListProperty<QmlStateOperation> *prop, QmlStateOperation *op) { + QList<OperationGuard> *list = static_cast<QList<OperationGuard> *>(prop->data); + list->append(OperationGuard(op, list)); + } + static void operations_clear(QmlListProperty<QmlStateOperation> *prop) { + QList<OperationGuard> *list = static_cast<QList<OperationGuard> *>(prop->data); + list->clear(); + } + static int operations_count(QmlListProperty<QmlStateOperation> *prop) { + QList<OperationGuard> *list = static_cast<QList<OperationGuard> *>(prop->data); + return list->count(); + } + static QmlStateOperation *operations_at(QmlListProperty<QmlStateOperation> *prop, int index) { + QList<OperationGuard> *list = static_cast<QList<OperationGuard> *>(prop->data); + return list->at(index); + } QmlTransitionManager transitionManager; diff --git a/src/declarative/util/qmlstategroup.cpp b/src/declarative/util/qmlstategroup.cpp index d289e17..4ad77c8 100644 --- a/src/declarative/util/qmlstategroup.cpp +++ b/src/declarative/util/qmlstategroup.cpp @@ -60,26 +60,19 @@ class QmlStateGroupPrivate : public QObjectPrivate Q_DECLARE_PUBLIC(QmlStateGroup) public: QmlStateGroupPrivate(QmlStateGroup *p) - : nullState(0), states(p), componentComplete(true), + : nullState(0), componentComplete(true), ignoreTrans(false), applyingState(false) {} QString currentState; QmlState *nullState; - struct StateList : public QmlConcreteList<QmlState *> - { - StateList(QmlStateGroup *g) - :group(g) {} - void append(QmlState *s) { - QmlConcreteList<QmlState *>::append(s); - if (s) s->setStateGroup(group); - } - private: - QmlStateGroup *group; - }; - StateList states; + static void append_state(QmlListProperty<QmlState> *list, QmlState *state); + static int count_state(QmlListProperty<QmlState> *list); + static QmlState *at_state(QmlListProperty<QmlState> *list, int index); + + QList<QmlState *> states; + QList<QmlTransition *> transitions; - QmlConcreteList<QmlTransition *> transitions; bool componentComplete; bool ignoreTrans; bool applyingState; @@ -151,10 +144,34 @@ QList<QmlState *> QmlStateGroup::states() const \sa {qmlstate}{States} */ -QmlList<QmlState *>* QmlStateGroup::statesProperty() +QmlListProperty<QmlState> QmlStateGroup::statesProperty() { Q_D(QmlStateGroup); - return &(d->states); + return QmlListProperty<QmlState>(this, &d->states, &QmlStateGroupPrivate::append_state, + &QmlStateGroupPrivate::count_state, + &QmlStateGroupPrivate::at_state); +} + +void QmlStateGroupPrivate::append_state(QmlListProperty<QmlState> *list, QmlState *state) +{ + QmlStateGroup *_this = static_cast<QmlStateGroup *>(list->object); + if (state) { + _this->d_func()->states.append(state); + state->setStateGroup(_this); + } + +} + +int QmlStateGroupPrivate::count_state(QmlListProperty<QmlState> *list) +{ + QmlStateGroup *_this = static_cast<QmlStateGroup *>(list->object); + return _this->d_func()->states.count(); +} + +QmlState *QmlStateGroupPrivate::at_state(QmlListProperty<QmlState> *list, int index) +{ + QmlStateGroup *_this = static_cast<QmlStateGroup *>(list->object); + return _this->d_func()->states.at(index); } /*! @@ -173,10 +190,10 @@ QmlList<QmlState *>* QmlStateGroup::statesProperty() \sa {state-transitions}{Transitions} */ -QmlList<QmlTransition *>* QmlStateGroup::transitionsProperty() +QmlListProperty<QmlTransition> QmlStateGroup::transitionsProperty() { Q_D(QmlStateGroup); - return &(d->transitions); + return QmlListProperty<QmlTransition>(this, d->transitions); } /*! diff --git a/src/declarative/util/qmlstategroup_p.h b/src/declarative/util/qmlstategroup_p.h index 48b9c66..d39ca03 100644 --- a/src/declarative/util/qmlstategroup_p.h +++ b/src/declarative/util/qmlstategroup_p.h @@ -58,8 +58,8 @@ class Q_DECLARATIVE_EXPORT QmlStateGroup : public QObject, public QmlParserStatu Q_DECLARE_PRIVATE(QmlStateGroup) Q_PROPERTY(QString state READ state WRITE setState NOTIFY stateChanged) - Q_PROPERTY(QmlList<QmlState *>* states READ statesProperty DESIGNABLE false) - Q_PROPERTY(QmlList<QmlTransition *>* transitions READ transitionsProperty DESIGNABLE false) + Q_PROPERTY(QmlListProperty<QmlState> states READ statesProperty DESIGNABLE false) + Q_PROPERTY(QmlListProperty<QmlTransition> transitions READ transitionsProperty DESIGNABLE false) public: QmlStateGroup(QObject * = 0); @@ -68,10 +68,10 @@ public: QString state() const; void setState(const QString &); - QmlList<QmlState *>* statesProperty(); + QmlListProperty<QmlState> statesProperty(); QList<QmlState *> states() const; - QmlList<QmlTransition *>* transitionsProperty(); + QmlListProperty<QmlTransition> transitionsProperty(); QmlState *findState(const QString &name) const; diff --git a/src/declarative/util/qmltimeline.cpp b/src/declarative/util/qmltimeline.cpp index 58c87e8..5c5df40 100644 --- a/src/declarative/util/qmltimeline.cpp +++ b/src/declarative/util/qmltimeline.cpp @@ -55,12 +55,12 @@ QT_BEGIN_NAMESPACE struct Update { Update(QmlTimeLineValue *_g, qreal _v) : g(_g), v(_v) {} - Update(const QmlTimeLineEvent &_e) + Update(const QmlTimeLineCallback &_e) : g(0), v(0), e(_e) {} QmlTimeLineValue *g; qreal v; - QmlTimeLineEvent e; + QmlTimeLineCallback e; }; struct QmlTimeLinePrivate @@ -79,7 +79,7 @@ struct QmlTimeLinePrivate }; Op() {} Op(Type t, int l, qreal v, qreal v2, int o, - const QmlTimeLineEvent &ev = QmlTimeLineEvent(), const QEasingCurve &es = QEasingCurve()) + const QmlTimeLineCallback &ev = QmlTimeLineCallback(), const QEasingCurve &es = QEasingCurve()) : type(t), length(l), value(v), value2(v2), order(o), event(ev), easing(es) {} Op(const Op &o) @@ -98,7 +98,7 @@ struct QmlTimeLinePrivate qreal value2; int order; - QmlTimeLineEvent event; + QmlTimeLineCallback event; QEasingCurve easing; }; struct TimeLine @@ -244,7 +244,7 @@ qreal QmlTimeLinePrivate::value(const Op &op, int time, qreal base, bool *change } case Op::Execute: - op.event.execute(); + op.event.d0(op.event.d1); *changed = false; return -1; } @@ -364,10 +364,10 @@ void QmlTimeLine::pause(QmlTimeLineObject &obj, int time) /*! Execute the \a event. */ -void QmlTimeLine::execute(const QmlTimeLineEvent &event) +void QmlTimeLine::callback(const QmlTimeLineCallback &callback) { - QmlTimeLinePrivate::Op op(QmlTimeLinePrivate::Op::Execute, 0, 0, 0., d->order++, event); - d->add(*event.eventObject(), op); + QmlTimeLinePrivate::Op op(QmlTimeLinePrivate::Op::Execute, 0, 0, 0., d->order++, callback); + d->add(*callback.callbackObject(), op); } /*! @@ -466,7 +466,7 @@ void QmlTimeLine::move(QmlTimeLineValue &timeLineValue, qreal destination, int t void QmlTimeLine::move(QmlTimeLineValue &timeLineValue, qreal destination, const QEasingCurve &easing, int time) { if (time <= 0) return; - QmlTimeLinePrivate::Op op(QmlTimeLinePrivate::Op::Move, time, destination, 0.0f, d->order++, QmlTimeLineEvent(), easing); + QmlTimeLinePrivate::Op op(QmlTimeLinePrivate::Op::Move, time, destination, 0.0f, d->order++, QmlTimeLineCallback(), easing); d->add(timeLineValue, op); } @@ -488,7 +488,7 @@ void QmlTimeLine::moveBy(QmlTimeLineValue &timeLineValue, qreal change, int time void QmlTimeLine::moveBy(QmlTimeLineValue &timeLineValue, qreal change, const QEasingCurve &easing, int time) { if (time <= 0) return; - QmlTimeLinePrivate::Op op(QmlTimeLinePrivate::Op::MoveBy, time, change, 0.0f, d->order++, QmlTimeLineEvent(), easing); + QmlTimeLinePrivate::Op op(QmlTimeLinePrivate::Op::MoveBy, time, change, 0.0f, d->order++, QmlTimeLineCallback(), easing); d->add(timeLineValue, op); } @@ -805,10 +805,11 @@ int QmlTimeLinePrivate::advance(int t) updateQueue = &updates; for (int ii = 0; ii < updates.count(); ++ii) { const Update &v = updates.at(ii).second; - if (v.g) + if (v.g) { v.g->setValue(v.v); - else - v.e.execute(); + } else { + v.e.d0(v.e.d1); + } } updateQueue = 0; } while(t); @@ -854,7 +855,7 @@ void QmlTimeLine::remove(QmlTimeLineObject *v) if (d->updateQueue) { for (int ii = 0; ii < d->updateQueue->count(); ++ii) { if (d->updateQueue->at(ii).second.g == v || - d->updateQueue->at(ii).second.e.eventObject() == v) { + d->updateQueue->at(ii).second.e.callbackObject() == v) { d->updateQueue->removeAt(ii); --ii; } @@ -910,17 +911,22 @@ QmlTimeLineObject::~QmlTimeLineObject() } } -QmlTimeLineEvent::QmlTimeLineEvent() +QmlTimeLineCallback::QmlTimeLineCallback() : d0(0), d1(0), d2(0) { } -QmlTimeLineEvent::QmlTimeLineEvent(const QmlTimeLineEvent &o) +QmlTimeLineCallback::QmlTimeLineCallback(QmlTimeLineObject *b, Callback f, void *d) +: d0(f), d1(d), d2(b) +{ +} + +QmlTimeLineCallback::QmlTimeLineCallback(const QmlTimeLineCallback &o) : d0(o.d0), d1(o.d1), d2(o.d2) { } -QmlTimeLineEvent &QmlTimeLineEvent::operator=(const QmlTimeLineEvent &o) +QmlTimeLineCallback &QmlTimeLineCallback::operator=(const QmlTimeLineCallback &o) { d0 = o.d0; d1 = o.d1; @@ -928,12 +934,7 @@ QmlTimeLineEvent &QmlTimeLineEvent::operator=(const QmlTimeLineEvent &o) return *this; } -void QmlTimeLineEvent::execute() const -{ - d0(d1); -} - -QmlTimeLineObject *QmlTimeLineEvent::eventObject() const +QmlTimeLineObject *QmlTimeLineCallback::callbackObject() const { return d2; } diff --git a/src/declarative/util/qmltimeline_p_p.h b/src/declarative/util/qmltimeline_p_p.h index f271a3f..076355d 100644 --- a/src/declarative/util/qmltimeline_p_p.h +++ b/src/declarative/util/qmltimeline_p_p.h @@ -60,10 +60,10 @@ QT_BEGIN_NAMESPACE class QEasingCurve; class QmlTimeLineValue; -class QmlTimeLineEvent; +class QmlTimeLineCallback; struct QmlTimeLinePrivate; class QmlTimeLineObject; -class Q_DECLARATIVE_EXPORT QmlTimeLine : public QAbstractAnimation +class QmlTimeLine : public QAbstractAnimation { Q_OBJECT public: @@ -75,7 +75,7 @@ public: void setSyncMode(SyncMode); void pause(QmlTimeLineObject &, int); - void execute(const QmlTimeLineEvent &); + void callback(const QmlTimeLineCallback &); void set(QmlTimeLineValue &, qreal); int accel(QmlTimeLineValue &, qreal velocity, qreal accel); @@ -117,7 +117,7 @@ private: QmlTimeLinePrivate *d; }; -class Q_DECLARATIVE_EXPORT QmlTimeLineObject +class QmlTimeLineObject { public: QmlTimeLineObject(); @@ -129,7 +129,7 @@ protected: QmlTimeLine *_t; }; -class Q_DECLARATIVE_EXPORT QmlTimeLineValue : public QmlTimeLineObject +class QmlTimeLineValue : public QmlTimeLineObject { public: QmlTimeLineValue(qreal v = 0.) : _v(v) {} @@ -147,36 +147,21 @@ private: qreal _v; }; -class Q_DECLARATIVE_EXPORT QmlTimeLineEvent +class QmlTimeLineCallback { public: - QmlTimeLineEvent(); - QmlTimeLineEvent(const QmlTimeLineEvent &o); + typedef void (*Callback)(void *); - template<class T, void (T::*method)()> - static QmlTimeLineEvent timeLineEvent(QmlTimeLineObject *b, T *c) - { - QmlTimeLineEvent rv; - rv.d0 = &callFunc<T, method>; - rv.d1 = (void *)c; - rv.d2 = b; - return rv; - } + QmlTimeLineCallback(); + QmlTimeLineCallback(QmlTimeLineObject *b, Callback, void * = 0); + QmlTimeLineCallback(const QmlTimeLineCallback &o); - QmlTimeLineEvent &operator=(const QmlTimeLineEvent &o); - void execute() const; - QmlTimeLineObject *eventObject() const; + QmlTimeLineCallback &operator=(const QmlTimeLineCallback &o); + QmlTimeLineObject *callbackObject() const; private: - typedef void (*CallFunc)(void *c); - - template <class T, void (T::*method)()> - static void callFunc(void *c) - { - T *cls = (T *)c; - (cls->*method)(); - } - CallFunc d0; + friend class QmlTimeLinePrivate; + Callback d0; void *d1; QmlTimeLineObject *d2; }; diff --git a/src/declarative/util/qmltransition.cpp b/src/declarative/util/qmltransition.cpp index 05b6f43..e2ce417 100644 --- a/src/declarative/util/qmltransition.cpp +++ b/src/declarative/util/qmltransition.cpp @@ -83,10 +83,10 @@ class QmlTransitionPrivate : public QObjectPrivate { Q_DECLARE_PUBLIC(QmlTransition) public: - QmlTransitionPrivate() : fromState(QLatin1String("*")), toState(QLatin1String("*")) - , reversed(false), reversible(false), endState(0) + QmlTransitionPrivate() + : fromState(QLatin1String("*")), toState(QLatin1String("*")), + reversed(false), reversible(false), endState(0) { - animations.parent = this; group.trans = this; } @@ -101,23 +101,15 @@ public: { endState->complete(); } - - class AnimationList : public QmlConcreteList<QmlAbstractAnimation *> - { - public: - AnimationList() : parent(0) {} - virtual void append(QmlAbstractAnimation *a); - virtual void clear() { QmlConcreteList<QmlAbstractAnimation *>::clear(); } //### - - QmlTransitionPrivate *parent; - }; - AnimationList animations; + static void append_animation(QmlListProperty<QmlAbstractAnimation> *list, QmlAbstractAnimation *a); + QList<QmlAbstractAnimation *> animations; }; -void QmlTransitionPrivate::AnimationList::append(QmlAbstractAnimation *a) +void QmlTransitionPrivate::append_animation(QmlListProperty<QmlAbstractAnimation> *list, QmlAbstractAnimation *a) { - QmlConcreteList<QmlAbstractAnimation *>::append(a); - parent->group.addAnimation(a->qtAnimation()); + QmlTransition *q = static_cast<QmlTransition *>(list->object); + q->d_func()->animations.append(a); + q->d_func()->group.addAnimation(a->qtAnimation()); a->setDisableUserControl(); } @@ -246,10 +238,10 @@ void QmlTransition::setToState(const QString &t) and assign that to animations the animations property. \default */ -QmlList<QmlAbstractAnimation *>* QmlTransition::animations() +QmlListProperty<QmlAbstractAnimation> QmlTransition::animations() { Q_D(QmlTransition); - return &d->animations; + return QmlListProperty<QmlAbstractAnimation>(this, &d->animations, QmlTransitionPrivate::append_animation); } QT_END_NAMESPACE diff --git a/src/declarative/util/qmltransition_p.h b/src/declarative/util/qmltransition_p.h index 5a989bc..ea02a33 100644 --- a/src/declarative/util/qmltransition_p.h +++ b/src/declarative/util/qmltransition_p.h @@ -65,7 +65,7 @@ class Q_DECLARATIVE_EXPORT QmlTransition : public QObject Q_PROPERTY(QString from READ fromState WRITE setFromState) Q_PROPERTY(QString to READ toState WRITE setToState) Q_PROPERTY(bool reversible READ reversible WRITE setReversible) - Q_PROPERTY(QmlList<QmlAbstractAnimation *>* animations READ animations) + Q_PROPERTY(QmlListProperty<QmlAbstractAnimation> animations READ animations) Q_CLASSINFO("DefaultProperty", "animations") Q_CLASSINFO("DeferredPropertyNames", "animations") @@ -82,7 +82,7 @@ public: bool reversible() const; void setReversible(bool); - QmlList<QmlAbstractAnimation *>* animations(); + QmlListProperty<QmlAbstractAnimation> animations(); void prepare(QmlStateOperation::ActionList &actions, QList<QmlMetaProperty> &after, diff --git a/src/declarative/util/qmlview.cpp b/src/declarative/util/qmlview.cpp index 05b6016..632e8e2 100644 --- a/src/declarative/util/qmlview.cpp +++ b/src/declarative/util/qmlview.cpp @@ -126,12 +126,13 @@ void FrameBreakAnimation::updateCurrentTime(int msecs) server->frameBreak(); } -class QmlViewPrivate : public QGraphicsViewPrivate +class QmlViewPrivate { - Q_DECLARE_PUBLIC(QmlView) public: - QmlViewPrivate() - : root(0), component(0), resizeMode(QmlView::SizeViewToRootObject) {} + QmlViewPrivate(QmlView *view) + : q(view), root(0), component(0), resizeMode(QmlView::SizeViewToRootObject) {} + + QmlView *q; QGuard<QGraphicsObject> root; QGuard<QmlGraphicsItem> qmlRoot; @@ -214,16 +215,14 @@ public: Constructs a QmlView with the given \a parent. */ QmlView::QmlView(QWidget *parent) -: QGraphicsView(*(new QmlViewPrivate), parent) +: QGraphicsView(parent), d(new QmlViewPrivate(this)) { - Q_D(QmlView); setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred); d->init(); } void QmlViewPrivate::init() { - Q_Q(QmlView); #ifdef Q_ENABLE_PERFORMANCE_LOG { QmlPerfTimer<QmlPerf::FontDatabase> perf; @@ -252,7 +251,6 @@ void QmlViewPrivate::init() */ QmlView::~QmlView() { - Q_D(QmlView); delete d->root; } @@ -265,7 +263,6 @@ QmlView::~QmlView() */ void QmlView::setSource(const QUrl& url) { - Q_D(QmlView); d->source = url; } @@ -276,7 +273,6 @@ void QmlView::setSource(const QUrl& url) */ QUrl QmlView::source() const { - Q_D(const QmlView); return d->source; } @@ -286,7 +282,6 @@ QUrl QmlView::source() const */ QmlEngine* QmlView::engine() { - Q_D(QmlView); return &d->engine; } @@ -299,7 +294,6 @@ QmlEngine* QmlView::engine() */ QmlContext* QmlView::rootContext() { - Q_D(QmlView); return d->engine.rootContext(); } @@ -310,7 +304,6 @@ QmlContext* QmlView::rootContext() */ void QmlView::execute() { - Q_D(QmlView); delete d->root; delete d->component; d->component = new QmlComponent(&d->engine, d->source, this); @@ -340,7 +333,6 @@ void QmlView::execute() QmlView::Status QmlView::status() const { - Q_D(const QmlView); if (!d->component) return QmlView::Null; @@ -353,7 +345,6 @@ QmlView::Status QmlView::status() const */ QList<QmlError> QmlView::errors() const { - Q_D(const QmlView); if (d->component) return d->component->errors(); return QList<QmlError>(); @@ -379,7 +370,6 @@ QList<QmlError> QmlView::errors() const void QmlView::setResizeMode(ResizeMode mode) { - Q_D(QmlView); if (d->resizeMode == mode) return; @@ -397,7 +387,6 @@ void QmlView::setResizeMode(ResizeMode mode) QmlView::ResizeMode QmlView::resizeMode() const { - Q_D(const QmlView); return d->resizeMode; } @@ -406,7 +395,6 @@ QmlView::ResizeMode QmlView::resizeMode() const */ void QmlView::continueExecute() { - Q_D(QmlView); disconnect(d->component, SIGNAL(statusChanged(QmlComponent::Status)), this, SLOT(continueExecute())); @@ -483,7 +471,6 @@ void QmlView::continueExecute() */ void QmlView::sizeChanged() { - Q_D(QmlView); // delay, so we catch both width and height changing. d->resizetimer.start(0,this); } @@ -495,7 +482,6 @@ void QmlView::sizeChanged() */ void QmlView::timerEvent(QTimerEvent* e) { - Q_D(QmlView); if (!e || e->timerId() == d->resizetimer.timerId()) { if (d->qmlRoot) { QSize sz(d->qmlRoot->width(),d->qmlRoot->height()); @@ -514,7 +500,6 @@ void QmlView::timerEvent(QTimerEvent* e) */ QSize QmlView::sizeHint() const { - Q_D(const QmlView); if (d->qmlRoot) { if (d->initialSize.width() <= 0) d->initialSize.setWidth(d->qmlRoot->width()); @@ -529,7 +514,6 @@ QSize QmlView::sizeHint() const */ QGraphicsObject *QmlView::rootObject() const { - Q_D(const QmlView); return d->root; } @@ -540,7 +524,6 @@ QGraphicsObject *QmlView::rootObject() const */ void QmlView::resizeEvent(QResizeEvent *e) { - Q_D(QmlView); if (d->resizeMode == SizeRootObjectToView && d->qmlRoot) { d->qmlRoot->setWidth(width()); d->qmlRoot->setHeight(height()); @@ -560,7 +543,6 @@ void QmlView::resizeEvent(QResizeEvent *e) */ void QmlView::paintEvent(QPaintEvent *event) { - Q_D(QmlView); int time = 0; if (frameRateDebug() || QmlViewDebugServer::isDebuggingEnabled()) time = d->frameTimer.restart(); diff --git a/src/declarative/util/qmlview.h b/src/declarative/util/qmlview.h index 1c6d865..1d6ef1c 100644 --- a/src/declarative/util/qmlview.h +++ b/src/declarative/util/qmlview.h @@ -65,8 +65,6 @@ class Q_DECLARATIVE_EXPORT QmlView : public QGraphicsView Q_PROPERTY(ResizeMode resizeMode READ resizeMode WRITE setResizeMode) Q_PROPERTY(Status status READ status NOTIFY statusChanged) - Q_DECLARE_PRIVATE(QmlView) - public: explicit QmlView(QWidget *parent = 0); virtual ~QmlView(); @@ -103,6 +101,8 @@ protected: virtual void resizeEvent(QResizeEvent *); virtual void paintEvent(QPaintEvent *event); void timerEvent(QTimerEvent*); + + QmlViewPrivate *d; }; QT_END_NAMESPACE diff --git a/src/declarative/util/qmlxmllistmodel.cpp b/src/declarative/util/qmlxmllistmodel.cpp index 06ef747..58caf12 100644 --- a/src/declarative/util/qmlxmllistmodel.cpp +++ b/src/declarative/util/qmlxmllistmodel.cpp @@ -131,19 +131,6 @@ QML_DECLARE_TYPE(QmlXmlListModelRole) QT_BEGIN_NAMESPACE -class QmlXmlListModelPrivate; -struct QmlXmlRoleList : public QmlConcreteList<QmlXmlListModelRole *> -{ - QmlXmlRoleList(QmlXmlListModelPrivate *p) - : model(p) {} - virtual void append(QmlXmlListModelRole *role); - virtual void clear(); - virtual void removeAt(int i); - virtual void insert(int i, QmlXmlListModelRole *role); - - QmlXmlListModelPrivate *model; -}; - class QmlXmlQuery : public QThread { Q_OBJECT @@ -165,7 +152,7 @@ public: m_abort = true; } - int doQuery(QString query, QString namespaces, QByteArray data, QmlXmlRoleList *roleObjects) { + int doQuery(QString query, QString namespaces, QByteArray data, QList<QmlXmlListModelRole *> *roleObjects) { QMutexLocker locker(&m_mutex); m_modelData.clear(); m_size = 0; @@ -230,7 +217,7 @@ private: QString m_prefix; int m_size; int m_queryId; - const QmlXmlRoleList *m_roleObjects; + const QList<QmlXmlListModelRole *> *m_roleObjects; QList<QList<QVariant> > m_modelData; }; @@ -348,7 +335,7 @@ public: QmlXmlListModelPrivate() : isComponentComplete(true), size(-1), highestRole(Qt::UserRole) , reply(0), status(QmlXmlListModel::Null), progress(0.0) - , queryId(-1), roleObjects(this) {} + , queryId(-1), roleObjects() {} bool isComponentComplete; QUrl src; @@ -364,42 +351,39 @@ public: qreal progress; QmlXmlQuery qmlXmlQuery; int queryId; - QmlXmlRoleList roleObjects; + QList<QmlXmlListModelRole *> roleObjects; + static void append_role(QmlListProperty<QmlXmlListModelRole> *list, QmlXmlListModelRole *role); + static void clear_role(QmlListProperty<QmlXmlListModelRole> *list); + static void removeAt_role(QmlListProperty<QmlXmlListModelRole> *list, int i); + static void insert_role(QmlListProperty<QmlXmlListModelRole> *list, int i, QmlXmlListModelRole *role); QList<QList<QVariant> > data; }; -void QmlXmlRoleList::append(QmlXmlListModelRole *role) +void QmlXmlListModelPrivate::append_role(QmlListProperty<QmlXmlListModelRole> *list, QmlXmlListModelRole *role) { - insert(size(), role); + QmlXmlListModel *_this = qobject_cast<QmlXmlListModel *>(list->object); + if (_this) { + int i = _this->d_func()->roleObjects.count(); + _this->d_func()->roleObjects.append(role); + if (_this->d_func()->roleNames.contains(role->name())) { + qmlInfo(role) << QObject::tr("\"%1\" duplicates a previous role name and will be disabled.").arg(role->name()); + return; + } + _this->d_func()->roles.insert(i, _this->d_func()->highestRole); + _this->d_func()->roleNames.insert(i, role->name()); + ++_this->d_func()->highestRole; + } } -//### clear, removeAt, and insert need to invalidate any cached data (in data table) as well +//### clear needs to invalidate any cached data (in data table) as well // (and the model should emit the appropriate signals) -void QmlXmlRoleList::clear() -{ - model->roles.clear(); - model->roleNames.clear(); - QmlConcreteList<QmlXmlListModelRole *>::clear(); -} - -void QmlXmlRoleList::removeAt(int i) +void QmlXmlListModelPrivate::clear_role(QmlListProperty<QmlXmlListModelRole> *list) { - model->roles.removeAt(i); - model->roleNames.removeAt(i); - QmlConcreteList<QmlXmlListModelRole *>::removeAt(i); -} - -void QmlXmlRoleList::insert(int i, QmlXmlListModelRole *role) -{ - QmlConcreteList<QmlXmlListModelRole *>::insert(i, role); - if (model->roleNames.contains(role->name())) { - qmlInfo(role) << QCoreApplication::translate("QmlXmlRoleList", "\"%1\" duplicates a previous role name and will be disabled.").arg(role->name()); - return; - } - model->roles.insert(i, model->highestRole); - model->roleNames.insert(i, role->name()); - ++model->highestRole; + QmlXmlListModel *_this = static_cast<QmlXmlListModel *>(list->object); + _this->d_func()->roles.clear(); + _this->d_func()->roleNames.clear(); + _this->d_func()->roleObjects.clear(); } /*! @@ -448,10 +432,13 @@ QmlXmlListModel::~QmlXmlListModel() The roles to make available for this model. */ -QmlList<QmlXmlListModelRole *> *QmlXmlListModel::roleObjects() +QmlListProperty<QmlXmlListModelRole> QmlXmlListModel::roleObjects() { Q_D(QmlXmlListModel); - return &d->roleObjects; + QmlListProperty<QmlXmlListModelRole> list(this, d->roleObjects); + list.append = &QmlXmlListModelPrivate::append_role; + list.clear = &QmlXmlListModelPrivate::clear_role; + return list; } QHash<int,QVariant> QmlXmlListModel::data(int index, const QList<int> &roles) const diff --git a/src/declarative/util/qmlxmllistmodel_p.h b/src/declarative/util/qmlxmllistmodel_p.h index 51d942d..a6627e2 100644 --- a/src/declarative/util/qmlxmllistmodel_p.h +++ b/src/declarative/util/qmlxmllistmodel_p.h @@ -70,7 +70,7 @@ class Q_DECLARATIVE_EXPORT QmlXmlListModel : public QListModelInterface, public Q_PROPERTY(QString xml READ xml WRITE setXml) Q_PROPERTY(QString query READ query WRITE setQuery) Q_PROPERTY(QString namespaceDeclarations READ namespaceDeclarations WRITE setNamespaceDeclarations) - Q_PROPERTY(QmlList<QmlXmlListModelRole *> *roles READ roleObjects) + Q_PROPERTY(QmlListProperty<QmlXmlListModelRole> roles READ roleObjects) Q_PROPERTY(int count READ count NOTIFY countChanged) Q_CLASSINFO("DefaultProperty", "roles") @@ -84,7 +84,7 @@ public: virtual QList<int> roles() const; virtual QString toString(int role) const; - QmlList<QmlXmlListModelRole *> *roleObjects(); + QmlListProperty<QmlXmlListModelRole> roleObjects(); QUrl source() const; void setSource(const QUrl&); |