summaryrefslogtreecommitdiffstats
path: root/src/corelib/itemmodels
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@theqtcompany.com>2014-11-24 13:37:06 +0100
committerFrederik Gladhorn <frederik.gladhorn@theqtcompany.com>2014-11-24 13:39:13 +0100
commit34aba4724f196e34ed02cf50073f41968f119bb6 (patch)
tree0ebdfcabda989ab76ee6de53c6461553c7a767a5 /src/corelib/itemmodels
parentb86b2a742afae118bf974c82ba966ddb0cae4afb (diff)
parentb1cf07f495e10c93e53651ac03e46ebdaea0a97e (diff)
Merge remote-tracking branch 'origin/5.4' into dev
Conflicts: src/corelib/io/qiodevice.cpp src/plugins/bearer/linux_common/qofonoservice_linux.cpp src/plugins/bearer/linux_common/qofonoservice_linux_p.h src/plugins/platforms/android/qandroidplatformtheme.cpp src/tools/bootstrap/bootstrap.pro src/widgets/styles/qmacstyle_mac.mm Change-Id: Ia02aab6c4598ce74e9c30bb4666d5e2ef000f99b
Diffstat (limited to 'src/corelib/itemmodels')
-rw-r--r--src/corelib/itemmodels/qabstractitemmodel.cpp41
-rw-r--r--src/corelib/itemmodels/qabstractproxymodel.cpp34
-rw-r--r--src/corelib/itemmodels/qabstractproxymodel_p.h2
-rw-r--r--src/corelib/itemmodels/qitemselectionmodel.cpp2
-rw-r--r--src/corelib/itemmodels/qsortfilterproxymodel.cpp26
5 files changed, 61 insertions, 44 deletions
diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp
index 74a7ea1988..a9cfa3e7ca 100644
--- a/src/corelib/itemmodels/qabstractitemmodel.cpp
+++ b/src/corelib/itemmodels/qabstractitemmodel.cpp
@@ -1552,13 +1552,13 @@ QAbstractItemModel::~QAbstractItemModel()
*/
/*!
- \fn void QAbstractItemModel::rowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow)
+ \fn void QAbstractItemModel::rowsMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row)
\since 4.6
This signal is emitted after rows have been moved within the
- model. The items between \a sourceStart and \a sourceEnd
- inclusive, under the given \a sourceParent item have been moved to \a destinationParent
- starting at the row \a destinationRow.
+ model. The items between \a start and \a end
+ inclusive, under the given \a parent item have been moved to \a destination
+ starting at the row \a row.
\b{Note:} Components connected to this signal use it to adapt to changes
in the model's dimensions. It can only be emitted by the QAbstractItemModel
@@ -1584,13 +1584,13 @@ QAbstractItemModel::~QAbstractItemModel()
*/
/*!
- \fn void QAbstractItemModel::columnsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn)
+ \fn void QAbstractItemModel::columnsMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int column)
\since 4.6
This signal is emitted after columns have been moved within the
- model. The items between \a sourceStart and \a sourceEnd
- inclusive, under the given \a sourceParent item have been moved to \a destinationParent
- starting at the column \a destinationColumn.
+ model. The items between \a start and \a end
+ inclusive, under the given \a parent item have been moved to \a destination
+ starting at the column \a column.
\b{Note:} Components connected to this signal use it to adapt to changes
in the model's dimensions. It can only be emitted by the QAbstractItemModel
@@ -1842,7 +1842,9 @@ QMimeData *QAbstractItemModel::mimeData(const QModelIndexList &indexes) const
/*!
Returns \c{true} if a model can accept a drop of the \a data. This
- default implementation always returns \c{true}.
+ default implementation only checks if \a data has at least one format
+ in the list of mimeTypes() and if \a action is among the
+ model's supportedDropActions().
Reimplement this function in your custom model, if you want to
test whether the \a data can be dropped at \a row, \a column,
@@ -1855,12 +1857,19 @@ bool QAbstractItemModel::canDropMimeData(const QMimeData *data, Qt::DropAction a
int row, int column,
const QModelIndex &parent) const
{
- Q_UNUSED(data)
- Q_UNUSED(action)
Q_UNUSED(row)
Q_UNUSED(column)
Q_UNUSED(parent)
- return true;
+
+ if (!(action & supportedDropActions()))
+ return false;
+
+ const QStringList modelTypes = mimeTypes();
+ for (int i = 0; i < modelTypes.count(); ++i) {
+ if (data->hasFormat(modelTypes.at(i)))
+ return true;
+ }
+ return false;
}
/*!
@@ -2711,7 +2720,7 @@ bool QAbstractItemModelPrivate::allowMove(const QModelIndex &srcParent, int star
persistent indexes in the model, which you would otherwise be
required to do yourself. Using beginMoveRows and endMoveRows
is an alternative to emitting layoutAboutToBeChanged and
- layoutChanged directly along with changePersistentIndexes.
+ layoutChanged directly along with changePersistentIndex.
The \a sourceParent index corresponds to the parent from which the
rows are moved; \a sourceFirst and \a sourceLast are the first and last
@@ -2978,7 +2987,7 @@ void QAbstractItemModel::endRemoveColumns()
persistent indexes in the model, which you would otherwise be
required to do yourself. Using beginMoveRows and endMoveRows
is an alternative to emitting layoutAboutToBeChanged and
- layoutChanged directly along with changePersistentIndexes.
+ layoutChanged directly along with changePersistentIndex.
The \a sourceParent index corresponds to the parent from which the
columns are moved; \a sourceFirst and \a sourceLast are the first and last
@@ -3165,11 +3174,11 @@ void QAbstractItemModel::changePersistentIndex(const QModelIndex &from, const QM
/*!
\since 4.1
- Changes the QPersistentModelIndexes that is equal to the indexes in the
+ Changes the {QPersistentModelIndex}es that are equal to the indexes in the
given \a from model index list to the given \a to model index list.
If no persistent model indexes equal to the indexes in the given \a from
- model index list was found, nothing is changed.
+ model index list are found, nothing is changed.
\sa persistentIndexList(), changePersistentIndex()
*/
diff --git a/src/corelib/itemmodels/qabstractproxymodel.cpp b/src/corelib/itemmodels/qabstractproxymodel.cpp
index ce26293183..b7f988ef7c 100644
--- a/src/corelib/itemmodels/qabstractproxymodel.cpp
+++ b/src/corelib/itemmodels/qabstractproxymodel.cpp
@@ -384,6 +384,26 @@ QMimeData* QAbstractProxyModel::mimeData(const QModelIndexList &indexes) const
return d->model->mimeData(list);
}
+void QAbstractProxyModelPrivate::mapDropCoordinatesToSource(int row, int column, const QModelIndex &parent,
+ int *sourceRow, int *sourceColumn, QModelIndex *sourceParent) const
+{
+ Q_Q(const QAbstractProxyModel);
+ *sourceRow = -1;
+ *sourceColumn = -1;
+ if (row == -1 && column == -1) {
+ *sourceParent = q->mapToSource(parent);
+ } else if (row == q->rowCount(parent)) {
+ *sourceParent = q->mapToSource(parent);
+ *sourceRow = model->rowCount(*sourceParent);
+ } else {
+ QModelIndex proxyIndex = q->index(row, column, parent);
+ QModelIndex sourceIndex = q->mapToSource(proxyIndex);
+ *sourceRow = sourceIndex.row();
+ *sourceColumn = sourceIndex.column();
+ *sourceParent = sourceIndex.parent();
+ }
+}
+
/*!
\reimp
\since 5.4
@@ -392,8 +412,11 @@ bool QAbstractProxyModel::canDropMimeData(const QMimeData *data, Qt::DropAction
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());
+ int sourceDestinationRow;
+ int sourceDestinationColumn;
+ QModelIndex sourceParent;
+ d->mapDropCoordinatesToSource(row, column, parent, &sourceDestinationRow, &sourceDestinationColumn, &sourceParent);
+ return d->model->canDropMimeData(data, action, sourceDestinationRow, sourceDestinationColumn, sourceParent);
}
/*!
@@ -404,8 +427,11 @@ bool QAbstractProxyModel::dropMimeData(const QMimeData *data, Qt::DropAction act
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());
+ int sourceDestinationRow;
+ int sourceDestinationColumn;
+ QModelIndex sourceParent;
+ d->mapDropCoordinatesToSource(row, column, parent, &sourceDestinationRow, &sourceDestinationColumn, &sourceParent);
+ return d->model->dropMimeData(data, action, sourceDestinationRow, sourceDestinationColumn, sourceParent);
}
/*!
diff --git a/src/corelib/itemmodels/qabstractproxymodel_p.h b/src/corelib/itemmodels/qabstractproxymodel_p.h
index 9402092fa8..24af5afc64 100644
--- a/src/corelib/itemmodels/qabstractproxymodel_p.h
+++ b/src/corelib/itemmodels/qabstractproxymodel_p.h
@@ -59,6 +59,8 @@ public:
QAbstractProxyModelPrivate() : QAbstractItemModelPrivate(), model(0) {}
QAbstractItemModel *model;
virtual void _q_sourceModelDestroyed();
+ void mapDropCoordinatesToSource(int row, int column, const QModelIndex &parent,
+ int *source_row, int *source_column, QModelIndex *source_parent) const;
};
QT_END_NAMESPACE
diff --git a/src/corelib/itemmodels/qitemselectionmodel.cpp b/src/corelib/itemmodels/qitemselectionmodel.cpp
index db78af8cf8..5395fd5d09 100644
--- a/src/corelib/itemmodels/qitemselectionmodel.cpp
+++ b/src/corelib/itemmodels/qitemselectionmodel.cpp
@@ -1076,7 +1076,7 @@ void QItemSelectionModelPrivate::_q_layoutChanged(const QList<QPersistentModelIn
If you omit the QItemSelectionModel::Current command, a new current
selection will be created, and the previous one added to the whole
selection. All functions operate on both layers; for example,
- selectedItems() will return items from both layers.
+ \l {QTableWidget::selectedItems()}{selecteditems()} will return items from both layers.
\sa {Model/View Programming}, QAbstractItemModel, {Chart Example}
*/
diff --git a/src/corelib/itemmodels/qsortfilterproxymodel.cpp b/src/corelib/itemmodels/qsortfilterproxymodel.cpp
index a95c7dc8b3..0b2b0e4188 100644
--- a/src/corelib/itemmodels/qsortfilterproxymodel.cpp
+++ b/src/corelib/itemmodels/qsortfilterproxymodel.cpp
@@ -1196,11 +1196,7 @@ void QSortFilterProxyModelPrivate::_q_sourceDataChanged(const QModelIndex &sourc
parents << q->mapFromSource(source_parent);
emit q->layoutAboutToBeChanged(parents, QAbstractItemModel::VerticalSortHint);
QModelIndexPairList source_indexes = store_persistent_indexes();
- remove_source_items(m->proxy_rows, m->source_rows, source_rows_resort,
- source_parent, Qt::Vertical, false);
- sort_source_rows(source_rows_resort, source_parent);
- insert_source_items(m->proxy_rows, m->source_rows, source_rows_resort,
- source_parent, Qt::Vertical, false);
+ sort_source_rows(m->source_rows, source_parent);
update_persistent_indexes(source_indexes);
emit q->layoutChanged(parents, QAbstractItemModel::VerticalSortHint);
// Make sure we also emit dataChanged for the rows
@@ -2034,30 +2030,14 @@ Qt::DropActions QSortFilterProxyModel::supportedDropActions() const
return d->model->supportedDropActions();
}
+// Qt6: remove unnecessary reimplementation
/*!
\reimp
*/
bool QSortFilterProxyModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
int row, int column, const QModelIndex &parent)
{
- Q_D(QSortFilterProxyModel);
- if ((row == -1) && (column == -1))
- return d->model->dropMimeData(data, action, -1, -1, mapToSource(parent));
- int source_destination_row = -1;
- int source_destination_column = -1;
- QModelIndex source_parent;
- if (row == rowCount(parent)) {
- source_parent = mapToSource(parent);
- source_destination_row = d->model->rowCount(source_parent);
- } else {
- QModelIndex proxy_index = index(row, column, parent);
- QModelIndex source_index = mapToSource(proxy_index);
- source_destination_row = source_index.row();
- source_destination_column = source_index.column();
- source_parent = source_index.parent();
- }
- return d->model->dropMimeData(data, action, source_destination_row,
- source_destination_column, source_parent);
+ return QAbstractProxyModel::dropMimeData(data, action, row, column, parent);
}
/*!