aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/types/qqmllistmodel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/qml/types/qqmllistmodel.cpp')
-rw-r--r--src/qml/types/qqmllistmodel.cpp66
1 files changed, 26 insertions, 40 deletions
diff --git a/src/qml/types/qqmllistmodel.cpp b/src/qml/types/qqmllistmodel.cpp
index d088a5da42..d72d2e9487 100644
--- a/src/qml/types/qqmllistmodel.cpp
+++ b/src/qml/types/qqmllistmodel.cpp
@@ -341,7 +341,9 @@ ListModel::ListModel(ListLayout *layout, QQmlListModel *modelCache, int uid) : m
void ListModel::destroy()
{
- clear();
+ for (const auto &destroyer : remove(0, elements.count()))
+ destroyer();
+
m_uid = -1;
m_layout = 0;
if (m_modelCache && m_modelCache->m_primary == false)
@@ -562,16 +564,6 @@ void ListModel::set(int elementIndex, QV4::Object *object)
}
}
-void ListModel::clear()
-{
- int elementCount = elements.count();
- for (int i=0 ; i < elementCount ; ++i) {
- elements[i]->destroy(m_layout);
- delete elements[i];
- }
- elements.clear();
-}
-
QVector<std::function<void()>> ListModel::remove(int index, int count)
{
QVector<std::function<void()>> toDestroy;
@@ -2031,18 +2023,7 @@ int QQmlListModel::count() const
*/
void QQmlListModel::clear()
{
- const int cleared = count();
-
- emitItemsAboutToBeRemoved(0, cleared);
-
- if (m_dynamicRoles) {
- qDeleteAll(m_modelObjects);
- m_modelObjects.clear();
- } else {
- m_listModel->clear();
- }
-
- emitItemsRemoved(0, cleared);
+ removeElements(0, count());
}
/*!
@@ -2066,27 +2047,32 @@ void QQmlListModel::remove(QQmlV4Function *args)
return;
}
- emitItemsAboutToBeRemoved(index, removeCount);
+ removeElements(index, removeCount);
+ } else {
+ qmlWarning(this) << tr("remove: incorrect number of arguments");
+ }
+}
- QVector<std::function<void()>> toDestroy;
- if (m_dynamicRoles) {
- for (int i=0 ; i < removeCount ; ++i) {
- auto modelObject = m_modelObjects[index+i];
- toDestroy.append([modelObject](){
- delete modelObject;
- });
- }
- m_modelObjects.remove(index, removeCount);
- } else {
- toDestroy = m_listModel->remove(index, removeCount);
- }
+void QQmlListModel::removeElements(int index, int removeCount)
+{
+ emitItemsAboutToBeRemoved(index, removeCount);
- emitItemsRemoved(index, removeCount);
- for (const auto &destroyer : toDestroy)
- destroyer();
+ QVector<std::function<void()>> toDestroy;
+ if (m_dynamicRoles) {
+ for (int i=0 ; i < removeCount ; ++i) {
+ auto modelObject = m_modelObjects[index+i];
+ toDestroy.append([modelObject](){
+ delete modelObject;
+ });
+ }
+ m_modelObjects.remove(index, removeCount);
} else {
- qmlWarning(this) << tr("remove: incorrect number of arguments");
+ toDestroy = m_listModel->remove(index, removeCount);
}
+
+ emitItemsRemoved(index, removeCount);
+ for (const auto &destroyer : toDestroy)
+ destroyer();
}
/*!