From a860500f8e7f705939ce489849e73c640d4316ce Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Wed, 22 Oct 2014 09:18:33 -0400 Subject: Adapt the names in the documentation to the names used in the header This is needed since the names of the header are the ones you have to use in the QML signal handlers to access the variables Change-Id: I507e2ccc05a1fd2c5efd0bf4bef92ed33a186d95 Reviewed-by: Simon Hausmann --- src/corelib/itemmodels/qabstractitemmodel.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/corelib/itemmodels') diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp index 74a7ea1988..6b89c8377a 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 -- cgit v1.2.3 From bec1854cc023fb705319c582a636d5f484adafcc Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Sun, 16 Nov 2014 17:36:27 +0100 Subject: QSortFilterProxyModel: keep the sorting on unrelated changes Whenever the source model of a QSortFilterProxyModel changes, and the changes involve the sorted column, the implementation removes the changed rows from the mapping, sorts them, and inserts them back; in case of identical items, the rows are inserted at the end of the block of equal rows. The problem is that if the change doesn't actually happen on the roles that are used for sorting, then we shuffle the rows, terribly confusing the user. The typical case is a model with identical checkable rows: (un)checking one row will move it at the end. So, instead of trying to be smart with the removal/sort/insert sorted, simply resort everything under the changed parent index. Since the sorting used is stable, this keeps the items in the same positions. Task-number: QTBUG-1548 Change-Id: Id0e61bd49da53b0a3e8aefa6b6893ac41179dc6f Reviewed-by: David Faure --- src/corelib/itemmodels/qsortfilterproxymodel.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'src/corelib/itemmodels') diff --git a/src/corelib/itemmodels/qsortfilterproxymodel.cpp b/src/corelib/itemmodels/qsortfilterproxymodel.cpp index a95c7dc8b3..3c383532bb 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 -- cgit v1.2.3 From fbfc2b8e0b0edf9baa69193a96a57a6a6aa6cfaf Mon Sep 17 00:00:00 2001 From: Nico Vertriest Date: Tue, 11 Nov 2014 13:23:55 +0100 Subject: Doc: corrected autolink issues itemmodels Task-number: QTBUG-40362 Change-Id: I8423643e47d27358dbbce58009cc9039aecb74cf Reviewed-by: Martin Smith --- src/corelib/itemmodels/qabstractitemmodel.cpp | 8 ++++---- src/corelib/itemmodels/qitemselectionmodel.cpp | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/corelib/itemmodels') diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp index 6b89c8377a..b15d255e66 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.cpp +++ b/src/corelib/itemmodels/qabstractitemmodel.cpp @@ -2711,7 +2711,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 +2978,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 +3165,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/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 Date: Tue, 18 Nov 2014 21:47:41 +0100 Subject: QAbstractProxyModel: fix canDropMimeData/dropMimeData implementations The code in 4696e9dbaa4 was incorrect. It is perfectly valid to call these methods with row=-1 column=1 parent=some_index, this is exactly what happens in QListView and QTableView. Child row/column is only for trees. Move the coordinate mapping from QSortFilterProxyModel into a new mapDropCoordinatesToSource internal method, used by QAbstractProxyModel. Task-number: QTBUG-39549 Change-Id: I3312210473d84b639cbe4c01f70ea36437db3e91 Reviewed-by: Friedemann Kleint Reviewed-by: Stephen Kelly --- src/corelib/itemmodels/qabstractproxymodel.cpp | 34 +++++++++++++++++++++--- src/corelib/itemmodels/qabstractproxymodel_p.h | 2 ++ src/corelib/itemmodels/qsortfilterproxymodel.cpp | 20 ++------------ 3 files changed, 34 insertions(+), 22 deletions(-) (limited to 'src/corelib/itemmodels') 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/qsortfilterproxymodel.cpp b/src/corelib/itemmodels/qsortfilterproxymodel.cpp index 3c383532bb..0b2b0e4188 100644 --- a/src/corelib/itemmodels/qsortfilterproxymodel.cpp +++ b/src/corelib/itemmodels/qsortfilterproxymodel.cpp @@ -2030,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); } /*! -- cgit v1.2.3 From b13aa15e1007a1b5ed61049bbd9ef8f95b6d12a5 Mon Sep 17 00:00:00 2001 From: David Faure Date: Fri, 21 Nov 2014 10:46:22 +0100 Subject: QAbstractItemView: call canDropMimeData, as one would expect. The virtual method was added for 5.0 but never called. The old code (only checking mimetypes) is now the default implementation for canDropMimeData. Model subclasses can now refine this by having index-specific logic instead, or in order to inspect the dropped data (e.g. to accept files and refuse directories, which are all text/uri-list). [ChangeLog][QtWidgets][QAbstractItemView] now calls canDropMimeData in order to decide whether or not to accept the drop. Task-number: QTBUG-30534 Change-Id: Ied3aa964b4025bae6a1a26df89a681bfe61c3faa Reviewed-by: Stephen Kelly --- src/corelib/itemmodels/qabstractitemmodel.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/corelib/itemmodels') diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp index b15d255e66..a9cfa3e7ca 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.cpp +++ b/src/corelib/itemmodels/qabstractitemmodel.cpp @@ -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; } /*! -- cgit v1.2.3