QAbstractProxyModel: Forward drop-related API.
Forward canDropMimeData() and dropMimeData() to the source model. [ChangeLog][QtCore][QAbstractProxyModel] QAbstractProxyModel now forwards the drop-related API. Task-number: QTBUG-39549 Change-Id: Ib81fcec862586e4ecfb99b9e0f4eb1a16eace762 Reviewed-by: Jørgen Lind <jorgen.lind@digia.com> Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
This commit is contained in:
parent
8ded0a324d
commit
4696e9dbaa
@ -392,6 +392,30 @@ QMimeData* QAbstractProxyModel::mimeData(const QModelIndexList &indexes) const
|
||||
return d->model->mimeData(list);
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
\since 5.4
|
||||
*/
|
||||
bool QAbstractProxyModel::canDropMimeData(const QMimeData *data, Qt::DropAction action,
|
||||
int row, int column, const QModelIndex &parent) const
|
||||
{
|
||||
Q_D(const QAbstractProxyModel);
|
||||
const QModelIndex source = mapToSource(index(row, column, parent));
|
||||
return d->model->canDropMimeData(data, action, source.row(), source.column(), source.parent());
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
\since 5.4
|
||||
*/
|
||||
bool QAbstractProxyModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
|
||||
int row, int column, const QModelIndex &parent)
|
||||
{
|
||||
Q_D(QAbstractProxyModel);
|
||||
const QModelIndex source = mapToSource(index(row, column, parent));
|
||||
return d->model->dropMimeData(data, action, source.row(), source.column(), source.parent());
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
|
@ -91,6 +91,10 @@ public:
|
||||
QModelIndex sibling(int row, int column, const QModelIndex &idx) const;
|
||||
|
||||
QMimeData* mimeData(const QModelIndexList &indexes) const;
|
||||
bool canDropMimeData(const QMimeData *data, Qt::DropAction action,
|
||||
int row, int column, const QModelIndex &parent) const Q_DECL_OVERRIDE;
|
||||
bool dropMimeData(const QMimeData *data, Qt::DropAction action,
|
||||
int row, int column, const QModelIndex &parent) Q_DECL_OVERRIDE;
|
||||
QStringList mimeTypes() const;
|
||||
Qt::DropActions supportedDropActions() const;
|
||||
|
||||
|
@ -150,6 +150,8 @@ private slots:
|
||||
void chainedProxyModelRoleNames();
|
||||
|
||||
void noMapAfterSourceDelete();
|
||||
void forwardDropApi();
|
||||
|
||||
protected:
|
||||
void buildHierarchy(const QStringList &data, QAbstractItemModel *model);
|
||||
void checkHierarchy(const QStringList &data, const QAbstractItemModel *model);
|
||||
@ -3875,5 +3877,35 @@ void tst_QSortFilterProxyModel::noMapAfterSourceDelete()
|
||||
QVERIFY(!persistent.isValid());
|
||||
}
|
||||
|
||||
// QTBUG-39549, test whether canDropMimeData(), dropMimeData() are proxied as well
|
||||
// by invoking them on a QSortFilterProxyModel proxying a QStandardItemModel that allows drops
|
||||
// on row #1, filtering for that row.
|
||||
class DropTestModel : public QStandardItemModel {
|
||||
public:
|
||||
explicit DropTestModel(QObject *parent = 0) : QStandardItemModel(0, 1, parent)
|
||||
{
|
||||
appendRow(new QStandardItem(QStringLiteral("Row0")));
|
||||
appendRow(new QStandardItem(QStringLiteral("Row1")));
|
||||
}
|
||||
|
||||
bool canDropMimeData(const QMimeData *, Qt::DropAction,
|
||||
int row, int /* column */, const QModelIndex & /* parent */) const Q_DECL_OVERRIDE
|
||||
{ return row == 1; }
|
||||
|
||||
bool dropMimeData(const QMimeData *, Qt::DropAction,
|
||||
int row, int /* column */, const QModelIndex & /* parent */) Q_DECL_OVERRIDE
|
||||
{ return row == 1; }
|
||||
};
|
||||
|
||||
void tst_QSortFilterProxyModel::forwardDropApi()
|
||||
{
|
||||
QSortFilterProxyModel model;
|
||||
model.setSourceModel(new DropTestModel(&model));
|
||||
model.setFilterFixedString(QStringLiteral("Row1"));
|
||||
QCOMPARE(model.rowCount(), 1);
|
||||
QVERIFY(model.canDropMimeData(0, Qt::CopyAction, 0, 0, QModelIndex()));
|
||||
QVERIFY(model.dropMimeData(0, Qt::CopyAction, 0, 0, QModelIndex()));
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QSortFilterProxyModel)
|
||||
#include "tst_qsortfilterproxymodel.moc"
|
||||
|
Loading…
Reference in New Issue
Block a user