if (!m_delegate || index < 0 || index >= m_compositor.count(group)) {
qWarning() << "VisualDataModel::item: index out range" << index << m_compositor.count(group);
return 0;
+ } else if (!m_context->isValid()) {
+ return 0;
}
Compositor::iterator it = m_compositor.find(group, index);
void QQuickVisualDataModelPrivate::emitChanges()
{
- if (m_transaction || !m_complete)
+ if (m_transaction || !m_complete || !m_context->isValid())
return;
m_transaction = true;
bool QQuickVisualDataModelPrivate::insert(
Compositor::insert_iterator &before, const v8::Local<v8::Object> &object, int groups)
{
+ if (!m_context->isValid())
+ return false;
+
QQuickVisualDataModelItem *cacheItem = m_adaptorModel.createItem(m_cacheMetaType, m_context->engine(), -1);
if (!cacheItem)
return false;
return QQmlV8Handle::fromHandle(v8::Undefined());;
QQuickVisualDataModelPrivate *model = QQuickVisualDataModelPrivate::get(d->model);
- if (index < 0 || index >= model->m_compositor.count(d->group)) {
+ if (!model->m_context->isValid()) {
+ return QQmlV8Handle::fromHandle(v8::Undefined());
+ } else if (index < 0 || index >= model->m_compositor.count(d->group)) {
qmlInfo(this) << tr("get: index out of range");
return QQmlV8Handle::fromHandle(v8::Undefined());
}
void asynchronousMove();
void asynchronousMove_data();
void asynchronousCancel();
+ void invalidContext();
private:
template <int N> void groups_verify(
QCOMPARE(controller.incubatingObjectCount(), 0);
}
+void tst_qquickvisualdatamodel::invalidContext()
+{
+ QQmlEngine engine;
+ QaimModel model;
+ for (int i = 0; i < 8; i++)
+ model.addItem("Original item" + QString::number(i), "");
+
+ engine.rootContext()->setContextProperty("myModel", &model);
+
+ QScopedPointer<QQmlContext> context(new QQmlContext(engine.rootContext()));
+
+ QQmlComponent c(&engine, testFileUrl("visualdatamodel.qml"));
+
+
+ QQuickVisualDataModel *visualModel = qobject_cast<QQuickVisualDataModel*>(c.create(context.data()));
+ QVERIFY(visualModel);
+
+ QQuickItem *item = visualModel->item(4, false);
+ QVERIFY(item);
+ visualModel->release(item);
+
+ delete context.take();
+
+ model.insertItem(4, "new item", "");
+
+ item = visualModel->item(4, false);
+ QVERIFY(!item);
+}
+
QTEST_MAIN(tst_qquickvisualdatamodel)
#include "tst_qquickvisualdatamodel.moc"