diff options
Diffstat (limited to 'src/corelib/itemmodels')
-rw-r--r-- | src/corelib/itemmodels/qabstractitemmodel.cpp | 53 | ||||
-rw-r--r-- | src/corelib/itemmodels/qabstractitemmodel_p.h | 37 | ||||
-rw-r--r-- | src/corelib/itemmodels/qabstractproxymodel.cpp | 2 | ||||
-rw-r--r-- | src/corelib/itemmodels/qidentityproxymodel.cpp | 7 | ||||
-rw-r--r-- | src/corelib/itemmodels/qitemselectionmodel.cpp | 2 | ||||
-rw-r--r-- | src/corelib/itemmodels/qsortfilterproxymodel.cpp | 6 |
6 files changed, 60 insertions, 47 deletions
diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp index 90297b9115..0725d5e098 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.cpp +++ b/src/corelib/itemmodels/qabstractitemmodel.cpp @@ -480,6 +480,13 @@ public: Q_GLOBAL_STATIC(QEmptyItemModel, qEmptyModel) +QAbstractItemModelPrivate::QAbstractItemModelPrivate() + : QObjectPrivate(), + supportedDragActions(-1), + roleNames(defaultRoleNames()) +{ +} + QAbstractItemModelPrivate::~QAbstractItemModelPrivate() { } @@ -489,6 +496,30 @@ QAbstractItemModel *QAbstractItemModelPrivate::staticEmptyModel() return qEmptyModel(); } +void QAbstractItemModelPrivate::invalidatePersistentIndexes() +{ + for (QPersistentModelIndexData *data : qAsConst(persistent.indexes)) { + data->index = QModelIndex(); + data->model = 0; + } + persistent.indexes.clear(); +} + +/*! + \internal + Clean the QPersistentModelIndex relative to the index if there is one. + To be used before an index is invalided +*/ +void QAbstractItemModelPrivate::invalidatePersistentIndex(const QModelIndex &index) { + const auto it = persistent.indexes.constFind(index); + if (it != persistent.indexes.cend()) { + QPersistentModelIndexData *data = *it; + persistent.indexes.erase(it); + data->index = QModelIndex(); + data->model = 0; + } +} + namespace { struct DefaultRoleNames : public QHash<int, QByteArray> { @@ -607,7 +638,7 @@ void QAbstractItemModelPrivate::rowsInserted(const QModelIndex &parent, it != persistent_moved.constEnd(); ++it) { QPersistentModelIndexData *data = *it; QModelIndex old = data->index; - persistent.indexes.erase(persistent.indexes.find(old)); + persistent.indexes.erase(persistent.indexes.constFind(old)); data->index = q_func()->index(old.row() + count, old.column(), parent); if (data->index.isValid()) { persistent.insertMultiAtEnd(data->index, data); @@ -700,7 +731,7 @@ void QAbstractItemModelPrivate::movePersistentIndexes(const QVector<QPersistentM else column += change; - persistent.indexes.erase(persistent.indexes.find(data->index)); + persistent.indexes.erase(persistent.indexes.constFind(data->index)); data->index = q_func()->index(row, column, parent); if (data->index.isValid()) { persistent.insertMultiAtEnd(data->index, data); @@ -767,7 +798,7 @@ void QAbstractItemModelPrivate::rowsRemoved(const QModelIndex &parent, it != persistent_moved.constEnd(); ++it) { QPersistentModelIndexData *data = *it; QModelIndex old = data->index; - persistent.indexes.erase(persistent.indexes.find(old)); + persistent.indexes.erase(persistent.indexes.constFind(old)); data->index = q_func()->index(old.row() - count, old.column(), parent); if (data->index.isValid()) { persistent.insertMultiAtEnd(data->index, data); @@ -779,7 +810,7 @@ void QAbstractItemModelPrivate::rowsRemoved(const QModelIndex &parent, for (QVector<QPersistentModelIndexData *>::const_iterator it = persistent_invalidated.constBegin(); it != persistent_invalidated.constEnd(); ++it) { QPersistentModelIndexData *data = *it; - persistent.indexes.erase(persistent.indexes.find(data->index)); + persistent.indexes.erase(persistent.indexes.constFind(data->index)); data->index = QModelIndex(); data->model = 0; } @@ -812,7 +843,7 @@ void QAbstractItemModelPrivate::columnsInserted(const QModelIndex &parent, it != persistent_moved.constEnd(); ++it) { QPersistentModelIndexData *data = *it; QModelIndex old = data->index; - persistent.indexes.erase(persistent.indexes.find(old)); + persistent.indexes.erase(persistent.indexes.constFind(old)); data->index = q_func()->index(old.row(), old.column() + count, parent); if (data->index.isValid()) { persistent.insertMultiAtEnd(data->index, data); @@ -862,7 +893,7 @@ void QAbstractItemModelPrivate::columnsRemoved(const QModelIndex &parent, it != persistent_moved.constEnd(); ++it) { QPersistentModelIndexData *data = *it; QModelIndex old = data->index; - persistent.indexes.erase(persistent.indexes.find(old)); + persistent.indexes.erase(persistent.indexes.constFind(old)); data->index = q_func()->index(old.row(), old.column() - count, parent); if (data->index.isValid()) { persistent.insertMultiAtEnd(data->index, data); @@ -874,7 +905,7 @@ void QAbstractItemModelPrivate::columnsRemoved(const QModelIndex &parent, for (QVector<QPersistentModelIndexData *>::const_iterator it = persistent_invalidated.constBegin(); it != persistent_invalidated.constEnd(); ++it) { QPersistentModelIndexData *data = *it; - persistent.indexes.erase(persistent.indexes.find(data->index)); + persistent.indexes.erase(persistent.indexes.constFind(data->index)); data->index = QModelIndex(); data->model = 0; } @@ -3160,8 +3191,8 @@ void QAbstractItemModel::changePersistentIndex(const QModelIndex &from, const QM if (d->persistent.indexes.isEmpty()) return; // find the data and reinsert it sorted - const QHash<QModelIndex, QPersistentModelIndexData *>::iterator it = d->persistent.indexes.find(from); - if (it != d->persistent.indexes.end()) { + const auto it = d->persistent.indexes.constFind(from); + if (it != d->persistent.indexes.cend()) { QPersistentModelIndexData *data = *it; d->persistent.indexes.erase(it); data->index = to; @@ -3194,8 +3225,8 @@ void QAbstractItemModel::changePersistentIndexList(const QModelIndexList &from, for (int i = 0; i < from.count(); ++i) { if (from.at(i) == to.at(i)) continue; - const QHash<QModelIndex, QPersistentModelIndexData *>::iterator it = d->persistent.indexes.find(from.at(i)); - if (it != d->persistent.indexes.end()) { + const auto it = d->persistent.indexes.constFind(from.at(i)); + if (it != d->persistent.indexes.cend()) { QPersistentModelIndexData *data = *it; d->persistent.indexes.erase(it); data->index = to.at(i); diff --git a/src/corelib/itemmodels/qabstractitemmodel_p.h b/src/corelib/itemmodels/qabstractitemmodel_p.h index c2cbaf5298..19ee640f5c 100644 --- a/src/corelib/itemmodels/qabstractitemmodel_p.h +++ b/src/corelib/itemmodels/qabstractitemmodel_p.h @@ -46,7 +46,8 @@ // // -#include "private/qobject_p.h" +#include "QtCore/qabstractitemmodel.h" +#include "QtCore/private/qobject_p.h" #include "QtCore/qstack.h" #include "QtCore/qset.h" #include "QtCore/qhash.h" @@ -70,7 +71,7 @@ class Q_CORE_EXPORT QAbstractItemModelPrivate : public QObjectPrivate Q_DECLARE_PUBLIC(QAbstractItemModel) public: - QAbstractItemModelPrivate() : QObjectPrivate(), supportedDragActions(-1), roleNames(defaultRoleNames()) {} + QAbstractItemModelPrivate(); ~QAbstractItemModelPrivate(); void removePersistentIndexData(QPersistentModelIndexData *data); @@ -102,33 +103,13 @@ public: return (index.row() >= 0) && (index.column() >= 0) && (index.model() == q_func()); } - inline void invalidatePersistentIndexes() { - foreach (QPersistentModelIndexData *data, persistent.indexes) { - data->index = QModelIndex(); - data->model = 0; - } - persistent.indexes.clear(); - } - - /*! - \internal - clean the QPersistentModelIndex relative to the index if there is one. - To be used before an index is invalided - */ - inline void invalidatePersistentIndex(const QModelIndex &index) { - QHash<QModelIndex, QPersistentModelIndexData *>::iterator it = persistent.indexes.find(index); - if(it != persistent.indexes.end()) { - QPersistentModelIndexData *data = *it; - persistent.indexes.erase(it); - data->index = QModelIndex(); - data->model = 0; - } - } + void invalidatePersistentIndexes(); + void invalidatePersistentIndex(const QModelIndex &index); struct Change { - Change() : first(-1), last(-1) {} - Change(const Change &c) : parent(c.parent), first(c.first), last(c.last), needsAdjust(c.needsAdjust) {} - Change(const QModelIndex &p, int f, int l) : parent(p), first(f), last(l), needsAdjust(false) {} + Q_DECL_CONSTEXPR Change() : parent(), first(-1), last(-1), needsAdjust(false) {} + Q_DECL_CONSTEXPR Change(const QModelIndex &p, int f, int l) : parent(p), first(f), last(l), needsAdjust(false) {} + QModelIndex parent; int first, last; @@ -147,7 +128,7 @@ public: // rowsMoved signal. bool needsAdjust; - bool isValid() { return first >= 0 && last >= 0; } + Q_DECL_CONSTEXPR bool isValid() const { return first >= 0 && last >= 0; } }; QStack<Change> changes; diff --git a/src/corelib/itemmodels/qabstractproxymodel.cpp b/src/corelib/itemmodels/qabstractproxymodel.cpp index dbbbbb8ff4..1dd7ceba76 100644 --- a/src/corelib/itemmodels/qabstractproxymodel.cpp +++ b/src/corelib/itemmodels/qabstractproxymodel.cpp @@ -380,7 +380,7 @@ QMimeData* QAbstractProxyModel::mimeData(const QModelIndexList &indexes) const Q_D(const QAbstractProxyModel); QModelIndexList list; list.reserve(indexes.count()); - foreach(const QModelIndex &index, indexes) + for (const QModelIndex &index : indexes) list << mapToSource(index); return d->model->mimeData(list); } diff --git a/src/corelib/itemmodels/qidentityproxymodel.cpp b/src/corelib/itemmodels/qidentityproxymodel.cpp index f46fd135ca..88e1e3f905 100644 --- a/src/corelib/itemmodels/qidentityproxymodel.cpp +++ b/src/corelib/itemmodels/qidentityproxymodel.cpp @@ -490,7 +490,8 @@ void QIdentityProxyModelPrivate::_q_sourceLayoutAboutToBeChanged(const QList<QPe { Q_Q(QIdentityProxyModel); - foreach(const QPersistentModelIndex &proxyPersistentIndex, q->persistentIndexList()) { + const auto proxyPersistentIndexes = q->persistentIndexList(); + for (const QPersistentModelIndex &proxyPersistentIndex : proxyPersistentIndexes) { proxyIndexes << proxyPersistentIndex; Q_ASSERT(proxyPersistentIndex.isValid()); const QPersistentModelIndex srcPersistentIndex = q->mapToSource(proxyPersistentIndex); @@ -500,7 +501,7 @@ void QIdentityProxyModelPrivate::_q_sourceLayoutAboutToBeChanged(const QList<QPe QList<QPersistentModelIndex> parents; parents.reserve(sourceParents.size()); - foreach (const QPersistentModelIndex &parent, sourceParents) { + for (const QPersistentModelIndex &parent : sourceParents) { if (!parent.isValid()) { parents << QPersistentModelIndex(); continue; @@ -526,7 +527,7 @@ void QIdentityProxyModelPrivate::_q_sourceLayoutChanged(const QList<QPersistentM QList<QPersistentModelIndex> parents; parents.reserve(sourceParents.size()); - foreach (const QPersistentModelIndex &parent, sourceParents) { + for (const QPersistentModelIndex &parent : sourceParents) { if (!parent.isValid()) { parents << QPersistentModelIndex(); continue; diff --git a/src/corelib/itemmodels/qitemselectionmodel.cpp b/src/corelib/itemmodels/qitemselectionmodel.cpp index 51c670f79e..243558e6d9 100644 --- a/src/corelib/itemmodels/qitemselectionmodel.cpp +++ b/src/corelib/itemmodels/qitemselectionmodel.cpp @@ -482,7 +482,7 @@ static QVector<QPersistentModelIndex> qSelectionPersistentindexes(const QItemSel static QVector<QPair<QPersistentModelIndex, uint> > qSelectionPersistentRowLengths(const QItemSelection &sel) { QVector<QPair<QPersistentModelIndex, uint> > result; - Q_FOREACH (const QItemSelectionRange &range, sel) + for (const QItemSelectionRange &range : sel) rowLengthsFromRange(range, result); return result; } diff --git a/src/corelib/itemmodels/qsortfilterproxymodel.cpp b/src/corelib/itemmodels/qsortfilterproxymodel.cpp index 0771fd0e30..a3dad1ae07 100644 --- a/src/corelib/itemmodels/qsortfilterproxymodel.cpp +++ b/src/corelib/itemmodels/qsortfilterproxymodel.cpp @@ -1013,7 +1013,7 @@ QModelIndexPairList QSortFilterProxyModelPrivate::store_persistent_indexes() Q_Q(QSortFilterProxyModel); QModelIndexPairList source_indexes; source_indexes.reserve(persistent.indexes.count()); - foreach (QPersistentModelIndexData *data, persistent.indexes) { + for (QPersistentModelIndexData *data : qAsConst(persistent.indexes)) { QModelIndex proxy_index = data->index; QModelIndex source_index = q->mapToSource(proxy_index); source_indexes.append(qMakePair(proxy_index, QPersistentModelIndex(source_index))); @@ -1325,7 +1325,7 @@ void QSortFilterProxyModelPrivate::_q_sourceLayoutAboutToBeChanged(const QList<Q saved_persistent_indexes.clear(); QList<QPersistentModelIndex> parents; - foreach (const QPersistentModelIndex &parent, sourceParents) { + for (const QPersistentModelIndex &parent : sourceParents) { if (!parent.isValid()) { parents << QPersistentModelIndex(); continue; @@ -1366,7 +1366,7 @@ void QSortFilterProxyModelPrivate::_q_sourceLayoutChanged(const QList<QPersisten } QList<QPersistentModelIndex> parents; - foreach (const QPersistentModelIndex &parent, sourceParents) { + for (const QPersistentModelIndex &parent : sourceParents) { if (!parent.isValid()) { parents << QPersistentModelIndex(); continue; |