diff options
author | Qt Continuous Integration System <qt-info@nokia.com> | 2010-08-24 00:41:34 (GMT) |
---|---|---|
committer | Qt Continuous Integration System <qt-info@nokia.com> | 2010-08-24 00:41:34 (GMT) |
commit | 0067b1fd6ce3abb2600de9567039fd9710b176d2 (patch) | |
tree | be12bd794d3d9c6265bd17e123ab27766b295d2c | |
parent | d405aa6510514ce02b312994db55c305bde60285 (diff) | |
parent | 35db70bf1c046f880861bbf4f48b8741ced405c4 (diff) | |
download | Qt-0067b1fd6ce3abb2600de9567039fd9710b176d2.zip Qt-0067b1fd6ce3abb2600de9567039fd9710b176d2.tar.gz Qt-0067b1fd6ce3abb2600de9567039fd9710b176d2.tar.bz2 |
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7-integration
* '4.7' of scm.dev.nokia.troll.no:qt/qt-qml:
Fix PathView when setting an empty model that is later filled.
QDeclarativeVisualItemModel code cleanup.
5 files changed, 31 insertions, 51 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativepathview.cpp b/src/declarative/graphicsitems/qdeclarativepathview.cpp index 535fb90..4b97505 100644 --- a/src/declarative/graphicsitems/qdeclarativepathview.cpp +++ b/src/declarative/graphicsitems/qdeclarativepathview.cpp @@ -480,7 +480,8 @@ void QDeclarativePathView::setModel(const QVariant &model) connect(d->model, SIGNAL(modelReset()), this, SLOT(modelReset())); connect(d->model, SIGNAL(createdItem(int, QDeclarativeItem*)), this, SLOT(createdItem(int,QDeclarativeItem*))); } - d->offset = qmlMod(d->offset, qreal(d->model->count())); + if (d->model->count()) + d->offset = qmlMod(d->offset, qreal(d->model->count())); if (d->offset < 0) d->offset = d->model->count() + d->offset; d->regenerate(); diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp index 764676a..50a0a33 100644 --- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp @@ -238,20 +238,6 @@ QString QDeclarativeVisualItemModel::stringValue(int index, const QString &name) return QDeclarativeEngine::contextForObject(d->children.at(index).item)->contextProperty(name).toString(); } -QVariant QDeclarativeVisualItemModel::evaluate(int index, const QString &expression, QObject *objectContext) -{ - Q_D(QDeclarativeVisualItemModel); - if (index < 0 || index >= d->children.count()) - return QVariant(); - QDeclarativeContext *ccontext = qmlContext(this); - QDeclarativeContext *ctxt = new QDeclarativeContext(ccontext); - ctxt->setContextObject(d->children.at(index).item); - QDeclarativeExpression e(ctxt, objectContext, expression); - QVariant value = e.evaluate(); - delete ctxt; - return value; -} - int QDeclarativeVisualItemModel::indexOf(QDeclarativeItem *item, QObject *) const { Q_D(const QDeclarativeVisualItemModel); @@ -728,6 +714,7 @@ void QDeclarativeVisualDataModel::setModel(const QVariant &model) QObject::disconnect(d->m_abstractItemModel, SIGNAL(rowsMoved(const QModelIndex&,int,int,const QModelIndex&,int)), this, SLOT(_q_rowsMoved(const QModelIndex&,int,int,const QModelIndex&,int))); QObject::disconnect(d->m_abstractItemModel, SIGNAL(modelReset()), this, SLOT(_q_modelReset())); + d->m_abstractItemModel = 0; } else if (d->m_visualItemModel) { QObject::disconnect(d->m_visualItemModel, SIGNAL(itemsInserted(int,int)), this, SIGNAL(itemsInserted(int,int))); @@ -1167,38 +1154,6 @@ QString QDeclarativeVisualDataModel::stringValue(int index, const QString &name) return val; } -QVariant QDeclarativeVisualDataModel::evaluate(int index, const QString &expression, QObject *objectContext) -{ - Q_D(QDeclarativeVisualDataModel); - if (d->m_visualItemModel) - return d->m_visualItemModel->evaluate(index, expression, objectContext); - - if ((!d->m_listModelInterface && !d->m_abstractItemModel) || !d->m_delegate) - return QVariant(); - - QVariant value; - QObject *nobj = d->m_cache.item(index); - if (nobj) { - QDeclarativeItem *item = qobject_cast<QDeclarativeItem *>(nobj); - if (item) { - QDeclarativeExpression e(qmlContext(item), objectContext, expression); - value = e.evaluate(); - } - } else { - QDeclarativeContext *ccontext = d->m_context; - if (!ccontext) ccontext = qmlContext(this); - QDeclarativeContext *ctxt = new QDeclarativeContext(ccontext); - QDeclarativeVisualDataModelData *data = new QDeclarativeVisualDataModelData(index, this); - ctxt->setContextObject(data); - QDeclarativeExpression e(ctxt, objectContext, expression); - value = e.evaluate(); - delete data; - delete ctxt; - } - - return value; -} - int QDeclarativeVisualDataModel::indexOf(QDeclarativeItem *item, QObject *) const { QVariant val = QDeclarativeEngine::contextForObject(item)->contextProperty(QLatin1String("index")); diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel_p.h b/src/declarative/graphicsitems/qdeclarativevisualitemmodel_p.h index d5c0de2..50d2c53 100644 --- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel_p.h +++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel_p.h @@ -79,7 +79,6 @@ public: virtual ReleaseFlags release(QDeclarativeItem *item) = 0; virtual bool completePending() const = 0; virtual void completeItem() = 0; - virtual QVariant evaluate(int index, const QString &expression, QObject *objectContext) = 0; virtual QString stringValue(int, const QString &) { return QString(); } virtual int indexOf(QDeclarativeItem *item, QObject *objectContext) const = 0; @@ -122,7 +121,6 @@ public: virtual bool completePending() const; virtual void completeItem(); virtual QString stringValue(int index, const QString &role); - virtual QVariant evaluate(int index, const QString &expression, QObject *objectContext); virtual int indexOf(QDeclarativeItem *item, QObject *objectContext) const; @@ -177,7 +175,6 @@ public: bool completePending() const; void completeItem(); virtual QString stringValue(int index, const QString &role); - QVariant evaluate(int index, const QString &expression, QObject *objectContext); int indexOf(QDeclarativeItem *item, QObject *objectContext) const; diff --git a/tests/auto/declarative/qdeclarativepathview/data/emptymodel.qml b/tests/auto/declarative/qdeclarativepathview/data/emptymodel.qml new file mode 100644 index 0000000..177c405 --- /dev/null +++ b/tests/auto/declarative/qdeclarativepathview/data/emptymodel.qml @@ -0,0 +1,5 @@ +import Qt 4.7 + +PathView { + model: emptyModel +} diff --git a/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp b/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp index fdbb16d..e2ccfd2 100644 --- a/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp +++ b/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp @@ -84,7 +84,7 @@ private slots: void modelChanges(); void pathUpdateOnStartChanged(); void package(); - + void emptyModel(); private: QDeclarativeView *createView(); @@ -755,6 +755,28 @@ void tst_QDeclarativePathView::package() delete canvas; } +//QTBUG-13017 +void tst_QDeclarativePathView::emptyModel() +{ + QDeclarativeView *canvas = createView(); + + QStringListModel model; + + QDeclarativeContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("emptyModel", &model); + + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/emptymodel.qml")); + qApp->processEvents(); + + QDeclarativePathView *pathview = qobject_cast<QDeclarativePathView*>(canvas->rootObject()); + QVERIFY(pathview != 0); + + QCOMPARE(pathview->offset(), qreal(0.0)); + + delete canvas; +} + + QDeclarativeView *tst_QDeclarativePathView::createView() { QDeclarativeView *canvas = new QDeclarativeView(0); |