summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJerome Pasion <jerome.pasion@nokia.com>2010-08-02 08:55:11 (GMT)
committerJerome Pasion <jerome.pasion@nokia.com>2010-08-02 08:55:11 (GMT)
commit6d872ce4f906e16d2da2c2511da5b6d065c3367f (patch)
treeee498d7ab46e4f80a88debca70c990c614d23abf
parentf0e49104a864b3f658e8cc0036b742b20ad84872 (diff)
parentbc98dbff815f9eace168e5683c06d65d6ce9b3d4 (diff)
downloadQt-6d872ce4f906e16d2da2c2511da5b6d065c3367f.zip
Qt-6d872ce4f906e16d2da2c2511da5b6d065c3367f.tar.gz
Qt-6d872ce4f906e16d2da2c2511da5b6d065c3367f.tar.bz2
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/oslo-staging-1 into 4.7
-rw-r--r--src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp48
1 files changed, 37 insertions, 11 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp
index 7952b97..79c1c43 100644
--- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp
+++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp
@@ -78,7 +78,7 @@ public:
static void children_append(QDeclarativeListProperty<QDeclarativeItem> *prop, QDeclarativeItem *item) {
QDeclarative_setParent_noEvent(item, prop->object);
- static_cast<QDeclarativeVisualItemModelPrivate *>(prop->data)->children.append(item);
+ static_cast<QDeclarativeVisualItemModelPrivate *>(prop->data)->children.append(Item(item));
static_cast<QDeclarativeVisualItemModelPrivate *>(prop->data)->itemAppended();
static_cast<QDeclarativeVisualItemModelPrivate *>(prop->data)->emitChildrenChanged();
}
@@ -88,12 +88,12 @@ public:
}
static QDeclarativeItem *children_at(QDeclarativeListProperty<QDeclarativeItem> *prop, int index) {
- return static_cast<QDeclarativeVisualItemModelPrivate *>(prop->data)->children.at(index);
+ return static_cast<QDeclarativeVisualItemModelPrivate *>(prop->data)->children.at(index).item;
}
void itemAppended() {
Q_Q(QDeclarativeVisualItemModel);
- QDeclarativeVisualItemModelAttached *attached = QDeclarativeVisualItemModelAttached::properties(children.last());
+ QDeclarativeVisualItemModelAttached *attached = QDeclarativeVisualItemModelAttached::properties(children.last().item);
attached->setIndex(children.count()-1);
emit q->itemsInserted(children.count()-1, 1);
emit q->countChanged();
@@ -104,7 +104,25 @@ public:
emit q->childrenChanged();
}
- QList<QDeclarativeItem *> children;
+ int indexOf(QDeclarativeItem *item) const {
+ for (int i = 0; i < children.count(); ++i)
+ if (children.at(i).item == item)
+ return i;
+ return -1;
+ }
+
+ class Item {
+ public:
+ Item(QDeclarativeItem *i) : item(i), ref(0) {}
+
+ void addRef() { ++ref; }
+ bool deref() { return --ref == 0; }
+
+ QDeclarativeItem *item;
+ int ref;
+ };
+
+ QList<Item> children;
};
@@ -182,14 +200,22 @@ bool QDeclarativeVisualItemModel::isValid() const
QDeclarativeItem *QDeclarativeVisualItemModel::item(int index, bool)
{
Q_D(QDeclarativeVisualItemModel);
- return d->children.at(index);
+ QDeclarativeVisualItemModelPrivate::Item &item = d->children[index];
+ item.addRef();
+ return item.item;
}
QDeclarativeVisualModel::ReleaseFlags QDeclarativeVisualItemModel::release(QDeclarativeItem *item)
{
- if (item->scene())
- item->scene()->removeItem(item);
- QDeclarative_setParent_noEvent(item, this);
+ Q_D(QDeclarativeVisualItemModel);
+ int idx = d->indexOf(item);
+ if (idx >= 0) {
+ if (d->children[idx].deref()) {
+ if (item->scene())
+ item->scene()->removeItem(item);
+ QDeclarative_setParent_noEvent(item, this);
+ }
+ }
return 0;
}
@@ -208,7 +234,7 @@ QString QDeclarativeVisualItemModel::stringValue(int index, const QString &name)
Q_D(QDeclarativeVisualItemModel);
if (index < 0 || index >= d->children.count())
return QString();
- return QDeclarativeEngine::contextForObject(d->children.at(index))->contextProperty(name).toString();
+ return QDeclarativeEngine::contextForObject(d->children.at(index).item)->contextProperty(name).toString();
}
QVariant QDeclarativeVisualItemModel::evaluate(int index, const QString &expression, QObject *objectContext)
@@ -218,7 +244,7 @@ QVariant QDeclarativeVisualItemModel::evaluate(int index, const QString &express
return QVariant();
QDeclarativeContext *ccontext = qmlContext(this);
QDeclarativeContext *ctxt = new QDeclarativeContext(ccontext);
- ctxt->setContextObject(d->children.at(index));
+ ctxt->setContextObject(d->children.at(index).item);
QDeclarativeExpression e(ctxt, objectContext, expression);
QVariant value = e.evaluate();
delete ctxt;
@@ -228,7 +254,7 @@ QVariant QDeclarativeVisualItemModel::evaluate(int index, const QString &express
int QDeclarativeVisualItemModel::indexOf(QDeclarativeItem *item, QObject *) const
{
Q_D(const QDeclarativeVisualItemModel);
- return d->children.indexOf(item);
+ return d->indexOf(item);
}
QDeclarativeVisualItemModelAttached *QDeclarativeVisualItemModel::qmlAttachedProperties(QObject *obj)