From e410d2711ae2aba15b9da7b07a4f8e40a50ab9c5 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Tue, 22 Sep 2009 14:38:09 +0200 Subject: Ensure that QStandardItem::clone() is used when a prototype is set This fixes a regression introduced in Qt 4.5.0, when dragging an item within a QTreeView it would not call clone() when it was dropped even if a prototype was set on the QStandardItemModel. Reviewed-by: Marius Bugge Monsen --- src/gui/itemviews/qstandarditemmodel.cpp | 9 +++++---- src/gui/itemviews/qstandarditemmodel_p.h | 2 ++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/gui/itemviews/qstandarditemmodel.cpp b/src/gui/itemviews/qstandarditemmodel.cpp index bc25edd..8c9a2fd 100644 --- a/src/gui/itemviews/qstandarditemmodel.cpp +++ b/src/gui/itemviews/qstandarditemmodel.cpp @@ -2965,7 +2965,7 @@ QMimeData *QStandardItemModel::mimeData(const QModelIndexList &indexes) const Used by QStandardItemModel::dropMimeData stream out an item and his children */ -static void decodeDataRecursive(QDataStream &stream, QStandardItem *item) +void QStandardItemModelPrivate::decodeDataRecursive(QDataStream &stream, QStandardItem *item) { int colCount, childCount; stream >> *item; @@ -2976,7 +2976,7 @@ static void decodeDataRecursive(QDataStream &stream, QStandardItem *item) while(childPos > 0) { childPos--; - QStandardItem *child = new QStandardItem; + QStandardItem *child = createItem(); decodeDataRecursive(stream, child); item->setChild( childPos / colCount, childPos % colCount, child); } @@ -2989,6 +2989,7 @@ static void decodeDataRecursive(QDataStream &stream, QStandardItem *item) bool QStandardItemModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) { + Q_D(QStandardItemModel); // check if the action is supported if (!data || !(action == Qt::CopyAction || action == Qt::MoveAction)) return false; @@ -3020,9 +3021,9 @@ bool QStandardItemModel::dropMimeData(const QMimeData *data, Qt::DropAction acti while (!stream.atEnd()) { int r, c; - QStandardItem *item = new QStandardItem; + QStandardItem *item = d->createItem(); stream >> r >> c; - decodeDataRecursive(stream, item); + d->decodeDataRecursive(stream, item); rows.append(r); columns.append(c); diff --git a/src/gui/itemviews/qstandarditemmodel_p.h b/src/gui/itemviews/qstandarditemmodel_p.h index 3d842f3..430fcb6 100644 --- a/src/gui/itemviews/qstandarditemmodel_p.h +++ b/src/gui/itemviews/qstandarditemmodel_p.h @@ -175,6 +175,8 @@ public: void _q_emitItemChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight); + void decodeDataRecursive(QDataStream &stream, QStandardItem *item); + QVector columnHeaderItems; QVector rowHeaderItems; QStandardItem *root; -- cgit v0.12