aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/types
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@theqtcompany.com>2015-04-28 10:57:34 +0200
committerSimon Hausmann <simon.hausmann@theqtcompany.com>2015-04-28 14:29:59 +0200
commit94db5de2acefb6e96d4f6cfda2df14905a5e63c5 (patch)
treec361f5dd4989ee0743e2a9f94b64dbb2127e5dea /src/qml/types
parent11f67b80c4eab4b1e3eb8e6b1e8b69e7a60e42a9 (diff)
parentdee67b41b031791c7b6313e935e622ef8d594686 (diff)
Merge remote-tracking branch 'origin/5.5' into dev
Conflicts: tests/auto/quick/qquicktext/tst_qquicktext.cpp Change-Id: I075e742da8396a268d97d3ab34bcd9e0c0cf001f
Diffstat (limited to 'src/qml/types')
-rw-r--r--src/qml/types/qqmlinstantiator.cpp40
-rw-r--r--src/qml/types/qqmlinstantiator_p_p.h2
2 files changed, 34 insertions, 8 deletions
diff --git a/src/qml/types/qqmlinstantiator.cpp b/src/qml/types/qqmlinstantiator.cpp
index 8b59b0633d..7626ba5a05 100644
--- a/src/qml/types/qqmlinstantiator.cpp
+++ b/src/qml/types/qqmlinstantiator.cpp
@@ -48,6 +48,7 @@ QQmlInstantiatorPrivate::QQmlInstantiatorPrivate()
, active(true)
, async(false)
, ownModel(false)
+ , requestedIndex(-1)
, model(QVariant(1))
, instanceModel(0)
, delegate(0)
@@ -75,6 +76,15 @@ void QQmlInstantiatorPrivate::clear()
q->objectChanged();
}
+QObject *QQmlInstantiatorPrivate::modelObject(int index, bool async)
+{
+ requestedIndex = index;
+ QObject *o = instanceModel->object(index, async);
+ requestedIndex = -1;
+ return o;
+}
+
+
void QQmlInstantiatorPrivate::regenerate()
{
Q_Q(QQmlInstantiator);
@@ -92,7 +102,7 @@ void QQmlInstantiatorPrivate::regenerate()
}
for (int i = 0; i < instanceModel->count(); i++) {
- QObject *object = instanceModel->object(i, async);
+ QObject *object = modelObject(i, async);
// If the item was already created we won't get a createdItem
if (object)
_q_createdItem(i, object);
@@ -106,8 +116,18 @@ void QQmlInstantiatorPrivate::_q_createdItem(int idx, QObject* item)
Q_Q(QQmlInstantiator);
if (objects.contains(item)) //Case when it was created synchronously in regenerate
return;
+ if (requestedIndex != idx) // Asynchronous creation, reference the object
+ (void)instanceModel->object(idx, false);
item->setParent(q);
- objects.insert(idx, item);
+ if (objects.size() < idx + 1) {
+ int modelCount = instanceModel->count();
+ if (objects.capacity() < modelCount)
+ objects.reserve(modelCount);
+ objects.resize(idx + 1);
+ }
+ if (QObject *o = objects.at(idx))
+ instanceModel->release(o);
+ objects.replace(idx, item);
if (objects.count() == 1)
q->objectChanged();
q->objectAdded(idx, item);
@@ -153,11 +173,15 @@ void QQmlInstantiatorPrivate::_q_modelUpdated(const QQmlChangeSet &changeSet, bo
if (insert.isMove()) {
QVector<QPointer<QObject> > movedObjects = moved.value(insert.moveId);
objects = objects.mid(0, index) + movedObjects + objects.mid(index);
- } else for (int i = 0; i < insert.count; ++i) {
- int modelIndex = index + i;
- QObject* obj = instanceModel->object(modelIndex, async);
- if (obj)
- _q_createdItem(modelIndex, obj);
+ } else {
+ if (insert.index <= objects.size())
+ objects.insert(insert.index, insert.count, 0);
+ for (int i = 0; i < insert.count; ++i) {
+ int modelIndex = index + i;
+ QObject* obj = modelObject(modelIndex, async);
+ if (obj)
+ _q_createdItem(modelIndex, obj);
+ }
}
difference += insert.count;
}
@@ -169,7 +193,7 @@ void QQmlInstantiatorPrivate::_q_modelUpdated(const QQmlChangeSet &changeSet, bo
void QQmlInstantiatorPrivate::makeModel()
{
Q_Q(QQmlInstantiator);
- QQmlDelegateModel* delegateModel = new QQmlDelegateModel(qmlContext(q));
+ QQmlDelegateModel* delegateModel = new QQmlDelegateModel(qmlContext(q), q);
instanceModel = delegateModel;
ownModel = true;
delegateModel->setDelegate(delegate);
diff --git a/src/qml/types/qqmlinstantiator_p_p.h b/src/qml/types/qqmlinstantiator_p_p.h
index 6e936d8580..db8c469039 100644
--- a/src/qml/types/qqmlinstantiator_p_p.h
+++ b/src/qml/types/qqmlinstantiator_p_p.h
@@ -66,12 +66,14 @@ public:
void makeModel();
void _q_createdItem(int, QObject *);
void _q_modelUpdated(const QQmlChangeSet &, bool);
+ QObject *modelObject(int index, bool async);
bool componentComplete:1;
bool effectiveReset:1;
bool active:1;
bool async:1;
bool ownModel:1;
+ int requestedIndex;
QVariant model;
QQmlInstanceModel *instanceModel;
QQmlComponent *delegate;