diff options
Diffstat (limited to 'src/qml/types')
-rw-r--r-- | src/qml/types/qqmldelegatemodel.cpp | 51 | ||||
-rw-r--r-- | src/qml/types/qqmldelegatemodel_p_p.h | 4 |
2 files changed, 34 insertions, 21 deletions
diff --git a/src/qml/types/qqmldelegatemodel.cpp b/src/qml/types/qqmldelegatemodel.cpp index 0dbd9731c9..d62cc5d334 100644 --- a/src/qml/types/qqmldelegatemodel.cpp +++ b/src/qml/types/qqmldelegatemodel.cpp @@ -1312,8 +1312,12 @@ void QQmlDelegateModel::_q_itemsInserted(int index, int count) const QList<QQmlDelegateModelItem *> cache = d->m_cache; for (int i = 0, c = cache.count(); i < c; ++i) { QQmlDelegateModelItem *item = cache.at(i); - if (item->modelIndex() >= index) - item->setModelIndex(item->modelIndex() + count); + if (item->modelIndex() >= index) { + const int newIndex = item->modelIndex() + count; + const int row = newIndex; + const int column = 0; + item->setModelIndex(newIndex, row, column); + } } QVector<Compositor::Insert> inserts; @@ -1454,10 +1458,14 @@ void QQmlDelegateModel::_q_itemsRemoved(int index, int count) if (!d->m_cache.contains(item)) continue; - if (item->modelIndex() >= index + count) - item->setModelIndex(item->modelIndex() - count); - else if (item->modelIndex() >= index) - item->setModelIndex(-1); + if (item->modelIndex() >= index + count) { + const int newIndex = item->modelIndex() - count; + const int row = newIndex; + const int column = 0; + item->setModelIndex(newIndex, row, column); + } else if (item->modelIndex() >= index) { + item->setModelIndex(-1, -1, -1); + } } QVector<Compositor::Remove> removes; @@ -1502,10 +1510,17 @@ void QQmlDelegateModel::_q_itemsMoved(int from, int to, int count) const QList<QQmlDelegateModelItem *> cache = d->m_cache; for (int i = 0, c = cache.count(); i < c; ++i) { QQmlDelegateModelItem *item = cache.at(i); - if (item->modelIndex() >= from && item->modelIndex() < from + count) - item->setModelIndex(item->modelIndex() - from + to); - else if (item->modelIndex() >= minimum && item->modelIndex() < maximum) - item->setModelIndex(item->modelIndex() + difference); + if (item->modelIndex() >= from && item->modelIndex() < from + count) { + const int newIndex = item->modelIndex() - from + to; + const int row = newIndex; + const int column = 0; + item->setModelIndex(newIndex, row, column); + } else if (item->modelIndex() >= minimum && item->modelIndex() < maximum) { + const int newIndex = item->modelIndex() + difference; + const int row = newIndex; + const int column = 0; + item->setModelIndex(newIndex, row, column); + } } QVector<Compositor::Remove> removes; @@ -1562,7 +1577,7 @@ void QQmlDelegateModel::_q_modelReset() for (int i = 0, c = cache.count(); i < c; ++i) { QQmlDelegateModelItem *item = cache.at(i); if (item->modelIndex() != -1) - item->setModelIndex(-1); + item->setModelIndex(-1, -1, -1); } QVector<Compositor::Remove> removes; @@ -1959,8 +1974,7 @@ void QV4::Heap::QQmlDelegateModelItemObject::destroy() } -QQmlDelegateModelItem::QQmlDelegateModelItem( - QQmlDelegateModelItemMetaType *metaType, int modelIndex) +QQmlDelegateModelItem::QQmlDelegateModelItem(QQmlDelegateModelItemMetaType *metaType, int modelIndex, int row, int column) : v4(metaType->v4Engine) , metaType(metaType) , contextData(nullptr) @@ -1971,8 +1985,8 @@ QQmlDelegateModelItem::QQmlDelegateModelItem( , scriptRef(0) , groups(0) , index(modelIndex) - , row(QQmlDelegateModelPrivate::get(metaType->model)->m_adaptorModel.rowAt(modelIndex)) - , column(QQmlDelegateModelPrivate::get(metaType->model)->m_adaptorModel.columnAt(modelIndex)) + , row(row) + , column(column) { metaType->addref(); } @@ -2007,18 +2021,17 @@ void QQmlDelegateModelItem::Dispose() delete this; } -void QQmlDelegateModelItem::setModelIndex(int idx) +void QQmlDelegateModelItem::setModelIndex(int idx, int newRow, int newColumn) { if (idx == index) return; const int prevRow = row; const int prevColumn = column; - const QQmlAdaptorModel &adaptorModel = QQmlDelegateModelPrivate::get(metaType->model)->m_adaptorModel; index = idx; - row = adaptorModel.rowAt(idx); - column = adaptorModel.columnAt(idx); + row = newRow; + column = newColumn; Q_EMIT modelIndexChanged(); diff --git a/src/qml/types/qqmldelegatemodel_p_p.h b/src/qml/types/qqmldelegatemodel_p_p.h index a0c1f6aa12..0c24e79c1b 100644 --- a/src/qml/types/qqmldelegatemodel_p_p.h +++ b/src/qml/types/qqmldelegatemodel_p_p.h @@ -99,7 +99,7 @@ class QQmlDelegateModelItem : public QObject Q_PROPERTY(int column MEMBER column NOTIFY columnChanged) Q_PROPERTY(QObject *model READ modelObject CONSTANT) public: - QQmlDelegateModelItem(QQmlDelegateModelItemMetaType *metaType, int modelIndex); + QQmlDelegateModelItem(QQmlDelegateModelItemMetaType *metaType, int modelIndex, int row, int column); ~QQmlDelegateModelItem(); void referenceObject() { ++objectRef; } @@ -123,7 +123,7 @@ public: int groupIndex(Compositor::Group group); int modelIndex() const { return index; } - virtual void setModelIndex(int idx); + virtual void setModelIndex(int idx, int newRow, int newColumn); virtual QV4::ReturnedValue get() { return QV4::QObjectWrapper::wrap(v4, this); } |