diff options
author | Martin Jones <martin.jones@nokia.com> | 2009-11-04 00:33:45 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2009-11-04 00:33:45 (GMT) |
commit | 162f9d19231612f2b5ae55156ecfd449d3f2f8d7 (patch) | |
tree | 94addf99cfd8c7530af8a3687768d8b54e57b032 /src/declarative | |
parent | 3550d1b22b3a5f8f974ca2ba17a3d4f5d52b3743 (diff) | |
download | Qt-162f9d19231612f2b5ae55156ecfd449d3f2f8d7.zip Qt-162f9d19231612f2b5ae55156ecfd449d3f2f8d7.tar.gz Qt-162f9d19231612f2b5ae55156ecfd449d3f2f8d7.tar.bz2 |
Fix moving items in visual item model.
Diffstat (limited to 'src/declarative')
-rw-r--r-- | src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp | 32 | ||||
-rw-r--r-- | src/declarative/graphicsitems/qmlgraphicsvisualitemmodel_p.h | 1 |
2 files changed, 27 insertions, 6 deletions
diff --git a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp index 686c0da..80b2458 100644 --- a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp @@ -617,6 +617,8 @@ void QmlGraphicsVisualDataModel::setModel(const QVariant &model) this, SLOT(_q_rowsRemoved(const QModelIndex &,int,int))); QObject::disconnect(d->m_abstractItemModel, SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&)), this, SLOT(_q_dataChanged(const QModelIndex&,const QModelIndex&))); + QObject::disconnect(d->m_abstractItemModel, SIGNAL(rowsMoved(const QModelIndex&,int,int,const QModelIndex&,int)), + this, SLOT(_q_rowsMoved(const QModelIndex&,int,int,const QModelIndex&,int))); } else if (d->m_visualItemModel) { QObject::disconnect(d->m_visualItemModel, SIGNAL(itemsInserted(int,int)), this, SIGNAL(itemsInserted(int,int))); @@ -654,6 +656,8 @@ void QmlGraphicsVisualDataModel::setModel(const QVariant &model) this, SLOT(_q_rowsRemoved(const QModelIndex &,int,int))); QObject::connect(d->m_abstractItemModel, SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&)), this, SLOT(_q_dataChanged(const QModelIndex&,const QModelIndex&))); + QObject::connect(d->m_abstractItemModel, SIGNAL(rowsMoved(const QModelIndex&,int,int,const QModelIndex&,int)), + this, SLOT(_q_rowsMoved(const QModelIndex&,int,int,const QModelIndex&,int))); return; } if ((d->m_visualItemModel = qvariant_cast<QmlGraphicsVisualDataModel *>(model))) { @@ -978,9 +982,10 @@ void QmlGraphicsVisualDataModel::_q_itemsMoved(int from, int to, int count) for (QHash<int,QmlGraphicsVisualDataModelPrivate::ObjectRef>::Iterator iter = d->m_cache.begin(); iter != d->m_cache.end(); ) { + int diff = from > to ? count : -count; if (iter.key() >= qMin(from,to) && iter.key() < qMax(from+count,to+count)) { QmlGraphicsVisualDataModelPrivate::ObjectRef objRef = *iter; - int index = iter.key() + from - to; + int index = iter.key() + diff; iter = d->m_cache.erase(iter); items.insert(index, objRef); @@ -996,20 +1001,35 @@ void QmlGraphicsVisualDataModel::_q_itemsMoved(int from, int to, int count) emit itemsMoved(from, to, count); } -void QmlGraphicsVisualDataModel::_q_rowsInserted(const QModelIndex &, int begin, int end) +void QmlGraphicsVisualDataModel::_q_rowsInserted(const QModelIndex &parent, int begin, int end) { - _q_itemsInserted(begin, end - begin + 1); + if (!parent.isValid()) + _q_itemsInserted(begin, end - begin + 1); } -void QmlGraphicsVisualDataModel::_q_rowsRemoved(const QModelIndex &, int begin, int end) +void QmlGraphicsVisualDataModel::_q_rowsRemoved(const QModelIndex &parent, int begin, int end) { - _q_itemsRemoved(begin, end - begin + 1); + if (!parent.isValid()) + _q_itemsRemoved(begin, end - begin + 1); +} + +void QmlGraphicsVisualDataModel::_q_rowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow) +{ + const int count = sourceEnd - sourceStart + 1; + if (!destinationParent.isValid() && !sourceParent.isValid()) { + _q_itemsMoved(sourceStart, destinationRow, count); + } else if (!sourceParent.isValid()) { + _q_itemsRemoved(sourceStart, count); + } else if (!destinationParent.isValid()) { + _q_itemsInserted(destinationRow, count); + } } void QmlGraphicsVisualDataModel::_q_dataChanged(const QModelIndex &begin, const QModelIndex &end) { Q_D(QmlGraphicsVisualDataModel); - _q_itemsChanged(begin.row(), end.row() - begin.row() + 1, d->m_roles); + if (!begin.parent().isValid()) + _q_itemsChanged(begin.row(), end.row() - begin.row() + 1, d->m_roles); } void QmlGraphicsVisualDataModel::_q_createdPackage(int index, QmlPackage *package) diff --git a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel_p.h b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel_p.h index 8b0a8f5..3ff2a74 100644 --- a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel_p.h +++ b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel_p.h @@ -183,6 +183,7 @@ private Q_SLOTS: void _q_itemsMoved(int from, int to, int count); void _q_rowsInserted(const QModelIndex &,int,int); void _q_rowsRemoved(const QModelIndex &,int,int); + void _q_rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int); void _q_dataChanged(const QModelIndex&,const QModelIndex&); void _q_createdPackage(int index, QmlPackage *package); void _q_destroyingPackage(QmlPackage *package); |