diff options
Diffstat (limited to 'src/corelib/itemmodels')
-rw-r--r-- | src/corelib/itemmodels/qabstractitemmodel.cpp | 8 | ||||
-rw-r--r-- | src/corelib/itemmodels/qconcatenatetablesproxymodel.cpp | 11 | ||||
-rw-r--r-- | src/corelib/itemmodels/qitemselectionmodel.cpp | 4 | ||||
-rw-r--r-- | src/corelib/itemmodels/qitemselectionmodel.h | 6 | ||||
-rw-r--r-- | src/corelib/itemmodels/qsortfilterproxymodel.cpp | 95 |
5 files changed, 91 insertions, 33 deletions
diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp index db75163e50..997a634e76 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.cpp +++ b/src/corelib/itemmodels/qabstractitemmodel.cpp @@ -1945,8 +1945,8 @@ QStringList QAbstractItemModel::mimeTypes() const mimeTypes(). If you reimplement mimeTypes() in your custom model to return more MIME types, reimplement this function to make use of them. - If the list of \a indexes is empty, or there are no supported MIME types, 0 - is returned rather than a serialized empty list. + If the list of \a indexes is empty, or there are no supported MIME types, + \nullptr is returned rather than a serialized empty list. \sa mimeTypes(), dropMimeData() */ @@ -3196,9 +3196,8 @@ bool QAbstractItemModel::beginMoveColumns(const QModelIndex &sourceParent, int s destinationChange.needsAdjust = destinationParent.isValid() && destinationParent.row() >= sourceLast && destinationParent.parent() == sourceParent; d->changes.push(destinationChange); - d->itemsAboutToBeMoved(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild, Qt::Horizontal); - emit columnsAboutToBeMoved(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild, QPrivateSignal()); + d->itemsAboutToBeMoved(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild, Qt::Horizontal); return true; } @@ -3231,7 +3230,6 @@ void QAbstractItemModel::endMoveColumns() adjustedSource = createIndex(adjustedSource.row(), adjustedSource.column() + numMoved, adjustedSource.internalPointer()); d->itemsMoved(adjustedSource, removeChange.first, removeChange.last, adjustedDestination, insertChange.first, Qt::Horizontal); - emit columnsMoved(adjustedSource, removeChange.first, removeChange.last, adjustedDestination, insertChange.first, QPrivateSignal()); } diff --git a/src/corelib/itemmodels/qconcatenatetablesproxymodel.cpp b/src/corelib/itemmodels/qconcatenatetablesproxymodel.cpp index 0e29714677..efddc14603 100644 --- a/src/corelib/itemmodels/qconcatenatetablesproxymodel.cpp +++ b/src/corelib/itemmodels/qconcatenatetablesproxymodel.cpp @@ -313,8 +313,8 @@ QModelIndex QConcatenateTablesProxyModel::parent(const QModelIndex &index) const int QConcatenateTablesProxyModel::rowCount(const QModelIndex &parent) const { Q_D(const QConcatenateTablesProxyModel); - Q_ASSERT(checkIndex(parent, QAbstractItemModel::CheckIndexOption::ParentIsInvalid)); // flat model - Q_UNUSED(parent); + if (parent.isValid()) + return 0; // flat model return d->m_rowCount; } @@ -622,9 +622,14 @@ void QConcatenateTablesProxyModelPrivate::_q_slotDataChanged(const QModelIndex & Q_Q(QConcatenateTablesProxyModel); Q_ASSERT(from.isValid()); Q_ASSERT(to.isValid()); + if (from.column() >= m_columnCount) + return; + QModelIndex adjustedTo = to; + if (to.column() >= m_columnCount) + adjustedTo = to.siblingAtColumn(m_columnCount - 1); const QModelIndex myFrom = q->mapFromSource(from); Q_ASSERT(q->checkIndex(myFrom, QAbstractItemModel::CheckIndexOption::IndexIsValid)); - const QModelIndex myTo = q->mapFromSource(to); + const QModelIndex myTo = q->mapFromSource(adjustedTo); Q_ASSERT(q->checkIndex(myTo, QAbstractItemModel::CheckIndexOption::IndexIsValid)); emit q->dataChanged(myFrom, myTo, roles); } diff --git a/src/corelib/itemmodels/qitemselectionmodel.cpp b/src/corelib/itemmodels/qitemselectionmodel.cpp index 27442fb2fa..6eadc77f78 100644 --- a/src/corelib/itemmodels/qitemselectionmodel.cpp +++ b/src/corelib/itemmodels/qitemselectionmodel.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -274,6 +274,7 @@ QItemSelectionRange QItemSelectionRange::intersected(const QItemSelectionRange & */ +#if QT_DEPRECATED_SINCE(5, 15) /*! Returns \c true if the selection range is less than the \a other range given; otherwise returns \c false. @@ -312,6 +313,7 @@ bool QItemSelectionRange::operator<(const QItemSelectionRange &other) const std::less<const QAbstractItemModel *> less; return less(tl.model(), other.tl.model()); } +#endif /*! \fn bool QItemSelectionRange::isValid() const diff --git a/src/corelib/itemmodels/qitemselectionmodel.h b/src/corelib/itemmodels/qitemselectionmodel.h index 5820695592..d79fb89156 100644 --- a/src/corelib/itemmodels/qitemselectionmodel.h +++ b/src/corelib/itemmodels/qitemselectionmodel.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -114,7 +114,9 @@ public: { return (tl == other.tl && br == other.br); } inline bool operator!=(const QItemSelectionRange &other) const { return !operator==(other); } - bool operator<(const QItemSelectionRange &other) const; +#if QT_DEPRECATED_SINCE(5, 15) + QT_DEPRECATED bool operator<(const QItemSelectionRange &other) const; +#endif inline bool isValid() const { diff --git a/src/corelib/itemmodels/qsortfilterproxymodel.cpp b/src/corelib/itemmodels/qsortfilterproxymodel.cpp index bd4c7e93c5..3d7fe43cd3 100644 --- a/src/corelib/itemmodels/qsortfilterproxymodel.cpp +++ b/src/corelib/itemmodels/qsortfilterproxymodel.cpp @@ -307,6 +307,8 @@ public: QHash<QModelIndex, Mapping *>::const_iterator create_mapping( const QModelIndex &source_parent) const; + QHash<QModelIndex, Mapping *>::const_iterator create_mapping_recursive( + const QModelIndex &source_parent) const; QModelIndex proxy_to_source(const QModelIndex &proxyIndex) const; QModelIndex source_to_proxy(const QModelIndex &sourceIndex) const; bool can_create_mapping(const QModelIndex &source_parent) const; @@ -533,6 +535,29 @@ IndexMap::const_iterator QSortFilterProxyModelPrivate::create_mapping( return it; } +// Go up the tree, creating mappings, unless of course the parent is filtered out +IndexMap::const_iterator QSortFilterProxyModelPrivate::create_mapping_recursive(const QModelIndex &source_parent) const +{ + if (source_parent.isValid()) { + const QModelIndex source_grand_parent = source_parent.parent(); + IndexMap::const_iterator it = source_index_mapping.constFind(source_grand_parent); + IndexMap::const_iterator end = source_index_mapping.constEnd(); + if (it == end) { + it = create_mapping_recursive(source_grand_parent); + end = source_index_mapping.constEnd(); + if (it == end) + return end; + } + Mapping *gm = it.value(); + if (gm->proxy_rows.at(source_parent.row()) == -1 || + gm->proxy_columns.at(source_parent.column()) == -1) { + // Can't do, parent is filtered + return end; + } + } + return create_mapping(source_parent); +} + QModelIndex QSortFilterProxyModelPrivate::proxy_to_source(const QModelIndex &proxy_index) const { if (!proxy_index.isValid()) @@ -751,8 +776,10 @@ void QSortFilterProxyModelPrivate::remove_source_items( { Q_Q(QSortFilterProxyModel); QModelIndex proxy_parent = q->mapFromSource(source_parent); - if (!proxy_parent.isValid() && source_parent.isValid()) + if (!proxy_parent.isValid() && source_parent.isValid()) { + proxy_to_source.clear(); return; // nothing to do (already removed) + } const auto proxy_intervals = proxy_intervals_for_source_items( source_to_proxy, source_items); @@ -1404,11 +1431,20 @@ void QSortFilterProxyModelPrivate::_q_sourceDataChanged(const QModelIndex &sourc const QModelIndex &source_bottom_right = data_changed.bottomRight; const QModelIndex source_parent = source_top_left.parent(); + bool change_in_unmapped_parent = false; IndexMap::const_iterator it = source_index_mapping.constFind(source_parent); if (it == source_index_mapping.constEnd()) { - // Don't care, since we don't have mapping for this index - continue; + // We don't have mapping for this index, so we cannot know how things + // changed (in case the change affects filtering) in order to forward + // the change correctly. + // But we can at least forward the signal "as is", if the row isn't + // filtered out, this is better than nothing. + it = create_mapping_recursive(source_parent); + if (it == source_index_mapping.constEnd()) + continue; + change_in_unmapped_parent = true; } + Mapping *m = it.value(); // Figure out how the source changes affect us @@ -1418,7 +1454,7 @@ void QSortFilterProxyModelPrivate::_q_sourceDataChanged(const QModelIndex &sourc QVector<int> source_rows_resort; int end = qMin(source_bottom_right.row(), m->proxy_rows.count() - 1); for (int source_row = source_top_left.row(); source_row <= end; ++source_row) { - if (dynamic_sortfilter) { + if (dynamic_sortfilter && !change_in_unmapped_parent) { if (m->proxy_rows.at(source_row) != -1) { if (!filterAcceptsRowInternal(source_row, source_parent)) { // This source row no longer satisfies the filter, so it must be removed @@ -1489,15 +1525,19 @@ void QSortFilterProxyModelPrivate::_q_sourceDataChanged(const QModelIndex &sourc while (source_left_column < source_bottom_right.column() && m->proxy_columns.at(source_left_column) == -1) ++source_left_column; - const QModelIndex proxy_top_left = create_index( - proxy_start_row, m->proxy_columns.at(source_left_column), it); - int source_right_column = source_bottom_right.column(); - while (source_right_column > source_top_left.column() - && m->proxy_columns.at(source_right_column) == -1) - --source_right_column; - const QModelIndex proxy_bottom_right = create_index( - proxy_end_row, m->proxy_columns.at(source_right_column), it); - emit q->dataChanged(proxy_top_left, proxy_bottom_right, roles); + if (m->proxy_columns.at(source_left_column) != -1) { + const QModelIndex proxy_top_left = create_index( + proxy_start_row, m->proxy_columns.at(source_left_column), it); + int source_right_column = source_bottom_right.column(); + while (source_right_column > source_top_left.column() + && m->proxy_columns.at(source_right_column) == -1) + --source_right_column; + if (m->proxy_columns.at(source_right_column) != -1) { + const QModelIndex proxy_bottom_right = create_index( + proxy_end_row, m->proxy_columns.at(source_right_column), it); + emit q->dataChanged(proxy_top_left, proxy_bottom_right, roles); + } + } } } @@ -1629,8 +1669,8 @@ void QSortFilterProxyModelPrivate::_q_sourceRowsAboutToBeInserted( const bool toplevel = !source_parent.isValid(); const bool recursive_accepted = filter_recursive && !toplevel && filterAcceptsRowInternal(source_parent.row(), source_parent.parent()); - //Force the creation of a mapping now, even if its empty. - //We need it because the proxy can be acessed at the moment it emits rowsAboutToBeInserted in insert_source_items + //Force the creation of a mapping now, even if it's empty. + //We need it because the proxy can be accessed at the moment it emits rowsAboutToBeInserted in insert_source_items if (!filter_recursive || toplevel || recursive_accepted) { if (can_create_mapping(source_parent)) create_mapping(source_parent); @@ -1749,8 +1789,8 @@ void QSortFilterProxyModelPrivate::_q_sourceColumnsAboutToBeInserted( { Q_UNUSED(start); Q_UNUSED(end); - //Force the creation of a mapping now, even if its empty. - //We need it because the proxy can be acessed at the moment it emits columnsAboutToBeInserted in insert_source_items + //Force the creation of a mapping now, even if it's empty. + //We need it because the proxy can be accessed at the moment it emits columnsAboutToBeInserted in insert_source_items if (can_create_mapping(source_parent)) create_mapping(source_parent); } @@ -1797,7 +1837,10 @@ void QSortFilterProxyModelPrivate::_q_sourceColumnsRemoved( source_sort_column = -1; } - proxy_sort_column = q->mapFromSource(model->index(0,source_sort_column, source_parent)).column(); + if (source_sort_column >= 0) + proxy_sort_column = q->mapFromSource(model->index(0,source_sort_column, source_parent)).column(); + else + proxy_sort_column = -1; } void QSortFilterProxyModelPrivate::_q_sourceColumnsAboutToBeMoved( @@ -2558,9 +2601,12 @@ void QSortFilterProxyModel::sort(int column, Qt::SortOrder order) /*! \since 4.5 - \brief the column currently used for sorting + \return the column currently used for sorting + + This returns the most recently used sort column. The default value is -1, + which means that this proxy model does not sort. - This returns the most recently used sort column. + \sa sort() */ int QSortFilterProxyModel::sortColumn() const { @@ -2570,9 +2616,12 @@ int QSortFilterProxyModel::sortColumn() const /*! \since 4.5 - \brief the order currently used for sorting + \return the order currently used for sorting - This returns the most recently used sort order. + This returns the most recently used sort order. The default value is + Qt::AscendingOrder. + + \sa sort() */ Qt::SortOrder QSortFilterProxyModel::sortOrder() const { @@ -2847,6 +2896,8 @@ void QSortFilterProxyModel::setFilterFixedString(const QString &pattern) QComboBox. The default value is true. + + \sa sortColumn() */ bool QSortFilterProxyModel::dynamicSortFilter() const { |