aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarco Bubke <marco.bubke@digia.com>2012-10-22 17:57:05 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-10-23 13:24:54 +0200
commit3e9caba478695443669ff880334ea69db6f764eb (patch)
treef555cc9e454241b4d10fbeeb9f3ee1ddb29868de /src
parent85fd1c48f32c266168c2e3d8195f81e59a7dc5e6 (diff)
Change qml list interface
Change-Id: I185c6f4cef6105544504324c1616b5995c219fe3 Reviewed-by: Christiaan Janssen <christiaan.janssen@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/particles/qquickparticlegroup.cpp4
-rw-r--r--src/qml/qml/qqmllist.cpp43
-rw-r--r--src/qml/qml/qqmllist.h10
-rw-r--r--src/qml/qml/qqmlvme.cpp11
-rw-r--r--src/qml/qml/v8/qv8contextwrapper.cpp1
-rw-r--r--src/quick/items/qquickitem.cpp13
-rw-r--r--src/quick/items/qquickvisualdatamodel.cpp3
-rw-r--r--src/quick/items/qquickvisualitemmodel.cpp42
8 files changed, 92 insertions, 35 deletions
diff --git a/src/particles/qquickparticlegroup.cpp b/src/particles/qquickparticlegroup.cpp
index 63d54b0e6c..cae5423379 100644
--- a/src/particles/qquickparticlegroup.cpp
+++ b/src/particles/qquickparticlegroup.cpp
@@ -109,9 +109,9 @@ QQmlListProperty<QObject> QQuickParticleGroup::particleChildren()
{
QQuickParticleSystem* system = qobject_cast<QQuickParticleSystem*>(parent());
if (system)
- return QQmlListProperty<QObject>(this, 0, &QQuickParticleSystem::statePropertyRedirect);
+ return QQmlListProperty<QObject>(this, 0, &QQuickParticleSystem::statePropertyRedirect, 0, 0, 0);
else
- return QQmlListProperty<QObject>(this, 0, &delayedRedirect);
+ return QQmlListProperty<QObject>(this, 0, &delayedRedirect, 0, 0, 0);
}
void QQuickParticleGroup::setSystem(QQuickParticleSystem* arg)
diff --git a/src/qml/qml/qqmllist.cpp b/src/qml/qml/qqmllist.cpp
index 2aef3f2cd7..e90633ac1a 100644
--- a/src/qml/qml/qqmllist.cpp
+++ b/src/qml/qml/qqmllist.cpp
@@ -254,6 +254,32 @@ bool QQmlListReference::canCount() const
}
/*!
+ Return true if at(), count(), append() and clear() are implemented, so you can manipulate
+ the list.
+
+\sa isReadable(), at(), count(), append(), clear()
+*/
+bool QQmlListReference::isManipulable() const
+{
+ return (isValid()
+ && d->property.append
+ && d->property.count
+ && d->property.at
+ && d->property.clear);
+}
+
+
+/*!
+ Return true if at() and count() are implemented, so you can access the elements.
+
+\sa isManipulable(), at(), count()
+*/
+bool QQmlListReference::isReadable() const
+{
+ return (isValid() && d->property.count && d->property.at);
+}
+
+/*!
Appends \a object to the list. Returns true if the operation succeeded, otherwise false.
\sa canAppend()
@@ -366,16 +392,25 @@ can very useful while prototyping.
*/
/*!
+\fn QQmlListProperty::QQmlListProperty(QObject *object, void *data,
+ CountFunction count, AtFunction at)
+
+Construct a readonly QQmlListProperty from a set of operation functions. An opaque \a data handle
+may be passed which can be accessed from within the operation functions. The list property
+remains valid while \a object exists.
+*/
+
+/*!
\fn QQmlListProperty::QQmlListProperty(QObject *object, void *data, AppendFunction append,
- CountFunction count = 0, AtFunction at = 0,
- ClearFunction clear = 0)
+ CountFunction count, AtFunction at,
+ ClearFunction clear)
Construct a QQmlListProperty from a set of operation functions. An opaque \a data handle
may be passed which can be accessed from within the operation functions. The list property
remains valid while \a object exists.
-The \a append operation is compulsory and must be provided, while the \a count, \a at and
-\a clear methods are optional.
+You can pass a null pointer, but than the list will be not designable or changeable by the debugger.
+So provide all function, except it is not possible.
*/
/*!
diff --git a/src/qml/qml/qqmllist.h b/src/qml/qml/qqmllist.h
index bc2feaf22f..e772022636 100644
--- a/src/qml/qml/qqmllist.h
+++ b/src/qml/qml/qqmllist.h
@@ -69,10 +69,11 @@ public:
QQmlListProperty(QObject *o, QList<T *> &list)
: object(o), data(&list), append(qlist_append), count(qlist_count), at(qlist_at),
clear(qlist_clear), dummy1(0), dummy2(0) {}
- QQmlListProperty(QObject *o, void *d, AppendFunction a, CountFunction c = 0, AtFunction t = 0,
- ClearFunction r = 0)
+ QQmlListProperty(QObject *o, void *d, AppendFunction a, CountFunction c, AtFunction t,
+ ClearFunction r )
: object(o), data(d), append(a), count(c), at(t), clear(r), dummy1(0), dummy2(0) {}
-
+ QQmlListProperty(QObject *o, void *d, CountFunction c, AtFunction t)
+ : object(o), data(d), append(0), count(c), at(t), clear(0), dummy1(0), dummy2(0) {}
bool operator==(const QQmlListProperty &o) const {
return object == o.object &&
data == o.data &&
@@ -132,6 +133,9 @@ public:
bool canClear() const;
bool canCount() const;
+ bool isManipulable() const;
+ bool isReadable() const;
+
bool append(QObject *) const;
QObject *at(int) const;
bool clear() const;
diff --git a/src/qml/qml/qqmlvme.cpp b/src/qml/qml/qqmlvme.cpp
index 045869e15d..12de9ffebd 100644
--- a/src/qml/qml/qqmlvme.cpp
+++ b/src/qml/qml/qqmlvme.cpp
@@ -941,7 +941,10 @@ QObject *QQmlVME::run(QList<QQmlError> *errors,
QObject *assign = objects.pop();
const List &list = lists.top();
- list.qListProperty.append((QQmlListProperty<void>*)&list.qListProperty, assign);
+ if (list.qListProperty.append)
+ list.qListProperty.append((QQmlListProperty<void>*)&list.qListProperty, assign);
+ else
+ VME_EXCEPTION(tr("Cannot assign object to read only list"), -1);
QML_END_INSTR(StoreObjectQList)
QML_BEGIN_INSTR(AssignObjectList)
@@ -959,8 +962,10 @@ QObject *QQmlVME::run(QList<QQmlError> *errors,
if (!ptr)
VME_EXCEPTION(tr("Cannot assign object to list"), instr.line);
-
- list.qListProperty.append((QQmlListProperty<void>*)&list.qListProperty, ptr);
+ if (list.qListProperty.append)
+ list.qListProperty.append((QQmlListProperty<void>*)&list.qListProperty, ptr);
+ else
+ VME_EXCEPTION(tr("Cannot assign object to read only list"), -1);
QML_END_INSTR(AssignObjectList)
QML_BEGIN_INSTR(StoreInterface)
diff --git a/src/qml/qml/v8/qv8contextwrapper.cpp b/src/qml/qml/v8/qv8contextwrapper.cpp
index b2c60fe7a8..9f18afc5cb 100644
--- a/src/qml/qml/v8/qv8contextwrapper.cpp
+++ b/src/qml/qml/v8/qv8contextwrapper.cpp
@@ -309,7 +309,6 @@ v8::Handle<v8::Value> QV8ContextWrapper::Getter(v8::Local<v8::String> property,
const QVariant &value = cp->propertyValues.at(propertyIdx);
if (value.userType() == qMetaTypeId<QList<QObject*> >()) {
QQmlListProperty<QObject> prop(context->asQQmlContext(), (void*) qintptr(propertyIdx),
- 0,
QQmlContextPrivate::context_count,
QQmlContextPrivate::context_at);
return engine->listWrapper()->newList(prop, qMetaTypeId<QQmlListProperty<QObject> >());
diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp
index 62fc81fb67..f213111ccd 100644
--- a/src/quick/items/qquickitem.cpp
+++ b/src/quick/items/qquickitem.cpp
@@ -2609,12 +2609,6 @@ void QQuickItemPrivate::children_clear(QQmlListProperty<QQuickItem> *prop)
p->childItems.at(0)->setParentItem(0);
}
-void QQuickItemPrivate::visibleChildren_append(QQmlListProperty<QQuickItem>*, QQuickItem *self)
-{
- // do nothing
- qmlInfo(self) << "QQuickItem: visibleChildren property is readonly and cannot be assigned to.";
-}
-
int QQuickItemPrivate::visibleChildren_count(QQmlListProperty<QQuickItem> *prop)
{
QQuickItemPrivate *p = QQuickItemPrivate::get(static_cast<QQuickItem *>(prop->object));
@@ -3744,9 +3738,10 @@ QQmlListProperty<QQuickItem> QQuickItemPrivate::children()
*/
QQmlListProperty<QQuickItem> QQuickItemPrivate::visibleChildren()
{
- return QQmlListProperty<QQuickItem>(q_func(), 0, QQuickItemPrivate::visibleChildren_append,
- QQuickItemPrivate::visibleChildren_count,
- QQuickItemPrivate::visibleChildren_at);
+ return QQmlListProperty<QQuickItem>(q_func(),
+ 0,
+ QQuickItemPrivate::visibleChildren_count,
+ QQuickItemPrivate::visibleChildren_at);
}
diff --git a/src/quick/items/qquickvisualdatamodel.cpp b/src/quick/items/qquickvisualdatamodel.cpp
index 6f7afd5101..a297ec90df 100644
--- a/src/quick/items/qquickvisualdatamodel.cpp
+++ b/src/quick/items/qquickvisualdatamodel.cpp
@@ -597,7 +597,8 @@ QQmlListProperty<QQuickVisualDataGroup> QQuickVisualDataModel::groups()
d,
QQuickVisualDataModelPrivate::group_append,
QQuickVisualDataModelPrivate::group_count,
- QQuickVisualDataModelPrivate::group_at);
+ QQuickVisualDataModelPrivate::group_at,
+ 0);
}
/*!
diff --git a/src/quick/items/qquickvisualitemmodel.cpp b/src/quick/items/qquickvisualitemmodel.cpp
index 453b4a4b68..91f52695ad 100644
--- a/src/quick/items/qquickvisualitemmodel.cpp
+++ b/src/quick/items/qquickvisualitemmodel.cpp
@@ -62,6 +62,17 @@ class QQuickVisualItemModelPrivate : public QObjectPrivate
{
Q_DECLARE_PUBLIC(QQuickVisualItemModel)
public:
+ class Item {
+ public:
+ Item(QQuickItem *i) : item(i), ref(0) {}
+
+ void addRef() { ++ref; }
+ bool deref() { return --ref == 0; }
+
+ QQuickItem *item;
+ int ref;
+ };
+
QQuickVisualItemModelPrivate() : QObjectPrivate() {}
static void children_append(QQmlListProperty<QQuickItem> *prop, QQuickItem *item) {
@@ -78,6 +89,12 @@ public:
return static_cast<QQuickVisualItemModelPrivate *>(prop->data)->children.at(index).item;
}
+ static void children_clear(QQmlListProperty<QQuickItem> *prop) {
+ static_cast<QQuickVisualItemModelPrivate *>(prop->data)->itemCleared(static_cast<QQuickVisualItemModelPrivate *>(prop->data)->children);
+ static_cast<QQuickVisualItemModelPrivate *>(prop->data)->children.clear();
+ static_cast<QQuickVisualItemModelPrivate *>(prop->data)->emitChildrenChanged();
+ }
+
void itemAppended() {
Q_Q(QQuickVisualItemModel);
QQuickVisualItemModelAttached *attached = QQuickVisualItemModelAttached::properties(children.last().item);
@@ -88,6 +105,13 @@ public:
emit q->countChanged();
}
+ void itemCleared(const QList<Item> &children) {
+ Q_Q(QQuickVisualItemModel);
+ foreach (const Item &child, children)
+ emit q->destroyingItem(child.item);
+ emit q->countChanged();
+ }
+
void emitChildrenChanged() {
Q_Q(QQuickVisualItemModel);
emit q->childrenChanged();
@@ -100,16 +124,6 @@ public:
return -1;
}
- class Item {
- public:
- Item(QQuickItem *i) : item(i), ref(0) {}
-
- void addRef() { ++ref; }
- bool deref() { return --ref == 0; }
-
- QQuickItem *item;
- int ref;
- };
QList<Item> children;
};
@@ -168,8 +182,12 @@ QQuickVisualItemModel::QQuickVisualItemModel(QObject *parent)
QQmlListProperty<QQuickItem> QQuickVisualItemModel::children()
{
Q_D(QQuickVisualItemModel);
- return QQmlListProperty<QQuickItem>(this, d, d->children_append,
- d->children_count, d->children_at);
+ return QQmlListProperty<QQuickItem>(this,
+ d,
+ d->children_append,
+ d->children_count,
+ d->children_at,
+ d->children_clear);
}
/*!