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();
}
}
/*!
- \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");
+ }
}
/*!
virtual QVariant data(int index, int role) const;
Q_INVOKABLE void clear();
- Q_INVOKABLE void remove(int index);
+ Q_INVOKABLE void remove(QDeclarativeV8Function *args);
Q_INVOKABLE void append(QDeclarativeV8Function *args);
Q_INVOKABLE void insert(QDeclarativeV8Function *args);
Q_INVOKABLE QDeclarativeV8Handle get(int index) const;
void insert(int elementIndex, v8::Handle<v8::Object> object, QV8Engine *eng);
void clear();
- void remove(int index);
+ void remove(int index, int count);
int appendElement();
void insertElement(int index);
m_copy->clear();
}
-void QDeclarativeListModelWorkerAgent::remove(int index)
+void QDeclarativeListModelWorkerAgent::remove(QDeclarativeV8Function *args)
{
- m_copy->remove(index);
+ m_copy->remove(args);
}
void QDeclarativeListModelWorkerAgent::append(QDeclarativeV8Function *args)
int count() const;
Q_INVOKABLE void clear();
- Q_INVOKABLE void remove(int index);
+ Q_INVOKABLE void remove(QDeclarativeV8Function *args);
Q_INVOKABLE void append(QDeclarativeV8Function *args);
Q_INVOKABLE void insert(QDeclarativeV8Function *args);
Q_INVOKABLE QDeclarativeV8Handle get(int index) const;
QTest::newRow("remove2b") << "{append({'foo':123});append({'foo':456});remove(0);get(0).foo}" << 456 << "";
QTest::newRow("remove2c") << "{append({'foo':123});append({'foo':456});remove(1);get(0).foo}" << 123 << "";
QTest::newRow("remove3") << "{append({'foo':123});remove(0)}" << 0 << "";
- QTest::newRow("remove3a") << "{append({'foo':123});remove(-1);count}" << 1 << "<Unknown File>: QML ListModel: remove: index -1 out of range";
- QTest::newRow("remove4a") << "{remove(0)}" << 0 << "<Unknown File>: QML ListModel: remove: index 0 out of range";
- QTest::newRow("remove4b") << "{append({'foo':123});remove(0);remove(0);count}" << 0 << "<Unknown File>: QML ListModel: remove: index 0 out of range";
- QTest::newRow("remove4c") << "{append({'foo':123});remove(1);count}" << 1 << "<Unknown File>: QML ListModel: remove: index 1 out of range";
+ QTest::newRow("remove3a") << "{append({'foo':123});remove(-1);count}" << 1 << "<Unknown File>: QML ListModel: remove: indices [-1 - 0] out of range [0 - 1]";
+ QTest::newRow("remove4a") << "{remove(0)}" << 0 << "<Unknown File>: QML ListModel: remove: indices [0 - 1] out of range [0 - 0]";
+ QTest::newRow("remove4b") << "{append({'foo':123});remove(0);remove(0);count}" << 0 << "<Unknown File>: QML ListModel: remove: indices [0 - 1] out of range [0 - 0]";
+ QTest::newRow("remove4c") << "{append({'foo':123});remove(1);count}" << 1 << "<Unknown File>: QML ListModel: remove: indices [1 - 2] out of range [0 - 1]";
+ QTest::newRow("remove5a") << "{append({'foo':123});append({'foo':456});remove(0,2);count}" << 0 << "";
+ QTest::newRow("remove5b") << "{append({'foo':123});append({'foo':456});remove(0,1);count}" << 1 << "";
+ QTest::newRow("remove5c") << "{append({'foo':123});append({'foo':456});remove(1,1);count}" << 1 << "";
+ QTest::newRow("remove5d") << "{append({'foo':123});append({'foo':456});remove(0,1);get(0).foo}" << 456 << "";
+ QTest::newRow("remove5e") << "{append({'foo':123});append({'foo':456});remove(1,1);get(0).foo}" << 123 << "";
+ QTest::newRow("remove5f") << "{append({'foo':123});append({'foo':456});append({'foo':789});remove(0,1);remove(1,1);get(0).foo}" << 456 << "";
+ QTest::newRow("remove6a") << "{remove();count}" << 0 << "<Unknown File>: QML ListModel: remove: incorrect number of arguments";
+ QTest::newRow("remove6b") << "{remove(1,2,3);count}" << 0 << "<Unknown File>: QML ListModel: remove: incorrect number of arguments";
+ QTest::newRow("remove7a") << "{append({'foo':123});remove(0,0);count}" << 1 << "<Unknown File>: QML ListModel: remove: indices [0 - 0] out of range [0 - 1]";
+ QTest::newRow("remove7b") << "{append({'foo':123});remove(0,-1);count}" << 1 << "<Unknown File>: QML ListModel: remove: indices [0 - -1] out of range [0 - 1]";
QTest::newRow("insert1") << "{insert(0,{'foo':123});count}" << 1 << "";
QTest::newRow("insert2") << "{insert(1,{'foo':123});count}" << 0 << "<Unknown File>: QML ListModel: insert: index 1 out of range";