aboutsummaryrefslogtreecommitdiffstats
path: root/src/declarative/util/qdeclarativelistmodel.cpp
diff options
context:
space:
mode:
authorGlenn Watson <glenn.watson@nokia.com>2011-11-15 11:32:56 +1000
committerQt by Nokia <qt-info@nokia.com>2011-11-16 04:39:26 +0100
commiteef97750eb1c5b33ed8e0e8c0d1bbf6385239701 (patch)
treec98699d91734ef36af2eb78089af6a5475b56b72 /src/declarative/util/qdeclarativelistmodel.cpp
parentc9cd3b690386661fa19904ccf8958bf83ef0ad24 (diff)
Add optional count parameter to ListModel.remove
When calling remove on ListModel, it's now possible to supply a second parameter giving the number of items to remove. If the count parameter is omitted, it defaults to one, which maintains the previous behaviour. Task-number: QTBUG-22601 Change-Id: I0fb5c394a2b312095ce6e99e379d0f789d3ab4e6 Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'src/declarative/util/qdeclarativelistmodel.cpp')
-rw-r--r--src/declarative/util/qdeclarativelistmodel.cpp34
1 files changed, 22 insertions, 12 deletions
diff --git a/src/declarative/util/qdeclarativelistmodel.cpp b/src/declarative/util/qdeclarativelistmodel.cpp
index dceb0045e3..9e4d7269cd 100644
--- a/src/declarative/util/qdeclarativelistmodel.cpp
+++ b/src/declarative/util/qdeclarativelistmodel.cpp
@@ -554,11 +554,13 @@ void ListModel::clear()
elements.clear();
}
-void ListModel::remove(int index)
+void ListModel::remove(int index, int count)
{
- elements[index]->destroy(m_layout);
- delete elements[index];
- elements.remove(index);
+ for (int i=0 ; i < count ; ++i) {
+ elements[index+i]->destroy(m_layout);
+ delete elements[index+i];
+ }
+ elements.remove(index, count);
updateCacheIndices();
}
@@ -1455,22 +1457,30 @@ void QDeclarativeListModel::clear()
}
/*!
- \qmlmethod QtQuick2::ListModel::remove(int index)
+ \qmlmethod QtQuick2::ListModel::remove(int index, int count = 1)
Deletes the content at \a index from the model.
\sa clear()
*/
-void QDeclarativeListModel::remove(int index)
+void QDeclarativeListModel::remove(QDeclarativeV8Function *args)
{
- if (index < 0 || index >= count()) {
- qmlInfo(this) << tr("remove: index %1 out of range").arg(index);
- return;
- }
+ int argLength = args->Length();
+
+ if (argLength == 1 || argLength == 2) {
+ int index = (*args)[0]->Int32Value();
+ int removeCount = (argLength == 2 ? ((*args)[1]->Int32Value()) : 1);
- m_listModel->remove(index);
+ if (index < 0 || index+removeCount > count() || removeCount <= 0) {
+ qmlInfo(this) << tr("remove: indices [%1 - %2] out of range [0 - %3]").arg(index).arg(index+removeCount).arg(count());
+ return;
+ }
- emitItemsRemoved(index, 1);
+ m_listModel->remove(index, removeCount);
+ emitItemsRemoved(index, removeCount);
+ } else {
+ qmlInfo(this) << tr("remove: incorrect number of arguments");
+ }
}
/*!